Skip to contentSkip to conversation

Add sub-commands to fdt

PATCH New Kumar Gala 3 participants 8 messages Feb 15, 2008 – Feb 16, 2008

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH 1/1 Add sub-commands to fdt

fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt memrsv print                    - Show current mem reserves
fdt memrsv add    <addr> <size>     - Add a mem reserve
fdt memrsv delete <index>           - Delete a mem reserves
---
 common/cmd_fdt.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)
common/cmd_fdt.c +111 -0
index 9cd22ee..d0f8c27 100644
@@ -296,6 +296,111 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 				return err;
 			}
 		}
+
+	/********************************************************************
+	 * Display header info
+	 ********************************************************************/
+	} else if (argv[1][0] == 'h') {
+		u32 version = fdt_version(fdt);
+		printf("magic:\t\t\t0x%x\n", fdt_magic(fdt));
+		printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(fdt), fdt_totalsize(fdt));
+		printf("off_dt_struct:\t\t0x%x\n", fdt_off_dt_struct(fdt));
+		printf("off_dt_strings:\t\t0x%x\n", fdt_off_dt_strings(fdt));
+		printf("off_mem_rsvmap:\t\t0x%x\n", fdt_off_mem_rsvmap(fdt));
+		printf("version:\t\t%d\n", version);
+		printf("last_comp_version:\t%d\n", fdt_last_comp_version(fdt));
+		if (version >= 2)
+			printf("boot_cpuid_phys:\t0x%x\n",
+				fdt_boot_cpuid_phys(fdt));
+		if (version >= 3)
+			printf("size_dt_strings:\t0x%x\n",
+				fdt_size_dt_strings(fdt));
+		if (version >= 17)
+			printf("size_dt_struct:\t\t0x%x\n",
+				fdt_size_dt_struct(fdt));
+		printf("\n");
+
+	/********************************************************************
+	 * Set boot cpu id
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'b') && (argv[1][1] == 'o')) {
+		unsigned long tmp = simple_strtoul(argv[2], NULL, 16);
+		fdt_set_boot_cpuid_phys(fdt, tmp);
+
+	/********************************************************************
+	 * memory command
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][3] == 'o')) {
+		uint64_t addr, size;
+		int err;
+#ifdef CFG_64BIT_STRTOUL
+			addr = simple_strtoull(argv[2], NULL, 16);
+			size = simple_strtoull(argv[3], NULL, 16);
+#else
+			addr = simple_strtoul(argv[2], NULL, 16);
+			size = simple_strtoul(argv[3], NULL, 16);
+#endif
+		err = fdt_fixup_memory(fdt, addr, size);
+		if (err < 0)
+			return err;
+
+	/********************************************************************
+	 * mem reserve commands
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][3] == 'r')) {
+		if (argv[2][0] == 'p') {
+			uint64_t addr, size;
+			int total = fdt_num_mem_rsv(fdt);
+			int j, err;
+			printf("index\t\t   start\t\t    size\n");
+			printf("-------------------------------"
+				"-----------------\n");
+			for (j = 0; j < total; j++) {
+				err = fdt_get_mem_rsv(fdt, j, &addr, &size);
+				if (err < 0) {
+					printf("libfdt fdt_get_mem_rsv():  %s\n",
+							fdt_strerror(err));
+					return err;
+				}
+				printf("    %x\t%08x%08x\t%08x%08x\n", j,
+					(u32)(addr >> 32),
+					(u32)(addr & 0xffffffff),
+					(u32)(size >> 32),
+					(u32)(size & 0xffffffff));
+			}
+		} else if (argv[2][0] == 'a') {
+			uint64_t addr, size;
+			int err;
+#ifdef CFG_64BIT_STRTOUL
+			addr = simple_strtoull(argv[3], NULL, 16);
+			size = simple_strtoull(argv[4], NULL, 16);
+#else
+			addr = simple_strtoul(argv[3], NULL, 16);
+			size = simple_strtoul(argv[4], NULL, 16);
+#endif
+			err = fdt_add_mem_rsv(fdt, addr, size);
+
+			if (err < 0) {
+				printf("libfdt fdt_add_mem_rsv():  %s\n",
+					fdt_strerror(err));
+				return err;
+			}
+		} else if (argv[2][0] == 'd') {
+			unsigned long idx = simple_strtoul(argv[3], NULL, 16);
+			int err = fdt_del_mem_rsv(fdt, idx);
+
+			if (err < 0) {
+				printf("libfdt fdt_del_mem_rsv():  %s\n",
+					fdt_strerror(err));
+				return err;
+			}
+		} else {
+			/* Unrecognized command */
+			printf ("Usage:\n%s\n", cmdtp->usage);
+			return 1;
+		}
 	}
 #ifdef CONFIG_OF_BOARD_SETUP
 	/* Call the board-specific fixup routine */
