Skip to contentSkip to conversation

board_f: Copy GD to new GD even if relocation disabled

PATCH In review Marek Vasut 4 participants 4 messages Oct 10, 2021 – Oct 15, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board_f: Copy GD to new GD even if relocation disabled

Even if U-Boot has relocation disabled via GD_FLG_SKIP_RELOC , the relocated stage of U-Boot still picks GD from new_gd location. The U-Boot itself is not relocated, but GD might be, so copy the GD to new GD location even if relocation is disabled.

---
 common/board_f.c | 1 +
 1 file changed, 1 insertion(+)
common/board_f.c +1 -0
index 3dc0eaa59c..2161a7411d 100644
@@ -674,6 +674,7 @@ static int reloc_bloblist(void)
 static int setup_reloc(void)
 {
 	if (gd->flags & GD_FLG_SKIP_RELOC) {
+		memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
 		debug("Skipping relocation due to flag\n");
 		return 0;
 	}
Signature · 1 line
2.33.0
#1 lore raw
Quoted 18 lines · Marek Vasut

Even if U-Boot has relocation disabled via GD_FLG_SKIP_RELOC , the relocated stage of U-Boot still picks GD from new_gd location. The U-Boot itself is not relocated, but GD might be, so copy the GD to new GD location even if relocation is disabled.

---
  common/board_f.c | 1 +
  1 file changed, 1 insertion(+)
common/board_f.c +0 -0
index 3dc0eaa59c..2161a7411d 100644

common/board_f.c static int reloc_bloblist(void) · line 680

Quoted 7 lines
common/board_f.c +1 -0
@@ -674,6 +674,7 @@ static int reloc_bloblist(void)
  static int setup_reloc(void)
  {
  	if (gd->flags & GD_FLG_SKIP_RELOC) {
+		memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
  		debug("Skipping relocation due to flag\n");
  		return 0;
  	}

I still think my patch is better :)
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

But anyway if you prefer, you could have a v2 to include dtb relocation.

Regards,
Peng.

#2 lore raw

Hi,

Quoted 16 lines · Peng Fan (OSS)
Quoted 12 lines · Marek Vasut

Even if U-Boot has relocation disabled via GD_FLG_SKIP_RELOC , the relocated stage of U-Boot still picks GD from new_gd location. The U-Boot itself is not relocated, but GD might be, so copy the GD to new GD location even if relocation is disabled.

---
  common/board_f.c | 1 +
  1 file changed, 1 insertion(+)
Quoted 16 lines

common/board_f.c static int reloc_bloblist(void) · line 680

Quoted 13 lines
common/board_f.c +1 -0
index 3dc0eaa59c..2161a7411d 100644
@@ -674,6 +674,7 @@ static int reloc_bloblist(void)
  static int setup_reloc(void)
  {
      if (gd->flags & GD_FLG_SKIP_RELOC) {
+             memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
              debug("Skipping relocation due to flag\n");
              return 0;
      }

I still think my patch is better :)
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, better to avoid duplicating the memcpy() as you have done Peng.

Quoted 2 lines

But anyway if you prefer, you could have a v2 to include dtb relocation.

Regards,
Simon

#3 lore raw
In reply to Peng Fan (OSS)

On 10/14/21 3:52 AM, Peng Fan (OSS) wrote:
[...]

Quoted 18 lines

common/board_f.c static int reloc_bloblist(void) · line 680

Quoted 13 lines
common/board_f.c +1 -0
index 3dc0eaa59c..2161a7411d 100644
@@ -674,6 +674,7 @@ static int reloc_bloblist(void)
   static int setup_reloc(void)
   {
       if (gd->flags & GD_FLG_SKIP_RELOC) {
+        memcpy(gd->new_gd, (char *)gd, sizeof(gd_t));
           debug("Skipping relocation due to flag\n");
           return 0;
       }

I still think my patch is better :)
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Quoted 1 line

But anyway if you prefer, you could have a v2 to include dtb relocation.

Your patch does not reflect the gd->reloc_off update in new_gd in case GD_SKIP_RELOC_FLAG is NOT set, that's a bug. This patch does not have that problem. I thought about expanding the if above to deduplicate the memcpy, but that looked rather ugly, but we can try that instead.