Skip to contentSkip to conversation

board_f: Do not mark pre-relocated fdt space as reserved

PATCH New Lokesh Vutla 3 participants 7 messages Apr 16, 2019 – May 3, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 board_f: Do not mark pre-relocated fdt space as reserved

SPL while copying u-boot and dtb it does the following:
- Copy u-boot
- Copy right dtb.
- mark dtb location as reserved in dtb.

U-Boot when copying images at U-Boot prompt, is not able to copy to the above dtb location as it sees the region as reserved. But at this stage dtb is re located to end of DDR. And the above dtb region is not reserved anymore. So delete this reserved region when re locating dtb.

---
 common/board_f.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
common/board_f.c +13 -0
index 149a7229e8..e4383ae3fa 100644
@@ -651,10 +651,23 @@ static int init_post(void)
 static int reloc_fdt(void)
 {
 #ifndef CONFIG_OF_EMBED
+	uint64_t addr, size;
+	int i, cnt, err;
+
 	if (gd->flags & GD_FLG_SKIP_RELOC)
 		return 0;
 	if (gd->new_fdt) {
 		memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);
+
+		/* Deleting the previously marked FDT reserved region */
+		cnt = fdt_num_mem_rsv(gd->new_fdt);
+		for (i = 0; i < cnt ; i++) {
+			err = fdt_get_mem_rsv(gd->new_fdt, i, &addr, &size);
+			if (!err && addr == (uintptr_t)gd->fdt_blob) {
+				fdt_del_mem_rsv(gd->new_fdt, i);
+				break;
+			}
+		}
 		gd->fdt_blob = gd->new_fdt;
 	}
 #endif
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 board_f: Do not mark pre-relocated fdt space as reserved

[This is a follow-up to https://patchwork.ozlabs.org/patch/1033584/ right?]

Am 16.04.2019 um 10:43 schrieb Lokesh Vutla:

Quoted 4 lines

SPL while copying u-boot and dtb it does the following:
- Copy u-boot
- Copy right dtb.
- mark dtb location as reserved in dtb.

Hmm, why does it do that? Reserving space when U-Boot starts Linux *might* make sense, but why should SPL add this reservation when starting U-Boot? These steps are for U-Boot in a fit-image, right? Because I can't see this for U-Boot as uImage.

Am I correct that 'fdt_shrink_to_minimum()' adds this reservation? The name of that function doesn't suggest that to me. Would it make more sense to let this funtion only *change* the reservation, i.e. only add it if it is removed at the beginning of said function? Would that fix your issue?

Something like this:

common/fdt_support.c +5 -4
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
         uint64_t addr, size;
         int total, ret;
         uint actualsize;
+       int fdt_memrsv = 0;
 
         if (!blob)
                 return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
                 fdt_get_mem_rsv(blob, i, &addr, &size);
                 if (addr == (uintptr_t)blob) {
                         fdt_del_mem_rsv(blob, i);
+                       fdt_memrsv = 1;
                         break;
                 }
         }
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
         /* Change the fdt header to reflect the correct size */
         fdt_set_totalsize(blob, actualsize);
 
-       /* Add the new reservation */
-       ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-       if (ret < 0)
-               return ret;
+       if (fdt_memrsv) {
+               /* Add the new reservation */
+               ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), 

actualsize);
+ if (ret < 0)
+ return ret;
+ }

         return actualsize;

}

Quoted 27 lines

U-Boot when copying images at U-Boot prompt, is not able to copy to the above dtb location as it sees the region as reserved. But at this stage dtb is re located to end of DDR. And the above dtb region is not reserved anymore. So delete this reserved region when re locating dtb.

---
  common/board_f.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
