X-Git-Url: http://git.ozlabs.org/?p=yaboot.git;a=blobdiff_plain;f=second%2Fyaboot.c;h=fd5dee3c5399e818f9469ec5540aa79e2af0ce53;hp=a061275dab85b4e42bedb7d45c3767b302e2bf30;hb=57870d23dbeac8a33e8f2689fe5ed52528530c18;hpb=96f82eabe29d6d4039098d5320b3304acbedf67b diff --git a/second/yaboot.c b/second/yaboot.c index a061275..fd5dee3 100644 --- a/second/yaboot.c +++ b/second/yaboot.c @@ -1,38 +1,45 @@ -/* Yaboot - secondary boot loader for Linux on ppc. - - Copyright (C) 1999 Benjamin Herrenschmidt - - portions based on poof - - Copyright (C) 1999 Marius Vollmer - - portions based on quik - - Copyright (C) 1996 Paul Mackerras. - - Because this program is derived from the corresponding file in the - silo-0.64 distribution, it is also - - Copyright (C) 1996 Pete A. Zaitcev - 1996 Maurizio Plaza - 1996 David S. Miller - 1996 Miguel de Icaza - 1996 Jakub Jelinek - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ +/* + * Yaboot - secondary boot loader for Linux on PowerPC. + * + * Copyright (C) 2001, 2002 Ethan Benson + * + * Copyright (C) 1999, 2000, 2001 Benjamin Herrenschmidt + * + * IBM CHRP support + * + * Copyright (C) 2001 Peter Bergner + * + * portions based on poof + * + * Copyright (C) 1999 Marius Vollmer + * + * portions based on quik + * + * Copyright (C) 1996 Paul Mackerras. + * + * Because this program is derived from the corresponding file in the + * silo-0.64 distribution, it is also + * + * Copyright (C) 1996 Pete A. Zaitcev + * 1996 Maurizio Plaza + * 1996 David S. Miller + * 1996 Miguel de Icaza + * 1996 Jakub Jelinek + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include "stdarg.h" #include "string.h" @@ -428,7 +435,7 @@ bail: if (opened) file.fs->close(&file); - if (result != 1 && conf_file) + if (conf_file) free(conf_file); return result; @@ -909,6 +916,7 @@ yaboot_text_ui(void) sysmap_base = prom_claim(loadinfo.base+loadinfo.memsize, 0x100000, 0); if (sysmap_base == (void *)-1) { prom_printf("Claim failed for sysmap memory\n"); + prom_pause(); sysmap_base = 0; } else { sysmap_size = file.fs->read(&file, 0xfffff, sysmap_base); @@ -956,7 +964,7 @@ yaboot_text_ui(void) 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"); @@ -972,6 +980,7 @@ yaboot_text_ui(void) 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); @@ -1074,7 +1083,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) /* 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"); @@ -1093,24 +1102,24 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) 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 @@ -1137,7 +1146,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) if (loadinfo->memsize == 0) { prom_printf("Can't find a loadable segment !\n"); - return 0; + goto bail; } /* leave some room (1Mb) for boot infos */ @@ -1154,7 +1163,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) 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 @@ -1166,7 +1175,7 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) } 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", @@ -1185,13 +1194,13 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) 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; } } @@ -1199,6 +1208,11 @@ load_elf32(struct boot_file_t *file, loadinfo_t *loadinfo) /* Return success at loading the Elf32 kernel */ return 1; + +bail: + if (ph) + free(ph); + return 0; } static int @@ -1213,7 +1227,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) /* 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"); @@ -1232,24 +1246,24 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) 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 @@ -1276,7 +1290,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) if (loadinfo->memsize == 0) { prom_printf("Can't find a loadable segment !\n"); - return 0; + goto bail; } /* leave some room (1Mb) for boot infos */ @@ -1305,7 +1319,7 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) } 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", @@ -1324,13 +1338,13 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) 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; } } @@ -1338,6 +1352,11 @@ load_elf64(struct boot_file_t *file, loadinfo_t *loadinfo) /* Return success at loading the Elf64 kernel */ return 1; + +bail: + if (ph) + free(ph); + return 0; } static int @@ -1514,11 +1533,13 @@ yaboot_main(void) 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; }