mirror of
git://projects.qi-hardware.com/xburst-tools.git
synced 2024-11-01 14:14:38 +02:00
phase2: simplify the bootloader_second_phase mega-loop
This puts the loop body in a new function called try_this_kernel. As an added benefit, we can drop one level of indentation. This change is hard to read as a patch. It gets better if one just applies it and then looks at it with "git diff -w" or similar. Signed-off-by: Werner Almesberger <werner@openmoko.org>
This commit is contained in:
parent
b98b8f5ea1
commit
32f76a7afe
@ -96,23 +96,16 @@ int read_file(const char * filepath, u8 * destination, int size)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bootloader_second_phase(void)
|
static void try_this_kernel(void)
|
||||||
{
|
{
|
||||||
void (*the_kernel)(int zero, int arch, uint params);
|
void (*the_kernel)(int zero, int arch, uint params);
|
||||||
int kernel = 0;
|
|
||||||
const struct board_variant * board_variant =
|
const struct board_variant * board_variant =
|
||||||
(this_board->get_board_variant)();
|
(this_board->get_board_variant)();
|
||||||
unsigned int initramfs_len = 0;
|
unsigned int initramfs_len = 0;
|
||||||
static char commandline_rootfs_append[512] = "";
|
static char commandline_rootfs_append[512] = "";
|
||||||
|
static void * last_block_init = NULL;
|
||||||
|
static int last_block_init_result = 0;
|
||||||
int ret;
|
int ret;
|
||||||
void * last_block_init = NULL;
|
|
||||||
int last_block_init_result = 0;
|
|
||||||
|
|
||||||
/* we try the possible kernels for this board in order */
|
|
||||||
|
|
||||||
this_kernel = &this_board->kernel_source[kernel++];
|
|
||||||
|
|
||||||
while (this_kernel->name) {
|
|
||||||
const char *p;
|
const char *p;
|
||||||
char * cmdline;
|
char * cmdline;
|
||||||
struct tag *params = (struct tag *)this_board->linux_tag_placement;
|
struct tag *params = (struct tag *)this_board->linux_tag_placement;
|
||||||
@ -140,17 +133,14 @@ void bootloader_second_phase(void)
|
|||||||
* block device to one time
|
* block device to one time
|
||||||
*/
|
*/
|
||||||
if (this_kernel->block_init != last_block_init)
|
if (this_kernel->block_init != last_block_init)
|
||||||
last_block_init_result =
|
last_block_init_result = (this_kernel->block_init)();
|
||||||
(this_kernel->block_init)();
|
|
||||||
|
|
||||||
if (last_block_init_result) {
|
if (last_block_init_result) {
|
||||||
puts("block device init failed\n");
|
puts("block device init failed\n");
|
||||||
if (this_kernel->block_init != last_block_init)
|
if (this_kernel->block_init != last_block_init)
|
||||||
indicate(UI_IND_MOUNT_FAIL);
|
indicate(UI_IND_MOUNT_FAIL);
|
||||||
this_kernel = &this_board->
|
last_block_init = this_kernel[1].block_init;
|
||||||
kernel_source[kernel++];
|
return;
|
||||||
last_block_init = this_kernel->block_init;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
last_block_init = this_kernel->block_init;
|
last_block_init = this_kernel->block_init;
|
||||||
}
|
}
|
||||||
@ -161,25 +151,19 @@ void bootloader_second_phase(void)
|
|||||||
if (this_kernel->partition_index) {
|
if (this_kernel->partition_index) {
|
||||||
unsigned char *p = kernel_dram;
|
unsigned char *p = kernel_dram;
|
||||||
|
|
||||||
if ((int)this_kernel->block_read(kernel_dram, 0, 4)
|
if ((int)this_kernel->block_read(kernel_dram, 0, 4) < 0) {
|
||||||
< 0) {
|
|
||||||
puts("Bad partition read\n");
|
puts("Bad partition read\n");
|
||||||
this_kernel = &this_board->
|
|
||||||
kernel_source[kernel++];
|
|
||||||
indicate(UI_IND_MOUNT_FAIL);
|
indicate(UI_IND_MOUNT_FAIL);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((p[0x1fe] != 0x55) || (p[0x1ff] != 0xaa)) {
|
if ((p[0x1fe] != 0x55) || (p[0x1ff] != 0xaa)) {
|
||||||
puts("partition signature missing\n");
|
puts("partition signature missing\n");
|
||||||
this_kernel = &this_board->
|
|
||||||
kernel_source[kernel++];
|
|
||||||
indicate(UI_IND_MOUNT_FAIL);
|
indicate(UI_IND_MOUNT_FAIL);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p += 0x1be + 8 + (0x10 *
|
p += 0x1be + 8 + (0x10 * (this_kernel->partition_index - 1));
|
||||||
(this_kernel->partition_index - 1));
|
|
||||||
|
|
||||||
partition_offset_blocks = (((u32)p[3]) << 24) |
|
partition_offset_blocks = (((u32)p[3]) << 24) |
|
||||||
(((u32)p[2]) << 16) |
|
(((u32)p[2]) << 16) |
|
||||||
@ -213,24 +197,20 @@ void bootloader_second_phase(void)
|
|||||||
puts(")\n");
|
puts(")\n");
|
||||||
indicate(UI_IND_SKIPPING);
|
indicate(UI_IND_SKIPPING);
|
||||||
}
|
}
|
||||||
this_kernel = &this_board->kernel_source[kernel++];
|
return;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is there a commandline append file? */
|
/* is there a commandline append file? */
|
||||||
|
|
||||||
commandline_rootfs_append[0] = '\0';
|
commandline_rootfs_append[0] = '\0';
|
||||||
read_file(this_board->append, (u8 *)commandline_rootfs_append,
|
read_file(this_board->append, (u8 *)commandline_rootfs_append, 512);
|
||||||
512);
|
|
||||||
|
|
||||||
indicate(UI_IND_KERNEL_PULL);
|
indicate(UI_IND_KERNEL_PULL);
|
||||||
|
|
||||||
/* pull the kernel image */
|
/* pull the kernel image */
|
||||||
|
|
||||||
if (read_file(this_kernel->filepath, kernel_dram, 4096) < 0) {
|
if (read_file(this_kernel->filepath, kernel_dram, 4096) < 0)
|
||||||
this_kernel = &this_board->kernel_source[kernel++];
|
return;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
hdr = (image_header_t *)kernel_dram;
|
hdr = (image_header_t *)kernel_dram;
|
||||||
|
|
||||||
@ -238,8 +218,7 @@ void bootloader_second_phase(void)
|
|||||||
puts("bad magic ");
|
puts("bad magic ");
|
||||||
print32(hdr->ih_magic);
|
print32(hdr->ih_magic);
|
||||||
puts("\n");
|
puts("\n");
|
||||||
this_kernel = &this_board->kernel_source[kernel++];
|
return;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
puts(" Found: \"");
|
puts(" Found: \"");
|
||||||
@ -251,11 +230,9 @@ void bootloader_second_phase(void)
|
|||||||
kernel_size = ((__be32_to_cpu(hdr->ih_size) +
|
kernel_size = ((__be32_to_cpu(hdr->ih_size) +
|
||||||
sizeof(image_header_t) + 2048) & ~(2048 - 1));
|
sizeof(image_header_t) + 2048) & ~(2048 - 1));
|
||||||
|
|
||||||
if (read_file(this_kernel->filepath, kernel_dram,
|
if (read_file(this_kernel->filepath, kernel_dram, kernel_size) < 0) {
|
||||||
kernel_size) < 0) {
|
|
||||||
this_kernel = &this_board->kernel_source[kernel++];
|
|
||||||
indicate(UI_IND_KERNEL_PULL_FAIL);
|
indicate(UI_IND_KERNEL_PULL_FAIL);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
indicate(UI_IND_KERNEL_PULL_OK);
|
indicate(UI_IND_KERNEL_PULL_OK);
|
||||||
@ -269,9 +246,8 @@ void bootloader_second_phase(void)
|
|||||||
16 * 1024 * 1024);
|
16 * 1024 * 1024);
|
||||||
if (initramfs_len < 0) {
|
if (initramfs_len < 0) {
|
||||||
puts("initramfs load failed\n");
|
puts("initramfs load failed\n");
|
||||||
this_kernel = &this_board->kernel_source[kernel++];
|
|
||||||
indicate(UI_IND_INITRAMFS_PULL_FAIL);
|
indicate(UI_IND_INITRAMFS_PULL_FAIL);
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
indicate(UI_IND_INITRAMFS_PULL_OK);
|
indicate(UI_IND_INITRAMFS_PULL_OK);
|
||||||
}
|
}
|
||||||
@ -289,8 +265,7 @@ void bootloader_second_phase(void)
|
|||||||
puts(" vs hdr CRC 0x");
|
puts(" vs hdr CRC 0x");
|
||||||
print32(__be32_to_cpu(hdr->ih_dcrc));
|
print32(__be32_to_cpu(hdr->ih_dcrc));
|
||||||
puts("\n");
|
puts("\n");
|
||||||
this_kernel = &this_board->kernel_source[kernel++];
|
return;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
the_kernel = (void (*)(int, int, uint))
|
the_kernel = (void (*)(int, int, uint))
|
||||||
@ -344,8 +319,7 @@ void bootloader_second_phase(void)
|
|||||||
* to have the debugging options added to the commandline
|
* to have the debugging options added to the commandline
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (this_board->commandline_board_debug &&
|
if (this_board->commandline_board_debug && this_board->get_ui_keys)
|
||||||
this_board->get_ui_keys)
|
|
||||||
if ((this_board->get_ui_keys)() & UI_ACTION_SKIPKERNEL)
|
if ((this_board->get_ui_keys)() & UI_ACTION_SKIPKERNEL)
|
||||||
cmdline += strlen(strcpy(cmdline, this_board->
|
cmdline += strlen(strcpy(cmdline, this_board->
|
||||||
commandline_board_debug));
|
commandline_board_debug));
|
||||||
@ -383,6 +357,14 @@ void bootloader_second_phase(void)
|
|||||||
/* we won't come back here no matter what */
|
/* we won't come back here no matter what */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bootloader_second_phase(void)
|
||||||
|
{
|
||||||
|
/* we try the possible kernels for this board in order */
|
||||||
|
|
||||||
|
for (this_kernel = this_board->kernel_source; this_kernel->name;
|
||||||
|
this_kernel++)
|
||||||
|
try_this_kernel();
|
||||||
|
|
||||||
/* none of the kernels worked out */
|
/* none of the kernels worked out */
|
||||||
|
|
||||||
puts("\nNo usable kernel image found\n");
|
puts("\nNo usable kernel image found\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user