X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=second%2Fyaboot.c;h=fd5dee3c5399e818f9469ec5540aa79e2af0ce53;hb=fb19c524bfae0a8105d9321eec4c60daa2f60a03;hp=a292c7396e7053f422dd351ddf3f04217e9afc7f;hpb=2ad0d7649e5042cad43a16b4a03bf53f39948316;p=yaboot.git diff --git a/second/yaboot.c b/second/yaboot.c index a292c73..fd5dee3 100644 --- a/second/yaboot.c +++ b/second/yaboot.c @@ -1,7 +1,7 @@ /* * 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 * @@ -435,7 +435,7 @@ bail: if (opened) file.fs->close(&file); - if (result != 1 && conf_file) + if (conf_file) free(conf_file); return result; @@ -916,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); @@ -963,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"); @@ -979,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); @@ -1081,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"); @@ -1100,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 @@ -1144,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 */ @@ -1161,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 @@ -1173,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", @@ -1192,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; } } @@ -1206,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 @@ -1220,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"); @@ -1239,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 @@ -1283,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 */ @@ -1312,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", @@ -1331,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; } } @@ -1345,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 @@ -1521,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; }