bootstage: Correct relocation algorithm
authorSimon Glass <sjg@chromium.org>
Mon, 21 Oct 2019 23:26:50 +0000 (17:26 -0600)
committerSimon Glass <sjg@chromium.org>
Sun, 27 Oct 2019 16:56:51 +0000 (10:56 -0600)
At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>
common/board_f.c
common/board_r.c
common/bootstage.c

index 4852a3b0d8475618e29fda14ace78a6fac34f45e..e3591cbaebdbf48aa9fd65ddafdd26c1a167b530 100644 (file)
@@ -696,6 +696,7 @@ static int reloc_bootstage(void)
                      gd->bootstage, gd->new_bootstage, size);
                memcpy(gd->new_bootstage, gd->bootstage, size);
                gd->bootstage = gd->new_bootstage;
                      gd->bootstage, gd->new_bootstage, size);
                memcpy(gd->new_bootstage, gd->bootstage, size);
                gd->bootstage = gd->new_bootstage;
+               bootstage_relocate();
        }
 #endif
 
        }
 #endif
 
index d6fb5047a26511cc0cf997664e9f9a387dee1ee3..c1ecb06b743d26403a02923f70431133839dac95 100644 (file)
@@ -670,7 +670,6 @@ static init_fnc_t init_sequence_r[] = {
 #ifdef CONFIG_SYS_NONCACHED_MEMORY
        initr_noncached,
 #endif
 #ifdef CONFIG_SYS_NONCACHED_MEMORY
        initr_noncached,
 #endif
-       bootstage_relocate,
 #ifdef CONFIG_OF_LIVE
        initr_of_live,
 #endif
 #ifdef CONFIG_OF_LIVE
        initr_of_live,
 #endif
index 4557ed4508c59323a1818e1f67572ed4d7f8e0b5..e8b7bbf81a6d1b30feaf6d7986f9603f82932671 100644 (file)
@@ -53,14 +53,23 @@ int bootstage_relocate(void)
 {
        struct bootstage_data *data = gd->bootstage;
        int i;
 {
        struct bootstage_data *data = gd->bootstage;
        int i;
+       char *ptr;
+
+       /* Figure out where to relocate the strings to */
+       ptr = (char *)(data + 1);
 
        /*
         * Duplicate all strings.  They may point to an old location in the
         * program .text section that can eventually get trashed.
         */
        debug("Relocating %d records\n", data->rec_count);
 
        /*
         * Duplicate all strings.  They may point to an old location in the
         * program .text section that can eventually get trashed.
         */
        debug("Relocating %d records\n", data->rec_count);
-       for (i = 0; i < data->rec_count; i++)
-               data->record[i].name = strdup(data->record[i].name);
+       for (i = 0; i < data->rec_count; i++) {
+               const char *from = data->record[i].name;
+
+               strcpy(ptr, from);
+               data->record[i].name = ptr;
+               ptr += strlen(ptr) + 1;
+       }
 
        return 0;
 }
 
        return 0;
 }
@@ -490,7 +499,17 @@ int bootstage_unstash(const void *base, int size)
 
 int bootstage_get_size(void)
 {
 
 int bootstage_get_size(void)
 {
-       return sizeof(struct bootstage_data);
+       struct bootstage_data *data = gd->bootstage;
+       struct bootstage_record *rec;
+       int size;
+       int i;
+
+       size = sizeof(struct bootstage_data);
+       for (rec = data->record, i = 0; i < data->rec_count;
+            i++, rec++)
+               size += strlen(rec->name) + 1;
+
+       return size;
 }
 
 int bootstage_init(bool first)
 }
 
 int bootstage_init(bool first)