diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index cf445eeca..7a4336aab 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -241,23 +241,6 @@ int serialboot(void) return 1; } -#if defined(CONFIG_CPU_VARIANT_LINUX) - -#ifndef KERNEL_IMAGE_RAM_OFFSET -#define KERNEL_IMAGE_RAM_OFFSET 0x00000000 -#endif -#ifndef ROOTFS_IMAGE_RAM_OFFSET -#define ROOTFS_IMAGE_RAM_OFFSET 0x00800000 -#endif -#ifndef DEVICE_TREE_IMAGE_RAM_OFFSET -#define DEVICE_TREE_IMAGE_RAM_OFFSET 0x01000000 -#endif -#ifndef EMULATOR_IMAGE_RAM_OFFSET -#define EMULATOR_IMAGE_RAM_OFFSET 0x01100000 -#endif - -#endif - #ifdef CSR_ETHMAC_BASE #ifndef LOCALIP1 @@ -274,138 +257,100 @@ int serialboot(void) #define REMOTEIP4 100 #endif -#define DEFAULT_TFTP_SERVER_PORT 69 /* IANA well known port: UDP/69 */ #ifndef TFTP_SERVER_PORT -#define TFTP_SERVER_PORT DEFAULT_TFTP_SERVER_PORT +#define TFTP_SERVER_PORT 69 #endif -static int tftp_get_v(unsigned int ip, unsigned short server_port, -const char *filename, char *buffer) -{ - int r; - - r = tftp_get(ip, server_port, filename, buffer); - if(r > 0) - printf("Downloaded %d bytes from %s over TFTP to 0x%08x\n", r, filename, buffer); - else - printf("Unable to download %s over TFTP\n", filename); - return r; -} - static const unsigned char macadr[6] = {0x10, 0xe2, 0xd5, 0x00, 0x00, 0x00}; -#if defined(CONFIG_CPU_TYPE_MOR1KX) && defined(CONFIG_CPU_VARIANT_LINUX) -static int try_get_kernel_rootfs_dtb(unsigned int ip, unsigned short tftp_port) +static int copy_file_from_tftp_to_ram(unsigned int ip, unsigned short server_port, +const char *filename, char *buffer) { - unsigned long tftp_dst_addr; int size; - - tftp_dst_addr = MAIN_RAM_BASE + KERNEL_IMAGE_RAM_OFFSET; - size = tftp_get_v(ip, tftp_port, "Image", (void *)tftp_dst_addr); - if (size <= 0) { - printf("Network boot failed\n"); - return 0; - } - - tftp_dst_addr = MAIN_RAM_BASE + DEVICE_TREE_IMAGE_RAM_OFFSET; - size = tftp_get_v(ip, tftp_port, "mor1kx.dtb", (void *)tftp_dst_addr); - if(size <= 0) { - printf("No mor1kx.dtb found\n"); - return 0; - } - - tftp_dst_addr = MAIN_RAM_BASE + ROOTFS_IMAGE_RAM_OFFSET; - size = tftp_get_v(ip, tftp_port, "rootfs.cpio", (void *)tftp_dst_addr); - if(size <= 0) { - printf("No rootfs.cpio found (optional)\n"); - } - - return 1; + printf("Copying %s to 0x%08x... ", filename, buffer); + size = tftp_get(ip, server_port, filename, buffer); + if(size > 0) + printf("(%d bytes)", size); + printf("\n"); + return size; } -#endif -#if defined(CONFIG_CPU_TYPE_VEXRISCV) && defined(CONFIG_CPU_VARIANT_LINUX) -static int try_get_kernel_rootfs_dtb_emulator(unsigned int ip, unsigned short tftp_port) +static void netboot_from_json(const char * filename, unsigned int ip, unsigned short tftp_port) { - unsigned long tftp_dst_addr; int size; + uint8_t i; + uint8_t count; - tftp_dst_addr = MAIN_RAM_BASE + KERNEL_IMAGE_RAM_OFFSET; - size = tftp_get_v(ip, tftp_port, "Image", (void *)tftp_dst_addr); - if (size <= 0) { - printf("Network boot failed\n"); - return 0; + /* FIXME: modify/increase if too limiting */ + char json_buffer[256]; + char image_filename[32]; + char image_address[32]; + uint8_t image_found; + + /* Read JSON file */ + size = tftp_get(ip, tftp_port, filename, json_buffer); + if (size <= 0) + return; + + /* Parse JSON file */ + jsmntok_t t[16]; + 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