@@ -689,6 +794,12 @@ U_BOOT_CMD(
 	"fdt set    <path> <prop> [<val>]    - Set <property> [to <val>]\n"
 	"fdt mknode <path> <node>            - Create a new node after <path>\n"
 	"fdt rm     <path> [<prop>]          - Delete the node or <property>\n"
+	"fdt header                          - Display header info\n"
+	"fdt bootcpu <id>                    - Set boot cpuid\n"
+	"fdt memory <addr> <size>            - Add/Update memory node\n"
+	"fdt memrsv print                    - Show current mem reserves\n"
+	"fdt memrsv add    <addr> <size>     - Add a mem reserve\n"
+	"fdt memrsv delete <index>           - Delete a mem reserves\n"
 	"fdt chosen - Add/update the /chosen branch in the tree\n"
 #ifdef CONFIG_OF_HAS_UBOOT_ENV
 	"fdt env    - Add/replace the /u-boot-env branch in the tree\n"
Signature · 1 line
1.5.3.8
#1 lore raw

PATCH 1/1 Add sub-commands to fdt

Quoted 8 lines · Kumar Gala
fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt memrsv print                    - Show current mem reserves
fdt memrsv add    <addr> <size>     - Add a mem reserve
fdt memrsv delete <index>           - Delete a mem reserves

Cool, procrastination pays off again! :-)

Quoted 25 lines
---
 common/cmd_fdt.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 111 insertions(+), 0 deletions(-)
common/cmd_fdt.c +13 -0
index 9cd22ee..d0f8c27 100644
@@ -296,6 +296,111 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 				return err;
 			}
 		}
+
+	/********************************************************************
+	 * Display header info
+	 ********************************************************************/
+	} else if (argv[1][0] == 'h') {
+		u32 version = fdt_version(fdt);
+		printf("magic:\t\t\t0x%x\n", fdt_magic(fdt));
+		printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(fdt), fdt_totalsize(fdt));
+		printf("off_dt_struct:\t\t0x%x\n", fdt_off_dt_struct(fdt));
+		printf("off_dt_strings:\t\t0x%x\n", fdt_off_dt_strings(fdt));
+		printf("off_mem_rsvmap:\t\t0x%x\n", fdt_off_mem_rsvmap(fdt));
+		printf("version:\t\t%d\n", version);
+		printf("last_comp_version:\t%d\n", fdt_last_comp_version(fdt));

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 321

Quoted 10 lines
common/cmd_fdt.c +10 -0
+		if (version >= 2)
+			printf("boot_cpuid_phys:\t0x%x\n",
+				fdt_boot_cpuid_phys(fdt));
+		if (version >= 3)
+			printf("size_dt_strings:\t0x%x\n",
+				fdt_size_dt_strings(fdt));
+		if (version >= 17)
+			printf("size_dt_struct:\t\t0x%x\n",
+				fdt_size_dt_struct(fdt));
+		printf("\n");

