All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2] cmd/fdt: add possibilty to have 'extrasize' on fdt resize
@ 2016-09-20 16:10 Hannes Schmelzer
  2016-09-22 13:50 ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Hannes Schmelzer @ 2016-09-20 16:10 UTC (permalink / raw)
  To: u-boot

From: Hannes Schmelzer <hannes.schmelzer@br-automation.com>

Sometimes devicetree nodes and or properties are added out of the u-boot
console, maybe through some script or manual interaction.

The devicetree as loaded or embedded is quite small, so the devicetree
has to be resized to take up those new nodes/properties.

In original the devicetree was only extended by effective
4 * add_mem_rsv.

With this commit we can add an argument to the "fdt resize" command,
which takes the extrasize to be added.

Signed-off-by: Hannes Schmelzer <hannes.schmelzer@br-automation.com>

Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
---

Changes in v2:
- add function comment in fdt_support.h

 board/compulab/cm_fx6/cm_fx6.c |  2 +-
 cmd/fdt.c                      |  9 +++++++--
 common/fdt_support.c           |  3 ++-
 common/image-fdt.c             |  2 +-
 include/fdt_support.h          | 10 +++++++++-
 5 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/board/compulab/cm_fx6/cm_fx6.c b/board/compulab/cm_fx6/cm_fx6.c
index 28e9a8f..5b88bcc 100644
--- a/board/compulab/cm_fx6/cm_fx6.c
+++ b/board/compulab/cm_fx6/cm_fx6.c
@@ -602,7 +602,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 	char baseboard_name[16];
 	int err;
 
-	fdt_shrink_to_minimum(blob); /* Make room for new properties */
+	fdt_shrink_to_minimum(blob, 0); /* Make room for new properties */
 
 	/* MAC addr */
 	if (eth_getenv_enetaddr("ethaddr", enetaddr)) {
diff --git a/cmd/fdt.c b/cmd/fdt.c
index 58af772..b503357 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -662,7 +662,12 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #endif
 	/* resize the fdt */
 	else if (strncmp(argv[1], "re", 2) == 0) {
-		fdt_shrink_to_minimum(working_fdt);
+		uint extrasize;
+		if (argc > 2)
+			extrasize = simple_strtoul(argv[2], NULL, 16);
+		else
+			extrasize = 0;
+		fdt_shrink_to_minimum(working_fdt, extrasize);
 	}
 	else {
 		/* Unrecognized command */
@@ -1056,7 +1061,7 @@ static char fdt_help_text[] =
 	"fdt systemsetup                     - Do system-specific set up\n"
 #endif
 	"fdt move   <fdt> <newaddr> <length> - Copy the fdt to <addr> and make it active\n"
-	"fdt resize                          - Resize fdt to size + padding to 4k addr\n"
+	"fdt resize [<extrasize>]            - Resize fdt to size + padding to 4k addr + some optional <extrasize> if needed\n"
 	"fdt print  <path> [<prop>]          - Recursive print starting at <path>\n"
 	"fdt list   <path> [<prop>]          - Print one level starting at <path>\n"
 	"fdt get value <var> <path> <prop>   - Get <property> and store in <var>\n"
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 2020586..0609470 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -523,7 +523,7 @@ void fdt_fixup_ethernet(void *fdt)
 }
 
 /* Resize the fdt to its actual size + a bit of padding */
-int fdt_shrink_to_minimum(void *blob)
+int fdt_shrink_to_minimum(void *blob, uint extrasize)
 {
 	int i;
 	uint64_t addr, size;
@@ -551,6 +551,7 @@ int fdt_shrink_to_minimum(void *blob)
 	actualsize = fdt_off_dt_strings(blob) +
 		fdt_size_dt_strings(blob) + 5 * sizeof(struct fdt_reserve_entry);
 
+	actualsize += extrasize;
 	/* Make it so the fdt ends on a page boundary */
 	actualsize = ALIGN(actualsize + ((uintptr_t)blob & 0xfff), 0x1000);
 	actualsize = actualsize - ((uintptr_t)blob & 0xfff);
diff --git a/common/image-fdt.c b/common/image-fdt.c
index d6ee225..2ef1253 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -503,7 +503,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
 		lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
 			 (phys_size_t)fdt_totalsize(blob));
 
-	ret = fdt_shrink_to_minimum(blob);
+	ret = fdt_shrink_to_minimum(blob, 0);
 	if (ret < 0)
 		goto err;
 	of_size = ret;
diff --git a/include/fdt_support.h b/include/fdt_support.h
index e9f3497..adc7454 100644
--- a/include/fdt_support.h
+++ b/include/fdt_support.h
@@ -167,7 +167,15 @@ void ft_pci_setup(void *blob, bd_t *bd);
 int ft_system_setup(void *blob, bd_t *bd);
 
 void set_working_fdt_addr(ulong addr);
-int fdt_shrink_to_minimum(void *blob);
+
+/**
+ * shrink down the given blob to minimum size + some extrasize if required
+ *
+ * @param blob		FDT blob to update
+ * @param extrasize	additional bytes needed
+ * @return 0 if ok, or -FDT_ERR_... on error
+ */
+int fdt_shrink_to_minimum(void *blob, uint extrasize);
 int fdt_increase_size(void *fdt, int add_len);
 
 int fdt_fixup_nor_flash_size(void *blob);
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2] cmd/fdt: add possibilty to have 'extrasize' on fdt resize
  2016-09-20 16:10 [U-Boot] [PATCH v2] cmd/fdt: add possibilty to have 'extrasize' on fdt resize Hannes Schmelzer