common/board_f.c +3 -0
index 149a7229e8..e4383ae3fa 100644
@@ -651,10 +651,23 @@ static int init_post(void)
  static int reloc_fdt(void)
  {
  #ifndef CONFIG_OF_EMBED
+	uint64_t addr, size;
+	int i, cnt, err;
+
  	if (gd->flags & GD_FLG_SKIP_RELOC)
  		return 0;
  	if (gd->new_fdt) {
  		memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);

common/board_f.c static int init_post(void) · line 670

Quoted 10 lines
common/board_f.c +10 -0
+
+		/* Deleting the previously marked FDT reserved region */
+		cnt = fdt_num_mem_rsv(gd->new_fdt);
+		for (i = 0; i < cnt ; i++) {
+			err = fdt_get_mem_rsv(gd->new_fdt, i, &addr, &size);
+			if (!err && addr == (uintptr_t)gd->fdt_blob) {
+				fdt_del_mem_rsv(gd->new_fdt, i);
+				break;
+			}
+		}

That code should work, but it's a bit unexpected in this location

Quoted 4 lines
common/board_f.c +0 -0
  		gd->fdt_blob = gd->new_fdt;
  	}
  #endif
#2 lore raw

PATCH 1/1 board_f: Do not mark pre-relocated fdt space as reserved

Quoted 1 line · Simon Goldschmidt

[This is a follow-up to https://patchwork.ozlabs.org/patch/1033584/ right?]

Right.

Quoted 43 lines

Am 16.04.2019 um 10:43 schrieb Lokesh Vutla:

Quoted 4 lines

SPL while copying u-boot and dtb it does the following:
- Copy u-boot
- Copy right dtb.
- mark dtb location as reserved in dtb.

Hmm, why does it do that? Reserving space when U-Boot starts Linux *might* make sense, but why should SPL add this reservation when starting U-Boot? These steps are for U-Boot in a fit-image, right? Because I can't see this for U-Boot as uImage.

Am I correct that 'fdt_shrink_to_minimum()' adds this reservation? The name of that function doesn't suggest that to me. Would it make more sense to let this funtion only *change* the reservation, i.e. only add it if it is removed at the beginning of said function? Would that fix your issue?

Something like this:

common/fdt_support.c +2 -0
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
         uint64_t addr, size;
         int total, ret;
         uint actualsize;
+       int fdt_memrsv = 0;
 
         if (!blob)
                 return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
                 fdt_get_mem_rsv(blob, i, &addr, &size);
                 if (addr == (uintptr_t)blob) {
                         fdt_del_mem_rsv(blob, i);
+                       fdt_memrsv = 1;
                         break;
                 }
         }
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
         /* Change the fdt header to reflect the correct size */
         fdt_set_totalsize(blob, actualsize);
 

common/fdt_support.c int fdt_shrink_to_minimum(void *blob, uint extrasize) · line 637

Quoted 10 lines
common/fdt_support.c +6 -4
-       /* Add the new reservation */
-       ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-       if (ret < 0)
-               return ret;
+       if (fdt_memrsv) {
+               /* Add the new reservation */
+               ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
+               if (ret < 0)
+                       return ret;
+       }

Agreed. This works and more appropriate place to fix it. Will you post a separate patch or do you want me to post it on your behalf?

Thanks and regards,
Lokesh

Quoted 50 lines
common/fdt_support.c +0 -0
         return actualsize;
  }
 
Quoted 28 lines

U-Boot when copying images at U-Boot prompt, is not able to copy to the above dtb location as it sees the region as reserved. But at this stage dtb is re located to end of DDR. And the above dtb region is not reserved anymore. So delete this reserved region when re locating dtb.

---
  common/board_f.c | 13 +++++++++++++

  1 file changed, 13 insertions(+)
common/board_f.c +3 -0
index 149a7229e8..e4383ae3fa 100644
@@ -651,10 +651,23 @@ static int init_post(void)
   static int reloc_fdt(void)
   {
   #ifndef CONFIG_OF_EMBED
+    uint64_t addr, size;
+    int i, cnt, err;
+
       if (gd->flags & GD_FLG_SKIP_RELOC)
           return 0;
       if (gd->new_fdt) {
           memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);

common/board_f.c static int init_post(void) · line 670

Quoted 10 lines
common/board_f.c +10 -0
+
+        /* Deleting the previously marked FDT reserved region */
+        cnt = fdt_num_mem_rsv(gd->new_fdt);
+        for (i = 0; i < cnt ; i++) {
+            err = fdt_get_mem_rsv(gd->new_fdt, i, &addr, &size);
+            if (!err && addr == (uintptr_t)gd->fdt_blob) {
+                fdt_del_mem_rsv(gd->new_fdt, i);
+                break;
+            }
+        }

That code should work, but it's a bit unexpected in this location

Quoted 4 lines
common/board_f.c +0 -0
           gd->fdt_blob = gd->new_fdt;
       }
   #endif
