1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-30 00:34:05 +02:00

phase2: separate CRC from try_this_kernel

As an added benefit, we can drop one level of indentation.

Signed-off-by: Werner Almesberger <werner@openmoko.org>
This commit is contained in:
Werner Almesberger 2009-01-09 04:32:49 +00:00 committed by Andy Green
parent 668e3f5ed9
commit d3ee803b58

View File

@ -223,6 +223,29 @@ static void do_params(unsigned initramfs_len,
params->hdr.size = 0; params->hdr.size = 0;
} }
static int do_crc(const image_header_t *hdr, const void *kernel_dram)
{
unsigned long crc;
/*
* It's good for now to know that our kernel is intact from
* the storage before we jump into it and maybe crash silently
* even though it costs us some time
*/
crc = crc32(0, kernel_dram + sizeof(image_header_t),
__be32_to_cpu(hdr->ih_size));
if (crc == __be32_to_cpu(hdr->ih_dcrc))
return 1;
puts("\nKernel CRC ERROR: read 0x");
print32(crc);
puts(" vs hdr CRC 0x");
print32(__be32_to_cpu(hdr->ih_dcrc));
puts("\n");
return 0;
}
static void try_this_kernel(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);
@ -232,7 +255,6 @@ static void try_this_kernel(void)
static int last_block_init_result = 0; static int last_block_init_result = 0;
int ret; int ret;
void * kernel_dram = (void *)this_board->linux_mem_start + 0x8000; void * kernel_dram = (void *)this_board->linux_mem_start + 0x8000;
unsigned long crc;
image_header_t *hdr; image_header_t *hdr;
u32 kernel_size; u32 kernel_size;
@ -333,21 +355,8 @@ static void try_this_kernel(void)
indicate(UI_IND_INITRAMFS_PULL_OK); indicate(UI_IND_INITRAMFS_PULL_OK);
} }
/* if (!do_crc(hdr, kernel_dram))
* It's good for now to know that our kernel is intact from
* the storage before we jump into it and maybe crash silently
* even though it costs us some time
*/
crc = crc32(0, kernel_dram + sizeof(image_header_t),
__be32_to_cpu(hdr->ih_size));
if (crc != __be32_to_cpu(hdr->ih_dcrc)) {
puts("\nKernel CRC ERROR: read 0x");
print32(crc);
puts(" vs hdr CRC 0x");
print32(__be32_to_cpu(hdr->ih_dcrc));
puts("\n");
return; return;
}
the_kernel = (void (*)(int, int, uint)) the_kernel = (void (*)(int, int, uint))
(((char *)hdr) + sizeof(image_header_t)); (((char *)hdr) + sizeof(image_header_t));