From 668e3f5ed96d2c04b63d07f464428e79c07c1aef Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 9 Jan 2009 04:32:48 +0000 Subject: [PATCH] phase2: separate partition scan from try_this_kernel As an added benefit, we can drop one level of indentation. Signed-off-by: Werner Almesberger --- qiboot/src/phase2.c | 89 +++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/qiboot/src/phase2.c b/qiboot/src/phase2.c index e416be0..3ee349b 100644 --- a/qiboot/src/phase2.c +++ b/qiboot/src/phase2.c @@ -96,6 +96,53 @@ int read_file(const char * filepath, u8 * destination, int size) return len; } +static int do_partitions(void *kernel_dram) +{ + unsigned char *p = kernel_dram; + + /* if there's a partition table implied, parse it, otherwise + * just use a fixed offset + */ + if (!this_kernel->partition_index) { + partition_offset_blocks = + this_kernel->offset_blocks512_if_no_partition; + return 1; + } + + if ((int)this_kernel->block_read(kernel_dram, 0, 4) < 0) { + puts("Bad partition read\n"); + indicate(UI_IND_MOUNT_FAIL); + return 0; + } + + if ((p[0x1fe] != 0x55) || (p[0x1ff] != 0xaa)) { + puts("partition signature missing\n"); + indicate(UI_IND_MOUNT_FAIL); + return 0; + } + + p += 0x1be + 8 + (0x10 * (this_kernel->partition_index - 1)); + + partition_offset_blocks = (((u32)p[3]) << 24) | + (((u32)p[2]) << 16) | + (((u32)p[1]) << 8) | + p[0]; + partition_length_blocks = (((u32)p[7]) << 24) | + (((u32)p[6]) << 16) | + (((u32)p[5]) << 8) | + p[4]; + + puts(" Partition: "); + printdec(this_kernel->partition_index); + puts(" start +"); + printdec(partition_offset_blocks); + puts(" 512-byte blocks, size "); + printdec(partition_length_blocks / 2048); + puts(" MiB\n"); + + return 1; +} + static void do_params(unsigned initramfs_len, const char *commandline_rootfs_append) { @@ -217,46 +264,8 @@ static void try_this_kernel(void) last_block_init = this_kernel->block_init; } - /* if there's a partition table implied, parse it, otherwise - * just use a fixed offset - */ - if (this_kernel->partition_index) { - unsigned char *p = kernel_dram; - - if ((int)this_kernel->block_read(kernel_dram, 0, 4) < 0) { - puts("Bad partition read\n"); - indicate(UI_IND_MOUNT_FAIL); - return; - } - - if ((p[0x1fe] != 0x55) || (p[0x1ff] != 0xaa)) { - puts("partition signature missing\n"); - indicate(UI_IND_MOUNT_FAIL); - return; - } - - p += 0x1be + 8 + (0x10 * (this_kernel->partition_index - 1)); - - partition_offset_blocks = (((u32)p[3]) << 24) | - (((u32)p[2]) << 16) | - (((u32)p[1]) << 8) | - p[0]; - partition_length_blocks = (((u32)p[7]) << 24) | - (((u32)p[6]) << 16) | - (((u32)p[5]) << 8) | - p[4]; - - puts(" Partition: "); - printdec(this_kernel->partition_index); - puts(" start +"); - printdec(partition_offset_blocks); - puts(" 512-byte blocks, size "); - printdec(partition_length_blocks / 2048); - puts(" MiB\n"); - - } else - partition_offset_blocks = - this_kernel->offset_blocks512_if_no_partition; + if (!do_partitions(kernel_dram)) + return; /* does he want us to skip this? */