#3 lore raw

PATCH 1/1 board_f: Do not mark pre-relocated fdt space as reserved

Quoted 51 lines · Lokesh Vutla
Quoted 1 line · Simon Goldschmidt

[This is a follow-up to https://patchwork.ozlabs.org/patch/1033584/ right?]

Right.

Quoted 43 lines

Am 16.04.2019 um 10:43 schrieb Lokesh Vutla:

Quoted 4 lines

SPL while copying u-boot and dtb it does the following:
- Copy u-boot
- Copy right dtb.
- mark dtb location as reserved in dtb.

Hmm, why does it do that? Reserving space when U-Boot starts Linux *might* make sense, but why should SPL add this reservation when starting U-Boot? These steps are for U-Boot in a fit-image, right? Because I can't see this for U-Boot as uImage.

Am I correct that 'fdt_shrink_to_minimum()' adds this reservation? The name of that function doesn't suggest that to me. Would it make more sense to let this funtion only *change* the reservation, i.e. only add it if it is removed at the beginning of said function? Would that fix your issue?

Something like this:

common/fdt_support.c +2 -0
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
        uint64_t addr, size;
        int total, ret;
        uint actualsize;
+       int fdt_memrsv = 0;
 
        if (!blob)
                return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
                fdt_get_mem_rsv(blob, i, &addr, &size);
                if (addr == (uintptr_t)blob) {
                        fdt_del_mem_rsv(blob, i);
+                       fdt_memrsv = 1;
                        break;
                }
        }
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
        /* Change the fdt header to reflect the correct size */
        fdt_set_totalsize(blob, actualsize);
 
Quoted 13 lines

common/fdt_support.c int fdt_shrink_to_minimum(void *blob, uint extrasize)

Quoted 10 lines
common/fdt_support.c +6 -4
-       /* Add the new reservation */
-       ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-       if (ret < 0)
-               return ret;
+       if (fdt_memrsv) {
+               /* Add the new reservation */
+               ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
+               if (ret < 0)
+                       return ret;
+       }

Agreed. This works and more appropriate place to fix it. Will you post a separate patch or do you want me to post it on your behalf?

While it's good to know this fixes your issue, I'm not sure this doesn't break anything else.

Tom, Simon, can you add anything here? Why is the dtb memory added as reserved to itself? It seems to me this is redundant, as the code using the dtb should well know the pointer to it...

Lokesh, I can send a patch once this is discussed.

Regards,
Simon

Quoted 54 lines

Thanks and regards,
Lokesh

Quoted 50 lines
common/fdt_support.c +0 -0
        return actualsize;
 }
 
Quoted 28 lines

U-Boot when copying images at U-Boot prompt, is not able to copy to the above dtb location as it sees the region as reserved. But at this stage dtb is re located to end of DDR. And the above dtb region is not reserved anymore. So delete this reserved region when re locating dtb.

---
  common/board_f.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
