From 9283d9ebc829f94675c73df2d0f7b31c5346ed15 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Mon, 22 May 2006 22:16:20 +0000 Subject: [PATCH] openbios.patch-15-svn25.bz2 part II merge git-svn-id: svn://coreboot.org/openbios/openbios-devel@27 f158a5a8-5612-0410-a976-696ce0be7e32 --- arch/sparc32/aoutload.c | 26 +++++--- arch/sparc32/boot.c | 40 ++++++++++-- arch/sparc32/elfload.c | 35 +++++++---- arch/sparc32/openbios.c | 12 +++- arch/sparc32/romvec.c | 27 ++------ arch/sparc32/tree.fs | 78 ------------------------ config/examples/cross-sparc32_config.xml | 1 + config/examples/sparc32_config.xml | 1 + include/sparc32/io.h | 2 +- 9 files changed, 93 insertions(+), 129 deletions(-) diff --git a/arch/sparc32/aoutload.c b/arch/sparc32/aoutload.c index 071b12b..b85561b 100644 --- a/arch/sparc32/aoutload.c +++ b/arch/sparc32/aoutload.c @@ -57,16 +57,23 @@ int aout_load(struct sys_info *info, const char *filename, const char *cmdline) int image_retval; struct exec ehdr; unsigned long start, size; + unsigned int offset; image_name = image_version = 0; if (!file_open(filename)) goto out; - if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { - debug("Can't read a.out header\n"); - retval = LOADER_NOT_SUPPORT; - goto out; + for (offset = 0; offset < 16 * 512; offset += 512) { + if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { + debug("Can't read a.out header\n"); + retval = LOADER_NOT_SUPPORT; + goto out; + } + if (!N_BADMAG(ehdr)) + break; + + file_seek(offset); } if (N_BADMAG(ehdr)) { @@ -76,9 +83,9 @@ int aout_load(struct sys_info *info, const char *filename, const char *cmdline) } if (N_MAGIC(ehdr) == NMAGIC) { - size = N_DATADDR(ehdr) + ehdr.a_data; + size = addr_fixup(N_DATADDR(ehdr)) + addr_fixup(ehdr.a_data); } else { - size = ehdr.a_text + ehdr.a_data; + size = addr_fixup(ehdr.a_text) + addr_fixup(ehdr.a_data); } start = 0x4000; // N_TXTADDR(ehdr); @@ -88,7 +95,7 @@ int aout_load(struct sys_info *info, const char *filename, const char *cmdline) printf("Loading a.out %s...\n", image_name ? image_name : "image"); - file_seek(N_TXTOFF(ehdr)); + file_seek(offset + N_TXTOFF(ehdr)); if (N_MAGIC(ehdr) == NMAGIC) { if (lfile_read(start, ehdr.a_text) != ehdr.a_text) { @@ -108,18 +115,19 @@ int aout_load(struct sys_info *info, const char *filename, const char *cmdline) debug("Loaded %lu bytes\n", size); - debug("entry point is %#x\n", start); + debug("entry point is %#lx\n", start); printf("Jumping to entry point...\n"); #if 1 { extern unsigned int qemu_mem_size; + extern char boot_device; void *init_openprom(unsigned long memsize, const char *cmdline, char boot_device); int (*entry)(const void *romvec, int p2, int p3, int p4, int p5); const void *romvec; - romvec = init_openprom(qemu_mem_size, cmdline, 'c'); + romvec = init_openprom(qemu_mem_size, cmdline, boot_device); entry = (void *) addr_fixup(start); image_retval = entry(romvec, 0, 0, 0, 0); } diff --git a/arch/sparc32/boot.c b/arch/sparc32/boot.c index 8c27199..a279f9e 100644 --- a/arch/sparc32/boot.c +++ b/arch/sparc32/boot.c @@ -16,24 +16,54 @@ int linux_load(struct sys_info *, const char *filename, const char *cmdline); void boot(void); struct sys_info sys_info; +uint32_t kernel_image; +uint32_t kernel_size; +uint32_t cmdline; +uint32_t cmdline_size; +char boot_device; void boot(void) { char *path=pop_fstr_copy(), *param; - // char *param="root=/dev/hda2 console=ttyS0,115200n8 console=tty0"; - + if (kernel_size) { + extern unsigned int qemu_mem_size; + void *init_openprom(unsigned long memsize, const char *cmdline, char boot_device); + + int (*entry)(const void *romvec, int p2, int p3, int p4, int p5); + const void *romvec; + + printk("[sparc] Kernel already loaded\n"); + romvec = init_openprom(qemu_mem_size, (void *)cmdline, boot_device); + entry = (void *) kernel_image; + entry(romvec, 0, 0, 0, 0); + } + if(!path) { + switch(boot_device) { + case 'a': + path = "/obio/SUNW,fdtwo"; + break; + case 'c': + path = "disk"; + break; + default: + case 'd': path = "cdrom"; - //printk("[sparc] Booting default not supported.\n"); - //return; + break; + case 'n': + path = "net"; + break; + } } param = strchr(path, ' '); if(param) { *param = '\0'; param++; - } + } else if (cmdline_size) { + param = (char *)cmdline; + } printk("[sparc] Booting file '%s' with parameters '%s'\n",path, param); diff --git a/arch/sparc32/elfload.c b/arch/sparc32/elfload.c index 1b0ab77..6a2c3ce 100644 --- a/arch/sparc32/elfload.c +++ b/arch/sparc32/elfload.c @@ -76,7 +76,8 @@ badseg: } static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, - unsigned short *sum_ptr) + unsigned short *sum_ptr, + unsigned int offset) { int i; char *buf = NULL; @@ -90,7 +91,7 @@ static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, if (phdr[i].p_type != PT_NOTE) continue; buf = malloc(phdr[i].p_filesz); - file_seek(phdr[i].p_offset); + file_seek(offset + phdr[i].p_offset); if (lfile_read(buf, phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read note segment\n"); goto out; @@ -132,7 +133,8 @@ out: } static int load_segments(Elf_phdr *phdr, int phnum, - unsigned long checksum_offset) + unsigned long checksum_offset, + unsigned int offset) { unsigned long bytes; //unsigned int start_time, time; @@ -145,7 +147,7 @@ static int load_segments(Elf_phdr *phdr, int phnum, continue; debug("segment %d addr:%#x file:%#x mem:%#x ", i, addr_fixup(phdr[i].p_paddr), phdr[i].p_filesz, phdr[i].p_memsz); - file_seek(phdr[i].p_offset); + file_seek(offset + phdr[i].p_offset); debug("loading... "); if (lfile_read(phys_to_virt(addr_fixup(phdr[i].p_paddr)), phdr[i].p_filesz) != phdr[i].p_filesz) { @@ -309,16 +311,24 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) Elf_Bhdr *boot_notes = NULL; int retval = -1; int image_retval; + unsigned int offset; image_name = image_version = 0; if (!file_open(filename)) goto out; - if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { - debug("Can't read ELF header\n"); - retval = LOADER_NOT_SUPPORT; - goto out; + for (offset = 0; offset < 16 * 512; offset += 512) { + if (lfile_read(&ehdr, sizeof ehdr) != sizeof ehdr) { + debug("Can't read ELF header\n"); + retval = LOADER_NOT_SUPPORT; + goto out; + } + + if (ehdr.e_ident[EI_MAG0] == ELFMAG0) + break; + + file_seek(offset); } if (ehdr.e_ident[EI_MAG0] != ELFMAG0 @@ -339,7 +349,7 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) phdr_size = ehdr.e_phnum * sizeof *phdr; phdr = malloc(phdr_size); - file_seek(ehdr.e_phoff); + file_seek(offset + ehdr.e_phoff); if (lfile_read(phdr, phdr_size) != phdr_size) { printf("Can't read program header\n"); goto out; @@ -348,14 +358,14 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) if (!check_mem_ranges(info, phdr, ehdr.e_phnum)) goto out; - checksum_offset = process_image_notes(phdr, ehdr.e_phnum, &checksum); + checksum_offset = process_image_notes(phdr, ehdr.e_phnum, &checksum, offset); printf("Loading %s", image_name ? image_name : "image"); if (image_version) printf(" version %s", image_version); printf("...\n"); - if (!load_segments(phdr, ehdr.e_phnum, checksum_offset)) + if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, offset)) goto out; if (checksum_offset) { @@ -373,12 +383,13 @@ int elf_load(struct sys_info *info, const char *filename, const char *cmdline) #if 1 { extern unsigned int qemu_mem_size; + extern char boot_device; void *init_openprom(unsigned long memsize, const char *cmdline, char boot_device); int (*entry)(const void *romvec, int p2, int p3, int p4, int p5); const void *romvec; - romvec = init_openprom(qemu_mem_size, cmdline, 'c'); + romvec = init_openprom(qemu_mem_size, cmdline, boot_device); entry = (void *) addr_fixup(ehdr.e_entry); image_retval = entry(romvec, 0, 0, 0, 0); } diff --git a/arch/sparc32/openbios.c b/arch/sparc32/openbios.c index b1d5519..1b973ba 100644 --- a/arch/sparc32/openbios.c +++ b/arch/sparc32/openbios.c @@ -19,6 +19,10 @@ void boot(void); void ob_ide_init(void); +#define IOMMU_BASE 0x10000000 /* First page of sun4m IOMMU */ +#define SLAVIO_BASE 0x71000000 +#define MACIO_BASE 0x70000000 + static unsigned char intdict[256 * 1024]; static void init_memory(void) @@ -50,17 +54,19 @@ arch_init( void ) modules_init(); #ifdef CONFIG_DRIVER_SBUS - init_mmu_swift(); + init_mmu_swift(IOMMU_BASE); ob_sbus_init(); #endif #ifdef CONFIG_DRIVER_ESP - ob_esp_init(); + ob_esp_init(MACIO_BASE); #endif #ifdef CONFIG_DRIVER_OBIO - ob_obio_init(0x71000000); + ob_obio_init(SLAVIO_BASE); + nvram_init(); #endif device_end(); + bind_func("platform-boot", boot ); } diff --git a/arch/sparc32/romvec.c b/arch/sparc32/romvec.c index dd6ccf1..bd83c9f 100644 --- a/arch/sparc32/romvec.c +++ b/arch/sparc32/romvec.c @@ -61,9 +61,6 @@ static const struct linux_arguments_v0 * const obp_argp = &obp_arg; static void (*synch_hook)(void); static struct linux_romvec romvec0; -static int prop_mem_reg[3]; -static int prop_mem_avail[3]; -static int prop_vmem_avail[6]; static void doublewalk(__attribute__((unused)) unsigned int ptab1, __attribute__((unused)) unsigned int va) @@ -418,31 +415,18 @@ init_openprom(unsigned long memsize, const char *cmdline, char boot_device) /* * Form memory descriptors. */ - totphys[0].theres_more = 0; + totphys[0].theres_more = NULL; totphys[0].start_adr = (char *) 0; totphys[0].num_bytes = memsize; - totavail[0].theres_more = 0; - totavail[0].start_adr = (char*) 0; + totavail[0].theres_more = NULL; + totavail[0].start_adr = (char *) 0; totavail[0].num_bytes = memsize; - totmap[0].theres_more = 0; + totmap[0].theres_more = NULL; totmap[0].start_adr = &_start; totmap[0].num_bytes = (unsigned long) &_iomem - (unsigned long) &_start; - prop_mem_reg[0] = 0; - prop_mem_reg[1] = 0; - prop_mem_reg[2] = memsize; - prop_mem_avail[0] = 0; - prop_mem_avail[1] = 0; - prop_mem_avail[2] = va2pa((unsigned long)&_data) - 1; - prop_vmem_avail[0] = 0; - prop_vmem_avail[1] = 0; - prop_vmem_avail[2] = (unsigned long)&_start - 1; - prop_vmem_avail[3] = 0; - prop_vmem_avail[4] = 0xffe00000; - prop_vmem_avail[5] = 0x00200000; - // Linux wants a R/W romvec table romvec0.pv_magic_cookie = LINUX_OPPROM_MAGIC; romvec0.pv_romvers = 0; @@ -478,6 +462,7 @@ init_openprom(unsigned long memsize, const char *cmdline, char boot_device) romvec0.pv_v2devops.v2_dev_seek = obp_devseek; obp_arg.boot_dev_ctrl = 0; obp_arg.boot_dev_unit = 0; + obp_arg.dev_partition = 4; obp_arg.argv[0] = "sd(0,0,0):d"; switch(boot_device) { @@ -503,7 +488,7 @@ init_openprom(unsigned long memsize, const char *cmdline, char boot_device) } obp_arg.argv[1] = cmdline; romvec0.pv_v2bootargs.bootpath = &obp_arg.argv[0]; - romvec0.pv_v2bootargs.bootargs = &cmdline; + romvec0.pv_v2bootargs.bootargs = &obp_arg.argv[1]; romvec0.pv_v2bootargs.fd_stdin = &obp_fd_stdin; romvec0.pv_v2bootargs.fd_stdout = &obp_fd_stdout; diff --git a/arch/sparc32/tree.fs b/arch/sparc32/tree.fs index 755c781..a266ea4 100644 --- a/arch/sparc32/tree.fs +++ b/arch/sparc32/tree.fs @@ -5,9 +5,6 @@ " SUNW,SparcStation-5" encode-string " name" property " SparcStation" encode-string " banner-name" property " sun4m" encode-string " compatible" property - h# 01800000 encode-int 0 encode-int encode+ 0 encode-int encode+ h# 00000081 encode-int encode+ - 0 encode-int encode+ 0 encode-int encode+ 0 encode-int encode+ 0 encode-int encode+ - " idprom" property \ XXX " /obio/zs@0,100000:a" encode-string " stdin-path" property " /obio/zs@0,100000:a" encode-string " stdout-path" property : encode-unit encode-unit-sbus ; @@ -15,8 +12,6 @@ new-device " memory" device-name - h# 100000 encode-int " available" property \ XXX - h# 0 encode-int h# 10000000 encode-int encode+ h# 00000300 encode-int encode+ " reg" property \ XXX external : open true ; : close ; @@ -26,8 +21,6 @@ finish-device new-device " virtual-memory" device-name - h# 100000 encode-int " available" property \ XXX - h# 0 encode-int h# 10000000 encode-int encode+ h# 00000300 encode-int encode+ " reg" property \ XXX external : open true ; : close ; @@ -131,7 +124,6 @@ finish-device " /iommu/sbus" find-device new-device " espdma" device-name - h# 4 encode-int h# 08400000 encode-int encode+ h# 00000010 encode-int encode+ " reg" property external : encode-unit encode-unit-sbus ; : decode-unit decode-unit-sbus ; @@ -180,76 +172,6 @@ new-device : decode-unit decode-unit-sbus ; finish-device -" /obio" find-device -new-device - " SUNW,fdtwo" device-name - " block" device-type - h# 0 encode-int h# 00400000 encode-int encode+ h# 0000000f encode-int encode+ " reg" property - h# 2b encode-int 0 encode-int encode+ " intr" property -finish-device - -" /obio" find-device -new-device - " auxio" device-name - h# 0 encode-int h# 00900000 encode-int encode+ h# 00000001 encode-int encode+ " reg" property -finish-device - -" /obio" find-device -new-device - " counter" device-name - h# 0 encode-int h# 00d00000 encode-int encode+ h# 00000010 encode-int encode+ - h# 0 encode-int encode+ h# 00d10000 encode-int encode+ h# 00000010 encode-int encode+ - " reg" property -finish-device - -" /obio" find-device -new-device - " eeprom" device-name - h# 0 encode-int h# 00200000 encode-int encode+ h# 00002000 encode-int encode+ " reg" property - " mk48t08" model -finish-device - -" /obio" find-device -new-device - " interrupt" device-name - h# 0 encode-int h# 00e00000 encode-int encode+ h# 00000010 encode-int encode+ - h# 0 encode-int encode+ h# 00e10000 encode-int encode+ h# 00000010 encode-int encode+ - " reg" property -finish-device - -" /obio" find-device -new-device - " power" device-name - h# 0 encode-int h# 00910000 encode-int encode+ h# 00000001 encode-int encode+ " reg" property - h# 22 encode-int 0 encode-int encode+ " intr" property -finish-device - -" /obio" find-device -new-device - " slavioconfig" device-name - h# 0 encode-int h# 00800000 encode-int encode+ h# 00000001 encode-int encode+ " reg" property -finish-device - -" /obio" find-device -new-device - " zs" device-name - " serial" device-type - h# 0 encode-int h# 00000000 encode-int encode+ h# 00000008 encode-int encode+ " reg" property - 1 encode-int " slave" property - h# 2c encode-int 0 encode-int encode+ " intr" property - -1 encode-int " keyboard" property - -1 encode-int " mouse" property -finish-device - -" /obio" find-device -new-device - " zs" device-name - " serial" device-type - h# 0 encode-int h# 00100000 encode-int encode+ h# 00000008 encode-int encode+ " reg" property - 0 encode-int " slave" property - h# 2c encode-int 0 encode-int encode+ " intr" property -finish-device - " /options" find-device " disk" encode-string " boot-from" property diff --git a/config/examples/cross-sparc32_config.xml b/config/examples/cross-sparc32_config.xml index 367bbbc..8279de1 100644 --- a/config/examples/cross-sparc32_config.xml +++ b/config/examples/cross-sparc32_config.xml @@ -61,6 +61,7 @@