Very nice.
* I think we should add the size of the reserved map.
* It would be very useful to know how much space is available in the reserved map
* It would be very useful to know how much space is available in the dt_struct and dt_space space (I believe the "spare" in the blob can be used for both the dt_struct and the dt_strings, but I'm not sure, don't have time to look it up right now).

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 334

Quoted 12 lines
common/cmd_fdt.c +12 -0
+	/********************************************************************
+	 * Set boot cpu id
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'b') && (argv[1][1] == 'o')) {
+		unsigned long tmp = simple_strtoul(argv[2], NULL, 16);
+		fdt_set_boot_cpuid_phys(fdt, tmp);
+
+	/********************************************************************
+	 * memory command
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][3] == 'o')) {

Did we miss (argv[1][2] == 'm'), is the term checking (argv[1][3] == 'o') wrong, or are we trying to accommodate dyslecix people? I can picture our fearless leader typing "fdt meromy", assuming he types that many characters. :-D

Quoted 8 lines
common/cmd_fdt.c +8 -0
+		uint64_t addr, size;
+		int err;
+#ifdef CFG_64BIT_STRTOUL
+			addr = simple_strtoull(argv[2], NULL, 16);
+			size = simple_strtoull(argv[3], NULL, 16);
+#else
+			addr = simple_strtoul(argv[2], NULL, 16);
+			size = simple_strtoul(argv[3], NULL, 16);

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 352

Quoted 10 lines
common/cmd_fdt.c +10 -0
+#endif
+		err = fdt_fixup_memory(fdt, addr, size);
+		if (err < 0)
+			return err;
+
+	/********************************************************************
+	 * mem reserve commands
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][3] == 'r')) {

Hmm, missing (argv[1][2] == 'm') again. Once is an accident, twice is by design. I take it you are skipping the argv[1][2] check since it isn't a significant character - code savings. I can accept that, although it really hurts my humor to have a logical explanation (pun intended ;-).

Quoted 9 lines
common/cmd_fdt.c +9 -0
+		if (argv[2][0] == 'p') {
+			uint64_t addr, size;
+			int total = fdt_num_mem_rsv(fdt);
+			int j, err;
+			printf("index\t\t   start\t\t    size\n");
+			printf("-------------------------------"
+				"-----------------\n");
+			for (j = 0; j < total; j++) {
+				err = fdt_get_mem_rsv(fdt, j, &addr, &size);

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 371

Quoted 10 lines
common/cmd_fdt.c +10 -0
+				if (err < 0) {
+					printf("libfdt fdt_get_mem_rsv():  %s\n",
+							fdt_strerror(err));
+					return err;
+				}
+				printf("    %x\t%08x%08x\t%08x%08x\n", j,
+					(u32)(addr >> 32),
+					(u32)(addr & 0xffffffff),
+					(u32)(size >> 32),
+					(u32)(size & 0xffffffff));

Trivia: If the compiler supports CFG_64BIT_STRTOUL, it /probably/ supports the "%llx" format. I ran into trouble with this originally (the compiler for my mpc8360 had problems passing a 64 bit varargs arg, IIRC). The above works in both 32bit and 64bit support cases and I personally prefer the above slightly extra work rather than Yet Another #ifdef (YA#).

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 376

Quoted 5 lines
common/cmd_fdt.c +5 -0
+			}
+		} else if (argv[2][0] == 'a') {
+			uint64_t addr, size;
+			int err;
+#ifdef CFG_64BIT_STRTOUL

...but some are unavoidable.

Quoted 6 lines
common/cmd_fdt.c +6 -0
+			addr = simple_strtoull(argv[3], NULL, 16);
+			size = simple_strtoull(argv[4], NULL, 16);
+#else
+			addr = simple_strtoul(argv[3], NULL, 16);
+			size = simple_strtoul(argv[4], NULL, 16);
+#endif

[snip]

common/cmd_fdt.c U_BOOT_CMD( · line 801

Quoted 11 lines

#ifdef CONFIG_OF_BOARD_SETUP

common/cmd_fdt.c +5 -0
 	/* Call the board-specific fixup routine */