common/board_f.c +3 -0
index 149a7229e8..e4383ae3fa 100644
@@ -651,10 +651,23 @@ static int init_post(void)
  static int reloc_fdt(void)
  {
  #ifndef CONFIG_OF_EMBED
+    uint64_t addr, size;
+    int i, cnt, err;
+
      if (gd->flags & GD_FLG_SKIP_RELOC)
          return 0;
      if (gd->new_fdt) {
          memcpy(gd->new_fdt, gd->fdt_blob, gd->fdt_size);

common/board_f.c static int init_post(void) · line 670

Quoted 10 lines
common/board_f.c +10 -0
+
+        /* Deleting the previously marked FDT reserved region */
+        cnt = fdt_num_mem_rsv(gd->new_fdt);
+        for (i = 0; i < cnt ; i++) {
+            err = fdt_get_mem_rsv(gd->new_fdt, i, &addr, &size);
+            if (!err && addr == (uintptr_t)gd->fdt_blob) {
+                fdt_del_mem_rsv(gd->new_fdt, i);
+                break;
+            }
+        }

That code should work, but it's a bit unexpected in this location

Quoted 4 lines
common/board_f.c +0 -0
          gd->fdt_blob = gd->new_fdt;
      }
  #endif
#4 lore raw

PATCH 1/1 board_f: Do not mark pre-relocated fdt space as reserved

Quoted 66 lines · Simon Goldschmidt
Quoted 51 lines · Lokesh Vutla
Quoted 1 line · Simon Goldschmidt

[This is a follow-up to https://patchwork.ozlabs.org/patch/1033584/ right?]

Right.

Quoted 43 lines

Am 16.04.2019 um 10:43 schrieb Lokesh Vutla:

Quoted 4 lines

SPL while copying u-boot and dtb it does the following:
- Copy u-boot
- Copy right dtb.
- mark dtb location as reserved in dtb.

Hmm, why does it do that? Reserving space when U-Boot starts Linux *might* make sense, but why should SPL add this reservation when starting U-Boot? These steps are for U-Boot in a fit-image, right? Because I can't see this for U-Boot as uImage.

Am I correct that 'fdt_shrink_to_minimum()' adds this reservation? The name of that function doesn't suggest that to me. Would it make more sense to let this funtion only *change* the reservation, i.e. only add it if it is removed at the beginning of said function? Would that fix your issue?

Something like this:

common/fdt_support.c +2 -0
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
        uint64_t addr, size;
        int total, ret;
        uint actualsize;
+       int fdt_memrsv = 0;
 
        if (!blob)
                return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
                fdt_get_mem_rsv(blob, i, &addr, &size);
                if (addr == (uintptr_t)blob) {
                        fdt_del_mem_rsv(blob, i);
+                       fdt_memrsv = 1;
                        break;
                }
        }
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
        /* Change the fdt header to reflect the correct size */
        fdt_set_totalsize(blob, actualsize);
 
Quoted 13 lines

common/fdt_support.c int fdt_shrink_to_minimum(void *blob, uint extrasize)

Quoted 10 lines
common/fdt_support.c +6 -4
-       /* Add the new reservation */
-       ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-       if (ret < 0)
-               return ret;
+       if (fdt_memrsv) {
+               /* Add the new reservation */
+               ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
+               if (ret < 0)
+                       return ret;
+       }

Agreed. This works and more appropriate place to fix it. Will you post a separate patch or do you want me to post it on your behalf?

Quoted 8 lines

While it's good to know this fixes your issue, I'm not sure this doesn't break anything else.

Tom, Simon, can you add anything here? Why is the dtb memory added as reserved to itself? It seems to me this is redundant, as the code using the dtb should well know the pointer to it...

Lokesh, I can send a patch once this is discussed.

OK, so the history of that call is really what's seen in:
commit 41c5eaa7253ed82bbae1eda5667755872c615164

Author: Andy Fleming <[email protected]>
Date:   Mon Jun 16 13:58:56 2008 -0500

Resize device tree to allow space for board changes and the chosen node

Current code requires that a compiled device tree have space added to the end to leave room for extra nodes added by board code (and the chosen node). This requires that device tree creators anticipate how much space U-Boot will add to the tree, which is absurd. Ideally, the code would resize and/or relocate the tree when it needed more space, but this would require a systemic change to the fdt code, which is non-trivial. Instead, we resize the tree inside boot_relocate_fdt, reserving either the remainder of the bootmap (in the case where the fdt is inside the bootmap), or adding CFG_FDT_PAD bytes to the size.

Which is all about preparing things for passing the device tree we loaded specifically for Linux. In:
commit 3082d2348c8e13342f5fdd10e9b3f7408062dbf9

Author: Kumar Gala <[email protected]>
Date:   Fri Aug 15 08:24:42 2008 -0500

fdt: refactor fdt resize code

Move the fdt resizing code out of ppc specific boot code and into common fdt support code.

The code was moved to a more common area. So the intent on "reserve" was to make sure that we had enough space set aside for the dtb to be able to be updated at runtime, by U-Boot, for various needs and that we wouldn't give that memory away to something else / allow it to be clobbered.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190422/670deeaa/attachment.sig>
#5 lore raw

PATCH 1/1 board_f: Do not mark pre-relocated fdt space as reserved

Simon,

Quoted 105 lines · Tom Rini
Quoted 66 lines · Simon Goldschmidt
Quoted 51 lines · Lokesh Vutla
Quoted 1 line · Simon Goldschmidt

[This is a follow-up to https://patchwork.ozlabs.org/patch/1033584/ right?]

Right.

Quoted 43 lines

Am 16.04.2019 um 10:43 schrieb Lokesh Vutla:

Quoted 4 lines

SPL while copying u-boot and dtb it does the following:
- Copy u-boot
- Copy right dtb.
- mark dtb location as reserved in dtb.

Hmm, why does it do that? Reserving space when U-Boot starts Linux *might* make sense, but why should SPL add this reservation when starting U-Boot? These steps are for U-Boot in a fit-image, right? Because I can't see this for U-Boot as uImage.

Am I correct that 'fdt_shrink_to_minimum()' adds this reservation? The name of that function doesn't suggest that to me. Would it make more sense to let this funtion only *change* the reservation, i.e. only add it if it is removed at the beginning of said function? Would that fix your issue?

Something like this:

common/fdt_support.c +2 -0
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
        uint64_t addr, size;
        int total, ret;
        uint actualsize;
+       int fdt_memrsv = 0;
 
        if (!blob)
                return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
                fdt_get_mem_rsv(blob, i, &addr, &size);
                if (addr == (uintptr_t)blob) {
                        fdt_del_mem_rsv(blob, i);
+                       fdt_memrsv = 1;
                        break;
                }
        }
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
        /* Change the fdt header to reflect the correct size */
        fdt_set_totalsize(blob, actualsize);
 
Quoted 13 lines

common/fdt_support.c int fdt_shrink_to_minimum(void *blob, uint extrasize)

Quoted 10 lines
common/fdt_support.c +6 -4
-       /* Add the new reservation */
-       ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-       if (ret < 0)
-               return ret;
+       if (fdt_memrsv) {
+               /* Add the new reservation */
+               ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
+               if (ret < 0)
+                       return ret;
+       }

Agreed. This works and more appropriate place to fix it. Will you post a separate patch or do you want me to post it on your behalf?

Quoted 8 lines

While it's good to know this fixes your issue, I'm not sure this doesn't break anything else.

Tom, Simon, can you add anything here? Why is the dtb memory added as reserved to itself? It seems to me this is redundant, as the code using the dtb should well know the pointer to it...

Lokesh, I can send a patch once this is discussed.

OK, so the history of that call is really what's seen in:
commit 41c5eaa7253ed82bbae1eda5667755872c615164

Author: Andy Fleming <[email protected]>
Date:   Mon Jun 16 13:58:56 2008 -0500

Resize device tree to allow space for board changes and the chosen node

Current code requires that a compiled device tree have space added to the end to leave room for extra nodes added by board code (and the chosen node). This requires that device tree creators anticipate how much space U-Boot will add to the tree, which is absurd. Ideally, the code would resize and/or relocate the tree when it needed more space, but this would require a systemic change to the fdt code, which is non-trivial. Instead, we resize the tree inside boot_relocate_fdt, reserving either the remainder of the bootmap (in the case where the fdt is inside the bootmap), or adding CFG_FDT_PAD bytes to the size.

Which is all about preparing things for passing the device tree we loaded specifically for Linux. In:
commit 3082d2348c8e13342f5fdd10e9b3f7408062dbf9

Author: Kumar Gala <[email protected]>
Date:   Fri Aug 15 08:24:42 2008 -0500

fdt: refactor fdt resize code

Move the fdt resizing code out of ppc specific boot code and into common fdt support code.

Quoted 8 lines

The code was moved to a more common area. So the intent on "reserve" was to make sure that we had enough space set aside for the dtb to be able to be updated at runtime, by U-Boot, for various needs and that we wouldn't give that memory away to something else / allow it to be clobbered.

Any update on this? Any chance you will be posting your changes?

Thanks and regards,
Lokesh

#6 lore raw

PATCH 1/1 board_f: Do not mark pre-relocated fdt space as reserved

Hi Lokesh,

Quoted 110 lines · Lokesh Vutla

Simon,

Quoted 107 lines · Tom Rini
Quoted 66 lines · Simon Goldschmidt
Quoted 51 lines · Lokesh Vutla
Quoted 1 line · Simon Goldschmidt

[This is a follow-up to https://patchwork.ozlabs.org/patch/1033584/ right?]

Right.

Quoted 43 lines

Am 16.04.2019 um 10:43 schrieb Lokesh Vutla:

Quoted 4 lines

SPL while copying u-boot and dtb it does the following:
- Copy u-boot
- Copy right dtb.
- mark dtb location as reserved in dtb.

Hmm, why does it do that? Reserving space when U-Boot starts Linux *might* make sense, but why should SPL add this reservation when starting U-Boot? These steps are for U-Boot in a fit-image, right? Because I can't see this for U-Boot as uImage.

Am I correct that 'fdt_shrink_to_minimum()' adds this reservation? The name of that function doesn't suggest that to me. Would it make more sense to let this funtion only *change* the reservation, i.e. only add it if it is removed at the beginning of said function? Would that fix your issue?

Something like this:

common/fdt_support.c +2 -0
index ab08a0114f..4e7cf6ebe9 100644
@@ -597,6 +597,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
         uint64_t addr, size;
         int total, ret;
         uint actualsize;
+       int fdt_memrsv = 0;
 
         if (!blob)
                 return 0;
@@ -606,6 +607,7 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
                 fdt_get_mem_rsv(blob, i, &addr, &size);
                 if (addr == (uintptr_t)blob) {
                         fdt_del_mem_rsv(blob, i);
+                       fdt_memrsv = 1;
                         break;
                 }
         }
@@ -627,10 +629,12 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize)
         /* Change the fdt header to reflect the correct size */
         fdt_set_totalsize(blob, actualsize);
 
