/*
* Yaboot - secondary boot loader for Linux on PowerPC.
*
- * Copyright (C) 2001 Ethan Benson
+ * Copyright (C) 2001, 2002 Ethan Benson
*
* Copyright (C) 1999, 2000, 2001 Benjamin Herrenschmidt
*
if (opened)
file.fs->close(&file);
- if (result != 1 && conf_file)
+ if (conf_file)
free(conf_file);
return result;
prom_perror(result, params.rd.file);
}
else {
-#define INITRD_CHUNKSIZE 0x400000
+#define INITRD_CHUNKSIZE 0x100000
initrd_base = prom_claim(loadinfo.base+loadinfo.memsize, INITRD_CHUNKSIZE, 0);
if (initrd_base == (void *)-1) {
prom_printf("Claim failed for initrd memory\n");
initrd_more = prom_claim(initrd_want, INITRD_CHUNKSIZE, 0);
if (initrd_more != initrd_want) {
prom_printf("Claim failed for initrd memory at %p rc=%p\n",initrd_want,initrd_more);
+ prom_pause();
break;
}
initrd_read = file.fs->read(&file, INITRD_CHUNKSIZE, initrd_more);
/* Read the rest of the Elf header... */
if ((*(file->fs->read))(file, size, &e->e_version) < size) {
prom_printf("\nCan't read Elf32 image header\n");
- return 0;
+ goto bail;
}
DEBUG_F("Elf32 header:\n");
if (e->e_phnum > MAX_HEADERS) {
prom_printf ("Can only load kernels with one program header\n");
- return 0;
+ goto bail;
}
ph = (Elf32_Phdr *)malloc(sizeof(Elf32_Phdr) * e->e_phnum);
if (!ph) {
prom_printf ("Malloc error\n");
- return 0;
+ goto bail;
}
/* Now, we read the section header */
if ((*(file->fs->seek))(file, e->e_phoff) != FILE_ERR_OK) {
prom_printf ("seek error\n");
- return 0;
+ goto bail;
}
if ((*(file->fs->read))(file, sizeof(Elf32_Phdr) * e->e_phnum, ph) !=
sizeof(Elf32_Phdr) * e->e_phnum) {
prom_printf ("read error\n");
- return 0;
+ goto bail;
}
/* Scan through the program header
if (loadinfo->memsize == 0) {
prom_printf("Can't find a loadable segment !\n");
- return 0;
+ goto bail;
}
/* leave some room (1Mb) for boot infos */
loadaddr = KERNELADDR;
} else {
flat_vmlinux = 0;
- loadaddr = e->e_entry;
+ loadaddr = loadinfo->load_loc;
}
/* On some systems, loadaddr may already be claimed, so try some
}
if (loadinfo->base == (void *)-1) {
prom_printf("Claim error, can't allocate kernel memory\n");
- return 0;
+ goto bail;
}
DEBUG_F("After ELF parsing, load base: %p, mem_sz: 0x%08lx\n",
if ((*(file->fs->seek))(file, p->p_offset) != FILE_ERR_OK) {
prom_printf ("Seek error\n");
prom_release(loadinfo->base, loadinfo->memsize);
- return 0;
+ goto bail;
}
offset = p->p_vaddr - loadinfo->load_loc;
if ((*(file->fs->read))(file, p->p_filesz, loadinfo->base+offset) != p->p_filesz) {
prom_printf ("Read failed\n");
prom_release(loadinfo->base, loadinfo->memsize);
- return 0;
+ goto bail;
}
}
/* Return success at loading the Elf32 kernel */
return 1;
+
+bail:
+ if (ph)
+ free(ph);
+ return 0;
}
static int
/* Read the rest of the Elf header... */
if ((*(file->fs->read))(file, size, &e->e_version) < size) {
prom_printf("\nCan't read Elf64 image header\n");
- return 0;
+ goto bail;
}
DEBUG_F("Elf64 header:\n");
if (e->e_phnum > MAX_HEADERS) {
prom_printf ("Can only load kernels with one program header\n");
- return 0;
+ goto bail;
}
ph = (Elf64_Phdr *)malloc(sizeof(Elf64_Phdr) * e->e_phnum);
if (!ph) {
prom_printf ("Malloc error\n");
- return 0;
+ goto bail;
}
/* Now, we read the section header */
if ((*(file->fs->seek))(file, e->e_phoff) != FILE_ERR_OK) {
prom_printf ("Seek error\n");
- return 0;
+ goto bail;
}
if ((*(file->fs->read))(file, sizeof(Elf64_Phdr) * e->e_phnum, ph) !=
sizeof(Elf64_Phdr) * e->e_phnum) {
prom_printf ("Read error\n");
- return 0;
+ goto bail;
}
/* Scan through the program header
if (loadinfo->memsize == 0) {
prom_printf("Can't find a loadable segment !\n");
- return 0;
+ goto bail;
}
/* leave some room (1Mb) for boot infos */
}
if (loadinfo->base == (void *)-1) {
prom_printf("Claim error, can't allocate kernel memory\n");
- return 0;
+ goto bail;
}
DEBUG_F("After ELF parsing, load base: %p, mem_sz: 0x%08lx\n",
if ((*(file->fs->seek))(file, p->p_offset) != FILE_ERR_OK) {
prom_printf ("Seek error\n");
prom_release(loadinfo->base, loadinfo->memsize);
- return 0;
+ goto bail;
}
offset = p->p_vaddr - loadinfo->load_loc;
if ((*(file->fs->read))(file, p->p_filesz, loadinfo->base+offset) != p->p_filesz) {
prom_printf ("Read failed\n");
prom_release(loadinfo->base, loadinfo->memsize);
- return 0;
+ goto bail;
}
}
/* Return success at loading the Elf64 kernel */
return 1;
+
+bail:
+ if (ph)
+ free(ph);
+ return 0;
}
static int
if ((ptype != NULL) && (strcmp(ptype, "Apple_Bootstrap")))
prom_printf("\nWARNING: Bootstrap partition type is wrong: \"%s\"\n"
" type should be: \"Apple_Bootstrap\"\n\n", ptype);
+ if (ptype)
+ free(ptype);
}
}
yaboot_text_ui();
-
+
prom_printf("Bye.\n");
return 0;
}