From afd21d0a3e4a62c64a74368b34af2ae689c76f89 Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Thu, 16 Dec 2010 15:41:52 -0800 Subject: N210: ZPU firmware bootloader changes --- firmware/microblaze/usrp2p/bootloader/init_bootloader.c | 8 +++++++- firmware/microblaze/usrp2p/bootloader_utils.c | 11 ++++++++++- firmware/microblaze/usrp2p/bootloader_utils.h | 4 ++-- firmware/microblaze/usrp2p/spi_flash_read.c | 6 ++++-- 4 files changed, 23 insertions(+), 6 deletions(-) (limited to 'firmware/microblaze') diff --git a/firmware/microblaze/usrp2p/bootloader/init_bootloader.c b/firmware/microblaze/usrp2p/bootloader/init_bootloader.c index 53b50e34e..dc22ef8d0 100644 --- a/firmware/microblaze/usrp2p/bootloader/init_bootloader.c +++ b/firmware/microblaze/usrp2p/bootloader/init_bootloader.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { hal_uart_init(); spif_init(); i2c_init(); //for EEPROM - puts("USRP2+ bootloader\n"); + puts("USRP2+ bootloader super ultra ZPU edition\n"); bool production_image = find_safe_booted_flag(); set_safe_booted_flag(0); //haven't booted yet @@ -93,17 +93,23 @@ int main(int argc, char *argv[]) { if(is_valid_fw_image(PROD_FW_IMAGE_LOCATION_ADDR)) { puts("Valid production firmware found. Loading..."); spi_flash_read(PROD_FW_IMAGE_LOCATION_ADDR, FW_IMAGE_SIZE_BYTES, (void *)RAM_BASE); + puts("Finished loading. Starting image."); + delay(300); start_program(); puts("ERROR: Return from main program! This should never happen!"); //if this happens, though, the safest thing to do is reboot the whole FPGA and start over. + delay(300); icap_reload_fpga(SAFE_FPGA_IMAGE_LOCATION_ADDR); return 1; } puts("No valid production firmware found. Trying safe firmware..."); if(is_valid_fw_image(SAFE_FW_IMAGE_LOCATION_ADDR)) { spi_flash_read(SAFE_FW_IMAGE_LOCATION_ADDR, FW_IMAGE_SIZE_BYTES, (void *)RAM_BASE); + puts("Finished loading. Starting image."); + delay(300); start_program(); puts("ERROR: return from main program! This should never happen!"); + delay(300); icap_reload_fpga(SAFE_FPGA_IMAGE_LOCATION_ADDR); return 1; } diff --git a/firmware/microblaze/usrp2p/bootloader_utils.c b/firmware/microblaze/usrp2p/bootloader_utils.c index d04cffcf6..fa56c199a 100644 --- a/firmware/microblaze/usrp2p/bootloader_utils.c +++ b/firmware/microblaze/usrp2p/bootloader_utils.c @@ -11,15 +11,20 @@ #include #include #include +#include int is_valid_fpga_image(uint32_t addr) { +// printf("is_valid_fpga_image(): starting with addr=%x...\n", addr); uint8_t imgbuf[64]; spi_flash_read(addr, 64, imgbuf); //we're just looking for leading 0xFF padding, followed by the sync bytes 0xAA 0x99 int i = 0; for(i; i<63; i++) { if(imgbuf[i] == 0xFF) continue; - if(imgbuf[i] == 0xAA && imgbuf[i+1] == 0x99) return 1; + if(imgbuf[i] == 0xAA && imgbuf[i+1] == 0x99) { + //printf("is_valid_fpga_image(): found valid FPGA image\n"); + return 1; + } } return 0; @@ -27,8 +32,12 @@ int is_valid_fpga_image(uint32_t addr) { int is_valid_fw_image(uint32_t addr) { static const uint8_t fwheader[] = {0x0b, 0x0b, 0x0b, 0x0b, 0x80, 0x70}; //just lookin for a jump to anywhere located at the reset vector + //printf("is_valid_fw_image(): starting with addr=%x...\n", addr); uint8_t buf[12]; spi_flash_read(addr, 6, buf); + //printf("is_valid_fw_image(): read "); + //for(int i = 0; i < 5; i++) printf("%x ", buf[i]); + //printf("\n"); return memcmp(buf, fwheader, 6) == 0; } diff --git a/firmware/microblaze/usrp2p/bootloader_utils.h b/firmware/microblaze/usrp2p/bootloader_utils.h index 9fdeebf17..3ad0d4f74 100644 --- a/firmware/microblaze/usrp2p/bootloader_utils.h +++ b/firmware/microblaze/usrp2p/bootloader_utils.h @@ -9,8 +9,8 @@ //we're working in bytes and byte addresses so we can run the same code with Flash chips of different sector sizes. //it's really 1463736, but rounded up to 1.5MB #define FPGA_IMAGE_SIZE_BYTES 1572864 -//16K -#define FW_IMAGE_SIZE_BYTES 16384 +//16K - 4B for the hell of it +#define FW_IMAGE_SIZE_BYTES 15360 #define SAFE_FPGA_IMAGE_LOCATION_ADDR 0x00000000 #define SAFE_FW_IMAGE_LOCATION_ADDR 0x003F0000 diff --git a/firmware/microblaze/usrp2p/spi_flash_read.c b/firmware/microblaze/usrp2p/spi_flash_read.c index 4682c5fe6..02155b209 100644 --- a/firmware/microblaze/usrp2p/spi_flash_read.c +++ b/firmware/microblaze/usrp2p/spi_flash_read.c @@ -19,6 +19,7 @@ #include "spi_flash_private.h" #include // abort +#include static size_t _spi_flash_log2_memory_size; @@ -99,8 +100,9 @@ spi_flash_read(uint32_t flash_addr, size_t nbytes, void *buf) * Read up to 16 bytes at a time until done */ unsigned char *dst = (unsigned char *) buf; - size_t m; - for (size_t n = 0; n < nbytes; n += m, dst += m){ + uint32_t m; + for (uint32_t n = 0; n < nbytes; n += m, dst += m){ + spif_regs->ctrl = FLAGS | LEN(16 * 8); // xfer 16 bytes spif_regs->ctrl = FLAGS | LEN(16 * 8) | SPI_CTRL_GO_BSY; spif_wait(); -- cgit v1.2.3