Quoted 13 lines

common/fdt_support.c int fdt_shrink_to_minimum(void *blob, uint extrasize)

Quoted 10 lines
common/fdt_support.c +6 -4
-       /* Add the new reservation */
-       ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
-       if (ret < 0)
-               return ret;
+       if (fdt_memrsv) {
+               /* Add the new reservation */
+               ret = fdt_add_mem_rsv(blob, map_to_sysmem(blob), actualsize);
+               if (ret < 0)
+                       return ret;
+       }

Agreed. This works and more appropriate place to fix it. Will you post a separate patch or do you want me to post it on your behalf?

Quoted 8 lines

While it's good to know this fixes your issue, I'm not sure this doesn't break anything else.

Tom, Simon, can you add anything here? Why is the dtb memory added as reserved to itself? It seems to me this is redundant, as the code using the dtb should well know the pointer to it...

Lokesh, I can send a patch once this is discussed.

OK, so the history of that call is really what's seen in:
commit 41c5eaa7253ed82bbae1eda5667755872c615164

Author: Andy Fleming <[email protected]>
Date:   Mon Jun 16 13:58:56 2008 -0500

Resize device tree to allow space for board changes and the chosen node

Current code requires that a compiled device tree have space added to the end to leave room for extra nodes added by board code (and the chosen node). This requires that device tree creators anticipate how much space U-Boot will add to the tree, which is absurd. Ideally, the code would resize and/or relocate the tree when it needed more space, but this would require a systemic change to the fdt code, which is non-trivial. Instead, we resize the tree inside boot_relocate_fdt, reserving either the remainder of the bootmap (in the case where the fdt is inside the bootmap), or adding CFG_FDT_PAD bytes to the size.

Which is all about preparing things for passing the device tree we loaded specifically for Linux. In:
commit 3082d2348c8e13342f5fdd10e9b3f7408062dbf9

Author: Kumar Gala <[email protected]>
Date:   Fri Aug 15 08:24:42 2008 -0500

fdt: refactor fdt resize code

Move the fdt resizing code out of ppc specific boot code and into common fdt support code.

Quoted 8 lines
Quoted 6 lines

The code was moved to a more common area. So the intent on "reserve" was to make sure that we had enough space set aside for the dtb to be able to be updated at runtime, by U-Boot, for various needs and that we wouldn't give that memory away to something else / allow it to be clobbered.

Any update on this? Any chance you will be posting your changes?

No, sorry, not update. I'll send the patch I suggested above and we'll see how the discussion continues.

Regards,
Simon