From c28abb9c614f65ce2096cc4a66fc886c77d0e5a4 Mon Sep 17 00:00:00 2001 From: Gerald Van Baren Date: Sat, 14 Apr 2007 22:51:24 -0400 Subject: Improve the bootm command for CONFIG_OF_LIBFDT In bootm, create the "/chosen" node only if it doesn't already exist (better matches the previous behavior). Update for proper reserved memory map handling for initrd. --- common/fdt_support.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'common/fdt_support.c') diff --git a/common/fdt_support.c b/common/fdt_support.c index 14a4df5fa..91b729f37 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -55,9 +55,33 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force) return err; } -#warning "Don't double-add the reserved map" if (initrd_start && initrd_end) { - err = fdt_add_reservemap_entry(fdt, + struct fdt_reserve_entry *re; + int used; + int total; + int j; + + err = fdt_num_reservemap(fdt, &used, &total); + if (err < 0) { + printf("libfdt: %s\n", fdt_strerror(err)); + return err; + } + if (used >= total) { + printf("fdt_chosen: no room in the reserved map (%d of %d)\n", + used, total); + return -1; + } + /* + * Look for an existing entry and update it. If we don't find + * the entry, we will j be the next available slot. + */ + for (j = 0; j < used; j++) { + err = fdt_get_reservemap(fdt, j, &re); + if (re->address == initrd_start) { + break; + } + } + err = fdt_replace_reservemap_entry(fdt, j, initrd_start, initrd_end - initrd_start + 1); if (err < 0) { printf("libfdt: %s\n", fdt_strerror(err)); @@ -202,13 +226,13 @@ int fdt_env(void *fdt) continue; err = fdt_setprop(fdt, nodeoffset, lval, rval, strlen(rval)+1); if (err < 0) { - printf("libfdt: %s\n", lval, fdt_strerror(err)); + printf("libfdt: %s\n", fdt_strerror(err)); return err; } } return 0; } -#endif /* CONFIG_OF_HAS_UBOOT_ENV */ +#endif /* ifdef CONFIG_OF_HAS_UBOOT_ENV */ /********************************************************************/ @@ -318,6 +342,6 @@ int fdt_bd_t(void *fdt) return 0; } -#endif /* CONFIG_OF_HAS_BD_T */ +#endif /* ifdef CONFIG_OF_HAS_BD_T */ #endif /* CONFIG_OF_LIBFDT */ -- cgit v1.2.3