fdt: Check if the FDT address is configured
authorMarek Vasut <marex@denx.de>
Wed, 5 Sep 2012 06:34:44 +0000 (08:34 +0200)
committerGerald Van Baren <gvb@unssw.com>
Sat, 15 Sep 2012 13:16:08 +0000 (09:16 -0400)
In case the "fdt addr" command wasn't ran yet and any other "fdt"
subcommand was issued, the system crashed due to NULL pointer being
used.

This is caused by "fdt addr" command setting up a pointer to the
FDT memory location. Prior issuing "fdt addr", the pointer is NULL
so calling any other subcommands crashed the u-boot.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Simon Glass <sjg@chromium.org>
common/cmd_fdt.c

index 9a5c53ec06c76ae15706d6f2f86a715c7893fe96..e2225c4d5c64e188b50a2f9f205426dac11ba5df 100644 (file)
@@ -114,10 +114,21 @@ int do_fdt (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
                        }
                }
 
+               return CMD_RET_SUCCESS;
+       }
+
+       if (!working_fdt) {
+               puts(
+                       "No FDT memory address configured. Please configure\n"
+                       "the FDT address via \"fdt addr <address>\" command.\n"
+                       "Aborting!\n");
+               return CMD_RET_FAILURE;
+       }
+
        /*
         * Move the working_fdt
         */
-       } else if (strncmp(argv[1], "mo", 2) == 0) {
+       if (strncmp(argv[1], "mo", 2) == 0) {
                struct fdt_header *newaddr;
                int  len;
                int  err;