CHROMIUM: Assign the frame buffer address as FDT one instead of u-boot one.

The framebuffer address should be specified in the device tree and not u-boot
assigned. This FDT value should be the same as the one defined in Linux kernel;
otherwise, it causes screen flicker. The FDT value overrides the framebuffer
allocated at the top of memory by board_init_f().

If the framebuffer address is not defined in the FDT, falls back to use the
address allocated by board_init_f().

BUG=chrome-os-partner:5338
TEST=build without error and boot Chrome OS on Aebl, see the screen not
corrupted and splash screen showed.

Change-Id: Ia6a996d127d74d6084900814d2c934fb95518e23
diff --git a/common/cmd_vboot_twostop.c b/common/cmd_vboot_twostop.c
index 55b5a9d..3941f34 100644
--- a/common/cmd_vboot_twostop.c
+++ b/common/cmd_vboot_twostop.c
@@ -160,6 +160,7 @@
 wipe_unused_memory(crossystem_data_t *cdata, VbCommonParams *cparams)
 {
 #ifdef CONFIG_OF_CONTROL
+	int fb_size, lcd_line_length;
 	memory_wipe_t wipe;
 	struct fdt_memory config;
 
@@ -182,6 +183,12 @@
 			    (uintptr_t)TEGRA_LP0_ADDR,
 			    (uintptr_t)(TEGRA_LP0_ADDR + TEGRA_LP0_SIZE));
 
+	/* Excludes the frame buffer. */
+	fb_size = lcd_get_size(&lcd_line_length);
+	memory_wipe_exclude(&wipe,
+			    (uintptr_t)gd->fb_base,
+			    (uintptr_t)gd->fb_base + fb_size);
+
 	memory_wipe_execute(&wipe);
 #else
 	printf("wipe_unused_memory depends on fdt_decode_memory which"
diff --git a/drivers/video/tegra2.c b/drivers/video/tegra2.c
index 2600d8d..a8d83d3 100644
--- a/drivers/video/tegra2.c
+++ b/drivers/video/tegra2.c
@@ -233,12 +233,21 @@
 	}
 
 	/*
-	 * The device tree allows for the frame buffer to be specified if
-	 * needed, but for now, U-Boot will set this. This may change if
-	 * we find that Linux is unable to use the address that U-Boot picks,
-	 * and this causes screen flicker.
+	 * The framebuffer address should be specified in the device tree.
+	 * This FDT value should be the same as the one defined in Linux kernel;
+	 * otherwise, it causes screen flicker. The FDT value overrides the
+	 * framebuffer allocated at the top of memory by board_init_f().
+	 *
+	 * If the framebuffer address is not defined in the FDT, falls back to
+	 * use the address allocated by board_init_f().
 	 */
-	config.frame_buffer = (u32)lcd_base;
+	if (config.frame_buffer != ADDR_T_NONE) {
+		gd->fb_base = config.frame_buffer;
+		lcd_base = (void *)(gd->fb_base);
+	} else {
+		config.frame_buffer = (u32)lcd_base;
+	}
+
 	update_panel_size(&config);
 	size = lcd_get_size(&line_length),