@ 2016-09-22 13:50 ` Simon Glass
  2016-10-02 21:31   ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2016-09-22 13:50 UTC (permalink / raw)
  To: u-boot

On 20 September 2016 at 10:10, Hannes Schmelzer <oe5hpm@oevsv.at> wrote:
>
> From: Hannes Schmelzer <hannes.schmelzer@br-automation.com>
>
> Sometimes devicetree nodes and or properties are added out of the u-boot
> console, maybe through some script or manual interaction.
>
> The devicetree as loaded or embedded is quite small, so the devicetree
> has to be resized to take up those new nodes/properties.
>
> In original the devicetree was only extended by effective
> 4 * add_mem_rsv.
>
> With this commit we can add an argument to the "fdt resize" command,
> which takes the extrasize to be added.
>
> Signed-off-by: Hannes Schmelzer <hannes.schmelzer@br-automation.com>
>
> Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
> ---
>
> Changes in v2:
> - add function comment in fdt_support.h
>
>  board/compulab/cm_fx6/cm_fx6.c |  2 +-
>  cmd/fdt.c                      |  9 +++++++--
>  common/fdt_support.c           |  3 ++-
>  common/image-fdt.c             |  2 +-
>  include/fdt_support.h          | 10 +++++++++-
>  5 files changed, 20 insertions(+), 6 deletions(-)

Acked-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH v2] cmd/fdt: add possibilty to have 'extrasize' on fdt resize
  2016-09-22 13:50 ` Simon Glass
@ 2016-10-02 21:31   ` Simon Glass
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Glass @ 2016-10-02 21:31 UTC (permalink / raw)
  To: u-boot

On 22 September 2016 at 07:50, Simon Glass <sjg@chromium.org> wrote:
> On 20 September 2016 at 10:10, Hannes Schmelzer <oe5hpm@oevsv.at> wrote:
>>
>> From: Hannes Schmelzer <hannes.schmelzer@br-automation.com>
>>
>> Sometimes devicetree nodes and or properties are added out of the u-boot
>> console, maybe through some script or manual interaction.
>>
>> The devicetree as loaded or embedded is quite small, so the devicetree
>> has to be resized to take up those new nodes/properties.
>>
>> In original the devicetree was only extended by effective
>> 4 * add_mem_rsv.
>>
>> With this commit we can add an argument to the "fdt resize" command,
>> which takes the extrasize to be added.
>>
>> Signed-off-by: Hannes Schmelzer <hannes.schmelzer@br-automation.com>
>>
>> Signed-off-by: Hannes Schmelzer <oe5hpm@oevsv.at>
>> ---
>>
>> Changes in v2:
>> - add function comment in fdt_support.h
>>
>>  board/compulab/cm_fx6/cm_fx6.c |  2 +-
>>  cmd/fdt.c                      |  9 +++++++--
>>  common/fdt_support.c           |  3 ++-
>>  common/image-fdt.c             |  2 +-
>>  include/fdt_support.h          | 10 +++++++++-
>>  5 files changed, 20 insertions(+), 6 deletions(-)
>
> Acked-by: Simon Glass <sjg@chromium.org>

Applied to u-boot-fdt, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-02 21:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-20 16:10 [U-Boot] [PATCH v2] cmd/fdt: add possibilty to have 'extrasize' on fdt resize Hannes Schmelzer
2016-09-22 13:50 ` Simon Glass
2016-10-02 21:31   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.