aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/zpu/usrp2p/bootloader_utils.c
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2011-04-22 11:28:27 -0700
committerNick Foster <nick@nerdnetworks.org>2011-04-22 11:28:27 -0700
commit361300327fceb20a5256cc9c5e5c6096cdbcd014 (patch)
treed740ba064a1e42b2057484bcc325e9c045cc1fa3 /firmware/zpu/usrp2p/bootloader_utils.c
parent3dd74062fc6cfad68a62faac6669bada96f3aecf (diff)
downloaduhd-361300327fceb20a5256cc9c5e5c6096cdbcd014.tar.gz
uhd-361300327fceb20a5256cc9c5e5c6096cdbcd014.tar.bz2
uhd-361300327fceb20a5256cc9c5e5c6096cdbcd014.zip
N210: TXRX_UHD now has bootloader #ifdef'ed into it. Safe firmware now embedded into FPGA bootloader.
Also did some cleanup of unused source files and consolidated bootloader stuff into bootloader_utils.
Diffstat (limited to 'firmware/zpu/usrp2p/bootloader_utils.c')
-rw-r--r--firmware/zpu/usrp2p/bootloader_utils.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/firmware/zpu/usrp2p/bootloader_utils.c b/firmware/zpu/usrp2p/bootloader_utils.c
index 371c518a7..15e21f054 100644
--- a/firmware/zpu/usrp2p/bootloader_utils.c
+++ b/firmware/zpu/usrp2p/bootloader_utils.c
@@ -10,8 +10,13 @@
#include <string.h>
#include <bootloader_utils.h>
#include <spi_flash.h>
+#include <i2c.h>
#include <memory_map.h>
#include <nonstdio.h>
+#include <xilinx_s3_icap.h>
+#include <mdelay.h>
+
+#define BUTTON_PUSHED ((router_status->irqs & PIC_BUTTON) ? 0 : 1)
int is_valid_fpga_image(uint32_t addr) {
// printf("is_valid_fpga_image(): starting with addr=%x...\n", addr);
@@ -46,3 +51,51 @@ void start_program(void)
//all this does is tap that register
*((volatile uint32_t *) SR_ADDR_BLDRDONE) = 1;
}
+
+void do_the_bootload_thing(void) {
+ bool production_image = find_safe_booted_flag();
+ set_safe_booted_flag(0); //haven't booted yet
+
+ if(BUTTON_PUSHED) { //see memory_map.h
+ puts("Starting USRP2+ in safe mode. Loading safe firmware.");
+ return;
+ }
+
+ if(!production_image) {
+ puts("Checking for valid production FPGA image...");
+ if(is_valid_fpga_image(PROD_FPGA_IMAGE_LOCATION_ADDR)) {
+ puts("Valid production FPGA image found. Attempting to boot.");
+ set_safe_booted_flag(1);
+ mdelay(300); //so serial output can finish
+ icap_reload_fpga(PROD_FPGA_IMAGE_LOCATION_ADDR);
+ }
+ puts("No valid production FPGA image found.\nFalling through to built-in firmware.");
+ return;
+ }
+ 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.");
+ mdelay(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.
+ mdelay(300);
+ icap_reload_fpga(SAFE_FPGA_IMAGE_LOCATION_ADDR);
+ return;
+ }
+ puts("No valid production firmware found. Falling through to built-in 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.");
+ mdelay(300);
+ start_program();
+ puts("ERROR: return from main program! This should never happen!");
+ mdelay(300);
+ icap_reload_fpga(SAFE_FPGA_IMAGE_LOCATION_ADDR);
+ return;
+ }
+ puts("ERROR: no safe firmware image available. Falling through to built-in firmware.");
+ */
+}