Author: blueswirl Date: 2009-03-08 10:45:25 +0100 (Sun, 08 Mar 2009) New Revision: 479
Removed: trunk/openbios-devel/include/openbios/firmware_abi.h Modified: trunk/openbios-devel/arch/ppc/qemu/main.c trunk/openbios-devel/arch/sparc64/openbios.c trunk/openbios-devel/drivers/obio.c Log: Use firmware configuration instead of NVRAM (initial patch by Aurelien Jarno)
Use firmware configuration device for boot device, kernel, initrd and kernel command line parameters on PPC, Sparc32 and Sparc64.
Modified: trunk/openbios-devel/arch/ppc/qemu/main.c =================================================================== --- trunk/openbios-devel/arch/ppc/qemu/main.c 2009-03-08 09:39:53 UTC (rev 478) +++ trunk/openbios-devel/arch/ppc/qemu/main.c 2009-03-08 09:45:25 UTC (rev 479) @@ -22,6 +22,8 @@ #include "libc/vsprintf.h" #include "kernel.h" #include "ofmem.h" +#define NO_QEMU_PROTOS +#include "openbios/fw_cfg.h"
//#define DEBUG_ELF
@@ -319,24 +321,6 @@ close_io( fd ); }
-static uint8_t nvram_read(uint16_t offset) -{ - outb(offset & 0xff, NVRAM_ADDR_LO); - outb(offset >> 8, NVRAM_ADDR_HI); - return inb(NVRAM_DATA); -} - -static uint32_t nvram_read_be32(uint16_t offset) -{ - uint32_t ret; - - ret = nvram_read(offset) << 24; - ret |= nvram_read(offset + 1) << 16; - ret |= nvram_read(offset + 2) << 8; - ret |= nvram_read(offset + 3); - return ret; -} - #define QUIK_SECOND_BASEADDR 0x3e0000 #define QUIK_FIRST_BASEADDR 0x3f4000 #define QUIK_SECOND_SIZE (QUIK_FIRST_BASEADDR - QUIK_SECOND_BASEADDR) @@ -446,8 +430,7 @@ try_path(path, param); try_bootinfo(path, param); } else { - char boot_device = nvram_read(0x34); - + uint16_t boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE); switch (boot_device) { case 'c': path = strdup("hd:0"); @@ -474,21 +457,22 @@ { unsigned long kernel_image, kernel_size; unsigned long initrd_image, initrd_size; - unsigned long cmdline, cmdline_len; + const char * kernel_cmdline;
- kernel_size = nvram_read_be32(0x3c); + kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE); if (kernel_size) { - kernel_image = nvram_read_be32(0x38); - cmdline = nvram_read_be32(0x40); - cmdline_len = nvram_read_be32(0x44); - initrd_image = nvram_read_be32(0x48); - initrd_size = nvram_read_be32(0x4c); + kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR); + kernel_cmdline = (const char *) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE); + initrd_image = fw_cfg_read_i32(FW_CFG_INITRD_ADDR); + initrd_size = fw_cfg_read_i32(FW_CFG_INITRD_SIZE); printk("[ppc] Kernel already loaded (0x%8.8lx + 0x%8.8lx) " "(initrd 0x%8.8lx + 0x%8.8lx)\n", kernel_image, kernel_size, initrd_image, initrd_size); - if (cmdline_len > 0) { - phandle_t ph = find_dev("/chosen"); - set_property(ph, "bootargs", strdup((char *)cmdline), cmdline_len + 1); + if (kernel_cmdline) { + phandle_t ph; + printk("[ppc] Kernel command line: %s\n", kernel_cmdline); + ph = find_dev("/chosen"); + set_property(ph, "bootargs", strdup(kernel_cmdline), strlen(kernel_cmdline) + 1); } call_elf(initrd_image, initrd_size, kernel_image); } @@ -501,7 +485,8 @@ void boot( void ) { - char boot_device = nvram_read(0x34); + uint16_t boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE); + fword("update-chosen"); if (boot_device == 'm') { check_preloaded_kernel();
Modified: trunk/openbios-devel/arch/sparc64/openbios.c =================================================================== --- trunk/openbios-devel/arch/sparc64/openbios.c 2009-03-08 09:39:53 UTC (rev 478) +++ trunk/openbios-devel/arch/sparc64/openbios.c 2009-03-08 09:45:25 UTC (rev 479) @@ -15,9 +15,6 @@ #include "openbios.h" #include "openbios/pci.h" #include "asm/pci.h" -#include "libc/byteorder.h" -#define cpu_to_be16(x) __cpu_to_be16(x) -#include "openbios/firmware_abi.h" #include "boot.h" #include "../../drivers/timer.h" // XXX #define NO_QEMU_PROTOS @@ -42,11 +39,9 @@ #define NVRAM_SIZE 0x2000 #define NVRAM_IDPROM 0x1fd8 #define NVRAM_IDPROM_SIZE 32 -#define NVRAM_OB_START (sizeof(ohwcfg_v3_t) + sizeof(struct sparc_arch_cfg)) +#define NVRAM_OB_START (0) #define NVRAM_OB_SIZE ((0x1fd0 - NVRAM_OB_START) & ~15)
-static ohwcfg_v3_t nv_info; - #define OBIO_CMDLINE_MAX 256 static char obio_cmdline[OBIO_CMDLINE_MAX];
@@ -275,7 +270,7 @@
void arch_nvram_get(char *data) { - uint32_t size; + uint32_t size = 0; const struct cpudef *cpu; const char *bootpath; char buf[256]; @@ -284,9 +279,8 @@ uint32_t clock_frequency; uint16_t machine_id; const char *stdin_path, *stdout_path; + const char *kernel_cmdline;
- nvram_read(0, (char *)&nv_info, sizeof(ohwcfg_v3_t)); - fw_cfg_init();
fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); @@ -304,16 +298,20 @@ for(;;); }
- kernel_image = nv_info.kernel_image; - kernel_size = nv_info.kernel_size; - size = nv_info.cmdline_size; - if (size > OBIO_CMDLINE_MAX - 1) - size = OBIO_CMDLINE_MAX - 1; - memcpy(&obio_cmdline, (void *)(long)nv_info.cmdline, size); + kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE); + if (kernel_size) + kernel_image = fw_cfg_read_i64(FW_CFG_KERNEL_ADDR); + kernel_cmdline = (const char *) fw_cfg_read_i64(FW_CFG_KERNEL_CMDLINE); + if (kernel_cmdline) { + size = strlen(kernel_cmdline); + if (size > OBIO_CMDLINE_MAX - 1) + size = OBIO_CMDLINE_MAX - 1; + memcpy(&obio_cmdline, kernel_cmdline, size); + } obio_cmdline[size] = '\0'; qemu_cmdline = (uint64_t)obio_cmdline; cmdline_size = size; - boot_device = nv_info.boot_devices[0]; + boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE);
if (kernel_size) printk("kernel addr %llx size %llx\n", kernel_image, kernel_size); @@ -372,7 +370,7 @@ push_str("/chosen"); fword("find-device");
- if (nv_info.boot_devices[0] == 'c') + if (boot_device == 'c') bootpath = "disk:a"; else bootpath = "cdrom:a";
Modified: trunk/openbios-devel/drivers/obio.c =================================================================== --- trunk/openbios-devel/drivers/obio.c 2009-03-08 09:39:53 UTC (rev 478) +++ trunk/openbios-devel/drivers/obio.c 2009-03-08 09:45:25 UTC (rev 479) @@ -20,8 +20,6 @@ #include "openbios/nvram.h" #include "ofmem.h" #include "obio.h" -#define cpu_to_be16(x) __cpu_to_be16(x) -#include "openbios/firmware_abi.h" #define NO_QEMU_PROTOS #include "openbios/fw_cfg.h" #include "escc.h" @@ -157,9 +155,8 @@ }
static unsigned char *nvram; -static ohwcfg_v3_t nv_info;
-#define NVRAM_OB_START (sizeof(ohwcfg_v3_t) + sizeof(struct sparc_arch_cfg)) +#define NVRAM_OB_START (0) #define NVRAM_OB_SIZE ((NVRAM_IDPROM - NVRAM_OB_START) & ~15)
void @@ -654,14 +651,14 @@ const char *stdin, *stdout; unsigned int i; char nographic; - uint32_t size; + uint32_t size = 0; uint16_t machine_id; const struct cpudef *cpu; const struct machdef *mach; - ohwcfg_v3_t *header; char buf[256]; uint32_t temp; phandle_t chosen; + const char *kernel_cmdline;
ob_new_obio_device("eeprom", NULL);
@@ -694,23 +691,21 @@ for(;;); }
- memcpy(&nv_info, nvram, sizeof(nv_info)); - kernel_image = nv_info.kernel_image; - kernel_size = nv_info.kernel_size; - size = nv_info.cmdline_size; - if (size > OBIO_CMDLINE_MAX - 1) - size = OBIO_CMDLINE_MAX - 1; - memcpy(&obio_cmdline, (void *)(long)nv_info.cmdline, size); + kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE); + if (kernel_size) + kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR); + kernel_cmdline = (const char *) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE); + if (kernel_cmdline) { + size = strlen(kernel_cmdline); + if (size > OBIO_CMDLINE_MAX - 1) + size = OBIO_CMDLINE_MAX - 1; + memcpy(&obio_cmdline, kernel_cmdline, size); + } obio_cmdline[size] = '\0'; qemu_cmdline = (uint32_t) &obio_cmdline; cmdline_size = size; - header = (ohwcfg_v3_t *)nvram; - header->kernel_image = 0; - header->kernel_size = 0; - header->cmdline_size = 0; - header->crc = OHW_compute_crc(header, 0x00, 0xF8); + boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE);
- boot_device = nv_info.boot_devices[0]; fw_cfg_read(FW_CFG_NOGRAPHIC, &nographic, 1); graphic_depth = fw_cfg_read_i16(FW_CFG_SUN4M_DEPTH);
Deleted: trunk/openbios-devel/include/openbios/firmware_abi.h =================================================================== --- trunk/openbios-devel/include/openbios/firmware_abi.h 2009-03-08 09:39:53 UTC (rev 478) +++ trunk/openbios-devel/include/openbios/firmware_abi.h 2009-03-08 09:45:25 UTC (rev 479) @@ -1,198 +0,0 @@ -#ifndef FIRMWARE_ABI_H -#define FIRMWARE_ABI_H - -#ifndef __ASSEMBLY__ -/* Open Hack'Ware NVRAM configuration structure */ - -/* Version 3 */ -typedef struct ohwcfg_v3_t ohwcfg_v3_t; -struct ohwcfg_v3_t { - /* 0x00: structure identifier */ - uint8_t struct_ident[0x10]; - /* 0x10: structure version and NVRAM description */ - uint32_t struct_version; - uint16_t nvram_size; - uint16_t pad0; - uint16_t nvram_arch_ptr; - uint16_t nvram_arch_size; - uint16_t nvram_arch_crc; - uint8_t pad1[0x02]; - /* 0x20: host architecture */ - uint8_t arch[0x10]; - /* 0x30: RAM/ROM description */ - uint64_t RAM0_base; - uint64_t RAM0_size; - uint64_t RAM1_base; - uint64_t RAM1_size; - uint64_t RAM2_base; - uint64_t RAM2_size; - uint64_t RAM3_base; - uint64_t RAM3_size; - uint64_t ROM_base; - uint64_t ROM_size; - /* 0x80: Kernel description */ - uint64_t kernel_image; - uint64_t kernel_size; - /* 0x90: Kernel command line */ - uint64_t cmdline; - uint64_t cmdline_size; - /* 0xA0: Kernel boot image */ - uint64_t initrd_image; - uint64_t initrd_size; - /* 0xB0: NVRAM image */ - uint64_t NVRAM_image; - uint8_t pad2[8]; - /* 0xC0: graphic configuration */ - uint16_t width; - uint16_t height; - uint16_t depth; - uint16_t graphic_flags; - /* 0xC8: CPUs description */ - uint8_t nb_cpus; - uint8_t boot_cpu; - uint8_t nboot_devices; - uint8_t pad3[5]; - /* 0xD0: boot devices */ - uint8_t boot_devices[0x10]; - /* 0xE0 */ - uint8_t pad4[0x1C]; /* 28 */ - /* 0xFC: checksum */ - uint16_t crc; - uint8_t pad5[0x02]; -} __attribute__ (( packed )); - -#define OHW_GF_NOGRAPHICS 0x0001 - -static inline uint16_t -OHW_crc_update (uint16_t prev, uint16_t value) -{ - uint16_t tmp; - uint16_t pd, pd1, pd2; - - tmp = prev >> 8; - pd = prev ^ value; - pd1 = pd & 0x000F; - pd2 = ((pd >> 4) & 0x000F) ^ pd1; - tmp ^= (pd1 << 3) | (pd1 << 8); - tmp ^= pd2 | (pd2 << 7) | (pd2 << 12); - - return tmp; -} - -static inline uint16_t -OHW_compute_crc (ohwcfg_v3_t *header, uint32_t start, uint32_t count) -{ - uint32_t i; - uint16_t crc = 0xFFFF; - uint8_t *ptr = (uint8_t *)header; - int odd; - - odd = count & 1; - count &= ~1; - for (i = 0; i != count; i++) { - crc = OHW_crc_update(crc, (ptr[start + i] << 8) | ptr[start + i + 1]); - } - if (odd) { - crc = OHW_crc_update(crc, ptr[start + i] << 8); - } - - return crc; -} - -/* Sparc32 runtime NVRAM structure for SMP CPU boot */ -struct sparc_arch_cfg { - uint32_t smp_ctx; - uint32_t smp_ctxtbl; - uint32_t smp_entry; - uint8_t valid; - uint8_t unused[51]; -}; - -/* OpenBIOS NVRAM partition */ -struct OpenBIOS_nvpart_v1 { - uint8_t signature; - uint8_t checksum; - uint16_t len; // BE, length divided by 16 - char name[12]; -}; - -#define OPENBIOS_PART_SYSTEM 0x70 -#define OPENBIOS_PART_FREE 0x7f - -static inline void -OpenBIOS_finish_partition(struct OpenBIOS_nvpart_v1 *header, uint32_t size) -{ - unsigned int i, sum; - uint8_t *tmpptr; - - // Length divided by 16 - header->len = cpu_to_be16(size >> 4); - - // Checksum - tmpptr = (uint8_t *)header; - sum = *tmpptr; - for (i = 0; i < 14; i++) { - sum += tmpptr[2 + i]; - sum = (sum + ((sum & 0xff00) >> 8)) & 0xff; - } - header->checksum = sum & 0xff; -} - -static inline uint32_t -OpenBIOS_set_var(uint8_t *nvram, uint32_t addr, const char *str) -{ - uint32_t len; - - len = strlen(str) + 1; - memcpy(&nvram[addr], str, len); - - return addr + len; -} - -/* Sun IDPROM structure at the end of NVRAM */ -struct Sun_nvram { - uint8_t type; - uint8_t machine_id; - uint8_t macaddr[6]; - uint8_t unused[7]; - uint8_t checksum; -}; - -static inline void -Sun_init_header(struct Sun_nvram *header, const uint8_t *macaddr, int machine_id) -{ - uint8_t tmp, *tmpptr; - unsigned int i; - - header->type = 1; - header->machine_id = machine_id & 0xff; - memcpy(&header->macaddr, macaddr, 6); - /* Calculate checksum */ - tmp = 0; - tmpptr = (uint8_t *)header; - for (i = 0; i < 15; i++) - tmp ^= tmpptr[i]; - - header->checksum = tmp; -} - -#else /* __ASSEMBLY__ */ - -/* Structure offsets for asm use */ - -/* Open Hack'Ware NVRAM configuration structure */ -#define OHW_ARCH_PTR 0x18 -#define OHW_RAM_SIZE 0x38 -#define OHW_BOOT_CPU 0xC9 - -/* Sparc32 runtime NVRAM structure for SMP CPU boot */ -#define SPARC_SMP_CTX 0x0 -#define SPARC_SMP_CTXTBL 0x4 -#define SPARC_SMP_ENTRY 0x8 -#define SPARC_SMP_VALID 0xc - -/* Sun IDPROM structure at the end of NVRAM */ -#define SPARC_MACHINE_ID 0x1fd9 - -#endif /* __ASSEMBLY__ */ -#endif /* FIRMWARE_ABI_H */