@@ -689,6 +794,12 @@ U_BOOT_CMD(
 	"fdt set    <path> <prop> [<val>]    - Set <property> [to <val>]\n"
 	"fdt mknode <path> <node>            - Create a new node after <path>\n"
 	"fdt rm     <path> [<prop>]          - Delete the node or <property>\n"
+	"fdt header                          - Display header info\n"
+	"fdt bootcpu <id>                    - Set boot cpuid\n"
+	"fdt memory <addr> <size>            - Add/Update memory node\n"
+	"fdt memrsv print                    - Show current mem reserves\n"
+	"fdt memrsv add    <addr> <size>     - Add a mem reserve\n"
                         ^^^

common/cmd_fdt.c U_BOOT_CMD( · line 801

Quoted 1 line
common/cmd_fdt.c +1 -0
+	"fdt memrsv add <addr> <size>        - Add a mem reserve\n"

It is a weakly held personal preference, but I would kill the extra spaces between add and <addr>, I don't see that it helps readability.

common/cmd_fdt.c U_BOOT_CMD( · line 805

Quoted 4 lines
common/cmd_fdt.c +1 -0
+	"fdt memrsv delete <index>           - Delete a mem reserves\n"
 	"fdt chosen - Add/update the /chosen branch in the tree\n"
 #ifdef CONFIG_OF_HAS_UBOOT_ENV
 	"fdt env    - Add/replace the /u-boot-env branch in the tree\n"

THANKS!
gvb

author
#2 lore raw

PATCH 1/1 Add sub-commands to fdt

Quoted 45 lines · Jerry Van Baren
Quoted 7 lines · Kumar Gala
fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt memrsv print                    - Show current mem reserves
fdt memrsv add    <addr> <size>     - Add a mem reserve
fdt memrsv delete <index>           - Delete a mem reserves

Cool, procrastination pays off again! :-)

Quoted 34 lines

---
common/cmd_fdt.c | 111 ++++++++++++++++++++++++++++++++++++++++++++
++++++++++

1 files changed, 111 insertions(+), 0 deletions(-)
common/cmd_fdt.c +8 -0
index 9cd22ee..d0f8c27 100644
@@ -296,6 +296,111 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int  
 argc, char *argv[])
 				return err;
 			}
 		}
+
+	/ 
 ********************************************************************
+	 * Display header info
+	  
 ********************************************************************/
+	} else if (argv[1][0] == 'h') {
+		u32 version = fdt_version(fdt);
+		printf("magic:\t\t\t0x%x\n", fdt_magic(fdt));
+		printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(fdt),  

fdt_totalsize(fdt));

common/cmd_fdt.c +10 -0
+		printf("off_dt_struct:\t\t0x%x\n", fdt_off_dt_struct(fdt));
+		printf("off_dt_strings:\t\t0x%x\n", fdt_off_dt_strings(fdt));
+		printf("off_mem_rsvmap:\t\t0x%x\n", fdt_off_mem_rsvmap(fdt));
+		printf("version:\t\t%d\n", version);
+		printf("last_comp_version:\t%d\n", fdt_last_comp_version(fdt));
+		if (version >= 2)
+			printf("boot_cpuid_phys:\t0x%x\n",
+				fdt_boot_cpuid_phys(fdt));
+		if (version >= 3)
+			printf("size_dt_strings:\t0x%x\n",
Quoted 8 lines

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 321

Quoted 5 lines
common/cmd_fdt.c +5 -0
+				fdt_size_dt_strings(fdt));
+		if (version >= 17)
+			printf("size_dt_struct:\t\t0x%x\n",
+				fdt_size_dt_struct(fdt));
+		printf("\n");

