From ac35e158c1a908f8ea35ded97587c78a72babcae Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Thu, 16 Jul 2020 18:09:18 +0200 Subject: [PATCH] bios/boot: add bootargs support on netboot/sdcardboot to optionally specify r1/r2/r3/addr. For example: { "Image": "0x40000000", "bootargs": { "r1": "0x12345678", } } will copy Image to 0x40000000 and set r1 to 0x12345678. By default, r1,r2,r3 are set to 0 and addr is the address if the last loaded image, so: { "Image": "0x40000000", "rootfs.cpio": "0x40800000", "rv32.dtb": "0x41000000", "emulator.bin": "0x41100000", } is equivalent to: { "Image": "0x40000000", "rootfs.cpio": "0x40800000", "rv32.dtb": "0x41000000", "emulator.bin": "0x41100000", "bootargs": { "r1": "0x00000000", "r2": "0x00000000", "r3": "0x00000000", "addr": "0x00000000", } } --- litex/soc/software/bios/boot.c | 144 +++++++++++++++++++++++---------- 1 file changed, 103 insertions(+), 41 deletions(-) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index 1419a8e03..7a8198b2c 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -156,7 +156,7 @@ int serialboot(void) printf("Booting from serial...\n"); printf("Press Q or ESC to abort boot completely.\n"); - /* send the serialboot "magic" request to Host */ + /* Send the serialboot "magic" request to Host */ c = str; while(*c) { uart_write(*c); @@ -171,7 +171,7 @@ int serialboot(void) printf("Cancelled\n"); return 0; } - /* assume ACK_OK */ + /* Assume ACK_OK */ failed = 0; while(1) { @@ -239,7 +239,7 @@ int serialboot(void) addr = get_uint32(&frame.payload[0]); for (i = 4; i < frame.payload_length; i++) { - // erase page at sector boundaries before writing + /* Erase page at sector boundaries before writing */ if ((addr & (SPIFLASH_SECTOR_SIZE - 1)) == 0) { erase_flash_sector(addr); } @@ -314,10 +314,17 @@ static void netboot_from_json(const char * filename, unsigned int ip, unsigned s uint8_t count; /* FIXME: modify/increase if too limiting */ - char json_buffer[256]; - char image_filename[32]; - char image_address[32]; - uint8_t image_found; + char json_buffer[1024]; + char json_name[32]; + char json_value[32]; + + unsigned long boot_r1 = 0; + unsigned long boot_r2 = 0; + unsigned long boot_r3 = 0; + unsigned long boot_addr = 0; + + uint8_t image_found = 0; + uint8_t boot_addr_found = 0; /* Read JSON file */ size = tftp_get(ip, tftp_port, filename, json_buffer); @@ -325,31 +332,55 @@ static void netboot_from_json(const char * filename, unsigned int ip, unsigned s return; /* Parse JSON file */ - jsmntok_t t[16]; + jsmntok_t t[32]; jsmn_parser p; jsmn_init(&p); - image_found = 0; count = jsmn_parse(&p, json_buffer, strlen(json_buffer), t, sizeof(t)/sizeof(*t)); for (i=0; i