]> git.sur5r.net Git - u-boot/commitdiff
fdt: refactor initrd related code
authorKumar Gala <galak@kernel.crashing.org>
Fri, 15 Aug 2008 13:24:43 +0000 (08:24 -0500)
committerWolfgang Denk <wd@denx.de>
Tue, 26 Aug 2008 21:45:20 +0000 (23:45 +0200)
Created a new fdt_initrd() to deal with setting the initrd properties
in the device tree and fixing up the mem reserve.  We can use this
both in the choosen node handling and lets us remove some duplicated
code when we fixup the initrd info in bootm on PPC.

Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
common/fdt_support.c
include/fdt_support.h
lib_ppc/bootm.c

index c0ca9e0600937237075677b5db0d65e8b48f884f..a7773aba0799cbce54dfe4820c2acc8ff645af0b 100644 (file)
@@ -99,44 +99,85 @@ static int fdt_fixup_stdout(void *fdt, int chosenoff)
 }
 #endif
 
-int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
+int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force)
 {
        int   nodeoffset;
-       int   err;
-       u32   tmp;              /* used to set 32 bit integer properties */
-       char  *str;             /* used to set string properties */
+       int   err, j, total;
+       u32   tmp;
        const char *path;
+       uint64_t addr, size;
 
-       err = fdt_check_header(fdt);
-       if (err < 0) {
-               printf("fdt_chosen: %s\n", fdt_strerror(err));
-               return err;
+       /* Find the "chosen" node.  */
+       nodeoffset = fdt_path_offset (fdt, "/chosen");
+
+       /* If there is no "chosen" node in the blob return */
+       if (nodeoffset < 0) {
+               printf("fdt_initrd: %s\n", fdt_strerror(nodeoffset));
+               return nodeoffset;
        }
 
-       if (initrd_start && initrd_end) {
-               uint64_t addr, size;
-               int  total = fdt_num_mem_rsv(fdt);
-               int  j;
+       /* just return if initrd_start/end aren't valid */
+       if ((initrd_start == 0) || (initrd_end == 0))
+               return 0;
 
-               /*
-                * 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 < total; j++) {
-                       err = fdt_get_mem_rsv(fdt, j, &addr, &size);
-                       if (addr == initrd_start) {
-                               fdt_del_mem_rsv(fdt, j);
-                               break;
-                       }
+       total = fdt_num_mem_rsv(fdt);
+
+       /*
+        * 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 < total; j++) {
+               err = fdt_get_mem_rsv(fdt, j, &addr, &size);
+               if (addr == initrd_start) {
+                       fdt_del_mem_rsv(fdt, j);
+                       break;
                }
+       }
 
-               err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1);
+       err = fdt_add_mem_rsv(fdt, initrd_start, initrd_end - initrd_start + 1);
+       if (err < 0) {
+               printf("fdt_initrd: %s\n", fdt_strerror(err));
+               return err;
+       }
+
+       path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
+       if ((path == NULL) || force) {
+               tmp = __cpu_to_be32(initrd_start);
+               err = fdt_setprop(fdt, nodeoffset,
+                       "linux,initrd-start", &tmp, sizeof(tmp));
+               if (err < 0) {
+                       printf("WARNING: "
+                               "could not set linux,initrd-start %s.\n",
+                               fdt_strerror(err));
+                       return err;
+               }
+               tmp = __cpu_to_be32(initrd_end);
+               err = fdt_setprop(fdt, nodeoffset,
+                       "linux,initrd-end", &tmp, sizeof(tmp));
                if (err < 0) {
-                       printf("fdt_chosen: %s\n", fdt_strerror(err));
+                       printf("WARNING: could not set linux,initrd-end %s.\n",
+                               fdt_strerror(err));
+
                        return err;
                }
        }
 
+       return 0;
+}
+
+int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
+{
+       int   nodeoffset;
+       int   err;
+       char  *str;             /* used to set string properties */
+       const char *path;
+
+       err = fdt_check_header(fdt);
+       if (err < 0) {
+               printf("fdt_chosen: %s\n", fdt_strerror(err));
+               return err;
+       }
+
        /*
         * Find the "chosen" node.
         */
@@ -173,24 +214,8 @@ int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force)
                                        fdt_strerror(err));
                }
        }
-       if (initrd_start && initrd_end) {
-               path = fdt_getprop(fdt, nodeoffset, "linux,initrd-start", NULL);
-               if ((path == NULL) || force) {
-                       tmp = __cpu_to_be32(initrd_start);
-                       err = fdt_setprop(fdt, nodeoffset,
-                               "linux,initrd-start", &tmp, sizeof(tmp));
-                       if (err < 0)
-                               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: could not set linux,initrd-end %s.\n",
-                                       fdt_strerror(err));
-               }
-       }
+
+       fdt_initrd(fdt, initrd_start, initrd_end, force);
 
 #ifdef CONFIG_OF_STDOUT_VIA_ALIAS
        path = fdt_getprop(fdt, nodeoffset, "linux,stdout-path", NULL);
index aa0fc5801af16d573f887ff39219570524523986..424c3c6b7e0c804fc0fbf5acdedd5cb630759c20 100644 (file)
@@ -29,6 +29,7 @@
 #include <fdt.h>
 
 int fdt_chosen(void *fdt, ulong initrd_start, ulong initrd_end, int force);
+int fdt_initrd(void *fdt, ulong initrd_start, ulong initrd_end, int force);
 void do_fixup_by_path(void *fdt, const char *path, const char *prop,
                      const void *val, int len, int create);
 void do_fixup_by_path_u32(void *fdt, const char *path, const char *prop,
index 300e00a2dab6df3d737ef89748009c43c26f8266..9892aface7e19030c65087e7b75c22245d102715 100644 (file)
@@ -182,32 +182,8 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
 
 #if defined(CONFIG_OF_LIBFDT)
        /* fixup the initrd now that we know where it should be */
-       if ((of_flat_tree) && (initrd_start && initrd_end)) {
-               uint64_t addr, size;
-               int  total = fdt_num_mem_rsv(of_flat_tree);
-               int  j;
-
-               /* Look for the dummy entry and delete it */
-               for (j = 0; j < total; j++) {
-                       fdt_get_mem_rsv(of_flat_tree, j, &addr, &size);
-                       if (addr == images->rd_start) {
-                               fdt_del_mem_rsv(of_flat_tree, j);
-                               break;
-                       }
-               }
-
-               ret = fdt_add_mem_rsv(of_flat_tree, initrd_start,
-                                       initrd_end - initrd_start + 1);
-               if (ret < 0) {
-                       printf("fdt_chosen: %s\n", fdt_strerror(ret));
-                       goto error;
-               }
-
-               do_fixup_by_path_u32(of_flat_tree, "/chosen",
-                                       "linux,initrd-start", initrd_start, 0);
-               do_fixup_by_path_u32(of_flat_tree, "/chosen",
-                                       "linux,initrd-end", initrd_end, 0);
-       }
+       if ((of_flat_tree) && (initrd_start && initrd_end))
+               fdt_initrd(of_flat_tree, initrd_start, initrd_end, 1);
 #endif
        debug ("## Transferring control to Linux (at address %08lx) ...\n",
                (ulong)kernel);