Very nice.
* I think we should add the size of the reserved map.

done

Quoted 2 lines

* It would be very useful to know how much space is available in the reserved map

not sure how we do this.

Quoted 4 lines

* It would be very useful to know how much space is available in the dt_struct and dt_space space (I believe the "spare" in the blob can be used for both the dt_struct and the dt_strings, but I'm not sure, don't have time to look it up right now).

How about I leave that as an exercise for the reader :)

Quoted 13 lines
Quoted 13 lines
common/cmd_fdt.c +1 -0
+	/ 

********************************************************************

common/cmd_fdt.c +2 -0
+	 * Set boot cpu id
+	  

********************************************************************/

common/cmd_fdt.c +5 -0
+	} else if ((argv[1][0] == 'b') && (argv[1][1] == 'o')) {
+		unsigned long tmp = simple_strtoul(argv[2], NULL, 16);
+		fdt_set_boot_cpuid_phys(fdt, tmp);
+
+	/ 

********************************************************************

common/cmd_fdt.c +2 -0
+	 * memory command
+	  
Quoted 8 lines

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 334

Quoted 3 lines

********************************************************************/

common/cmd_fdt.c +2 -0
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][3] == 'o')) {

Did we miss (argv[1][2] == 'm'), is the term checking (argv[1][3] == 'o') wrong, or are we trying to accommodate dyslecix people? I can picture our fearless leader typing "fdt meromy", assuming he types that many characters. :-D

I was trying to be slightly smart, I can add the check for argv[1][2] == 'm'

Quoted 20 lines
Quoted 20 lines
common/cmd_fdt.c +14 -0
+		uint64_t addr, size;
+		int err;
+#ifdef CFG_64BIT_STRTOUL
+			addr = simple_strtoull(argv[2], NULL, 16);
+			size = simple_strtoull(argv[3], NULL, 16);
+#else
+			addr = simple_strtoul(argv[2], NULL, 16);
+			size = simple_strtoul(argv[3], NULL, 16);
+#endif
+		err = fdt_fixup_memory(fdt, addr, size);
+		if (err < 0)
+			return err;
+
+	/ 

********************************************************************

common/cmd_fdt.c +2 -0
+	 * mem reserve commands
+	  

********************************************************************/

Quoted 8 lines

common/cmd_fdt.c

Quoted 2 lines
common/cmd_fdt.c +2 -0
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][3] == 'r')) {

Hmm, missing (argv[1][2] == 'm') again. Once is an accident, twice is by design. I take it you are skipping the argv[1][2] check since it isn't a significant character - code savings. I can accept that, although it really hurts my humor to have a logical explanation (pun intended ;-).

ditto.

Quoted 20 lines
Quoted 20 lines
common/cmd_fdt.c +18 -0
+		if (argv[2][0] == 'p') {
+			uint64_t addr, size;
+			int total = fdt_num_mem_rsv(fdt);
+			int j, err;
+			printf("index\t\t   start\t\t    size\n");
+			printf("-------------------------------"
+				"-----------------\n");
+			for (j = 0; j < total; j++) {
+				err = fdt_get_mem_rsv(fdt, j, &addr, &size);
+				if (err < 0) {
+					printf("libfdt fdt_get_mem_rsv():  %s\n",
+							fdt_strerror(err));
+					return err;
+				}
+				printf("    %x\t%08x%08x\t%08x%08x\n", j,
+					(u32)(addr >> 32),
+					(u32)(addr & 0xffffffff),
+					(u32)(size >> 32),
Quoted 8 lines

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 371

Quoted 1 line
common/cmd_fdt.c +1 -0
+					(u32)(size & 0xffffffff));

Trivia: If the compiler supports CFG_64BIT_STRTOUL, it /probably/ supports the "%llx" format. I ran into trouble with this originally (the compiler for my mpc8360 had problems passing a 64 bit varargs arg, IIRC). The above works in both 32bit and 64bit support cases and I personally prefer the above slightly extra work rather than Yet Another #ifdef (YA#).

yeah, wanted less #ifdef's.

Quoted 33 lines

common/cmd_fdt.c int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) · line 376

Quoted 7 lines
common/cmd_fdt.c +5 -0
+			}
+		} else if (argv[2][0] == 'a') {
+			uint64_t addr, size;
+			int err;
+#ifdef CFG_64BIT_STRTOUL

...but some are unavoidable.

Quoted 6 lines
common/cmd_fdt.c +6 -0
+			addr = simple_strtoull(argv[3], NULL, 16);
+			size = simple_strtoull(argv[4], NULL, 16);
+#else
+			addr = simple_strtoul(argv[3], NULL, 16);
+			size = simple_strtoul(argv[4], NULL, 16);
+#endif

[snip]

common/cmd_fdt.c U_BOOT_CMD( · line 801

Quoted 13 lines
#ifdef CONFIG_OF_BOARD_SETUP
	/* Call the board-specific fixup routine */
common/cmd_fdt.c +0 -0
@@ -689,6 +794,12 @@ U_BOOT_CMD(
 	"fdt set    <path> <prop> [<val>]    - Set <property> [to <val>]\n"
 	"fdt mknode <path> <node>            - Create a new node after  

<path>\n"
"fdt rm <path> [<prop>] - Delete the node or
<property>\n"

common/cmd_fdt.c +5 -0
+	"fdt header                          - Display header info\n"
+	"fdt bootcpu <id>                    - Set boot cpuid\n"
+	"fdt memory <addr> <size>            - Add/Update memory node\n"
+	"fdt memrsv print                    - Show current mem reserves\n"
+	"fdt memrsv add    <addr> <size>     - Add a mem reserve\n"
                       ^^^
Quoted 3 lines

common/cmd_fdt.c U_BOOT_CMD( · line 801

Quoted 1 line
common/cmd_fdt.c +1 -0
+	"fdt memrsv add <addr> <size>        - Add a mem reserve\n"

It is a weakly held personal preference, but I would kill the extra spaces between add and <addr>, I don't see that it helps readability.

will fix.

Quoted 7 lines
Quoted 4 lines
common/cmd_fdt.c +1 -0
+	"fdt memrsv delete <index>           - Delete a mem reserves\n"

"fdt chosen - Add/update the /chosen branch in the tree\n"
#ifdef CONFIG_OF_HAS_UBOOT_ENV
"fdt env - Add/replace the /u-boot-env branch in the tree\n"

THANKS!
gvb

author
#3 lore raw

PATCH v2 1/1 Add sub-commands to fdt

In reply to Jerry Van Baren
fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt memrsv print                    - Show current mem reserves
fdt memrsv add <addr> <size>        - Add a mem reserve
fdt memrsv delete <index>           - Delete a mem reserves

---

fix help white space
be more explicit in arg checking for "memory" vs "memrsv"

 common/cmd_fdt.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 112 insertions(+), 0 deletions(-)
common/cmd_fdt.c +112 -0
index 9cd22ee..fb5d663 100644
@@ -296,6 +296,112 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 				return err;
 			}
 		}
+
+	/********************************************************************
+	 * Display header info
+	 ********************************************************************/
+	} else if (argv[1][0] == 'h') {
+		u32 version = fdt_version(fdt);
+		printf("magic:\t\t\t0x%x\n", fdt_magic(fdt));
+		printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(fdt), fdt_totalsize(fdt));
+		printf("off_dt_struct:\t\t0x%x\n", fdt_off_dt_struct(fdt));
+		printf("off_dt_strings:\t\t0x%x\n", fdt_off_dt_strings(fdt));
+		printf("off_mem_rsvmap:\t\t0x%x\n", fdt_off_mem_rsvmap(fdt));
+		printf("version:\t\t%d\n", version);
+		printf("last_comp_version:\t%d\n", fdt_last_comp_version(fdt));
+		if (version >= 2)
+			printf("boot_cpuid_phys:\t0x%x\n",
+				fdt_boot_cpuid_phys(fdt));
+		if (version >= 3)
+			printf("size_dt_strings:\t0x%x\n",
+				fdt_size_dt_strings(fdt));
+		if (version >= 17)
+			printf("size_dt_struct:\t\t0x%x\n",
+				fdt_size_dt_struct(fdt));
+		printf("number mem_rsv:\t\t0x%x\n", fdt_num_mem_rsv(fdt));
+		printf("\n");
+
+	/********************************************************************
+	 * Set boot cpu id
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'b') && (argv[1][1] == 'o')) {
+		unsigned long tmp = simple_strtoul(argv[2], NULL, 16);
+		fdt_set_boot_cpuid_phys(fdt, tmp);
+
+	/********************************************************************
+	 * memory command
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][2] == 'm') && (argv[1][3] == 'o')) {
+		uint64_t addr, size;
+		int err;
+#ifdef CFG_64BIT_STRTOUL
+			addr = simple_strtoull(argv[2], NULL, 16);
+			size = simple_strtoull(argv[3], NULL, 16);
+#else
+			addr = simple_strtoul(argv[2], NULL, 16);
+			size = simple_strtoul(argv[3], NULL, 16);
+#endif
+		err = fdt_fixup_memory(fdt, addr, size);
+		if (err < 0)
+			return err;
+
+	/********************************************************************
+	 * mem reserve commands
+	 ********************************************************************/
+	} else if ((argv[1][0] == 'm') && (argv[1][1] == 'e') &&
+		   (argv[1][2] == 'm') && (argv[1][3] == 'r')) {
+		if (argv[2][0] == 'p') {
+			uint64_t addr, size;
+			int total = fdt_num_mem_rsv(fdt);
+			int j, err;
+			printf("index\t\t   start\t\t    size\n");
+			printf("-------------------------------"
+				"-----------------\n");
+			for (j = 0; j < total; j++) {
+				err = fdt_get_mem_rsv(fdt, j, &addr, &size);
+				if (err < 0) {
+					printf("libfdt fdt_get_mem_rsv():  %s\n",
+							fdt_strerror(err));
+					return err;
+				}
+				printf("    %x\t%08x%08x\t%08x%08x\n", j,
+					(u32)(addr >> 32),
+					(u32)(addr & 0xffffffff),
+					(u32)(size >> 32),
+					(u32)(size & 0xffffffff));
+			}
+		} else if (argv[2][0] == 'a') {
+			uint64_t addr, size;
+			int err;
+#ifdef CFG_64BIT_STRTOUL
+			addr = simple_strtoull(argv[3], NULL, 16);
+			size = simple_strtoull(argv[4], NULL, 16);
+#else
+			addr = simple_strtoul(argv[3], NULL, 16);
+			size = simple_strtoul(argv[4], NULL, 16);
+#endif
+			err = fdt_add_mem_rsv(fdt, addr, size);
+
+			if (err < 0) {
+				printf("libfdt fdt_add_mem_rsv():  %s\n",
+					fdt_strerror(err));
+				return err;
+			}
+		} else if (argv[2][0] == 'd') {
+			unsigned long idx = simple_strtoul(argv[3], NULL, 16);
+			int err = fdt_del_mem_rsv(fdt, idx);
+
+			if (err < 0) {
+				printf("libfdt fdt_del_mem_rsv():  %s\n",
+					fdt_strerror(err));
+				return err;
+			}
+		} else {
+			/* Unrecognized command */
+			printf ("Usage:\n%s\n", cmdtp->usage);
+			return 1;
+		}
 	}
 #ifdef CONFIG_OF_BOARD_SETUP
 	/* Call the board-specific fixup routine */
