Fixed in Cilo I/O library; enhanced usability of lzma loader.

master
Philippe Vachon 16 years ago
parent f3010ee91e
commit 26b4e834aa

@ -38,7 +38,7 @@ int32_t cilo_seek(struct file *fp, uint32_t offset, uint8_t whence)
else fp->file_pos += offset;
break;
case SEEK_END:
/* unimplemented */
fp->file_pos = fp->file_len;
break;
default:
return 0;

@ -20,6 +20,8 @@ struct private_data {
ILzmaInCallback callback;
uint8_t *buffer;
struct file *fp;
uint32_t total_read;
uint32_t last;
};
int read_data(void *object, const uint8_t **buffer, uint32_t *size)
@ -30,11 +32,21 @@ int read_data(void *object, const uint8_t **buffer, uint32_t *size)
printf("FATAL: Attempt to read past end of file. Aborting.\n");
return LZMA_RESULT_DATA_ERROR;
}
*size = pvt->fp->file_len - cilo_tell(pvt->fp);
*size = *size > 512 ? 512 : *size;
pvt->total_read += *size;
uint32_t done = (pvt->total_read * 100)/pvt->fp->file_len;
if (done % 10 == 0 && done != pvt->last) {
printf("%d", done);
pvt->last = done;
} else if (done != pvt->last && done % 2 == 0) {
printf(".");
pvt->last = done;
}
cilo_read(pvt->buffer, *size, 1, pvt->fp);
*buffer = pvt->buffer;
@ -74,32 +86,28 @@ void load_lzma(struct file *fp, uint32_t load_address, char *cmd_line)
cilo_seek(fp, 4, SEEK_CUR);
uint16_t probs[LzmaGetNumProbs(&state.Properties)];
printf("Number of probability table entries: %d\n",
LzmaGetNumProbs(&state.Properties));
printf("Size of uncompressed file: %08x.\n", out_size);
/* setup structs */
pvt.callback.Read = read_data;
pvt.buffer = buffer;
pvt.fp = fp;
pvt.total_read = 0;
state.Probs = probs;
pvt.last = 100;
/* do the decoding */
uint32_t out_processed = 0;
printf("Loading kernel at %08x\n", load_address);
int result = LzmaDecode(&state, (ILzmaInCallback *)&pvt,
(uint8_t *)load_address, out_size, &out_processed);
if (result != LZMA_RESULT_OK) {
printf("Error in decoding LZMA-compressed kernel image. Aborting.\n");
printf("\nError in decoding LZMA-compressed kernel image. Aborting.\n");
return;
}
/* kick into kernel: */
printf("Starting LZMA decompressed kernel at %16x.\n", load_address);
printf("\nStarting kernel at 0x%016x.\n", load_address);
((void (*)(uint32_t mem_sz, char *cmd_line))(load_address))
(c_memsz(), cmd_line);
}

@ -62,7 +62,7 @@ void c_putsn(const char *s, int n)
*/
char c_getc(void)
{
char c;
volatile char c;
asm ( ".set noreorder\n "
"li $a0, %[syscall]\n"
@ -94,7 +94,7 @@ int c_gets(char *b, int n)
if (b[i - 1] == '\n' || b[i-1] == '\r') {
break;
}
else if (b[i - 1] == 0x8) {
else if (b[i - 1] == 0x8 || b[i - 1] == 0x7f) {
i--;
}
} while (i < n);

@ -108,7 +108,7 @@ enter_filename:
struct file kernel_file = cilo_open(kernel);
if (kernel_file.code == 0) {
if (kernel_file.code == -1) {
printf("Unable to find \"%s\" on the specified filesystem.\n",
kernel);
goto enter_filename;
@ -119,16 +119,13 @@ enter_filename:
printf("Loading LZMA-compressed kernel image.\n");
load_lzma(&kernel_file, LOADADDR, cmd_line);
} else {
printf("Booting %s.\n", kernel);
struct elf32_header hdr;
cilo_read(&hdr, sizeof(struct elf32_header), 1, &kernel_file);
cilo_seek(&kernel_file, 0, SEEK_SET);
/* check if this is a 32-bit or 64-bit kernel image. */
printf("Booting %s.\n", kernel);
if (load_elf32_file(&kernel_file, cmd_line)
< 0)
{

Loading…
Cancel
Save