From 188fff8fc3030a179bc5ebabf1975de88b4709d5 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 9 Jan 2009 04:32:52 +0000 Subject: [PATCH] zimage: separate uImage loader from try_this_kernel Finally all the restructuring pays off: we can cleanly separate the uImage loader from all the rest, which will make it easy to add loaders for other kernel image formats. Signed-off-by: Werner Almesberger --- qiboot/src/phase2.c | 68 +++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/qiboot/src/phase2.c b/qiboot/src/phase2.c index 20d2ce9..cf31e8b 100644 --- a/qiboot/src/phase2.c +++ b/qiboot/src/phase2.c @@ -277,6 +277,42 @@ static int do_crc(const image_header_t *hdr, const void *kernel_dram) return 0; } +static the_kernel_fn load_uimage(void *kernel_dram) +{ + image_header_t *hdr; + u32 kernel_size; + + hdr = (image_header_t *)kernel_dram; + + if (__be32_to_cpu(hdr->ih_magic) != IH_MAGIC) { + puts("bad magic "); + print32(hdr->ih_magic); + puts("\n"); + return NULL; + } + + puts(" Found: \""); + puts((const char *)hdr->ih_name); + puts("\"\n Size: "); + printdec(__be32_to_cpu(hdr->ih_size) >> 10); + puts(" KiB\n"); + + kernel_size = ((__be32_to_cpu(hdr->ih_size) + + sizeof(image_header_t) + 2048) & ~(2048 - 1)); + + if (read_file(this_kernel->filepath, kernel_dram, kernel_size) < 0) { + indicate(UI_IND_KERNEL_PULL_FAIL); + return NULL; + } + + indicate(UI_IND_KERNEL_PULL_OK); + + if (!do_crc(hdr, kernel_dram)) + return NULL; + + return (the_kernel_fn) (((char *)hdr) + sizeof(image_header_t)); +} + static void try_this_kernel(void) { the_kernel_fn the_kernel; @@ -284,8 +320,6 @@ static void try_this_kernel(void) static char commandline_rootfs_append[512] = ""; int ret; void * kernel_dram = (void *)this_board->linux_mem_start + 0x8000; - image_header_t *hdr; - u32 kernel_size; partition_offset_blocks = 0; partition_length_blocks = 0; @@ -328,30 +362,9 @@ static void try_this_kernel(void) if (read_file(this_kernel->filepath, kernel_dram, 4096) < 0) return; - hdr = (image_header_t *)kernel_dram; - - if (__be32_to_cpu(hdr->ih_magic) != IH_MAGIC) { - puts("bad magic "); - print32(hdr->ih_magic); - puts("\n"); + the_kernel = load_uimage(kernel_dram); + if (!the_kernel) return; - } - - puts(" Found: \""); - puts((const char *)hdr->ih_name); - puts("\"\n Size: "); - printdec(__be32_to_cpu(hdr->ih_size) >> 10); - puts(" KiB\n"); - - kernel_size = ((__be32_to_cpu(hdr->ih_size) + - sizeof(image_header_t) + 2048) & ~(2048 - 1)); - - if (read_file(this_kernel->filepath, kernel_dram, kernel_size) < 0) { - indicate(UI_IND_KERNEL_PULL_FAIL); - return; - } - - indicate(UI_IND_KERNEL_PULL_OK); /* initramfs if needed */ @@ -368,11 +381,6 @@ static void try_this_kernel(void) indicate(UI_IND_INITRAMFS_PULL_OK); } - if (!do_crc(hdr, kernel_dram)) - return; - - the_kernel = (the_kernel_fn) (((char *)hdr) + sizeof(image_header_t)); - do_params(initramfs_len, commandline_rootfs_append); /* give board implementation a chance to shut down