From 7c4c3722a38d40b0cf537ddae72b04f4088b190c Mon Sep 17 00:00:00 2001 From: Jason Jin Date: Tue, 7 Aug 2007 16:17:06 +0800 Subject: Add CONFIG_BIOSEMU define to guard all the bios emulator code This patch fix the compile issue on the board that did not enable the bios emulator diff --git a/drivers/bios_emulator/besys.c b/drivers/bios_emulator/besys.c index 2a8e1a0..4c4bc8d 100644 --- a/drivers/bios_emulator/besys.c +++ b/drivers/bios_emulator/besys.c @@ -49,6 +49,7 @@ #include "biosemui.h" +#if defined(CONFIG_BIOSEMU) /*------------------------- Global Variables ------------------------------*/ #ifndef __i386__ @@ -717,3 +718,4 @@ void X86API BE_outl(X86EMU_pioAddr port, u32 val) #endif LOG_outpd(port, val); } +#endif diff --git a/drivers/bios_emulator/bios.c b/drivers/bios_emulator/bios.c index ed5437e..7aa1bfb2e 100644 --- a/drivers/bios_emulator/bios.c +++ b/drivers/bios_emulator/bios.c @@ -43,6 +43,7 @@ #include "biosemui.h" +#if defined(CONFIG_BIOSEMU) /*----------------------------- Implementation ----------------------------*/ /**************************************************************************** @@ -319,3 +320,4 @@ void _BE_bios_init(u32 * intrTab) bios_intr_tab[0x6D] = int10; X86EMU_setupIntrFuncs(bios_intr_tab); } +#endif diff --git a/drivers/bios_emulator/biosemu.c b/drivers/bios_emulator/biosemu.c index 06d4ad3..4c3aedf 100644 --- a/drivers/bios_emulator/biosemu.c +++ b/drivers/bios_emulator/biosemu.c @@ -48,6 +48,8 @@ #include "biosemui.h" #include +#if defined(CONFIG_BIOSEMU) + BE_sysEnv _BE_env = {{0}}; static X86EMU_memFuncs _BE_mem __attribute__((section(".got2"))) = { BE_rdb, @@ -368,3 +370,4 @@ int X86API BE_int86x(int intno, RMREGS * in, RMREGS * out, RMSREGS * sregs) sregs->gs = M.x86.R_GS; return out->x.ax; } +#endif diff --git a/drivers/bios_emulator/x86emu/debug.c b/drivers/bios_emulator/x86emu/debug.c index 0f58a69..915739c 100644 --- a/drivers/bios_emulator/x86emu/debug.c +++ b/drivers/bios_emulator/x86emu/debug.c @@ -40,6 +40,8 @@ #include "x86emu/x86emui.h" #include +#if defined(CONFIG_BIOSEMU) + /*----------------------------- Implementation ----------------------------*/ #ifdef DEBUG @@ -459,3 +461,5 @@ void x86emu_dump_xregs(void) printk("NC "); printk("\n"); } + +#endif diff --git a/drivers/bios_emulator/x86emu/decode.c b/drivers/bios_emulator/x86emu/decode.c index 1e2dcfe..879f0a0 100644 --- a/drivers/bios_emulator/x86emu/decode.c +++ b/drivers/bios_emulator/x86emu/decode.c @@ -39,6 +39,8 @@ #include "x86emu/x86emui.h" +#if defined(CONFIG_BIOSEMU) + /*----------------------------- Implementation ----------------------------*/ /**************************************************************************** @@ -1142,3 +1144,5 @@ unsigned decode_rmXX_address(int mod, int rm) return decode_rm01_address(rm); return decode_rm10_address(rm); } + +#endif diff --git a/drivers/bios_emulator/x86emu/ops.c b/drivers/bios_emulator/x86emu/ops.c index d1380ce..d334fb5 100644 --- a/drivers/bios_emulator/x86emu/ops.c +++ b/drivers/bios_emulator/x86emu/ops.c @@ -76,6 +76,9 @@ ****************************************************************************/ #include "x86emu/x86emui.h" + +#if defined(CONFIG_BIOSEMU) + /*----------------------------- Implementation ----------------------------*/ /* constant arrays to do several instructions in just one function */ @@ -5429,3 +5432,5 @@ void (*x86emu_optab[256])(u8) __attribute__ ((section(".got2"))) = /* 0xfe */ x86emuOp_opcFE_byte_RM, /* 0xff */ x86emuOp_opcFF_word_RM, }; + +#endif diff --git a/drivers/bios_emulator/x86emu/ops2.c b/drivers/bios_emulator/x86emu/ops2.c index 631a340..81c0d49 100644 --- a/drivers/bios_emulator/x86emu/ops2.c +++ b/drivers/bios_emulator/x86emu/ops2.c @@ -46,6 +46,8 @@ #include "x86emu/x86emui.h" +#if defined(CONFIG_BIOSEMU) + /*----------------------------- Implementation ----------------------------*/ /**************************************************************************** @@ -1768,3 +1770,5 @@ void (*x86emu_optab2[256])(u8) __attribute__((section(".got2"))) = /* 0xfe */ x86emuOp2_illegal_op, /* 0xff */ x86emuOp2_illegal_op, }; + +#endif diff --git a/drivers/bios_emulator/x86emu/prim_ops.c b/drivers/bios_emulator/x86emu/prim_ops.c index e0827d7..c1152ea 100644 --- a/drivers/bios_emulator/x86emu/prim_ops.c +++ b/drivers/bios_emulator/x86emu/prim_ops.c @@ -100,6 +100,8 @@ #define PRIM_OPS_NO_REDEFINE_ASM #include "x86emu/x86emui.h" +#if defined(CONFIG_BIOSEMU) + /*------------------------- Global Variables ------------------------------*/ static u32 x86emu_parity_tab[8] = @@ -2443,3 +2445,5 @@ DB( if (CHECK_SP_ACCESS()) M.x86.R_SP += 4; return res; } + +#endif diff --git a/drivers/bios_emulator/x86emu/sys.c b/drivers/bios_emulator/x86emu/sys.c index bb7fcd9..566389f 100644 --- a/drivers/bios_emulator/x86emu/sys.c +++ b/drivers/bios_emulator/x86emu/sys.c @@ -41,6 +41,8 @@ #include "x86emu/x86emui.h" +#if defined(CONFIG_BIOSEMU) + /*------------------------- Global Variables ------------------------------*/ X86EMU_sysEnv _X86EMU_env; /* Global emulator machine state */ @@ -320,3 +322,5 @@ void X86EMU_prepareForInt(int num) M.x86.R_IP = mem_access_word(num * 4); M.x86.intr = 0; } + +#endif -- cgit v0.10.2 From 8096b3b8f772c1894ddeda9dbceff6a8826473a4 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Fri, 20 Apr 2007 22:46:53 -0400 Subject: libfdt: Conditionally compile based on CONFIG_OF_LIBFDT This is the way u-boot reduces configured-out code. At Wolfgang Grandegger and Wolfgang Denk's request, make libfdt conform. Signed-off-by: Gerald Van Baren diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 212b838..1ee67ad 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -16,6 +16,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" +#if CONFIG_OF_LIBFDT + #include "libfdt_env.h" #include @@ -83,3 +86,5 @@ int fdt_move(const void *fdt, void *buf, int bufsize) memmove(buf, fdt, fdt_totalsize(fdt)); return 0; } + +#endif /* CONFIG_OF_LIBFDT */ diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 4e2c325..defe59c 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -16,6 +16,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" +#if CONFIG_OF_LIBFDT + #include "libfdt_env.h" #include @@ -400,3 +403,6 @@ int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re) } return 0; } + +#endif /* CONFIG_OF_LIBFDT */ + diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c index aaafc53..693bfe4 100644 --- a/libfdt/fdt_rw.c +++ b/libfdt/fdt_rw.c @@ -16,6 +16,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" +#if CONFIG_OF_LIBFDT + #include "libfdt_env.h" #include @@ -291,3 +294,5 @@ int fdt_pack(void *fdt) fdt_set_header(fdt, totalsize, _blob_data_size(fdt)); return 0; } + +#endif /* CONFIG_OF_LIBFDT */ diff --git a/libfdt/fdt_strerror.c b/libfdt/fdt_strerror.c index 7f231ce..b49c952 100644 --- a/libfdt/fdt_strerror.c +++ b/libfdt/fdt_strerror.c @@ -16,6 +16,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" +#if CONFIG_OF_LIBFDT + #include "libfdt_env.h" #include @@ -62,3 +65,5 @@ const char *fdt_strerror(int errval) return ""; } + +#endif /* CONFIG_OF_LIBFDT */ diff --git a/libfdt/fdt_sw.c b/libfdt/fdt_sw.c index 672f4dd..c7eea8f 100644 --- a/libfdt/fdt_sw.c +++ b/libfdt/fdt_sw.c @@ -16,6 +16,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" +#if CONFIG_OF_LIBFDT + #include "libfdt_env.h" #include @@ -224,3 +227,5 @@ int fdt_finish(void *fdt) fdt_set_header(fdt, magic, FDT_MAGIC); return 0; } + +#endif /* CONFIG_OF_LIBFDT */ diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c index 2d2ed37..2d39aab 100644 --- a/libfdt/fdt_wip.c +++ b/libfdt/fdt_wip.c @@ -16,6 +16,9 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "config.h" +#if CONFIG_OF_LIBFDT + #include "libfdt_env.h" #include @@ -135,3 +138,5 @@ int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size) return 0; } + +#endif /* CONFIG_OF_LIBFDT */ -- cgit v0.10.2 From ba24e2ac3bdb5c489f3c787e7542b6474c4d65c6 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Wed, 25 Apr 2007 21:24:27 -0400 Subject: Improve error messages, more informative. Print more than the raw libfdt error message strings. This is especially useful for cluing in the user when the bootm command aborts due to blob problems. Signed-off-by: Gerald Van Baren diff --git a/common/fdt_support.c b/common/fdt_support.c index 69099c4..bcdc415 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -67,7 +67,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) return err; } if (used >= total) { - printf("fdt_chosen: no room in the reserved map (%d of %d)\n", + printf("WARNING fdt_chosen: no room in the reserved map (%d of %d)\n", used, total); return -1; } @@ -110,7 +110,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) */ nodeoffset = fdt_add_subnode(fdt, 0, "chosen"); if (nodeoffset < 0) { - printf("libfdt: %s\n", fdt_strerror(nodeoffset)); + printf("WARNING fdt_chosen: could not create the \"/chosen node\" (libfdt error %s).\n", fdt_strerror(nodeoffset)); return nodeoffset; } } @@ -122,22 +122,22 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) if (str != NULL) { err = fdt_setprop(fdt, nodeoffset, "bootargs", str, strlen(str)+1); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: could not set \"bootargs\" (libfdt error %s).\n", fdt_strerror(err)); } if (initrd_start && initrd_end) { tmp = __cpu_to_be32(initrd_start); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-start", &tmp, sizeof(tmp)); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: could not set \"linux,initrd-start\" (libfdt error %s).\n", fdt_strerror(err)); tmp = __cpu_to_be32(initrd_end); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-end", &tmp, sizeof(tmp)); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: could not set \"linux,initrd-end\" (libfdt error %s).\n", fdt_strerror(err)); } #ifdef OF_STDOUT_PATH err = fdt_setprop(fdt, nodeoffset, "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: could not set \"linux,stdout-path\" (libfdt error %s).\n", fdt_strerror(err)); #endif nodeoffset = fdt_path_offset (fdt, "/cpus"); @@ -145,7 +145,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) clock = cpu_to_be32(bd->bi_intfreq); err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: could not set \"clock-frequency\" (libfdt error %s).\n", fdt_strerror(err)); } #ifdef OF_TBCLK nodeoffset = fdt_path_offset (fdt, "/cpus/" OF_CPU "/timebase-frequency"); @@ -153,7 +153,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) clock = cpu_to_be32(OF_TBCLK); err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: could not set \"clock-frequency\" (libfdt error %s).\n", fdt_strerror(err)); } #endif return err; @@ -198,7 +198,7 @@ int fdt_env(void *fdt) */ nodeoffset = fdt_add_subnode(fdt, 0, "u-boot-env"); if (nodeoffset < 0) { - printf("libfdt: %s\n", fdt_strerror(nodeoffset)); + printf("WARNING fdt_env: could not create the \"/u-boot-env node\" (libfdt error %s).\n", fdt_strerror(nodeoffset)); return nodeoffset; } @@ -226,7 +226,7 @@ int fdt_env(void *fdt) continue; err = fdt_setprop(fdt, nodeoffset, lval, rval, strlen(rval)+1); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_env: could not set \"%s\" (libfdt error %s).\n", lval, fdt_strerror(err)); return err; } } @@ -318,6 +318,7 @@ int fdt_bd_t(void *fdt) */ nodeoffset = fdt_add_subnode(fdt, 0, "bd_t"); if (nodeoffset < 0) { + printf("WARNING fdt_bd_t: could not create the \"/bd_t node\" (libfdt error %s).\n", fdt_strerror(nodeoffset)); printf("libfdt: %s\n", fdt_strerror(nodeoffset)); return nodeoffset; } @@ -328,17 +329,17 @@ int fdt_bd_t(void *fdt) tmp = cpu_to_be32(getenv("bootargs")); err = fdt_setprop(fdt, nodeoffset, bd_map[i].name, &tmp, sizeof(tmp)); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_bd_t: could not set \"%s\" (libfdt error %s).\n", bd_map[i].name, fdt_strerror(err)); } /* * Add a couple of oddball entries... */ err = fdt_setprop(fdt, nodeoffset, "enetaddr", &bd->bi_enetaddr, 6); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_bd_t: could not set \"enetaddr\" (libfdt error %s).\n", fdt_strerror(err)); err = fdt_setprop(fdt, nodeoffset, "ethspeed", &bd->bi_ethspeed, 4); if (err < 0) - printf("libfdt: %s\n", fdt_strerror(err)); + printf("WARNING fdt_bd_t: could not set \"ethspeed\" (libfdt error %s).\n", fdt_strerror(err)); return 0; } -- cgit v0.10.2 From bb930e76fea6cf89ca2d98e2f7c7a6043d79327d Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Wed, 25 Apr 2007 22:23:36 -0400 Subject: Minor code clean up. Declare the variable fdt properly as extern. Call the "set_fn" function pointer the "short way" without the full dereferencing syntax. Signed-off-by: Gerald Van Baren diff --git a/common/fdt_support.c b/common/fdt_support.c index bcdc415..15f133c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -37,6 +37,11 @@ */ DECLARE_GLOBAL_DATA_PTR; +/* + * fdt points to our working device tree. + */ +struct fdt_header *fdt; + /********************************************************************/ diff --git a/include/libfdt_env.h b/include/libfdt_env.h index e746314..78f7258 100644 --- a/include/libfdt_env.h +++ b/include/libfdt_env.h @@ -26,7 +26,7 @@ #include #include -struct fdt_header *fdt; /* Pointer to the working fdt */ +extern struct fdt_header *fdt; /* Pointer to the working fdt */ #define fdt32_to_cpu(x) __be32_to_cpu(x) #define cpu_to_fdt32(x) __cpu_to_be32(x) -- cgit v0.10.2 From 6be07cc1ca458278c85ecdbf1a0536cff4c701ec Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Wed, 25 Apr 2007 22:47:15 -0400 Subject: Improve fdt move length handling. Make the length parameter optional: if not specified, do the move using the current size unchanged. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 08fe351..a119985 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -115,7 +115,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) int len; int err; - if (argc != 5) { + if (argc < 4) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } @@ -129,11 +129,20 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) } newaddr = (struct fdt_header *)simple_strtoul(argv[3], NULL, 16); - len = simple_strtoul(argv[4], NULL, 16); - if (len < fdt_totalsize(fdt)) { - printf ("New length %d < existing length %d, aborting.\n", - len, fdt_totalsize(fdt)); - return 1; + + /* + * If the user specifies a length, use that. Otherwise use the + * current length. + */ + if (argc <= 4) { + len = fdt_totalsize(fdt); + } else { + len = simple_strtoul(argv[4], NULL, 16); + if (len < fdt_totalsize(fdt)) { + printf ("New length 0x%X < existing length 0x%X, aborting.\n", + len, fdt_totalsize(fdt)); + return 1; + } } /* -- cgit v0.10.2 From 89c8757d8f213c47709bdc4efe0695263a6080a6 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Tue, 8 May 2007 21:27:35 -0400 Subject: Fix bugs in the CONFIG_OF_LIBFDT Stupid coding mistakes (identified by Timur Tabi, thanks). Signed-off-by: Gerald Van Baren diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 2436581..1cb0e43 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -788,7 +788,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, return; } #if defined(CONFIG_OF_LIBFDT) - if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) == 0) { + if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) { #else if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) { #endif @@ -944,7 +944,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, of_flat_tree = (char *)of_start; printf (" Loading Device Tree to %08lx, end %08lx ... ", of_start, of_start + of_len - 1); - err = fdt_open_into((void *)of_start, (void *)of_data, of_len); + err = fdt_open_into((void *)of_data, (void *)of_start, of_len); if (err != 0) { printf ("libfdt: %s " __FILE__ " %d\n", fdt_strerror(err), __LINE__); } -- cgit v0.10.2 From 38eb508e8e811e2e57628f445de3a24a23c7d804 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Sat, 12 May 2007 09:45:46 -0400 Subject: Reorganize and fix problems (returns) in the bootm command. Do *NOT* return after the "point of no return" has been passed. If something goes wrong, the board must be reset after that point. Move the "Transferring control to Linux" debug message back to where it belongs: just before transferring control to linux. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 1cb0e43..45ab13a 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -45,8 +45,8 @@ DECLARE_GLOBAL_DATA_PTR; - /*cmd_boot.c*/ - extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); +/*cmd_boot.c*/ +extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) #include @@ -756,8 +756,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, if ((ntohl(hdr->ih_load) < ((unsigned long)hdr + ntohl(hdr->ih_size) + sizeof(hdr))) && ((ntohl(hdr->ih_load) + ntohl(hdr->ih_size)) > (unsigned long)hdr)) { - printf ("ERROR: Load address overwrites Flat Device Tree uImage\n"); - return; + puts ("ERROR: Load address overwrites Flat Device Tree uImage\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } printf(" Verifying Checksum ... "); @@ -766,34 +766,34 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, header.ih_hcrc = 0; if(checksum != crc32(0, (uchar *)&header, sizeof(image_header_t))) { - printf("ERROR: Flat Device Tree header checksum is invalid\n"); - return; + puts ("ERROR: Flat Device Tree header checksum is invalid\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } checksum = ntohl(hdr->ih_dcrc); addr = (ulong)((uchar *)(hdr) + sizeof(image_header_t)); if(checksum != crc32(0, (uchar *)addr, ntohl(hdr->ih_size))) { - printf("ERROR: Flat Device Tree checksum is invalid\n"); - return; + puts ("ERROR: Flat Device Tree checksum is invalid\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } printf("OK\n"); if (ntohl(hdr->ih_type) != IH_TYPE_FLATDT) { - printf ("ERROR: uImage not Flat Device Tree type\n"); - return; + puts ("ERROR: uImage not Flat Device Tree type\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } if (ntohl(hdr->ih_comp) != IH_COMP_NONE) { - printf("ERROR: uImage is not uncompressed\n"); - return; + puts ("ERROR: uImage is not uncompressed\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #if defined(CONFIG_OF_LIBFDT) if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) { #else if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) { #endif - printf ("ERROR: uImage data is not a flat device tree\n"); - return; + puts ("ERROR: uImage data is not a flat device tree\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } memmove((void *)ntohl(hdr->ih_load), @@ -801,8 +801,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, ntohl(hdr->ih_size)); of_flat_tree = (char *)ntohl(hdr->ih_load); } else { - printf ("Did not find a flat flat device tree at address %08lX\n", of_flat_tree); - return; + puts ("Did not find a flat flat device tree\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } printf (" Booting using flat device tree at 0x%x\n", of_flat_tree); @@ -833,8 +833,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, #else if (((struct boot_param_header *)of_data)->magic != OF_DT_HEADER) { #endif - printf ("ERROR: image is not a flat device tree\n"); - return; + puts ("ERROR: image is not a flat device tree\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #if defined(CONFIG_OF_LIBFDT) @@ -842,8 +842,8 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, #else if (((struct boot_param_header *)of_data)->totalsize != ntohl(len_ptr[2])) { #endif - printf ("ERROR: flat device tree size does not agree with image\n"); - return; + puts ("ERROR: flat device tree size does not agree with image\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } } #endif @@ -916,15 +916,6 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, initrd_end = 0; } - debug ("## Transferring control to Linux (at address %08lx) ...\n", - (ulong)kernel); - - show_boot_progress (15); - -#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) - unlock_ram_in_cache(); -#endif - #if defined(CONFIG_OF_LIBFDT) /* move of_flat_tree if needed */ if (of_data) { @@ -953,19 +944,19 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, * if the user wants it (the logic is in the subroutines). */ if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { - printf("Failed creating the /chosen node (0x%08X), aborting.\n", of_flat_tree); - return; + puts ("ERROR: Failed creating the /chosen node, aborting.\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #ifdef CONFIG_OF_HAS_UBOOT_ENV if (fdt_env(of_flat_tree) < 0) { - printf("Failed creating the /u-boot-env node, aborting.\n"); - return; + puts ("ERROR: Failed creating the /u-boot-env node, aborting.\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #endif #ifdef CONFIG_OF_HAS_BD_T if (fdt_bd_t(of_flat_tree) < 0) { - printf("Failed creating the /bd_t node, aborting.\n"); - return; + puts ("ERROR: Failed creating the /bd_t node, aborting.\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #endif } @@ -990,55 +981,62 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, memmove ((void *)of_start, (void *)of_data, of_len); } #endif - - /* - * Linux Kernel Parameters (passing board info data): - * r3: ptr to board info data - * r4: initrd_start or 0 if no initrd - * r5: initrd_end - unused if r4 is 0 - * r6: Start of command line string - * r7: End of command line string - */ -#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) - if (!of_flat_tree) /* no device tree; boot old style */ -#endif - (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); - /* does not return */ - -#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) - /* - * Linux Kernel Parameters (passing device tree): - * r3: ptr to OF flat tree, followed by the board info data - * r4: physical pointer to the kernel itself - * r5: NULL - * r6: NULL - * r7: NULL - */ #if defined(CONFIG_OF_FLAT_TREE) ft_setup(of_flat_tree, kbd, initrd_start, initrd_end); /* ft_dump_blob(of_flat_tree); */ #endif #if defined(CONFIG_OF_LIBFDT) if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { - printf("Failed creating the /chosen node (0x%08X), aborting.\n", of_flat_tree); - return; + puts ("ERROR: Failed to create the /chosen node, aborting.\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #ifdef CONFIG_OF_HAS_UBOOT_ENV if (fdt_env(of_flat_tree) < 0) { - printf("Failed creating the /u-boot-env node, aborting.\n"); - return; + puts ("ERROR: Failed to create the /u-boot-env node, aborting.\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #endif #ifdef CONFIG_OF_HAS_BD_T if (fdt_bd_t(of_flat_tree) < 0) { - printf("Failed creating the /bd_t node, aborting.\n"); - return; + puts ("ERROR: Failed to create the /bd_t node, aborting.\nMust RESET board to recover\n"); + do_reset (cmdtp, flag, argc, argv); } #endif #endif /* if defined(CONFIG_OF_LIBFDT) */ - (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); + debug ("## Transferring control to Linux (at address %08lx) ...\n", + (ulong)kernel); + + show_boot_progress (15); + +#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500) + unlock_ram_in_cache(); #endif + +#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT) + if (of_flat_tree) { /* device tree; boot new style */ + /* + * Linux Kernel Parameters (passing device tree): + * r3: ptr to flattened device tree, followed by the board info data + * r4: physical pointer to the kernel itself + * r5: NULL + * r6: NULL + * r7: NULL + */ + (*kernel) ((bd_t *)of_flat_tree, (ulong)kernel, 0, 0, 0); + /* does not return */ + } +#endif + /* + * Linux Kernel Parameters (passing board info data): + * r3: ptr to board info data + * r4: initrd_start or 0 if no initrd + * r5: initrd_end - unused if r4 is 0 + * r6: Start of command line string + * r7: End of command line string + */ + (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end); + /* does not return */ } #endif /* CONFIG_PPC */ -- cgit v0.10.2 From 25114033ab21788810c48ba4df103b649da1223b Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Sat, 12 May 2007 09:47:25 -0400 Subject: FDT command improvements. Fix "fdt set" so that it will create a non-existing property. Add "fdt mknode" to create nodes. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index a119985..8402ca7 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -56,27 +56,38 @@ static char data[SCRATCHPAD]; static int fdt_valid(void); static void print_data(const void *data, int len); +static int findnodeoffset(const char *pathp) +{ + int nodeoffset; + + if (strcmp(pathp, "/") == 0) { + nodeoffset = 0; + } else { + nodeoffset = fdt_path_offset (fdt, pathp); + if (nodeoffset < 0) { + /* + * Not found or something else bad happened. + */ + printf ("findnodeoffset() libfdt: %s\n", fdt_strerror(nodeoffset)); + } + } + return nodeoffset; +} /* * Flattened Device Tree command, see the help for parameter definitions. */ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) { - char op; - if (argc < 2) { printf ("Usage:\n%s\n", cmdtp->usage); return 1; } - /* - * Figure out which subcommand was given - */ - op = argv[1][0]; /******************************************************************** * Set the address of the fdt ********************************************************************/ - if (op == 'a') { + if (argv[1][0] == 'a') { /* * Set the address [and length] of the fdt. */ @@ -102,7 +113,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) */ err = fdt_open_into(fdt, fdt, len); if (err != 0) { - printf ("libfdt: %s\n", fdt_strerror(err)); + printf ("libfdt fdt_open_into(): %s\n", fdt_strerror(err)); } } } @@ -110,7 +121,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) /******************************************************************** * Move the fdt ********************************************************************/ - } else if (op == 'm') { + } else if ((argv[1][0] == 'm') && (argv[1][1] == 'o')) { struct fdt_header *newaddr; int len; int err; @@ -150,15 +161,48 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) */ err = fdt_open_into(fdt, newaddr, len); if (err != 0) { - printf ("libfdt: %s\n", fdt_strerror(err)); + printf ("libfdt fdt_open_into(): %s\n", fdt_strerror(err)); return 1; } fdt = newaddr; /******************************************************************** - * Set the value of a node in the fdt. + * Make a new node + ********************************************************************/ + } else if ((argv[1][0] == 'm') && (argv[1][1] == 'k')) { + char *pathp; /* path */ + char *nodep; /* new node to add */ + int nodeoffset; /* node offset from libfdt */ + int err; + + /* + * Parameters: Node path, new node to be appended to the path. + */ + if (argc < 4) { + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + pathp = argv[2]; + nodep = argv[3]; + + nodeoffset = findnodeoffset(pathp); + if (nodeoffset < 0) { + /* + * Not found or something else bad happened. + */ + return 1; + } + err = fdt_add_subnode(fdt, nodeoffset, nodep); + if (err < 0) { + printf ("libfdt fdt_add_subnode(): %s\n", fdt_strerror(err)); + return 1; + } + + /******************************************************************** + * Set the value of a property in the fdt. ********************************************************************/ - } else if (op == 's') { + } else if (argv[1][0] == 's') { char *pathp; /* path */ char *prop; /* property */ struct fdt_property *nodep; /* node struct pointer */ @@ -183,102 +227,85 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) prop = argv[3]; newval = argv[4]; - if (strcmp(pathp, "/") == 0) { - nodeoffset = 0; - } else { - nodeoffset = fdt_path_offset (fdt, pathp); - if (nodeoffset < 0) { - /* - * Not found or something else bad happened. - */ - printf ("libfdt: %s\n", fdt_strerror(nodeoffset)); - return 1; - } - } - nodep = fdt_getprop (fdt, nodeoffset, prop, &oldlen); - if (oldlen < 0) { - printf ("libfdt %s\n", fdt_strerror(oldlen)); - return 1; - } else if (oldlen == 0) { + nodeoffset = findnodeoffset(pathp); + if (nodeoffset < 0) { /* - * The specified property has no value + * Not found or something else bad happened. */ - printf("%s has no value, cannot set one (yet).\n", prop); return 1; - } else { + } + /* + * Convert the new property + */ + vp = data; + if (*newval == '<') { /* - * Convert the new property + * Bigger values than bytes. */ - vp = data; - if (*newval == '<') { - /* - * Bigger values than bytes. - */ - len = 0; - newval++; - while ((*newval != '>') && (*newval != '\0')) { - cp = newval; - tmp = simple_strtoul(cp, &newval, 16); - if ((newval - cp) <= 2) { - *vp = tmp & 0xFF; - vp += 1; - len += 1; - } else if ((newval - cp) <= 4) { - *(uint16_t *)vp = __cpu_to_be16(tmp); - vp += 2; - len += 2; - } else if ((newval - cp) <= 8) { - *(uint32_t *)vp = __cpu_to_be32(tmp); - vp += 4; - len += 4; - } else { - printf("Sorry, I could not convert \"%s\"\n", cp); - return 1; - } - while (*newval == ' ') - newval++; - } - if (*newval != '>') { - printf("Unexpected character '%c'\n", *newval); - return 1; - } - } else if (*newval == '[') { - /* - * Byte stream. Convert the values. - */ - len = 0; - newval++; - while ((*newval != ']') && (*newval != '\0')) { - tmp = simple_strtoul(newval, &newval, 16); - *vp++ = tmp & 0xFF; - len++; - while (*newval == ' ') - newval++; - } - if (*newval != ']') { - printf("Unexpected character '%c'\n", *newval); + len = 0; + newval++; + while ((*newval != '>') && (*newval != '\0')) { + cp = newval; + tmp = simple_strtoul(cp, &newval, 16); + if ((newval - cp) <= 2) { + *vp = tmp & 0xFF; + vp += 1; + len += 1; + } else if ((newval - cp) <= 4) { + *(uint16_t *)vp = __cpu_to_be16(tmp); + vp += 2; + len += 2; + } else if ((newval - cp) <= 8) { + *(uint32_t *)vp = __cpu_to_be32(tmp); + vp += 4; + len += 4; + } else { + printf("Sorry, I could not convert \"%s\"\n", cp); return 1; } - } else { - /* - * Assume it is a string. Copy it into our data area for - * convenience (including the terminating '\0'). - */ - len = strlen(newval) + 1; - strcpy(data, newval); + while (*newval == ' ') + newval++; } - - ret = fdt_setprop(fdt, nodeoffset, prop, data, len); - if (ret < 0) { - printf ("libfdt %s\n", fdt_strerror(ret)); + if (*newval != '>') { + printf("Unexpected character '%c'\n", *newval); + return 1; + } + } else if (*newval == '[') { + /* + * Byte stream. Convert the values. + */ + len = 0; + newval++; + while ((*newval != ']') && (*newval != '\0')) { + tmp = simple_strtoul(newval, &newval, 16); + *vp++ = tmp & 0xFF; + len++; + while (*newval == ' ') + newval++; + } + if (*newval != ']') { + printf("Unexpected character '%c'\n", *newval); return 1; } + } else { + /* + * Assume it is a string. Copy it into our data area for + * convenience (including the terminating '\0'). + */ + len = strlen(newval) + 1; + strcpy(data, newval); + } + + ret = fdt_setprop(fdt, nodeoffset, prop, data, len); + if (ret < 0) { + printf ("libfdt fdt_setprop(): %s\n", fdt_strerror(ret)); + return 1; } /******************************************************************** * Print (recursive) / List (single level) ********************************************************************/ - } else if ((op == 'p') || (op == 'l')) { + } else if ((argv[1][0] == 'p') || (argv[1][0] == 'l')) { /* * Recursively print (a portion of) the fdt. */ @@ -297,7 +324,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) /* * list is an alias for print, but limited to 1 level */ - if (op == 'l') { + if (argv[1][0] == 'l') { depth = 1; } @@ -311,18 +338,12 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) else prop = NULL; - if (strcmp(pathp, "/") == 0) { - nodeoffset = 0; - printf("/"); - } else { - nodeoffset = fdt_path_offset (fdt, pathp); - if (nodeoffset < 0) { - /* - * Not found or something else bad happened. - */ - printf ("libfdt %s\n", fdt_strerror(nodeoffset)); - return 1; - } + nodeoffset = findnodeoffset(pathp); + if (nodeoffset < 0) { + /* + * Not found or something else bad happened. + */ + return 1; } /* * The user passed in a property as well as node path. Print only @@ -339,7 +360,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) printf("\n"); return 0; } else { - printf ("libfdt %s\n", fdt_strerror(len)); + printf ("libfdt fdt_getprop(): %s\n", fdt_strerror(len)); return 1; } } @@ -359,7 +380,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) level++; offstack[level] = nodeoffset; if (level >= MAX_LEVEL) { - printf("Aaaiii nested too deep.\n"); + printf("Aaaiii nested too deep. Aborting.\n"); return 1; } break; @@ -374,7 +395,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) case FDT_PROP: nodep = fdt_getprop (fdt, offstack[level], pathp, &len); if (len < 0) { - printf ("libfdt %s\n", fdt_strerror(len)); + printf ("libfdt fdt_getprop(): %s\n", fdt_strerror(len)); return 1; } else if (len == 0) { /* the property has no value */ @@ -403,7 +424,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) /******************************************************************** * Remove a property/node ********************************************************************/ - } else if (op == 'r') { + } else if (argv[1][0] == 'r') { int nodeoffset; /* node offset from libfdt */ int err; @@ -411,17 +432,12 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) * Get the path. The root node is an oddball, the offset * is zero and has no name. */ - if (strcmp(argv[2], "/") == 0) { - nodeoffset = 0; - } else { - nodeoffset = fdt_path_offset (fdt, argv[2]); - if (nodeoffset < 0) { - /* - * Not found or something else bad happened. - */ - printf ("libfdt %s\n", fdt_strerror(nodeoffset)); - return 1; - } + nodeoffset = findnodeoffset(argv[2]); + if (nodeoffset < 0) { + /* + * Not found or something else bad happened. + */ + return 1; } /* * Do the delete. A fourth parameter means delete a property, @@ -430,13 +446,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) if (argc > 3) { err = fdt_delprop(fdt, nodeoffset, argv[3]); if (err < 0) { - printf("fdt_delprop libfdt: %s\n", fdt_strerror(err)); + printf("libfdt fdt_delprop(): %s\n", fdt_strerror(err)); return err; } } else { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { - printf("fdt_del_node libfdt: %s\n", fdt_strerror(err)); + printf("libfdt fdt_del_node(): %s\n", fdt_strerror(err)); return err; } } @@ -444,19 +460,19 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) /******************************************************************** * Create a chosen node ********************************************************************/ - } else if (op == 'c') { + } else if (argv[1][0] == 'c') { fdt_chosen(fdt, 0, 0, 1); /******************************************************************** * Create a u-boot-env node ********************************************************************/ - } else if (op == 'e') { + } else if (argv[1][0] == 'e') { fdt_env(fdt); /******************************************************************** * Create a bd_t node ********************************************************************/ - } else if (op == 'b') { + } else if (argv[1][0] == 'b') { fdt_bd_t(fdt); /******************************************************************** @@ -486,7 +502,7 @@ static int fdt_valid(void) return 1; /* valid */ if (err < 0) { - printf("libfdt: %s", fdt_strerror(err)); + printf("libfdt fdt_check_header(): %s", fdt_strerror(err)); /* * Be more informative on bad version. */ @@ -630,7 +646,6 @@ U_BOOT_CMD( "fdt bd_t - Add/replace the \"/bd_t\" branch in the tree\n" #endif "Hints:\n" - " * Set a larger length with the fdt addr command to add to the blob.\n" " * If the property you are setting/printing has a '#' character,\n" " you MUST escape it with a \\ character or quote it with \" or\n" " it will be ignored as a comment.\n" -- cgit v0.10.2 From addd8ce83078c25f0eca5f23adbdfc64ca50a243 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Wed, 16 May 2007 22:39:59 -0400 Subject: Fix cmd_fdt line lengths, refactor code. Break lines that were greater than 80 characters in length. Move the fdt print and property parsing code to separate static functions to reduce coding clutter in the fdt_cmd handling body. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 8402ca7..7066d7d 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -45,16 +45,12 @@ DECLARE_GLOBAL_DATA_PTR; /* - * Scratchpad memory. - */ -static char data[SCRATCHPAD]; - - -/* * Function prototypes/declarations. */ static int fdt_valid(void); -static void print_data(const void *data, int len); +static int fdt_parse_prop(char *pathp, char *prop, char *newval, + char *data, int *len); +static int fdt_print(char *pathp, char *prop, int depth); static int findnodeoffset(const char *pathp) { @@ -68,7 +64,8 @@ static int findnodeoffset(const char *pathp) /* * Not found or something else bad happened. */ - printf ("findnodeoffset() libfdt: %s\n", fdt_strerror(nodeoffset)); + printf ("findnodeoffset() libfdt: %s\n", + fdt_strerror(nodeoffset)); } } return nodeoffset; @@ -105,7 +102,8 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) */ len = simple_strtoul(argv[3], NULL, 16); if (len < fdt_totalsize(fdt)) { - printf ("New length %d < existing length %d, ignoring.\n", + printf ("New length %d < existing length %d, " + "ignoring.\n", len, fdt_totalsize(fdt)); } else { /* @@ -113,7 +111,8 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) */ err = fdt_open_into(fdt, fdt, len); if (err != 0) { - printf ("libfdt fdt_open_into(): %s\n", fdt_strerror(err)); + printf ("libfdt fdt_open_into(): %s\n", + fdt_strerror(err)); } } } @@ -139,7 +138,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 1; } - newaddr = (struct fdt_header *)simple_strtoul(argv[3], NULL, 16); + newaddr = (struct fdt_header *)simple_strtoul(argv[3],NULL,16); /* * If the user specifies a length, use that. Otherwise use the @@ -150,7 +149,8 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) } else { len = simple_strtoul(argv[4], NULL, 16); if (len < fdt_totalsize(fdt)) { - printf ("New length 0x%X < existing length 0x%X, aborting.\n", + printf ("New length 0x%X < existing length " + "0x%X, aborting.\n", len, fdt_totalsize(fdt)); return 1; } @@ -161,7 +161,8 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) */ err = fdt_open_into(fdt, newaddr, len); if (err != 0) { - printf ("libfdt fdt_open_into(): %s\n", fdt_strerror(err)); + printf ("libfdt fdt_open_into(): %s\n", + fdt_strerror(err)); return 1; } fdt = newaddr; @@ -195,7 +196,8 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) } err = fdt_add_subnode(fdt, nodeoffset, nodep); if (err < 0) { - printf ("libfdt fdt_add_subnode(): %s\n", fdt_strerror(err)); + printf ("libfdt fdt_add_subnode(): %s\n", + fdt_strerror(err)); return 1; } @@ -204,16 +206,12 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) ********************************************************************/ } else if (argv[1][0] == 's') { char *pathp; /* path */ - char *prop; /* property */ - struct fdt_property *nodep; /* node struct pointer */ + char *prop; /* property */ char *newval; /* value from the user (as a string) */ - char *vp; /* temporary value pointer */ - char *cp; /* temporary char pointer */ int nodeoffset; /* node offset from libfdt */ - int len; /* new length of the property */ - int oldlen; /* original length of the property */ - unsigned long tmp; /* holds converted values */ - int ret; /* return value */ + static char data[SCRATCHPAD]; /* storage for the property */ + int len; /* new length of the property */ + int ret; /* return value */ /* * Parameters: Node path, property, value. @@ -234,67 +232,9 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) */ return 1; } - /* - * Convert the new property - */ - vp = data; - if (*newval == '<') { - /* - * Bigger values than bytes. - */ - len = 0; - newval++; - while ((*newval != '>') && (*newval != '\0')) { - cp = newval; - tmp = simple_strtoul(cp, &newval, 16); - if ((newval - cp) <= 2) { - *vp = tmp & 0xFF; - vp += 1; - len += 1; - } else if ((newval - cp) <= 4) { - *(uint16_t *)vp = __cpu_to_be16(tmp); - vp += 2; - len += 2; - } else if ((newval - cp) <= 8) { - *(uint32_t *)vp = __cpu_to_be32(tmp); - vp += 4; - len += 4; - } else { - printf("Sorry, I could not convert \"%s\"\n", cp); - return 1; - } - while (*newval == ' ') - newval++; - } - if (*newval != '>') { - printf("Unexpected character '%c'\n", *newval); - return 1; - } - } else if (*newval == '[') { - /* - * Byte stream. Convert the values. - */ - len = 0; - newval++; - while ((*newval != ']') && (*newval != '\0')) { - tmp = simple_strtoul(newval, &newval, 16); - *vp++ = tmp & 0xFF; - len++; - while (*newval == ' ') - newval++; - } - if (*newval != ']') { - printf("Unexpected character '%c'\n", *newval); - return 1; - } - } else { - /* - * Assume it is a string. Copy it into our data area for - * convenience (including the terminating '\0'). - */ - len = strlen(newval) + 1; - strcpy(data, newval); - } + ret = fdt_parse_prop(pathp, prop, newval, data, &len); + if (ret != 0) + return ret; ret = fdt_setprop(fdt, nodeoffset, prop, data, len); if (ret < 0) { @@ -306,20 +246,10 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) * Print (recursive) / List (single level) ********************************************************************/ } else if ((argv[1][0] == 'p') || (argv[1][0] == 'l')) { - /* - * Recursively print (a portion of) the fdt. - */ - static int offstack[MAX_LEVEL]; - static char tabs[MAX_LEVEL+1] = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; int depth = MAX_LEVEL; /* how deep to print */ char *pathp; /* path */ - char *prop; /* property */ - void *nodep; /* property node pointer */ - int nodeoffset; /* node offset from libfdt */ - int nextoffset; /* next node offset from libfdt */ - uint32_t tag; /* tag */ - int len; /* length of the property */ - int level = 0; /* keep track of nesting level */ + char *prop; /* property */ + int ret; /* return value */ /* * list is an alias for print, but limited to 1 level @@ -338,88 +268,9 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) else prop = NULL; - nodeoffset = findnodeoffset(pathp); - if (nodeoffset < 0) { - /* - * Not found or something else bad happened. - */ - return 1; - } - /* - * The user passed in a property as well as node path. Print only - * the given property and then return. - */ - if (prop) { - nodep = fdt_getprop (fdt, nodeoffset, prop, &len); - if (len == 0) { - printf("%s %s\n", pathp, prop); /* no property value */ - return 0; - } else if (len > 0) { - printf("%s=", prop); - print_data (nodep, len); - printf("\n"); - return 0; - } else { - printf ("libfdt fdt_getprop(): %s\n", fdt_strerror(len)); - return 1; - } - } - - /* - * The user passed in a node path and no property, print the node - * and all subnodes. - */ - offstack[0] = nodeoffset; - - while(level >= 0) { - tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, &pathp); - switch(tag) { - case FDT_BEGIN_NODE: - if(level <= depth) - printf("%s%s {\n", &tabs[MAX_LEVEL - level], pathp); - level++; - offstack[level] = nodeoffset; - if (level >= MAX_LEVEL) { - printf("Aaaiii nested too deep. Aborting.\n"); - return 1; - } - break; - case FDT_END_NODE: - level--; - if(level <= depth) - printf("%s};\n", &tabs[MAX_LEVEL - level]); - if (level == 0) { - level = -1; /* exit the loop */ - } - break; - case FDT_PROP: - nodep = fdt_getprop (fdt, offstack[level], pathp, &len); - if (len < 0) { - printf ("libfdt fdt_getprop(): %s\n", fdt_strerror(len)); - return 1; - } else if (len == 0) { - /* the property has no value */ - if(level <= depth) - printf("%s%s;\n", &tabs[MAX_LEVEL - level], pathp); - } else { - if(level <= depth) { - printf("%s%s=", &tabs[MAX_LEVEL - level], pathp); - print_data (nodep, len); - printf(";\n"); - } - } - break; - case FDT_NOP: - break; - case FDT_END: - return 1; - default: - if(level <= depth) - printf("Unknown tag 0x%08X\n", tag); - return 1; - } - nodeoffset = nextoffset; - } + ret = fdt_print(pathp, prop, depth); + if (ret != 0) + return ret; /******************************************************************** * Remove a property/node @@ -446,13 +297,15 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) if (argc > 3) { err = fdt_delprop(fdt, nodeoffset, argv[3]); if (err < 0) { - printf("libfdt fdt_delprop(): %s\n", fdt_strerror(err)); + printf("libfdt fdt_delprop(): %s\n", + fdt_strerror(err)); return err; } } else { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { - printf("libfdt fdt_del_node(): %s\n", fdt_strerror(err)); + printf("libfdt fdt_del_node(): %s\n", + fdt_strerror(err)); return err; } } @@ -486,7 +339,7 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return 0; } -/********************************************************************/ +/****************************************************************************/ static int fdt_valid(void) { @@ -509,12 +362,14 @@ static int fdt_valid(void) if (err == -FDT_ERR_BADVERSION) { if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) { printf (" - too old, fdt $d < %d", - fdt_version(fdt), FDT_FIRST_SUPPORTED_VERSION); + fdt_version(fdt), + FDT_FIRST_SUPPORTED_VERSION); fdt = NULL; } if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION) { printf (" - too new, fdt $d > %d", - fdt_version(fdt), FDT_LAST_SUPPORTED_VERSION); + fdt_version(fdt), + FDT_LAST_SUPPORTED_VERSION); fdt = NULL; } return 0; @@ -525,13 +380,91 @@ static int fdt_valid(void) return 1; } -/********************************************************************/ +/****************************************************************************/ /* - * OF flat tree handling - * Written by: Pantelis Antoniou - * Updated by: Matthew McClintock - * Converted to libfdt by: Gerald Van Baren + * Parse the user's input, partially heuristic. Valid formats: + * <00> - hex byte + * <0011> - hex half word (16 bits) + * <00112233> - hex word (32 bits) + * - hex double words (64 bits) are not supported, must use + * a byte stream instead. + * [00 11 22 .. nn] - byte stream + * "string" - If the the value doesn't start with "<" or "[", it is + * treated as a string. Note that the quotes are + * stripped by the parser before we get the string. + */ +static int fdt_parse_prop(char *pathp, char *prop, char *newval, + char *data, int *len) +{ + char *cp; /* temporary char pointer */ + unsigned long tmp; /* holds converted values */ + + if (*newval == '<') { + /* + * Bigger values than bytes. + */ + *len = 0; + newval++; + while ((*newval != '>') && (*newval != '\0')) { + cp = newval; + tmp = simple_strtoul(cp, &newval, 16); + if ((newval - cp) <= 2) { + *data = tmp & 0xFF; + data += 1; + *len += 1; + } else if ((newval - cp) <= 4) { + *(uint16_t *)data = __cpu_to_be16(tmp); + data += 2; + *len += 2; + } else if ((newval - cp) <= 8) { + *(uint32_t *)data = __cpu_to_be32(tmp); + data += 4; + *len += 4; + } else { + printf("Sorry, I could not convert \"%s\"\n", + cp); + return 1; + } + while (*newval == ' ') + newval++; + } + if (*newval != '>') { + printf("Unexpected character '%c'\n", *newval); + return 1; + } + } else if (*newval == '[') { + /* + * Byte stream. Convert the values. + */ + *len = 0; + newval++; + while ((*newval != ']') && (*newval != '\0')) { + tmp = simple_strtoul(newval, &newval, 16); + *data++ = tmp & 0xFF; + *len++; + while (*newval == ' ') + newval++; + } + if (*newval != ']') { + printf("Unexpected character '%c'\n", *newval); + return 1; + } + } else { + /* + * Assume it is a string. Copy it into our data area for + * convenience (including the terminating '\0'). + */ + *len = strlen(newval) + 1; + strcpy(data, newval); + } + return 0; +} + +/****************************************************************************/ + +/* + * Heuristic to guess if this is a string or concatenated strings. */ static int is_printable_string(const void *data, int len) @@ -571,6 +504,12 @@ static int is_printable_string(const void *data, int len) return 1; } + +/* + * Print the property in the best format, a heuristic guess. Print as + * a string, concatenated strings, a byte, word, double word, or (if all + * else fails) it is printed as a stream of bytes. + */ static void print_data(const void *data, int len) { int j; @@ -626,6 +565,119 @@ static void print_data(const void *data, int len) } } +/****************************************************************************/ + +/* + * Recursively print (a portion of) the fdt. The depth parameter + * determines how deeply nested the fdt is printed. + */ +static int fdt_print(char *pathp, char *prop, int depth) +{ + static int offstack[MAX_LEVEL]; + static char tabs[MAX_LEVEL+1] = + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; + void *nodep; /* property node pointer */ + int nodeoffset; /* node offset from libfdt */ + int nextoffset; /* next node offset from libfdt */ + uint32_t tag; /* tag */ + int len; /* length of the property */ + int level = 0; /* keep track of nesting level */ + + nodeoffset = findnodeoffset(pathp); + if (nodeoffset < 0) { + /* + * Not found or something else bad happened. + */ + return 1; + } + /* + * The user passed in a property as well as node path. + * Print only the given property and then return. + */ + if (prop) { + nodep = fdt_getprop (fdt, nodeoffset, prop, &len); + if (len == 0) { + /* no property value */ + printf("%s %s\n", pathp, prop); + return 0; + } else if (len > 0) { + printf("%s=", prop); + print_data (nodep, len); + printf("\n"); + return 0; + } else { + printf ("libfdt fdt_getprop(): %s\n", + fdt_strerror(len)); + return 1; + } + } + + /* + * The user passed in a node path and no property, + * print the node and all subnodes. + */ + offstack[0] = nodeoffset; + + while(level >= 0) { + tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, &pathp); + switch(tag) { + case FDT_BEGIN_NODE: + if(level <= depth) + printf("%s%s {\n", + &tabs[MAX_LEVEL - level], pathp); + level++; + offstack[level] = nodeoffset; + if (level >= MAX_LEVEL) { + printf("Aaaiii nested too deep. " + "Aborting.\n"); + return 1; + } + break; + case FDT_END_NODE: + level--; + if(level <= depth) + printf("%s};\n", &tabs[MAX_LEVEL - level]); + if (level == 0) { + level = -1; /* exit the loop */ + } + break; + case FDT_PROP: + nodep = fdt_getprop (fdt, offstack[level], pathp, &len); + if (len < 0) { + printf ("libfdt fdt_getprop(): %s\n", + fdt_strerror(len)); + return 1; + } else if (len == 0) { + /* the property has no value */ + if(level <= depth) + printf("%s%s;\n", + &tabs[MAX_LEVEL - level], + pathp); + } else { + if(level <= depth) { + printf("%s%s=", + &tabs[MAX_LEVEL - level], + pathp); + print_data (nodep, len); + printf(";\n"); + } + } + break; + case FDT_NOP: + break; + case FDT_END: + return 1; + default: + if(level <= depth) + printf("Unknown tag 0x%08X\n", tag); + return 1; + } + nodeoffset = nextoffset; + } + return 0; +} + /********************************************************************/ U_BOOT_CMD( -- cgit v0.10.2 From 1a861169bc3758f9de3aead62b058736c6891246 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Wed, 6 Jun 2007 22:47:58 -0400 Subject: Replace fdt_node_offset() with fdt_find_node_by_path(). The new name matches more closely the kernel's name, which is also a much better description. Signed-off-by: Wolfgang Grandegger Acked-by: Gerald Van Baren diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 7066d7d..65960c6 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -59,7 +59,7 @@ static int findnodeoffset(const char *pathp) if (strcmp(pathp, "/") == 0) { nodeoffset = 0; } else { - nodeoffset = fdt_path_offset (fdt, pathp); + nodeoffset = fdt_find_node_by_path (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. diff --git a/common/fdt_support.c b/common/fdt_support.c index 15f133c..efa63f0 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -97,7 +97,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) /* * Find the "chosen" node. */ - nodeoffset = fdt_path_offset (fdt, "/chosen"); + nodeoffset = fdt_find_node_by_path (fdt, "/chosen"); /* * If we have a "chosen" node already the "force the writing" @@ -145,7 +145,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) printf("WARNING fdt_chosen: could not set \"linux,stdout-path\" (libfdt error %s).\n", fdt_strerror(err)); #endif - nodeoffset = fdt_path_offset (fdt, "/cpus"); + nodeoffset = fdt_find_node_by_path (fdt, "/cpus"); if (nodeoffset >= 0) { clock = cpu_to_be32(bd->bi_intfreq); err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4); @@ -153,7 +153,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) printf("WARNING fdt_chosen: could not set \"clock-frequency\" (libfdt error %s).\n", fdt_strerror(err)); } #ifdef OF_TBCLK - nodeoffset = fdt_path_offset (fdt, "/cpus/" OF_CPU "/timebase-frequency"); + nodeoffset = fdt_find_node_by_path (fdt, "/cpus/" OF_CPU "/timebase-frequency"); if (nodeoffset >= 0) { clock = cpu_to_be32(OF_TBCLK); err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4); @@ -190,7 +190,7 @@ int fdt_env(void *fdt) * See if we already have a "u-boot-env" node, delete it if so. * Then create a new empty node. */ - nodeoffset = fdt_path_offset (fdt, "/u-boot-env"); + nodeoffset = fdt_find_node_by_path (fdt, "/u-boot-env"); if (nodeoffset >= 0) { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { @@ -310,7 +310,7 @@ int fdt_bd_t(void *fdt) * See if we already have a "bd_t" node, delete it if so. * Then create a new empty node. */ - nodeoffset = fdt_path_offset (fdt, "/bd_t"); + nodeoffset = fdt_find_node_by_path (fdt, "/bd_t"); if (nodeoffset >= 0) { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { diff --git a/include/libfdt.h b/include/libfdt.h index f8bac73..e080028 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -77,7 +77,7 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, const char *name, int namelen); int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); -int fdt_path_offset(const void *fdt, const char *path); +int fdt_find_node_by_path(const void *fdt, const char *path); struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, const char *name, int *lenp); diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index defe59c..1a03109 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -132,7 +132,7 @@ int fdt_subnode_offset(const void *fdt, int parentoffset, * Searches for the node corresponding to the given path and returns the * offset of that node. */ -int fdt_path_offset(const void *fdt, const char *path) +int fdt_find_node_by_path(const void *fdt, const char *path) { const char *end = path + strlen(path); const char *p = path; -- cgit v0.10.2 From 9675ee7208ab965d13ea8d8262d77ac4160ef549 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Thu, 17 May 2007 23:54:36 -0400 Subject: Add fdt_find_node_by_type() and fdt_find_compatible_node() to LIBFDT Signed-off-by: Wolfgang Grandegger Acked-by: Gerald Van Baren diff --git a/include/libfdt.h b/include/libfdt.h index e080028..340e89d 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -78,6 +78,12 @@ int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, int fdt_subnode_offset(const void *fdt, int parentoffset, const char *name); int fdt_find_node_by_path(const void *fdt, const char *path); +int fdt_find_node_by_type(const void *fdt, int nodeoffset, const char *type); + +int fdt_node_is_compatible(const void *fdt, int nodeoffset, + const char *compat); +int fdt_find_compatible_node(const void *fdt, int nodeoffset, + const char *type, const char *compat); struct fdt_property *fdt_get_property(const void *fdt, int nodeoffset, const char *name, int *lenp); diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 1a03109..923c389 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -51,6 +51,33 @@ static int offset_streq(const void *fdt, int offset, } /* + * Checks if the property name matches. + */ +static int prop_name_eq(const void *fdt, int offset, const char *name, + struct fdt_property **prop, int *lenp) +{ + int namestroff, len; + + *prop = fdt_offset_ptr_typed(fdt, offset, *prop); + if (! *prop) + return -FDT_ERR_BADSTRUCTURE; + + namestroff = fdt32_to_cpu((*prop)->nameoff); + if (streq(fdt_string(fdt, namestroff), name)) { + len = fdt32_to_cpu((*prop)->len); + *prop = fdt_offset_ptr(fdt, offset, + sizeof(**prop) + len); + if (*prop) { + if (lenp) + *lenp = len; + return 1; + } else + return -FDT_ERR_BADSTRUCTURE; + } + return 0; +} + +/* * Return a pointer to the string at the given string offset. */ char *fdt_string(const void *fdt, int stroffset) @@ -59,6 +86,118 @@ char *fdt_string(const void *fdt, int stroffset) } /* + * Check if the specified node is compatible by comparing the tokens + * in its "compatible" property with the specified string: + * + * nodeoffset - starting place of the node + * compat - the string to match to one of the tokens in the + * "compatible" list. + */ +int fdt_node_is_compatible(const void *fdt, int nodeoffset, + const char *compat) +{ + const char* cp; + int cplen, len; + + cp = fdt_getprop(fdt, nodeoffset, "compatible", &cplen); + if (cp == NULL) + return 0; + while (cplen > 0) { + if (strncmp(cp, compat, strlen(compat)) == 0) + return 1; + len = strlen(cp) + 1; + cp += len; + cplen -= len; + } + + return 0; +} + +/* + * Find a node by its device type property. On success, the offset of that + * node is returned or an error code otherwise: + * + * nodeoffset - the node to start searching from or 0, the node you pass + * will not be searched, only the next one will; typically, + * you pass 0 to start the search and then what the previous + * call returned. + * type - the device type string to match against. + */ +int fdt_find_node_by_type(const void *fdt, int nodeoffset, const char *type) +{ + int offset, nextoffset; + struct fdt_property *prop; + uint32_t tag; + int len, ret; + + CHECK_HEADER(fdt); + + tag = fdt_next_tag(fdt, nodeoffset, &nextoffset, NULL); + if (tag != FDT_BEGIN_NODE) + return -FDT_ERR_BADOFFSET; + if (nodeoffset) + nodeoffset = 0; /* start searching with next node */ + + while (1) { + offset = nextoffset; + tag = fdt_next_tag(fdt, offset, &nextoffset, NULL); + + switch (tag) { + case FDT_BEGIN_NODE: + nodeoffset = offset; + break; + + case FDT_PROP: + if (nodeoffset == 0) + break; + ret = prop_name_eq(fdt, offset, "device_type", + &prop, &len); + if (ret < 0) + return ret; + else if (ret > 0 && + strncmp(prop->data, type, len - 1) == 0) + return nodeoffset; + break; + + case FDT_END_NODE: + case FDT_NOP: + break; + + case FDT_END: + return -FDT_ERR_NOTFOUND; + + default: + return -FDT_ERR_BADSTRUCTURE; + } + } +} + +/* + * Find a node based on its device type and one of the tokens in its its + * "compatible" property. On success, the offset of that node is returned + * or an error code otherwise: + * + * nodeoffset - the node to start searching from or 0, the node you pass + * will not be searched, only the next one will; typically, + * you pass 0 to start the search and then what the previous + * call returned. + * type - the device type string to match against. + * compat - the string to match to one of the tokens in the + * "compatible" list. + */ +int fdt_find_compatible_node(const void *fdt, int nodeoffset, + const char *type, const char *compat) +{ + int offset; + + offset = fdt_find_node_by_type(fdt, nodeoffset, type); + if (offset < 0 || fdt_node_is_compatible(fdt, offset, compat)) + return offset; + + return -FDT_ERR_NOTFOUND; +} + +/* * Return the node offset of the node specified by: * parentoffset - starting place (0 to start at the root) * name - name being searched for @@ -187,7 +326,6 @@ struct fdt_property *fdt_get_property(const void *fdt, int level = 0; uint32_t tag; struct fdt_property *prop; - int namestroff; int offset, nextoffset; int err; @@ -227,24 +365,11 @@ struct fdt_property *fdt_get_property(const void *fdt, if (level != 0) continue; - err = -FDT_ERR_BADSTRUCTURE; - prop = fdt_offset_ptr_typed(fdt, offset, prop); - if (! prop) - goto fail; - namestroff = fdt32_to_cpu(prop->nameoff); - if (streq(fdt_string(fdt, namestroff), name)) { - /* Found it! */ - int len = fdt32_to_cpu(prop->len); - prop = fdt_offset_ptr(fdt, offset, - sizeof(*prop)+len); - if (! prop) - goto fail; - - if (lenp) - *lenp = len; - + err = prop_name_eq(fdt, offset, name, &prop, lenp); + if (err > 0) return prop; - } + else if (err < 0) + goto fail; break; case FDT_NOP: -- cgit v0.10.2 From 06e19a07701c968f15d72c083b5872a1a11c7b01 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Mon, 21 May 2007 23:27:16 -0400 Subject: For fdt_find_node_by_path(), handle the root path properly. Also removes the special case root path detection in cmd_fdt.c since it is no longer necessary. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 65960c6..7669676 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -52,25 +52,6 @@ static int fdt_parse_prop(char *pathp, char *prop, char *newval, char *data, int *len); static int fdt_print(char *pathp, char *prop, int depth); -static int findnodeoffset(const char *pathp) -{ - int nodeoffset; - - if (strcmp(pathp, "/") == 0) { - nodeoffset = 0; - } else { - nodeoffset = fdt_find_node_by_path (fdt, pathp); - if (nodeoffset < 0) { - /* - * Not found or something else bad happened. - */ - printf ("findnodeoffset() libfdt: %s\n", - fdt_strerror(nodeoffset)); - } - } - return nodeoffset; -} - /* * Flattened Device Tree command, see the help for parameter definitions. */ @@ -187,11 +168,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) pathp = argv[2]; nodep = argv[3]; - nodeoffset = findnodeoffset(pathp); + nodeoffset = fdt_find_node_by_path (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ + printf ("libfdt fdt_find_node_by_path() returned %s\n", + fdt_strerror(nodeoffset)); return 1; } err = fdt_add_subnode(fdt, nodeoffset, nodep); @@ -225,11 +208,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) prop = argv[3]; newval = argv[4]; - nodeoffset = findnodeoffset(pathp); + nodeoffset = fdt_find_node_by_path (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ + printf ("libfdt fdt_find_node_by_path() returned %s\n", + fdt_strerror(nodeoffset)); return 1; } ret = fdt_parse_prop(pathp, prop, newval, data, &len); @@ -283,11 +268,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) * Get the path. The root node is an oddball, the offset * is zero and has no name. */ - nodeoffset = findnodeoffset(argv[2]); + nodeoffset = fdt_find_node_by_path (fdt, argv[2]); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ + printf ("libfdt fdt_find_node_by_path() returned %s\n", + fdt_strerror(nodeoffset)); return 1; } /* @@ -584,11 +571,13 @@ static int fdt_print(char *pathp, char *prop, int depth) int len; /* length of the property */ int level = 0; /* keep track of nesting level */ - nodeoffset = findnodeoffset(pathp); + nodeoffset = fdt_find_node_by_path (fdt, pathp); if (nodeoffset < 0) { /* * Not found or something else bad happened. */ + printf ("libfdt fdt_find_node_by_path() returned %s\n", + fdt_strerror(nodeoffset)); return 1; } /* diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 923c389..ffd9209 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -283,6 +283,10 @@ int fdt_find_node_by_path(const void *fdt, const char *path) if (*path != '/') return -FDT_ERR_BADPATH; + /* Handle the root path: root offset is 0 */ + if (strcmp(path, "/") == 0) + return 0; + while (*p) { const char *q; -- cgit v0.10.2 From 35ec398f16e17df600edc1b38c1e9e62c15c9aa1 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Fri, 25 May 2007 22:08:57 -0400 Subject: Fix fdt_chosen() to call ft_board_setup(), clean up long lines. The fdt_chosen() function was adding/seting some properties ad-hoc improperly and duplicated (poorly) what was done in ft_board_setup() Clean up long lines (setting properties, printing errors). Signed-off-by: Gerald Van Baren diff --git a/common/fdt_support.c b/common/fdt_support.c index efa63f0..d12c751 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -32,6 +32,10 @@ #include #include +#ifdef CONFIG_OF_BOARD_SETUP +void ft_board_setup(void *blob, bd_t *bd); +#endif + /* * Global data (for the gd->bd) */ @@ -42,7 +46,6 @@ DECLARE_GLOBAL_DATA_PTR; */ struct fdt_header *fdt; - /********************************************************************/ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) @@ -50,9 +53,8 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) bd_t *bd = gd->bd; int nodeoffset; int err; - u32 tmp; /* used to set 32 bit integer properties */ - char *str; /* used to set string properties */ - ulong clock; + u32 tmp; /* used to set 32 bit integer properties */ + char *str; /* used to set string properties */ err = fdt_check_header(fdt); if (err < 0) { @@ -60,6 +62,17 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) return err; } +#ifdef CONFIG_OF_BOARD_SETUP + /* + * ft_board_setup() sets various board-specific properties to + * the proper values. + * + * STRICTLY SPEAKING, this is out of place, but it isn't clear + * where a better place would be. + */ + ft_board_setup(fdt, bd); +#endif + if (initrd_start && initrd_end) { struct fdt_reserve_entry re; int used; @@ -72,7 +85,8 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) return err; } if (used >= total) { - printf("WARNING fdt_chosen: no room in the reserved map (%d of %d)\n", + printf("WARNING fdt_chosen: " + "no room in the reserved map (%d of %d)\n", used, total); return -1; } @@ -115,7 +129,10 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) */ nodeoffset = fdt_add_subnode(fdt, 0, "chosen"); if (nodeoffset < 0) { - printf("WARNING fdt_chosen: could not create the \"/chosen node\" (libfdt error %s).\n", fdt_strerror(nodeoffset)); + printf("WARNING fdt_chosen: " + "could not create the \"/chosen node\" " + "(libfdt error %s).\n", + fdt_strerror(nodeoffset)); return nodeoffset; } } @@ -125,42 +142,42 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) */ str = getenv("bootargs"); if (str != NULL) { - err = fdt_setprop(fdt, nodeoffset, "bootargs", str, strlen(str)+1); + err = fdt_setprop(fdt, nodeoffset, + "bootargs", str, strlen(str)+1); if (err < 0) - printf("WARNING fdt_chosen: could not set \"bootargs\" (libfdt error %s).\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: " + "could not set \"bootargs\" " + "(libfdt error %s).\n", + fdt_strerror(err)); } if (initrd_start && initrd_end) { tmp = __cpu_to_be32(initrd_start); - err = fdt_setprop(fdt, nodeoffset, "linux,initrd-start", &tmp, sizeof(tmp)); + err = fdt_setprop(fdt, nodeoffset, + "linux,initrd-start", &tmp, sizeof(tmp)); if (err < 0) - printf("WARNING fdt_chosen: could not set \"linux,initrd-start\" (libfdt error %s).\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: " + "could not set \"linux,initrd-start\" " + "(libfdt error %s).\n", + fdt_strerror(err)); tmp = __cpu_to_be32(initrd_end); - err = fdt_setprop(fdt, nodeoffset, "linux,initrd-end", &tmp, sizeof(tmp)); + err = fdt_setprop(fdt, nodeoffset, + "linux,initrd-end", &tmp, sizeof(tmp)); if (err < 0) - printf("WARNING fdt_chosen: could not set \"linux,initrd-end\" (libfdt error %s).\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: " + "could not set \"linux,initrd-end\" " + "(libfdt error %s).\n", + fdt_strerror(err)); } #ifdef OF_STDOUT_PATH - err = fdt_setprop(fdt, nodeoffset, "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1); + err = fdt_setprop(fdt, nodeoffset, + "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1); if (err < 0) - printf("WARNING fdt_chosen: could not set \"linux,stdout-path\" (libfdt error %s).\n", fdt_strerror(err)); + printf("WARNING fdt_chosen: " + "could not set \"linux,stdout-path\" " + "(libfdt error %s).\n", + fdt_strerror(err)); #endif - nodeoffset = fdt_find_node_by_path (fdt, "/cpus"); - if (nodeoffset >= 0) { - clock = cpu_to_be32(bd->bi_intfreq); - err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4); - if (err < 0) - printf("WARNING fdt_chosen: could not set \"clock-frequency\" (libfdt error %s).\n", fdt_strerror(err)); - } -#ifdef OF_TBCLK - nodeoffset = fdt_find_node_by_path (fdt, "/cpus/" OF_CPU "/timebase-frequency"); - if (nodeoffset >= 0) { - clock = cpu_to_be32(OF_TBCLK); - err = fdt_setprop(fdt, nodeoffset, "clock-frequency", &clock, 4); - if (err < 0) - printf("WARNING fdt_chosen: could not set \"clock-frequency\" (libfdt error %s).\n", fdt_strerror(err)); - } -#endif return err; } @@ -203,7 +220,10 @@ int fdt_env(void *fdt) */ nodeoffset = fdt_add_subnode(fdt, 0, "u-boot-env"); if (nodeoffset < 0) { - printf("WARNING fdt_env: could not create the \"/u-boot-env node\" (libfdt error %s).\n", fdt_strerror(nodeoffset)); + printf("WARNING fdt_env: " + "could not create the \"/u-boot-env node\" " + "(libfdt error %s).\n", + fdt_strerror(nodeoffset)); return nodeoffset; } @@ -231,7 +251,10 @@ int fdt_env(void *fdt) continue; err = fdt_setprop(fdt, nodeoffset, lval, rval, strlen(rval)+1); if (err < 0) { - printf("WARNING fdt_env: could not set \"%s\" (libfdt error %s).\n", lval, fdt_strerror(err)); + printf("WARNING fdt_env: " + "could not set \"%s\" " + "(libfdt error %s).\n", + lval, fdt_strerror(err)); return err; } } @@ -297,7 +320,7 @@ int fdt_bd_t(void *fdt) bd_t *bd = gd->bd; int nodeoffset; int err; - u32 tmp; /* used to set 32 bit integer properties */ + u32 tmp; /* used to set 32 bit integer properties */ int i; err = fdt_check_header(fdt); @@ -323,7 +346,10 @@ int fdt_bd_t(void *fdt) */ nodeoffset = fdt_add_subnode(fdt, 0, "bd_t"); if (nodeoffset < 0) { - printf("WARNING fdt_bd_t: could not create the \"/bd_t node\" (libfdt error %s).\n", fdt_strerror(nodeoffset)); + printf("WARNING fdt_bd_t: " + "could not create the \"/bd_t node\" " + "(libfdt error %s).\n", + fdt_strerror(nodeoffset)); printf("libfdt: %s\n", fdt_strerror(nodeoffset)); return nodeoffset; } @@ -332,20 +358,29 @@ int fdt_bd_t(void *fdt) */ for (i = 0; i < sizeof(bd_map)/sizeof(bd_map[0]); i++) { tmp = cpu_to_be32(getenv("bootargs")); - err = fdt_setprop(fdt, nodeoffset, bd_map[i].name, &tmp, sizeof(tmp)); + err = fdt_setprop(fdt, nodeoffset, + bd_map[i].name, &tmp, sizeof(tmp)); if (err < 0) - printf("WARNING fdt_bd_t: could not set \"%s\" (libfdt error %s).\n", bd_map[i].name, fdt_strerror(err)); + printf("WARNING fdt_bd_t: " + "could not set \"%s\" " + "(libfdt error %s).\n", + bd_map[i].name, fdt_strerror(err)); } /* * Add a couple of oddball entries... */ err = fdt_setprop(fdt, nodeoffset, "enetaddr", &bd->bi_enetaddr, 6); if (err < 0) - printf("WARNING fdt_bd_t: could not set \"enetaddr\" (libfdt error %s).\n", fdt_strerror(err)); + printf("WARNING fdt_bd_t: " + "could not set \"enetaddr\" " + "(libfdt error %s).\n", + fdt_strerror(err)); err = fdt_setprop(fdt, nodeoffset, "ethspeed", &bd->bi_ethspeed, 4); if (err < 0) - printf("WARNING fdt_bd_t: could not set \"ethspeed\" (libfdt error %s).\n", fdt_strerror(err)); - + printf("WARNING fdt_bd_t: " + "could not set \"ethspeed\" " + "(libfdt error %s).\n", + fdt_strerror(err)); return 0; } #endif /* ifdef CONFIG_OF_HAS_BD_T */ -- cgit v0.10.2 From c45874b05aae897a6c29d1a97d4bb708fca2756c Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Mon, 25 Jun 2007 19:52:23 -0400 Subject: Asthetic improvements: error messages and line lengths. Tighten up the error messages, split overlength lines. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 45ab13a..6ce62be 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -362,7 +362,6 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if (i != BZ_OK) { printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i); show_boot_progress (-6); - udelay(100000); do_reset (cmdtp, flag, argc, argv); } break; @@ -741,32 +740,34 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, if(argc > 3) { of_flat_tree = (char *) simple_strtoul(argv[3], NULL, 16); hdr = (image_header_t *)of_flat_tree; -#if defined(CONFIG_OF_LIBFDT) - if (fdt_check_header(of_flat_tree) == 0) { +#if defined(CONFIG_OF_FLAT_TREE) + if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) { #else - if (*(ulong *)of_flat_tree == OF_DT_HEADER) { + if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) { #endif #ifndef CFG_NO_FLASH if (addr2info((ulong)of_flat_tree) != NULL) of_data = (ulong)of_flat_tree; #endif } else if (ntohl(hdr->ih_magic) == IH_MAGIC) { - printf("## Flat Device Tree Image at %08lX\n", hdr); + printf("## Flat Device Tree at %08lX\n", hdr); print_image_hdr(hdr); if ((ntohl(hdr->ih_load) < ((unsigned long)hdr + ntohl(hdr->ih_size) + sizeof(hdr))) && ((ntohl(hdr->ih_load) + ntohl(hdr->ih_size)) > (unsigned long)hdr)) { - puts ("ERROR: Load address overwrites Flat Device Tree uImage\nMust RESET board to recover\n"); + puts ("ERROR: fdt overwritten - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } - printf(" Verifying Checksum ... "); + puts (" Verifying Checksum ... "); memmove (&header, (char *)hdr, sizeof(image_header_t)); checksum = ntohl(header.ih_hcrc); header.ih_hcrc = 0; if(checksum != crc32(0, (uchar *)&header, sizeof(image_header_t))) { - puts ("ERROR: Flat Device Tree header checksum is invalid\nMust RESET board to recover\n"); + puts ("ERROR: fdt header checksum invalid - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } @@ -774,25 +775,29 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, addr = (ulong)((uchar *)(hdr) + sizeof(image_header_t)); if(checksum != crc32(0, (uchar *)addr, ntohl(hdr->ih_size))) { - puts ("ERROR: Flat Device Tree checksum is invalid\nMust RESET board to recover\n"); + puts ("ERROR: fdt checksum invalid - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } - printf("OK\n"); + puts ("OK\n"); if (ntohl(hdr->ih_type) != IH_TYPE_FLATDT) { - puts ("ERROR: uImage not Flat Device Tree type\nMust RESET board to recover\n"); + puts ("ERROR: uImage is not a fdt - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } if (ntohl(hdr->ih_comp) != IH_COMP_NONE) { - puts ("ERROR: uImage is not uncompressed\nMust RESET board to recover\n"); + puts ("ERROR: uImage is compressed - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } -#if defined(CONFIG_OF_LIBFDT) - if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) { -#else +#if defined(CONFIG_OF_FLAT_TREE) if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) { +#else + if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) { #endif - puts ("ERROR: uImage data is not a flat device tree\nMust RESET board to recover\n"); + puts ("ERROR: uImage data is not a fdt - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } @@ -801,10 +806,11 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, ntohl(hdr->ih_size)); of_flat_tree = (char *)ntohl(hdr->ih_load); } else { - puts ("Did not find a flat flat device tree\nMust RESET board to recover\n"); + puts ("Did not find a flat Flat Device Tree.\n" + "Must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } - printf (" Booting using flat device tree at 0x%x\n", + printf (" Booting using the fdt at 0x%x\n", of_flat_tree); } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]) && (len_ptr[2])) { u_long tail = ntohl(len_ptr[0]) % 4; @@ -828,21 +834,23 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, of_data += 4 - tail; } -#if defined(CONFIG_OF_LIBFDT) - if (fdt_check_header((void *)of_data) != 0) { +#if defined(CONFIG_OF_FLAT_TREE) + if (*((ulong *)(of_flat_tree + sizeof(image_header_t))) != OF_DT_HEADER) { #else - if (((struct boot_param_header *)of_data)->magic != OF_DT_HEADER) { + if (fdt_check_header(of_flat_tree + sizeof(image_header_t)) != 0) { #endif - puts ("ERROR: image is not a flat device tree\nMust RESET board to recover\n"); + puts ("ERROR: image is not a fdt - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } -#if defined(CONFIG_OF_LIBFDT) - if (be32_to_cpu(fdt_totalsize(of_data)) != ntohl(len_ptr[2])) { -#else +#if defined(CONFIG_OF_FLAT_TREE) if (((struct boot_param_header *)of_data)->totalsize != ntohl(len_ptr[2])) { +#else + if (be32_to_cpu(fdt_totalsize(of_data)) != ntohl(len_ptr[2])) { #endif - puts ("ERROR: flat device tree size does not agree with image\nMust RESET board to recover\n"); + puts ("ERROR: fdt size != image size - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } } @@ -937,30 +945,35 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, of_start, of_start + of_len - 1); err = fdt_open_into((void *)of_data, (void *)of_start, of_len); if (err != 0) { - printf ("libfdt: %s " __FILE__ " %d\n", fdt_strerror(err), __LINE__); - } - /* - * Add the chosen node if it doesn't exist, add the env and bd_t - * if the user wants it (the logic is in the subroutines). - */ - if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { - puts ("ERROR: Failed creating the /chosen node, aborting.\nMust RESET board to recover\n"); + puts ("ERROR: fdt move failed - " + "must RESET the board to recover.\n"); do_reset (cmdtp, flag, argc, argv); } + } + /* + * Add the chosen node if it doesn't exist, add the env and bd_t + * if the user wants it (the logic is in the subroutines). + */ + if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { + puts ("ERROR: /chosen node create failed - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } #ifdef CONFIG_OF_HAS_UBOOT_ENV - if (fdt_env(of_flat_tree) < 0) { - puts ("ERROR: Failed creating the /u-boot-env node, aborting.\nMust RESET board to recover\n"); - do_reset (cmdtp, flag, argc, argv); - } + if (fdt_env(of_flat_tree) < 0) { + puts ("ERROR: /u-boot-env node create failed - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); + } #endif #ifdef CONFIG_OF_HAS_BD_T - if (fdt_bd_t(of_flat_tree) < 0) { - puts ("ERROR: Failed creating the /bd_t node, aborting.\nMust RESET board to recover\n"); - do_reset (cmdtp, flag, argc, argv); - } -#endif + if (fdt_bd_t(of_flat_tree) < 0) { + puts ("ERROR: /bd_t node create failed - " + "must RESET the board to recover.\n"); + do_reset (cmdtp, flag, argc, argv); } #endif +#endif /* CONFIG_OF_LIBFDT */ #if defined(CONFIG_OF_FLAT_TREE) /* move of_flat_tree if needed */ if (of_data) { @@ -980,30 +993,13 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, of_start, of_start + of_len - 1); memmove ((void *)of_start, (void *)of_data, of_len); } -#endif -#if defined(CONFIG_OF_FLAT_TREE) + /* + * Create the /chosen node and modify the blob with board specific + * values as needed. + */ ft_setup(of_flat_tree, kbd, initrd_start, initrd_end); /* ft_dump_blob(of_flat_tree); */ #endif -#if defined(CONFIG_OF_LIBFDT) - if (fdt_chosen(of_flat_tree, initrd_start, initrd_end, 0) < 0) { - puts ("ERROR: Failed to create the /chosen node, aborting.\nMust RESET board to recover\n"); - do_reset (cmdtp, flag, argc, argv); - } -#ifdef CONFIG_OF_HAS_UBOOT_ENV - if (fdt_env(of_flat_tree) < 0) { - puts ("ERROR: Failed to create the /u-boot-env node, aborting.\nMust RESET board to recover\n"); - do_reset (cmdtp, flag, argc, argv); - } -#endif -#ifdef CONFIG_OF_HAS_BD_T - if (fdt_bd_t(of_flat_tree) < 0) { - puts ("ERROR: Failed to create the /bd_t node, aborting.\nMust RESET board to recover\n"); - do_reset (cmdtp, flag, argc, argv); - } -#endif -#endif /* if defined(CONFIG_OF_LIBFDT) */ - debug ("## Transferring control to Linux (at address %08lx) ...\n", (ulong)kernel); @@ -1017,7 +1013,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, if (of_flat_tree) { /* device tree; boot new style */ /* * Linux Kernel Parameters (passing device tree): - * r3: ptr to flattened device tree, followed by the board info data + * r3: pointer to the fdt, followed by the board info data * r4: physical pointer to the kernel itself * r5: NULL * r6: NULL -- cgit v0.10.2 From 6f35ded9e85493595e0eb66a82b502a95326d049 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Mon, 25 Jun 2007 20:55:58 -0400 Subject: Tighten up the error messages. Signed-off-by: Gerald Van Baren diff --git a/common/fdt_support.c b/common/fdt_support.c index d12c751..ec04a63 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -130,8 +130,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) nodeoffset = fdt_add_subnode(fdt, 0, "chosen"); if (nodeoffset < 0) { printf("WARNING fdt_chosen: " - "could not create the \"/chosen node\" " - "(libfdt error %s).\n", + "could not create the /chosen node (%s).\n", fdt_strerror(nodeoffset)); return nodeoffset; } @@ -146,8 +145,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) "bootargs", str, strlen(str)+1); if (err < 0) printf("WARNING fdt_chosen: " - "could not set \"bootargs\" " - "(libfdt error %s).\n", + "could not set bootargs (%s).\n", fdt_strerror(err)); } if (initrd_start && initrd_end) { @@ -156,16 +154,14 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) "linux,initrd-start", &tmp, sizeof(tmp)); if (err < 0) printf("WARNING fdt_chosen: " - "could not set \"linux,initrd-start\" " - "(libfdt error %s).\n", + "could not set linux,initrd-start (%s).\n", fdt_strerror(err)); tmp = __cpu_to_be32(initrd_end); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-end", &tmp, sizeof(tmp)); if (err < 0) printf("WARNING fdt_chosen: " - "could not set \"linux,initrd-end\" " - "(libfdt error %s).\n", + "could not set linux,initrd-end (%s).\n", fdt_strerror(err)); } #ifdef OF_STDOUT_PATH @@ -173,8 +169,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1); if (err < 0) printf("WARNING fdt_chosen: " - "could not set \"linux,stdout-path\" " - "(libfdt error %s).\n", + "could not set linux,stdout-path (%s).\n", fdt_strerror(err)); #endif @@ -221,8 +216,7 @@ int fdt_env(void *fdt) nodeoffset = fdt_add_subnode(fdt, 0, "u-boot-env"); if (nodeoffset < 0) { printf("WARNING fdt_env: " - "could not create the \"/u-boot-env node\" " - "(libfdt error %s).\n", + "could not create the /u-boot-env node (%s).\n", fdt_strerror(nodeoffset)); return nodeoffset; } @@ -252,8 +246,7 @@ int fdt_env(void *fdt) err = fdt_setprop(fdt, nodeoffset, lval, rval, strlen(rval)+1); if (err < 0) { printf("WARNING fdt_env: " - "could not set \"%s\" " - "(libfdt error %s).\n", + "could not set %s (%s).\n", lval, fdt_strerror(err)); return err; } @@ -347,8 +340,7 @@ int fdt_bd_t(void *fdt) nodeoffset = fdt_add_subnode(fdt, 0, "bd_t"); if (nodeoffset < 0) { printf("WARNING fdt_bd_t: " - "could not create the \"/bd_t node\" " - "(libfdt error %s).\n", + "could not create the /bd_t node (%s).\n", fdt_strerror(nodeoffset)); printf("libfdt: %s\n", fdt_strerror(nodeoffset)); return nodeoffset; @@ -362,8 +354,7 @@ int fdt_bd_t(void *fdt) bd_map[i].name, &tmp, sizeof(tmp)); if (err < 0) printf("WARNING fdt_bd_t: " - "could not set \"%s\" " - "(libfdt error %s).\n", + "could not set %s (%s).\n", bd_map[i].name, fdt_strerror(err)); } /* @@ -372,14 +363,12 @@ int fdt_bd_t(void *fdt) err = fdt_setprop(fdt, nodeoffset, "enetaddr", &bd->bi_enetaddr, 6); if (err < 0) printf("WARNING fdt_bd_t: " - "could not set \"enetaddr\" " - "(libfdt error %s).\n", + "could not set enetaddr (%s).\n", fdt_strerror(err)); err = fdt_setprop(fdt, nodeoffset, "ethspeed", &bd->bi_ethspeed, 4); if (err < 0) printf("WARNING fdt_bd_t: " - "could not set \"ethspeed\" " - "(libfdt error %s).\n", + "could not set ethspeed (%s).\n", fdt_strerror(err)); return 0; } -- cgit v0.10.2 From fd61e55dd8cb52ce3ff91b3917af26e24b6b0845 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Mon, 25 Jun 2007 23:25:28 -0400 Subject: Create new fdt boardsetup command, fix bug parsing [] form of set values. Previously ft_board_setup() was called by fdt_chosen() which was not really correctly structured. This splits ft_board_setup() out by creating a new fdt boardsetup command. Fix a bug when parsing fdt set command values which have the square bracket form [00 11 22 33] - the length was updated incorrectly in when parsing that form. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 7669676..824088c 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -37,7 +37,7 @@ #include #define MAX_LEVEL 32 /* how deeply nested we will go */ -#define SCRATCHPAD 1024 /* bytes of scratchpad memory */ +#define SCRATCHPAD 1024 /* bytes of scratchpad memory */ /* * Global data (for the gd->bd) @@ -47,6 +47,10 @@ DECLARE_GLOBAL_DATA_PTR; /* * Function prototypes/declarations. */ +#ifdef CONFIG_OF_BOARD_SETUP +void ft_board_setup(void *blob, bd_t *bd); +#endif + static int fdt_valid(void); static int fdt_parse_prop(char *pathp, char *prop, char *newval, char *data, int *len); @@ -297,6 +301,13 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) } } +#ifdef CONFIG_OF_BOARD_SETUP + /******************************************************************** + * Call the board-specific fixup routine + ********************************************************************/ + } else if (argv[1][0] == 'b') { + ft_board_setup(fdt, gd->bd); +#endif /******************************************************************** * Create a chosen node ********************************************************************/ @@ -429,7 +440,7 @@ static int fdt_parse_prop(char *pathp, char *prop, char *newval, while ((*newval != ']') && (*newval != '\0')) { tmp = simple_strtoul(newval, &newval, 16); *data++ = tmp & 0xFF; - *len++; + *len = *len + 1; while (*newval == ' ') newval++; } @@ -673,25 +684,25 @@ U_BOOT_CMD( fdt, 5, 0, do_fdt, "fdt - flattened device tree utility commands\n", "addr [] - Set the fdt location to \n" +#ifdef CONFIG_OF_BOARD_SETUP + "fdt boardsetup - Do board-specific set up\n" +#endif "fdt move - Copy the fdt to \n" "fdt print [] - Recursive print starting at \n" "fdt list [] - Print one level starting at \n" "fdt set [] - Set [to ]\n" "fdt mknode - Create a new node after \n" "fdt rm [] - Delete the node or \n" - "fdt chosen - Add/update the \"/chosen\" branch in the tree\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" + "fdt env - Add/replace the /u-boot-env branch in the tree\n" #endif #ifdef CONFIG_OF_HAS_BD_T - "fdt bd_t - Add/replace the \"/bd_t\" branch in the tree\n" + "fdt bd_t - Add/replace the /bd_t branch in the tree\n" #endif "Hints:\n" - " * If the property you are setting/printing has a '#' character,\n" - " you MUST escape it with a \\ character or quote it with \" or\n" - " it will be ignored as a comment.\n" - " * If the value has spaces in it, you MUST escape the spaces with\n" - " \\ characters or quote it with \"\"\n" + " If the property you are setting/printing has a '#' character or spaces,\n" + " you MUST escape it with a \\ character or quote it with \".\n" "Examples: fdt print / # print the whole tree\n" " fdt print /cpus \"#address-cells\"\n" " fdt set /cpus \"#address-cells\" \"[00 00 00 01]\"\n" diff --git a/common/fdt_support.c b/common/fdt_support.c index ec04a63..259bd42 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -32,10 +32,6 @@ #include #include -#ifdef CONFIG_OF_BOARD_SETUP -void ft_board_setup(void *blob, bd_t *bd); -#endif - /* * Global data (for the gd->bd) */ @@ -62,17 +58,6 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) return err; } -#ifdef CONFIG_OF_BOARD_SETUP - /* - * ft_board_setup() sets various board-specific properties to - * the proper values. - * - * STRICTLY SPEAKING, this is out of place, but it isn't clear - * where a better place would be. - */ - ft_board_setup(fdt, bd); -#endif - if (initrd_start && initrd_end) { struct fdt_reserve_entry re; int used; -- cgit v0.10.2 From e125a2ffc209dd34794e326c7175658253beadf3 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Tue, 10 Jul 2007 20:40:39 -0400 Subject: Call ft_board_setup() from the bootm command. In the patch titled "Create new fdt boardsetup command..." I removed the call to ft_board_setup() from the routine fdt_chosen(), but I forgot to add a direct call back into cmd_bootm.c This fixes the oversight by adding the direct call to the bootm command. Signed-off-by: Gerald Van Baren diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 6ce62be..981ffc5 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -973,6 +973,10 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, do_reset (cmdtp, flag, argc, argv); } #endif +#ifdef CONFIG_OF_BOARD_SETUP + /* Call the board-specific fixup routine */ + ft_board_setup(fdt, gd->bd); +#endif #endif /* CONFIG_OF_LIBFDT */ #if defined(CONFIG_OF_FLAT_TREE) /* move of_flat_tree if needed */ diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 824088c..9ddec47 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -44,13 +44,6 @@ */ DECLARE_GLOBAL_DATA_PTR; -/* - * Function prototypes/declarations. - */ -#ifdef CONFIG_OF_BOARD_SETUP -void ft_board_setup(void *blob, bd_t *bd); -#endif - static int fdt_valid(void); static int fdt_parse_prop(char *pathp, char *prop, char *newval, char *data, int *len); diff --git a/include/fdt_support.h b/include/fdt_support.h index a276834..60fa423 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -38,5 +38,11 @@ int fdt_env(void *fdt); int fdt_bd_t(void *fdt); #endif +#ifdef CONFIG_OF_BOARD_SETUP +void ft_board_setup(void *blob, bd_t *bd); +void ft_cpu_setup(void *blob, bd_t *bd); +void ft_pci_setup(void *blob, bd_t *bd); +#endif + #endif /* ifdef CONFIG_OF_LIBFDT */ #endif /* ifndef __FDT_SUPPORT_H */ -- cgit v0.10.2 From 91148bf7aeba142d6f348805db7625db7da64d6f Mon Sep 17 00:00:00 2001 From: Kim Phillips Date: Tue, 17 Jul 2007 13:56:53 -0500 Subject: fdt: do board setup based on fdt address specified on bootm line The last fdt patch to bootm did board setup based on the address specified by a prior fdt address command invocation. The bootm code, as its call to fdt_chosen does, should use the fdt specified by the user on the bootm command. Note this restores full functionality for the 8360's existing default boot environment values, e.g. 'run nfsboot' (i.e. no having to 'fdt addr $fdtaddr' before booting a kernel). Signed-off-by: Kim Phillips diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 981ffc5..e19f83e 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -975,7 +975,7 @@ do_bootm_linux (cmd_tbl_t *cmdtp, int flag, #endif #ifdef CONFIG_OF_BOARD_SETUP /* Call the board-specific fixup routine */ - ft_board_setup(fdt, gd->bd); + ft_board_setup(of_flat_tree, gd->bd); #endif #endif /* CONFIG_OF_LIBFDT */ #if defined(CONFIG_OF_FLAT_TREE) -- cgit v0.10.2 From 99dffca3b7590a16a00bc475c860b67b2a3f1462 Mon Sep 17 00:00:00 2001 From: Kim Phillips Date: Tue, 17 Jul 2007 13:57:04 -0500 Subject: fdt: allow for builds that don't want env and bd_t nodes protect fdt_env and fdt_bd_t invocations, fix codingstyle while in the area. Signed-off-by: Kim Phillips diff --git a/common/cmd_fdt.c b/common/cmd_fdt.c index 9ddec47..571b8f1 100644 --- a/common/cmd_fdt.c +++ b/common/cmd_fdt.c @@ -293,36 +293,28 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) return err; } } - + } #ifdef CONFIG_OF_BOARD_SETUP - /******************************************************************** - * Call the board-specific fixup routine - ********************************************************************/ - } else if (argv[1][0] == 'b') { + /* Call the board-specific fixup routine */ + else if (argv[1][0] == 'b') ft_board_setup(fdt, gd->bd); #endif - /******************************************************************** - * Create a chosen node - ********************************************************************/ - } else if (argv[1][0] == 'c') { + /* Create a chosen node */ + else if (argv[1][0] == 'c') fdt_chosen(fdt, 0, 0, 1); - /******************************************************************** - * Create a u-boot-env node - ********************************************************************/ - } else if (argv[1][0] == 'e') { +#ifdef CONFIG_OF_HAS_UBOOT_ENV + /* Create a u-boot-env node */ + else if (argv[1][0] == 'e') fdt_env(fdt); - - /******************************************************************** - * Create a bd_t node - ********************************************************************/ - } else if (argv[1][0] == 'b') { +#endif +#ifdef CONFIG_OF_HAS_BD_T + /* Create a bd_t node */ + else if (argv[1][0] == 'b') fdt_bd_t(fdt); - - /******************************************************************** - * Unrecognized command - ********************************************************************/ - } else { +#endif + else { + /* Unrecognized command */ printf ("Usage:\n%s\n", cmdtp->usage); return 1; } -- cgit v0.10.2 From 5fe6be6208dda852c3564e384bd78d75784dea3e Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Tue, 7 Aug 2007 21:14:22 -0400 Subject: Improve error print messages. Signed-off-by: Gerald Van Baren diff --git a/common/fdt_support.c b/common/fdt_support.c index 259bd42..caaa682 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -54,7 +54,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) err = fdt_check_header(fdt); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("fdt_chosen: %s\n", fdt_strerror(err)); return err; } @@ -66,11 +66,11 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) err = fdt_num_reservemap(fdt, &used, &total); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("fdt_chosen: %s\n", fdt_strerror(err)); return err; } if (used >= total) { - printf("WARNING fdt_chosen: " + printf("WARNING: " "no room in the reserved map (%d of %d)\n", used, total); return -1; @@ -88,7 +88,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) err = fdt_replace_reservemap_entry(fdt, j, initrd_start, initrd_end - initrd_start + 1); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("fdt_chosen: %s\n", fdt_strerror(err)); return err; } } @@ -114,8 +114,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) */ nodeoffset = fdt_add_subnode(fdt, 0, "chosen"); if (nodeoffset < 0) { - printf("WARNING fdt_chosen: " - "could not create the /chosen node (%s).\n", + printf("WARNING: could not create /chosen %s.\n", fdt_strerror(nodeoffset)); return nodeoffset; } @@ -129,8 +128,7 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) err = fdt_setprop(fdt, nodeoffset, "bootargs", str, strlen(str)+1); if (err < 0) - printf("WARNING fdt_chosen: " - "could not set bootargs (%s).\n", + printf("WARNING: could not set bootargs %s.\n", fdt_strerror(err)); } if (initrd_start && initrd_end) { @@ -138,23 +136,21 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) err = fdt_setprop(fdt, nodeoffset, "linux,initrd-start", &tmp, sizeof(tmp)); if (err < 0) - printf("WARNING fdt_chosen: " - "could not set linux,initrd-start (%s).\n", + printf("WARNING: " + "could not set linux,initrd-start %s.\n", fdt_strerror(err)); tmp = __cpu_to_be32(initrd_end); err = fdt_setprop(fdt, nodeoffset, "linux,initrd-end", &tmp, sizeof(tmp)); if (err < 0) - printf("WARNING fdt_chosen: " - "could not set linux,initrd-end (%s).\n", + printf("WARNING: could not set linux,initrd-end %s.\n", fdt_strerror(err)); } #ifdef OF_STDOUT_PATH err = fdt_setprop(fdt, nodeoffset, "linux,stdout-path", OF_STDOUT_PATH, strlen(OF_STDOUT_PATH)+1); if (err < 0) - printf("WARNING fdt_chosen: " - "could not set linux,stdout-path (%s).\n", + printf("WARNING: could not set linux,stdout-path %s.\n", fdt_strerror(err)); #endif @@ -179,7 +175,7 @@ int fdt_env(void *fdt) err = fdt_check_header(fdt); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("fdt_env: %s\n", fdt_strerror(err)); return err; } @@ -191,7 +187,7 @@ int fdt_env(void *fdt) if (nodeoffset >= 0) { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("fdt_env: %s\n", fdt_strerror(err)); return err; } } @@ -200,8 +196,7 @@ int fdt_env(void *fdt) */ nodeoffset = fdt_add_subnode(fdt, 0, "u-boot-env"); if (nodeoffset < 0) { - printf("WARNING fdt_env: " - "could not create the /u-boot-env node (%s).\n", + printf("WARNING: could not create /u-boot-env %s.\n", fdt_strerror(nodeoffset)); return nodeoffset; } @@ -230,8 +225,7 @@ int fdt_env(void *fdt) continue; err = fdt_setprop(fdt, nodeoffset, lval, rval, strlen(rval)+1); if (err < 0) { - printf("WARNING fdt_env: " - "could not set %s (%s).\n", + printf("WARNING: could not set %s %s.\n", lval, fdt_strerror(err)); return err; } @@ -303,7 +297,7 @@ int fdt_bd_t(void *fdt) err = fdt_check_header(fdt); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("fdt_bd_t: %s\n", fdt_strerror(err)); return err; } @@ -315,7 +309,7 @@ int fdt_bd_t(void *fdt) if (nodeoffset >= 0) { err = fdt_del_node(fdt, nodeoffset); if (err < 0) { - printf("libfdt: %s\n", fdt_strerror(err)); + printf("fdt_bd_t: %s\n", fdt_strerror(err)); return err; } } @@ -324,10 +318,9 @@ int fdt_bd_t(void *fdt) */ nodeoffset = fdt_add_subnode(fdt, 0, "bd_t"); if (nodeoffset < 0) { - printf("WARNING fdt_bd_t: " - "could not create the /bd_t node (%s).\n", + printf("WARNING: could not create /bd_t %s.\n", fdt_strerror(nodeoffset)); - printf("libfdt: %s\n", fdt_strerror(nodeoffset)); + printf("fdt_bd_t: %s\n", fdt_strerror(nodeoffset)); return nodeoffset; } /* @@ -338,8 +331,7 @@ int fdt_bd_t(void *fdt) err = fdt_setprop(fdt, nodeoffset, bd_map[i].name, &tmp, sizeof(tmp)); if (err < 0) - printf("WARNING fdt_bd_t: " - "could not set %s (%s).\n", + printf("WARNING: could not set %s %s.\n", bd_map[i].name, fdt_strerror(err)); } /* @@ -347,13 +339,11 @@ int fdt_bd_t(void *fdt) */ err = fdt_setprop(fdt, nodeoffset, "enetaddr", &bd->bi_enetaddr, 6); if (err < 0) - printf("WARNING fdt_bd_t: " - "could not set enetaddr (%s).\n", + printf("WARNING: could not set enetaddr %s.\n", fdt_strerror(err)); err = fdt_setprop(fdt, nodeoffset, "ethspeed", &bd->bi_ethspeed, 4); if (err < 0) - printf("WARNING fdt_bd_t: " - "could not set ethspeed (%s).\n", + printf("WARNING: could not set ethspeed %s.\n", fdt_strerror(err)); return 0; } -- cgit v0.10.2