From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LDd1S-0001PX-Br for qemu-devel@nongnu.org; Fri, 19 Dec 2008 05:55:58 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LDd1Q-0001Nx-J8 for qemu-devel@nongnu.org; Fri, 19 Dec 2008 05:55:57 -0500 Received: from [199.232.76.173] (port=38970 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LDd1Q-0001Nn-2R for qemu-devel@nongnu.org; Fri, 19 Dec 2008 05:55:56 -0500 Received: from moutng.kundenserver.de ([212.227.126.188]:65237) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LDd1P-0007mG-51 for qemu-devel@nongnu.org; Fri, 19 Dec 2008 05:55:55 -0500 Message-Id: <11945563.15381229684145569.JavaMail.servlet@kundenserver> From: laurent@lvivier.info MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_755_14009840.1229684145519" Date: Fri, 19 Dec 2008 11:55:45 +0100 Subject: [Qemu-devel] Re: [PATCH 0/2][RFC][PPC] openbios support Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: aurelien@aurel32.net Cc: blauwirbel@gmail.com, qemu-devel@nongnu.org ------=_Part_755_14009840.1229684145519 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable >On Fri, Dec 19, 2008 at 09:54:54AM +0100, laurent@lvivier.info wrote: >> >Laurent Vivier a =C3=A9crit : >> >> These two patches allows to load an openbios elf image instead of an >> >> openhackware image. >> >>=20 >> >> [PATCH 1/2][RFC] Modify hw/ppc_oldword.c to use qemu_ram_alloc(). >> >> [PATCH 2/2][RFC] Load an OpenBios ELF image instead of OpenHackware= =20 >binary >> > >> >Great job! We are closer to get rid of OpenHackware. >> > >> >However I have tried those patches with the latest SVN from OpenBios, >> >and I am unable to get the machine booting. Do we need other patches fo= r >> >OpenBios or QEMU? It would be nice to make them available, even if they >> >are not ready for merge. >>=20 >> Yes, we need more patches: >>=20 >> - for qemu, an nvram cleanup I already sent some month ago, and a little= PCI=20 >cleanup patch. > >Could you please resent it? I will apply it if everything is ok. Here it is. Note that the NVRAM is stored into a file. Regards, Laurent ------=_Part_755_14009840.1229684145519 Content-Type: application/octet-stream; name=0001-PowerMac-NVRAM-cleanup.patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-PowerMac-NVRAM-cleanup.patch >>From 7d45ab963a98c4b26bd087dedd6714d9f3c2fd5e Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Thu, 18 Dec 2008 22:08:00 +0100 Subject: [PATCH] PowerMac NVRAM cleanup Signed-off-by: Laurent Vivier --- hw/mac_nvram.c | 122 ++++++++++++++++++++++++++++++++++++++++++----------- hw/ppc_mac.h | 4 +- hw/ppc_oldworld.c | 4 +- 3 files changed, 101 insertions(+), 29 deletions(-) diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c index f608ace..95b249e 100644 --- a/hw/mac_nvram.c +++ b/hw/mac_nvram.c @@ -23,12 +23,17 @@ * THE SOFTWARE. */ #include "hw.h" +#include "firmware_abi.h" #include "ppc_mac.h" +#define DEF_SYSTEM_SIZE 0xc10 + struct MacIONVRAMState { + target_phys_addr_t mem_base; target_phys_addr_t size; + QEMUFile *file; int mem_index; - uint8_t data[0x2000]; + uint8_t data[NVRAM_SIZE]; }; /* Direct access to NVRAM */ @@ -38,7 +43,7 @@ uint32_t macio_nvram_read (void *opaque, uint32_t addr) uint32_t ret; // printf("%s: %p addr %04x\n", __func__, s, addr); - if (addr < 0x2000) + if (addr < NVRAM_SIZE) ret = s->data[addr]; else ret = -1; @@ -51,7 +56,7 @@ void macio_nvram_write (void *opaque, uint32_t addr, uint32_t val) MacIONVRAMState *s = opaque; // printf("%s: %p addr %04x val %02x\n", __func__, s, addr, val); - if (addr < 0x2000) + if (addr < NVRAM_SIZE) s->data[addr] = val; } @@ -61,9 +66,14 @@ static void macio_nvram_writeb (void *opaque, { MacIONVRAMState *s = opaque; - addr = (addr >> 4) & 0x1fff; + addr = (addr >> 4) & (NVRAM_SIZE-1); s->data[addr] = value; // printf("macio_nvram_writeb %04x = %02x\n", addr, value); + if (s->file) { + qemu_fseek(s->file, addr, SEEK_SET); + qemu_put_byte(s->file, value); + qemu_fflush(s->file); + } } static uint32_t macio_nvram_readb (void *opaque, target_phys_addr_t addr) @@ -71,7 +81,7 @@ static uint32_t macio_nvram_readb (void *opaque, target_phys_addr_t addr) MacIONVRAMState *s = opaque; uint32_t value; - addr = (addr >> 4) & 0x1fff; + addr = (addr >> 4) & (NVRAM_SIZE-1); value = s->data[addr]; // printf("macio_nvram_readb %04x = %02x\n", addr, value); @@ -90,17 +100,32 @@ static CPUReadMemoryFunc *nvram_read[] = { &macio_nvram_readb, }; -MacIONVRAMState *macio_nvram_init (int *mem_index, target_phys_addr_t size) +MacIONVRAMState *macio_nvram_init (int *mem_index, const char *filename) { MacIONVRAMState *s; + QEMUFile *file; s = qemu_mallocz(sizeof(MacIONVRAMState)); if (!s) return NULL; - s->size = size; + s->size = NVRAM_SIZE << 4; s->mem_index = cpu_register_io_memory(0, nvram_read, nvram_write, s); *mem_index = s->mem_index; + /* Read current file */ + file = qemu_fopen(filename, "rb"); + if (file) { + /* Read nvram contents */ + qemu_get_buffer(file, s->data, s->size >> 4); + qemu_fclose(file); + } + s->file = qemu_fopen(filename, "wb"); + if (s->file) { + /* Write back contents, as 'wb' mode cleaned the file */ + qemu_put_buffer(s->file, s->data, s->size >> 4); + qemu_fflush(s->file); + } + return s; } @@ -112,26 +137,73 @@ void macio_nvram_map (void *opaque, target_phys_addr_t mem_base) cpu_register_physical_memory(mem_base, s->size, s->mem_index); } -static uint8_t nvram_chksum (const uint8_t *buf, int n) +static void nvram_set_header(MacIONVRAMState *nvr, + uint32_t addr, + uint8_t signature, + uint16_t size, + const char* name) +{ + struct OpenBIOS_nvpart_v1 *nvpart = (struct OpenBIOS_nvpart_v1 *)(nvr->data + addr); + + memset(nvpart, 0, sizeof(*nvpart)); + nvpart->signature = signature; + strncpy(nvpart->name, name, sizeof(nvpart->name)); + OpenBIOS_finish_partition(nvpart, size); +} + +static void create_free_part(MacIONVRAMState *nvr, uint32_t addr, int size ) +{ + nvram_set_header(nvr, addr, OPENBIOS_PART_FREE, size, "777777777777"); +} + +static int +next_nvpart(MacIONVRAMState *nvr, uint32_t *addr, uint32_t end) +{ + struct OpenBIOS_nvpart_v1 *nvpart = (struct OpenBIOS_nvpart_v1 *)(nvr->data + *addr); + int len; + + len = be16_to_cpu(nvpart->len); + if (len == 0) + return 1; + + *addr = (*addr) + len; + if( *addr < end ) + return 1; + if( *addr == end ) + return 0; + return -1; +} + +static int create_nv_part(MacIONVRAMState *nvr, uint32_t base, int max_size, + int signature, const char *name, int size ) { - int sum, i; - sum = 0; - for(i = 0; i < n; i++) - sum += buf[i]; - return (sum & 0xff) + (sum >> 8); + struct OpenBIOS_nvpart_v1 *nvpart; + uint32_t addr = base; + uint32_t end = base + max_size; + int len; + + do { + nvpart = (struct OpenBIOS_nvpart_v1 *)(nvr->data + addr); + + if (nvpart->signature != OPENBIOS_PART_FREE) + continue; + + len = be16_to_cpu(nvpart->len) << 4; + if (len < size) + size = len; + + nvram_set_header(nvr, addr, signature, size, name); + if (len > size) + create_free_part(nvr, addr + size, len - size); + return size; + } while (next_nvpart(nvr, &addr, end) > 0 ); + return -1; } -/* set a free Mac OS NVRAM partition */ -void pmac_format_nvram_partition (MacIONVRAMState *nvr, int len) +/* set a system Mac OS NVRAM partition */ +void pmac_format_nvram_partition (MacIONVRAMState *nvr) { - uint8_t *buf; - char partition_name[12] = "wwwwwwwwwwww"; - - buf = nvr->data; - buf[0] = 0x7f; /* free partition magic */ - buf[1] = 0; /* checksum */ - buf[2] = len >> 8; - buf[3] = len; - memcpy(buf + 4, partition_name, 12); - buf[1] = nvram_chksum(buf, 16); + create_free_part(nvr, 0, sizeof(nvr->data)); + create_nv_part(nvr, 0, sizeof(nvr->data), + OPENBIOS_PART_SYSTEM, "common", DEF_SYSTEM_SIZE); } diff --git a/hw/ppc_mac.h b/hw/ppc_mac.h index c833d17..343c91e 100644 --- a/hw/ppc_mac.h +++ b/hw/ppc_mac.h @@ -64,9 +64,9 @@ PCIBus *pci_pmac_init(qemu_irq *pic); /* Mac NVRAM */ typedef struct MacIONVRAMState MacIONVRAMState; -MacIONVRAMState *macio_nvram_init (int *mem_index, target_phys_addr_t size); +MacIONVRAMState *macio_nvram_init (int *mem_index, const char *filename); void macio_nvram_map (void *opaque, target_phys_addr_t mem_base); -void pmac_format_nvram_partition (MacIONVRAMState *nvr, int len); +void pmac_format_nvram_partition (MacIONVRAMState *nvr); uint32_t macio_nvram_read (void *opaque, uint32_t addr); void macio_nvram_write (void *opaque, uint32_t addr, uint32_t val); diff --git a/hw/ppc_oldworld.c b/hw/ppc_oldworld.c index 73cf4ab..eb9f33f 100644 --- a/hw/ppc_oldworld.c +++ b/hw/ppc_oldworld.c @@ -348,8 +348,8 @@ static void ppc_heathrow_init (ram_addr_t ram_size, int vga_ram_size, adb_kbd_init(&adb_bus); adb_mouse_init(&adb_bus); - nvr = macio_nvram_init(&nvram_mem_index, 0x2000); - pmac_format_nvram_partition(nvr, 0x2000); + nvr = macio_nvram_init(&nvram_mem_index, "g3bw_nvram"); + pmac_format_nvram_partition(nvr); dbdma_init(&dbdma_mem_index); -- 1.5.6.5 ------=_Part_755_14009840.1229684145519--