app: aboot: Allow dynamic detection of device tree header size.
Change-Id: Ib585a7da2612af95583b130fa9d6f3e0fb8889ea
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 2f8aff1..0322505 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -600,6 +600,7 @@
struct dt_entry dt_entry;
unsigned dt_table_offset;
uint32_t dt_actual;
+ uint32_t dt_hdr_size;
#endif
if (!boot_into_recovery) {
memset(ffbm_mode_string, '\0', sizeof(ffbm_mode_string));
@@ -749,15 +750,14 @@
#if DEVICE_TREE
if(hdr->dt_size) {
- table = (struct dt_table*) dt_buf;
dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual);
+ table = (struct dt_table*) dt_table_offset;
- memmove((void *) dt_buf, (char *)dt_table_offset, page_size);
-
- if (dev_tree_validate(table, hdr->page_size) != 0) {
+ if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) {
dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
return -1;
}
+
/* Find index of device tree within device tree table */
if(dev_tree_get_entry_info(table, &dt_entry) != 0){
dprintf(CRITICAL, "ERROR: Device Tree Blob cannot be found\n");
@@ -828,18 +828,28 @@
#if DEVICE_TREE
if(hdr->dt_size != 0) {
- /* Read the device tree table into buffer */
+ /* Read the first page of device tree table into buffer */
if(mmc_read(ptn + offset,(unsigned int *) dt_buf, page_size)) {
dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n");
return -1;
}
table = (struct dt_table*) dt_buf;
- if (dev_tree_validate(table, hdr->page_size) != 0) {
+ if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) {
dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
return -1;
}
+ table = (struct dt_table*) memalign(CACHE_LINE, dt_hdr_size);
+ if (!table)
+ return -1;
+
+ /* Read the entire device tree table into buffer */
+ if(mmc_read(ptn + offset,(unsigned int *) table, dt_hdr_size)) {
+ dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n");
+ return -1;
+ }
+
/* Find index of device tree within device tree table */
if(dev_tree_get_entry_info(table, &dt_entry) != 0){
dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
@@ -911,6 +921,7 @@
struct dt_table *table;
struct dt_entry dt_entry;
uint32_t dt_actual;
+ uint32_t dt_hdr_size;
#endif
if (target_is_emmc_boot()) {
@@ -1102,11 +1113,22 @@
table = (struct dt_table*) dt_buf;
- if (dev_tree_validate(table, hdr->page_size) != 0) {
+ if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) {
dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
return -1;
}
+ table = (struct dt_table*) memalign(CACHE_LINE, dt_hdr_size);
+ if (!table)
+ return -1;
+
+ /* Read the entire device tree table into buffer */
+ if(flash_read(ptn, offset, (void *)table, dt_hdr_size)) {
+ dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n");
+ return -1;
+ }
+
+
/* Find index of device tree within device tree table */
if(dev_tree_get_entry_info(table, &dt_entry) != 0){
dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
@@ -1311,6 +1333,7 @@
uint32_t n;
struct dt_table *table;
struct dt_entry dt_entry;
+ uint32_t dt_hdr_size;
struct boot_img_hdr *hdr = (struct boot_img_hdr *) (boot_image_start);
@@ -1334,7 +1357,7 @@
/* offset now point to start of dt.img */
table = (struct dt_table*)(boot_image_start + dt_image_offset);
- if (dev_tree_validate(table, hdr->page_size) != 0) {
+ if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) {
dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
return -1;
}