@@ -689,6 +795,12 @@ U_BOOT_CMD(
 	"fdt set    <path> <prop> [<val>]    - Set <property> [to <val>]\n"
 	"fdt mknode <path> <node>            - Create a new node after <path>\n"
 	"fdt rm     <path> [<prop>]          - Delete the node or <property>\n"
+	"fdt header                          - Display header info\n"
+	"fdt bootcpu <id>                    - Set boot cpuid\n"
+	"fdt memory <addr> <size>            - Add/Update memory node\n"
+	"fdt memrsv print                    - Show current mem reserves\n"
+	"fdt memrsv add <addr> <size>        - Add a mem reserve\n"
+	"fdt memrsv delete <index>           - Delete a mem reserves\n"
 	"fdt chosen - Add/update the /chosen branch in the tree\n"
 #ifdef CONFIG_OF_HAS_UBOOT_ENV
 	"fdt env    - Add/replace the /u-boot-env branch in the tree\n"
Signature · 1 line
1.5.3.8
#4 lore raw

PATCH 1/1 Add sub-commands to fdt

In reply to Kumar Gala
Quoted 8 lines · Kumar Gala
fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt memrsv print                    - Show current mem reserves
fdt memrsv add    <addr> <size>     - Add a mem reserve
fdt memrsv delete <index>           - Delete a mem reserves

Hi Kumar,

I was thinking about this a bit more. How about if we change the "memrsv" subcommand to "rsvmem" then we can abbreviate the commands more:
fdt mo[ve]
fdt me[mory]
fdt rm <- would no longer be distinctive on 'r', NBD
fdt rs[vmem]
and save ourselves some typing.

What do you think?
gvb

author
#5 lore raw

PATCH 1/1 Add sub-commands to fdt

Quoted 11 lines · Jerry Van Baren
Quoted 7 lines · Kumar Gala
fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt memrsv print                    - Show current mem reserves
fdt memrsv add    <addr> <size>     - Add a mem reserve
fdt memrsv delete <index>           - Delete a mem reserves

Hi Kumar,

Quoted 8 lines

I was thinking about this a bit more. How about if we change the "memrsv" subcommand to "rsvmem" then we can abbreviate the commands more:
fdt mo[ve]
fdt me[mory]
fdt rm <- would no longer be distinctive on 'r', NBD
fdt rs[vmem]
and save ourselves some typing.

works for me. I'll make these changes.

I don't plan on dealing with the header info you asked about (beyond reporting the number of memrsv). I've given you the framework, I'll leave it to you to figure out how to compute the values you want :)

I also have some questions about how we can "dynamically" grow the device tree so we don't have to pad the .dtb's

- k

#7 lore raw

PATCH v3 1/1 Add sub-commands to fdt

Quoted 5 lines · Kumar Gala
Quoted 1 line

From e76f97d16c5932d19d698e42c6376d6bbdca2ecf Mon Sep 17 00:00:00 2001

From: Kumar Gala <[email protected]>
Date: Fri, 15 Feb 2008 03:34:36 -0600
Subject: [PATCH] Add sub-commands to fdt

Quoted 8 lines
fdt header                          - Display header info
fdt bootcpu <id>                    - Set boot cpuid
fdt memory <addr> <size>            - Add/Update memory node
fdt rsvmem print                    - Show current mem reserves
fdt rsvmem add <addr> <size>        - Add a mem reserve
fdt rsvmem delete <index>           - Delete a mem reserves

Applied to u-boot-fdt. Thanks.

FWIIW, I found that fdt header when the fdt address (blob) is invalid crashes my board. On the one hand, that's what you get from playing with sharp knives - I'm reluctant to inhibit the header printout if the blob is invalid, because that may be what I'm trying to find out. On the other hand, I hate to crash a board when it can be avoided.

At this point, I'm inclined to validate the magic number (only) before doing the dump.

gvb