Skip to content

Commit

Permalink
Made paths flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
devos50 committed Nov 8, 2023
1 parent 4a95aea commit 6024cbc
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 179 deletions.
54 changes: 37 additions & 17 deletions hw/arm/ipod_touch_2g.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,24 @@ static void ipod_touch_memory_setup(MachineState *machine, MemoryRegion *sysmem,
// load the bootrom (vrom)
uint8_t *file_data = NULL;
unsigned long fsize;
if (g_file_get_contents("/Users/martijndevos/Documents/ipod_touch_2g_emulation/bootrom_240_4", (char **)&file_data, &fsize, NULL)) {
if (g_file_get_contents(nms->bootrom_path, (char **)&file_data, &fsize, NULL)) {
allocate_ram(sysmem, "vrom", 0x0, 0x20000);
address_space_rw(nsas, VROM_MEM_BASE, MEMTXATTRS_UNSPECIFIED, (uint8_t *)file_data, fsize, 1);
}
}

static char *ipod_touch_get_bootrom_path(Object *obj, Error **errp)
{
IPodTouchMachineState *nms = IPOD_TOUCH_MACHINE(obj);
return g_strdup(nms->bootrom_path);
}

static void ipod_touch_set_bootrom_path(Object *obj, const char *value, Error **errp)
{
IPodTouchMachineState *nms = IPOD_TOUCH_MACHINE(obj);
g_strlcpy(nms->bootrom_path, value, sizeof(nms->bootrom_path));
}

static char *ipod_touch_get_nor_path(Object *obj, Error **errp)
{
IPodTouchMachineState *nms = IPOD_TOUCH_MACHINE(obj);
Expand All @@ -114,10 +126,28 @@ static void ipod_touch_set_nor_path(Object *obj, const char *value, Error **errp
g_strlcpy(nms->nor_path, value, sizeof(nms->nor_path));
}

static char *ipod_touch_get_nand_path(Object *obj, Error **errp)
{
IPodTouchMachineState *nms = IPOD_TOUCH_MACHINE(obj);
return g_strdup(nms->nand_path);
}

static void ipod_touch_set_nand_path(Object *obj, const char *value, Error **errp)
{
IPodTouchMachineState *nms = IPOD_TOUCH_MACHINE(obj);
g_strlcpy(nms->nand_path, value, sizeof(nms->nand_path));
}

static void ipod_touch_instance_init(Object *obj)
{
object_property_add_str(obj, "bootrom", ipod_touch_get_bootrom_path, ipod_touch_set_bootrom_path);
object_property_set_description(obj, "bootrom", "Path to the S5L8720 bootrom binary");

object_property_add_str(obj, "nor", ipod_touch_get_nor_path, ipod_touch_set_nor_path);
object_property_set_description(obj, "nor", "Path to the S5L8720 NOR image");

object_property_add_str(obj, "nand", ipod_touch_get_nand_path, ipod_touch_set_nand_path);
object_property_set_description(obj, "nand", "Path to the NAND files");
}

static inline qemu_irq s5l8900_get_irq(IPodTouchMachineState *s, int n)
Expand Down Expand Up @@ -263,26 +293,22 @@ static void ipod_touch_machine_init(MachineState *machine)

dev = exynos4210_uart_create(UART0_MEM_BASE, 256, 0, serial_hd(0), nms->irq[0][24]);
if (!dev) {
printf("Failed to create uart0 device!\n");
abort();
hw_error("Failed to create UART0 device!");
}

dev = exynos4210_uart_create(UART1_MEM_BASE, 256, 1, serial_hd(1), nms->irq[0][25]);
if (!dev) {
printf("Failed to create uart1 device!\n");
abort();
hw_error("Failed to create UART0 device!");
}

dev = exynos4210_uart_create(UART2_MEM_BASE, 256, 2, serial_hd(2), nms->irq[0][26]);
if (!dev) {
printf("Failed to create uart2 device!\n");
abort();
hw_error("Failed to create UART0 device!");
}

dev = exynos4210_uart_create(UART3_MEM_BASE, 256, 3, serial_hd(3), nms->irq[0][27]);
if (!dev) {
printf("Failed to create uart3 device!\n");
abort();
hw_error("Failed to create UART0 device!");
}

// dev = exynos4210_uart_create(UART4_MEM_BASE, 256, 4, serial_hd(4), nms->irq[0][28]);
Expand All @@ -295,14 +321,13 @@ static void ipod_touch_machine_init(MachineState *machine)
set_spi_base(0);
dev = sysbus_create_simple("ipodtouch.spi", SPI0_MEM_BASE, s5l8900_get_irq(nms, S5L8720_SPI0_IRQ));
IPodTouchSPIState *spi0_state = IPOD_TOUCH_SPI(dev);
spi0_state->nor->nor_path = nms->nor_path;
nms->spi0_state = spi0_state;
strcpy(spi0_state->nor->nor_path, nms->nor_path);

set_spi_base(1);
dev = sysbus_create_simple("ipodtouch.spi", SPI1_MEM_BASE, s5l8900_get_irq(nms, S5L8720_SPI1_IRQ));
IPodTouchSPIState *spi1_state = IPOD_TOUCH_SPI(dev);
nms->spi1_state = spi1_state;
//strcpy(spi1_state->nor->nor_path, nms->nor_path);

set_spi_base(2);
sysbus_create_simple("ipodtouch.spi", SPI2_MEM_BASE, s5l8900_get_irq(nms, S5L8720_SPI2_IRQ));
Expand Down Expand Up @@ -395,6 +420,7 @@ static void ipod_touch_machine_init(MachineState *machine)
// init the FMSS flash controller
dev = qdev_new("ipodtouch.fmss");
IPodTouchFMSSState *fmss_state = IPOD_TOUCH_FMSS(dev);
fmss_state->nand_path = nms->nand_path;
nms->fmss_state = fmss_state;
busdev = SYS_BUS_DEVICE(dev);
memory_region_add_subregion(sysmem, FMSS_MEM_BASE, &fmss_state->iomem);
Expand Down Expand Up @@ -452,12 +478,6 @@ static void ipod_touch_machine_init(MachineState *machine)
nms->pke_state = pke_state;
memory_region_add_subregion(sysmem, PKE_MEM_BASE, &pke_state->iomem);

// init block device engine
dev = qdev_new("ipodtouch.blockdevice");
IPodTouchBlockDeviceState *bdev_state = IPOD_TOUCH_BLOCK_DEVICE(dev);
nms->bdev_state = bdev_state;
memory_region_add_subregion(sysmem, BLOCK_DEVICE_MEM_BASE, &bdev_state->iomem);

// init the MBX
dev = qdev_new("ipodtouch.mbx");
IPodTouchMBXState *mbx_state = IPOD_TOUCH_MBX(dev);
Expand Down
108 changes: 0 additions & 108 deletions hw/arm/ipod_touch_block_device.c

This file was deleted.

13 changes: 3 additions & 10 deletions hw/arm/ipod_touch_fmss.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#include "hw/arm/ipod_touch_fmss.h"

static uint32_t reverse_byte_order(uint32_t value) {
return ((value & 0x000000FF) << 24) |
((value & 0x0000FF00) << 8) |
((value & 0x00FF0000) >> 8) |
((value & 0xFF000000) >> 24);
}

static uint8_t find_bit_index(uint8_t num) {
int index = 0;
while (num > 1) {
Expand Down Expand Up @@ -35,7 +28,7 @@ static void read_nand_pages(IPodTouchFMSSState *s)
cpu_physical_memory_write(0x0ff2a584, boot_args, strlen(boot_args));

// patch iBoot - we want to inject the bluetooth MAC address which is located as sub-node of uart1 and not uart3 in the device tree...
char *chr = "arm-io/uart1/bluetooth";
const char *chr = "arm-io/uart1/bluetooth";
cpu_physical_memory_write(0x0ff2206c, chr, strlen(chr));

int page_out_buf_ind = 0;
Expand All @@ -51,14 +44,14 @@ static void read_nand_pages(IPodTouchFMSSState *s)
cs = find_bit_index(cs);

if(cs > 3) {
printf("CS %d invalid! (og CS: %d, reading page %d)\n", cs, og_cs, page_nr);
printf("CS %d invalid! (original CS: %d, reading page %d)\n", cs, og_cs, page_nr);
dump_registers(s);
hw_error("CS %d invalid!", cs);
}

// prepare the page
char filename[200];
sprintf(filename, "/Users/martijndevos/Documents/generate_nand_it2g/nand/cs%d/%d.page", cs, page_nr);
sprintf(filename, "%s/cs%d/%d.page", s->nand_path, cs, page_nr);
struct stat st = {0};
if (stat(filename, &st) == -1) {
// page storage does not exist - initialize an empty buffer
Expand Down
7 changes: 1 addition & 6 deletions hw/arm/ipod_touch_nor_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
static void initialize_nor(IPodTouchNORSPIState *s)
{
unsigned long fsize;
// TODO still hardcoded, string copy not working...
if (g_file_get_contents("/Users/martijndevos/Documents/generate_nor_it2g/nor.bin", (char **)&s->nor_data, &fsize, NULL)) {
if (g_file_get_contents(s->nor_path, (char **)&s->nor_data, &fsize, NULL)) {
s->nor_initialized = true;
}
}
Expand All @@ -21,7 +20,6 @@ static uint32_t ipod_touch_nor_spi_transfer(SSIPeripheral *dev, uint32_t value)
if(s->cur_cmd == 0) {
// this is a new command -> set it
s->cur_cmd = value;
printf("NEW CMD %d\n", s->cur_cmd);
s->out_buf = malloc(0x1000);
s->in_buf = malloc(0x1000);
s->in_buf[0] = value;
Expand All @@ -35,7 +33,6 @@ static uint32_t ipod_touch_nor_spi_transfer(SSIPeripheral *dev, uint32_t value)
s->out_buf[0] = 0;
}
else if(value == NOR_GET_STATUS_CMD) {
printf("GET STATUS\n");
s->in_buf_size = 1;
s->out_buf_size = 1;
s->out_buf[0] = 0;
Expand All @@ -46,7 +43,6 @@ static uint32_t ipod_touch_nor_spi_transfer(SSIPeripheral *dev, uint32_t value)
for(int i = 0; i < 256; i++) { s->out_buf[i] = 0; }; // TODO we ignore this command for now
}
else if(value == NOR_READ_DATA_CMD) {
printf("Received read command!\n");
s->in_buf_size = 4;
s->out_buf_size = 4096;
}
Expand Down Expand Up @@ -88,7 +84,6 @@ static uint32_t ipod_touch_nor_spi_transfer(SSIPeripheral *dev, uint32_t value)
else if(s->cur_cmd == NOR_READ_DATA_CMD && s->in_buf_cur_ind == s->in_buf_size) {
if(!s->nor_initialized) { initialize_nor(s); }
s->nor_read_ind = (s->in_buf[1] << 16) | (s->in_buf[2] << 8) | s->in_buf[3];
printf("Setting NOR read index to: %d\n", s->nor_read_ind);
}
return 0x0;
}
Expand Down
10 changes: 4 additions & 6 deletions hw/arm/ipod_touch_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,15 @@ static void ipod_touch_spi_realize(DeviceState *dev, struct Error **errp)
fifo8_create(&s->rx_fifo, R_FIFO_RX_DEPTH);

// create the peripheral
IPodTouchNORSPIState *nor;
switch(s->base) {
case 0:
ssi_create_peripheral(s->spi, TYPE_IPOD_TOUCH_NOR_SPI);
nor = IPOD_TOUCH_NOR_SPI(dev);
{
DeviceState *dev = ssi_create_peripheral(s->spi, TYPE_IPOD_TOUCH_NOR_SPI);
IPodTouchNORSPIState *nor = IPOD_TOUCH_NOR_SPI(dev);
s->nor = nor;
break;
}
case 1:
//ssi_create_peripheral(s->spi, TYPE_IPOD_TOUCH_NOR_SPI);
//nor = IPOD_TOUCH_NOR_SPI(dev);
//s->nor = nor;
break;
case 4:
{
Expand Down
2 changes: 1 addition & 1 deletion hw/arm/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ arm_ss.add(when: 'CONFIG_FSL_IMX7', if_true: files('fsl-imx7.c', 'mcimx7d-sabre.
arm_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c', 'smmuv3.c'))
arm_ss.add(when: 'CONFIG_FSL_IMX6UL', if_true: files('fsl-imx6ul.c', 'mcimx6ul-evk.c'))
arm_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_soc.c'))
arm_ss.add(when: 'CONFIG_IPOD_TOUCH_2G', if_true: files('ipod_touch_2g.c', 'ipod_touch_clock.c', 'ipod_touch_chipid.c', 'ipod_touch_gpio.c', 'ipod_touch_sysic.c', 'ipod_touch_timer.c', 'ipod_touch_usb_otg.c', 'ipod_touch_usb_phys.c', 'ipod_touch_spi.c', 'ipod_touch_nor_spi.c', 'ipod_touch_sha1.c', 'ipod_touch_aes.c', 'ipod_touch_pke.c', 'ipod_touch_pcf50633_pmu.c', 'ipod_touch_unknown1.c', 'ipod_touch_lcd.c', 'ipod_touch_mipi_dsi.c', 'ipod_touch_fmss.c', 'ipod_touch_block_device.c', 'ipod_touch_mbx.c', 'ipod_touch_cd3272_mikey.c', 'ipod_touch_lis302dl.c', 'ipod_touch_multitouch.c', 'ipod_touch_scaler_csc.c', 'ipod_touch_sdio.c', 'ipod_touch_tvout.c'))
arm_ss.add(when: 'CONFIG_IPOD_TOUCH_2G', if_true: files('ipod_touch_2g.c', 'ipod_touch_clock.c', 'ipod_touch_chipid.c', 'ipod_touch_gpio.c', 'ipod_touch_sysic.c', 'ipod_touch_timer.c', 'ipod_touch_usb_otg.c', 'ipod_touch_usb_phys.c', 'ipod_touch_spi.c', 'ipod_touch_nor_spi.c', 'ipod_touch_sha1.c', 'ipod_touch_aes.c', 'ipod_touch_pke.c', 'ipod_touch_pcf50633_pmu.c', 'ipod_touch_unknown1.c', 'ipod_touch_lcd.c', 'ipod_touch_mipi_dsi.c', 'ipod_touch_fmss.c', 'ipod_touch_mbx.c', 'ipod_touch_cd3272_mikey.c', 'ipod_touch_lis302dl.c', 'ipod_touch_multitouch.c', 'ipod_touch_scaler_csc.c', 'ipod_touch_sdio.c', 'ipod_touch_tvout.c'))

hw_arch += {'arm': arm_ss}
5 changes: 2 additions & 3 deletions include/hw/arm/ipod_touch_2g.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "hw/arm/ipod_touch_lcd.h"
#include "hw/arm/ipod_touch_mipi_dsi.h"
#include "hw/arm/ipod_touch_fmss.h"
#include "hw/arm/ipod_touch_block_device.h"
#include "hw/arm/ipod_touch_mbx.h"
#include "hw/arm/ipod_touch_scaler_csc.h"
#include "hw/arm/ipod_touch_sdio.h"
Expand Down Expand Up @@ -80,7 +79,6 @@ const int S5L8900_GPIO_IRQS[5] = { S5L8900_GPIO_G0_IRQ, S5L8900_GPIO_G1_IRQ, S5L
#define DMAC1_0_MEM_BASE 0x38700000
#define DISPLAY_MEM_BASE 0x38900000
#define FMSS_MEM_BASE 0x38A00000
#define BLOCK_DEVICE_MEM_BASE 0x38A00F00
#define AES_MEM_BASE 0x38C00000
#define SDIO_MEM_BASE 0x38D00000
#define VIC0_MEM_BASE 0x38E00000
Expand Down Expand Up @@ -147,13 +145,14 @@ typedef struct {
IPodTouchLCDState *lcd_state;
IPodTouchMIPIDSIState *mipi_dsi_state;
IPodTouchFMSSState *fmss_state;
IPodTouchBlockDeviceState *bdev_state;
IPodTouchMBXState *mbx_state;
IPodTouchScalerCSCState *scaler_csc_state;
IPodTouchSDIOState *sdio_state;
IPodTouchTVOutState *tvout_state;
Clock *sysclk;
char bootrom_path[1024];
char nor_path[1024];
char nand_path[1024];
IT2G_CPREG_VAR_DEF(REG0);
IT2G_CPREG_VAR_DEF(REG1);
} IPodTouchMachineState;
Expand Down
Loading

0 comments on commit 6024cbc

Please sign in to comment.