From 22ed61f97815856bf74cec25ae6bca88bfbe5f44 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 22 Dec 2010 19:19:14 -0800 Subject: zpu: renamed the directory for the usrp2 fw to zpu to reflect the cpu type --- firmware/zpu/usrp2p/bootloader_utils.c | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 firmware/zpu/usrp2p/bootloader_utils.c (limited to 'firmware/zpu/usrp2p/bootloader_utils.c') diff --git a/firmware/zpu/usrp2p/bootloader_utils.c b/firmware/zpu/usrp2p/bootloader_utils.c new file mode 100644 index 000000000..379c5f957 --- /dev/null +++ b/firmware/zpu/usrp2p/bootloader_utils.c @@ -0,0 +1,48 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Ettus Research LLC + * + */ + +//contains routines for loading programs from Flash. depends on Flash libraries. +//also contains routines for reading / writing EEPROM flags for the bootloader +#include +#include +#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 + for(size_t i = 0; i<63; i++) { + if(imgbuf[i] == 0xFF) continue; + if(imgbuf[i] == 0xAA && imgbuf[i+1] == 0x99) { + //printf("is_valid_fpga_image(): found valid FPGA image\n"); + return 1; + } + } + + return 0; +} + +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; +} + +void start_program(void) +{ + //ignoring the addr now + //all this does is tap that register + *((volatile uint32_t *) SR_ADDR_BLDRDONE) = 1; +} -- cgit v1.2.3 From 4de4c05f27978ba3f1dfdd14feddd82e26edf1fd Mon Sep 17 00:00:00 2001 From: Nick Foster Date: Thu, 30 Dec 2010 15:22:43 -0800 Subject: ZPU: bootloader only checks first 4 bytes of program flash image for validity --- firmware/zpu/usrp2p/bootloader_utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'firmware/zpu/usrp2p/bootloader_utils.c') diff --git a/firmware/zpu/usrp2p/bootloader_utils.c b/firmware/zpu/usrp2p/bootloader_utils.c index 379c5f957..371c518a7 100644 --- a/firmware/zpu/usrp2p/bootloader_utils.c +++ b/firmware/zpu/usrp2p/bootloader_utils.c @@ -30,14 +30,14 @@ 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 + static const uint8_t fwheader[] = {0x0b, 0x0b, 0x0b, 0x0b}; //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); + spi_flash_read(addr, 4, 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; + return memcmp(buf, fwheader, 4) == 0; } void start_program(void) -- cgit v1.2.3