[U-Boot-Users] [PATCH 4/9] [new uImage] rework error handling so common functions don't reset
Kumar Gala
galak at kernel.crashing.org
Thu Feb 28 04:51:46 CET 2008
Changed image_get_ramdisk() to just return NULL on error and have
get_ramdisk() propogate that error to the caller. It's left to the
caller to call do_reset() if it wants to.
Also moved calling do_reset() in get_fdt() and fdt_relocate() on ppc
to a common location. In the future we will change get_fdt() and
fdt_relocate() to return success/failure and not call do_reset() at all.
Signed-off-by: Kumar Gala <galak at kernel.crashing.org>
---
common/image.c | 26 ++++++++++++++--------
include/image.h | 2 +-
lib_m68k/bootm.c | 13 ++++++++++-
lib_ppc/bootm.c | 61 ++++++++++++++++++++++++++++++++++++-----------------
4 files changed, 70 insertions(+), 32 deletions(-)
diff --git a/common/image.c b/common/image.c
index 92c067f..d4acb6b 100644
--- a/common/image.c
+++ b/common/image.c
@@ -51,8 +51,6 @@
#include <fdt_support.h>
#endif
-extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
-
#ifdef CONFIG_CMD_BDI
extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
#endif
@@ -491,7 +489,7 @@ ulong gen_get_image (ulong img_addr)
*
* returns:
* pointer to a ramdisk image header, if image was found and valid
- * otherwise, board is reset
+ * otherwise, return NULL
*/
static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
int argc, char *argv[],
@@ -505,13 +503,13 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
if (!image_check_magic (rd_hdr)) {
puts ("Bad Magic Number\n");
show_boot_progress (-10);
- do_reset (cmdtp, flag, argc, argv);
+ return NULL;
}
if (!image_check_hcrc (rd_hdr)) {
puts ("Bad Header Checksum\n");
show_boot_progress (-11);
- do_reset (cmdtp, flag, argc, argv);
+ return NULL;
}
show_boot_progress (10);
@@ -522,7 +520,7 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) {
puts ("Bad Data CRC\n");
show_boot_progress (-12);
- do_reset (cmdtp, flag, argc, argv);
+ return NULL;
}
puts("OK\n");
}
@@ -535,7 +533,7 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
printf ("No Linux %s Ramdisk Image\n",
image_get_arch_name(arch));
show_boot_progress (-13);
- do_reset (cmdtp, flag, argc, argv);
+ return NULL;
}
return rd_hdr;
@@ -561,9 +559,9 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
* rd_start and rd_end are set to ramdisk start/end addresses if
* ramdisk image is found and valid
* rd_start and rd_end are set to 0 if no ramdisk exists
- * board is reset if ramdisk image is found but corrupted
+ * return 1 if ramdisk image is found but corrupted
*/
-void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images, uint8_t arch,
ulong *rd_start, ulong *rd_end)
{
@@ -630,6 +628,12 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
rd_hdr = image_get_ramdisk (cmdtp, flag, argc, argv,
rd_addr, arch, images->verify);
+ if (rd_hdr == NULL) {
+ *rd_start = 0;
+ *rd_end = 0;
+ return 1;
+ }
+
rd_data = image_get_data (rd_hdr);
rd_len = image_get_data_size (rd_hdr);
rd_load = image_get_load (rd_hdr);
@@ -639,7 +643,7 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
fit_hdr = (void *)rd_addr;
debug ("* ramdisk: FIT format image\n");
fit_unsupported_reset ("ramdisk");
- do_reset (cmdtp, flag, argc, argv);
+ return 1;
#endif
default:
printf ("Wrong Image Format for %s command\n",
@@ -687,6 +691,8 @@ void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
}
debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
*rd_start, *rd_end);
+
+ return 0;
}
#if defined(CONFIG_PPC) || defined(CONFIG_M68K)
diff --git a/include/image.h b/include/image.h
index 1cec1db..025ec0f 100644
--- a/include/image.h
+++ b/include/image.h
@@ -382,7 +382,7 @@ void image_print_contents (image_header_t *hdr);
int gen_image_get_format (void *img_addr);
ulong gen_get_image (ulong img_addr);
-void get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images, uint8_t arch,
ulong *rd_start, ulong *rd_end);
diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c
index 74240af..c9d2a27 100644
--- a/lib_m68k/bootm.c
+++ b/lib_m68k/bootm.c
@@ -35,6 +35,8 @@
DECLARE_GLOBAL_DATA_PTR;
+extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+
#define PHYSADDR(x) x
#define LINUX_MAX_ENVS 256
@@ -52,6 +54,7 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
ulong rd_data_start, rd_data_end, rd_len;
ulong initrd_start, initrd_end;
+ int ret;
ulong cmd_start, cmd_end;
bd_t *kbd;
@@ -95,9 +98,12 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
/* find ramdisk */
- get_ramdisk (cmdtp, flag, argc, argv, images,
+ ret = get_ramdisk (cmdtp, flag, argc, argv, images,
IH_ARCH_M68K, &rd_data_start, &rd_data_end);
+ if (ret)
+ goto error;
+
rd_len = rd_data_end - rd_data_start;
alloc_current = ramdisk_high (alloc_current, rd_data_start, rd_len,
sp_limit, get_sp (), &initrd_start, &initrd_end);
@@ -117,6 +123,11 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
*/
(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
/* does not return */
+ return ;
+
+error:
+ do_reset (cmdtp, flag, argc, argv);
+ return ;
}
static ulong get_sp (void)
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c
index de6995e..9f48b8d 100644
--- a/lib_ppc/bootm.c
+++ b/lib_ppc/bootm.c
@@ -41,7 +41,7 @@
#include <fdt_support.h>
static void fdt_error (const char *msg);
-static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+static int get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images, char **of_flat_tree, ulong *of_size);
static ulong fdt_relocate (ulong alloc_current,
cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
@@ -95,7 +95,10 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
#if defined(CONFIG_OF_LIBFDT)
/* find flattened device tree */
- get_fdt (cmdtp, flag, argc, argv, images, &of_flat_tree, &of_size);
+ ret = get_fdt (cmdtp, flag, argc, argv, images, &of_flat_tree, &of_size);
+
+ if (ret)
+ goto error;
#endif
if (!of_size) {
@@ -113,18 +116,21 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
#if defined(CONFIG_FIT)
} else if (images->fit_uname_os) {
fit_unsupported_reset ("PPC linux bootm");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
#endif
} else {
puts ("Could not find kernel entry point!\n");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
/* find ramdisk */
- get_ramdisk (cmdtp, flag, argc, argv, images,
+ ret = get_ramdisk (cmdtp, flag, argc, argv, images,
IH_ARCH_PPC, &rd_data_start, &rd_data_end);
+ if (ret)
+ goto error;
+
rd_len = rd_data_end - rd_data_start;
#if defined(CONFIG_OF_LIBFDT)
@@ -139,18 +145,18 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
/* pass in dummy initrd info, we'll fix up later */
if (fdt_chosen(of_flat_tree, rd_data_start, rd_data_end, 0) < 0) {
fdt_error ("/chosen node create failed");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
#ifdef CONFIG_OF_HAS_UBOOT_ENV
if (fdt_env(of_flat_tree) < 0) {
fdt_error ("/u-boot-env node create failed");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
#endif
#ifdef CONFIG_OF_HAS_BD_T
if (fdt_bd_t(of_flat_tree) < 0) {
fdt_error ("/bd_t node create failed");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
#endif
#ifdef CONFIG_OF_BOARD_SETUP
@@ -183,7 +189,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
initrd_end - initrd_start + 1);
if (ret < 0) {
printf("fdt_chosen: %s\n", fdt_strerror(ret));
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
do_fixup_by_path_u32(of_flat_tree, "/chosen",
@@ -225,6 +231,11 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
*/
(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
/* does not return */
+ return ;
+
+error:
+ do_reset (cmdtp, flag, argc, argv);
+ return ;
}
static ulong get_sp (void)
@@ -304,7 +315,7 @@ static image_header_t *image_get_fdt (ulong fdt_addr)
return fdt_hdr;
}
-static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
+static int get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
{
ulong fdt_addr;
@@ -369,7 +380,7 @@ static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
fdt_addr);
fdt_hdr = image_get_fdt (fdt_addr);
if (!fdt_hdr)
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
/*
* move image data to the load address,
@@ -383,7 +394,7 @@ static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
if ((load_start < image_end) && (load_end > image_start)) {
fdt_error ("fdt overwritten");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
memmove ((void *)image_get_load (fdt_hdr),
(void *)image_get_data (fdt_hdr),
@@ -406,7 +417,7 @@ static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
fit_hdr = (void *)fdt_addr;
debug ("* fdt: FIT format image\n");
fit_unsupported_reset ("PPC fdt");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
} else
#endif
{
@@ -420,7 +431,7 @@ static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
break;
default:
fdt_error ("Did not find a cmdline Flattened Device Tree");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
printf (" Booting using the fdt blob at 0x%x\n", fdt_blob);
@@ -446,29 +457,35 @@ static void get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
if (fdt_check_header (fdt_blob) != 0) {
fdt_error ("image is not a fdt");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) {
fdt_error ("fdt size != image size");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
} else {
fdt_error ("Did not find a Flattened Device Tree "
"in a legacy multi-component image");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
} else {
debug ("## No Flattened Device Tree\n");
*of_flat_tree = NULL;
*of_size = 0;
- return;
+ return 0;
}
*of_flat_tree = fdt_blob;
*of_size = be32_to_cpu (fdt_totalsize (fdt_blob));
debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
*of_flat_tree, *of_size);
+
+ return 0;
+
+error:
+ do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
static ulong fdt_relocate (ulong alloc_current,
@@ -485,7 +502,7 @@ static ulong fdt_relocate (ulong alloc_current,
if (fdt_check_header (fdt_blob) != 0) {
fdt_error ("image is not a fdt");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
#ifndef CFG_NO_FLASH
@@ -524,7 +541,7 @@ static ulong fdt_relocate (ulong alloc_current,
err = fdt_open_into (fdt_blob, (void *)of_start, of_len);
if (err != 0) {
fdt_error ("fdt move failed");
- do_reset (cmdtp, flag, argc, argv);
+ goto error;
}
puts ("OK\n");
@@ -536,5 +553,9 @@ static ulong fdt_relocate (ulong alloc_current,
}
return new_alloc_current;
+
+error:
+ do_reset (cmdtp, flag, argc, argv);
+ return 1;
}
#endif
--
1.5.4.1
More information about the U-Boot
mailing list