diff options
| -rw-r--r-- | firmware/zpu/apps/txrx_uhd.c | 10 | ||||
| -rw-r--r-- | firmware/zpu/lib/u2_init.c | 7 | ||||
| -rw-r--r-- | firmware/zpu/usrp2p/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | firmware/zpu/usrp2p/bootloader/init_bootloader.c | 20 | ||||
| -rw-r--r-- | firmware/zpu/usrp2p/spi_flash.h | 23 | ||||
| -rw-r--r-- | firmware/zpu/usrp2p/spi_flash_read.c | 46 | ||||
| -rw-r--r-- | firmware/zpu/usrp2p/u2p_init.c | 33 | ||||
| -rw-r--r-- | firmware/zpu/usrp2p/u2p_init.h | 18 | 
8 files changed, 101 insertions, 57 deletions
| diff --git a/firmware/zpu/apps/txrx_uhd.c b/firmware/zpu/apps/txrx_uhd.c index 3fcda8a4e..79f301d42 100644 --- a/firmware/zpu/apps/txrx_uhd.c +++ b/firmware/zpu/apps/txrx_uhd.c @@ -333,16 +333,6 @@ main(void)  {    u2_init(); -//we do this to see if we should set a default ip addr or not -#ifdef USRP2P -  bool safe_fw = find_safe_booted_flag(); -  set_safe_booted_flag(0); -  if(safe_fw) { -    set_default_ip_addr(); -    set_default_mac_addr(); -  } -#endif -    putstr("\nTxRx-UHD-ZPU\n");    print_mac_addr(ethernet_mac_addr()); newline();    print_ip_addr(get_ip_addr()); newline(); diff --git a/firmware/zpu/lib/u2_init.c b/firmware/zpu/lib/u2_init.c index 71bd2c594..db26be538 100644 --- a/firmware/zpu/lib/u2_init.c +++ b/firmware/zpu/lib/u2_init.c @@ -26,6 +26,9 @@  #include "clocks.h"  #include "usrp2/fw_common.h"  #include "nonstdio.h" +#ifdef USRP2P +#include "u2p_init.h" +#endif  /*   * We ought to arrange for this to be called before main, but for now, @@ -50,6 +53,10 @@ u2_init(void)    i2c_init();    hal_enable_ints(); +#ifdef USRP2P +  u2p_init(); +#endif +    // flash all leds to let us know board is alive    hal_set_led_src(0x0, 0x1f); /* software ctrl */    hal_set_leds(0x0, 0x1f);    mdelay(300); diff --git a/firmware/zpu/usrp2p/CMakeLists.txt b/firmware/zpu/usrp2p/CMakeLists.txt index 41ef8f1dd..74d9e233d 100644 --- a/firmware/zpu/usrp2p/CMakeLists.txt +++ b/firmware/zpu/usrp2p/CMakeLists.txt @@ -30,6 +30,7 @@ ADD_LIBRARY(libusrp2pfw STATIC      ethernet.c      xilinx_s3_icap.c      udp_fw_update.c +    u2p_init.c  )  ADD_SUBDIRECTORY(bootloader) diff --git a/firmware/zpu/usrp2p/bootloader/init_bootloader.c b/firmware/zpu/usrp2p/bootloader/init_bootloader.c index cfa80ffea..f71b0a7b2 100644 --- a/firmware/zpu/usrp2p/bootloader/init_bootloader.c +++ b/firmware/zpu/usrp2p/bootloader/init_bootloader.c @@ -11,6 +11,7 @@  #include <spi_flash.h>  #include <spi_flash_private.h>  //#include <clocks.h> +#include <mdelay.h>  #include <ihex.h>  #include <bootloader_utils.h>  #include <string.h> @@ -49,17 +50,14 @@ void load_ihex(void) { //simple IHEX parser to load proper records into RAM. loa  	}  } -void delay(uint32_t t) { -	while(t-- != 0) asm("NOP"); -} -  int main(int argc, char *argv[]) { -  hal_disable_ints();	// In case we got here via jmp 0x0 +	hal_disable_ints();	// In case we got here via jmp 0x0  	output_regs->leds = 0xFF; -	delay(5000); +	mdelay(100);  	output_regs->leds = 0x00;  	hal_uart_init();  	spif_init(); +	spi_flash_init();  	i2c_init(); //for EEPROM  	puts("USRP2+ bootloader super ultra ZPU edition\n"); @@ -85,7 +83,7 @@ int main(int argc, char *argv[]) {  		if(is_valid_fpga_image(PROD_FPGA_IMAGE_LOCATION_ADDR)) {  			puts("Valid production FPGA image found. Attempting to boot.");  			set_safe_booted_flag(1); -			delay(300); //so serial output can finish +			mdelay(300); //so serial output can finish  			icap_reload_fpga(PROD_FPGA_IMAGE_LOCATION_ADDR);  		}  		puts("No valid production FPGA image found.\nAttempting to load production firmware..."); @@ -94,11 +92,11 @@ int main(int argc, char *argv[]) {  		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); +		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. -		delay(300); +		mdelay(300);  		icap_reload_fpga(SAFE_FPGA_IMAGE_LOCATION_ADDR);  		return 1;  	} @@ -106,10 +104,10 @@ int main(int argc, char *argv[]) {  	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); +		mdelay(300);  		start_program();  		puts("ERROR: return from main program! This should never happen!"); -		delay(300); +		mdelay(300);  		icap_reload_fpga(SAFE_FPGA_IMAGE_LOCATION_ADDR);  		return 1;  	} diff --git a/firmware/zpu/usrp2p/spi_flash.h b/firmware/zpu/usrp2p/spi_flash.h index bbe7b650d..bfecab468 100644 --- a/firmware/zpu/usrp2p/spi_flash.h +++ b/firmware/zpu/usrp2p/spi_flash.h @@ -30,20 +30,15 @@  uint32_t spi_flash_rdid(void);	/* Read ID */  uint32_t spi_flash_rdsr(void);	/* Read Status Register */ -size_t spi_flash_log2_sector_size(void) __attribute__((pure));  /* either 16 or 18 */ -size_t spi_flash_log2_memory_size(void); - -static inline size_t -spi_flash_sector_size(void) -{ -  return ((size_t) 1) << spi_flash_log2_sector_size(); -} - -static inline size_t -spi_flash_memory_size(void) -{ -  return ((size_t) 1) << spi_flash_log2_memory_size(); -} + +//! call before using any spi flash utilities +void spi_flash_init(void); + +size_t spi_flash_log2_sector_size(void); + +size_t spi_flash_sector_size(void); + +size_t spi_flash_memory_size(void);  void spi_flash_read(uint32_t flash_addr,  size_t nbytes, void *buf); diff --git a/firmware/zpu/usrp2p/spi_flash_read.c b/firmware/zpu/usrp2p/spi_flash_read.c index 75721b0f7..c65b8c1a1 100644 --- a/firmware/zpu/usrp2p/spi_flash_read.c +++ b/firmware/zpu/usrp2p/spi_flash_read.c @@ -21,42 +21,44 @@  #include <stdlib.h>		// abort  #include <nonstdio.h> -//FIXME cannot be zero or it gets optimized out and the get size functions break... -#define UNINITIALIZED 0xdeadbeef -  uint32_t   spi_flash_rdid(void)  {    return spif_transact(SPI_TXRX, SPI_SS_FLASH, RDID_CMD << 24, 32, FLAGS) & 0xffffff;  } -size_t  -spi_flash_log2_sector_size(void) -{ -  static unsigned char log2_sector_size[3] = { -    16, /* M25P32  */ -    16, /* M25P64  */ -    18, /* M25P128 */ -  }; -  return log2_sector_size[spi_flash_log2_memory_size() - 22]; -} +static size_t _spi_flash_log2_memory_size, _spi_flash_log2_sector_size; -size_t -spi_flash_log2_memory_size(void) +void spi_flash_init(void)  { -  static size_t _spi_flash_log2_memory_size = UNINITIALIZED; - -  if (_spi_flash_log2_memory_size == UNINITIALIZED){      uint32_t id = spi_flash_rdid();      uint8_t type = (id >> 8) & 0xff;      uint8_t size = (id >> 0) & 0xff;      if (type != 0x20 || size < 22 || size > 24) -      abort(); - +        abort();      _spi_flash_log2_memory_size = size; -  } -  return _spi_flash_log2_memory_size; +    static unsigned char log2_sector_size[3] = { +        16, /* M25P32  */ +        16, /* M25P64  */ +        18, /* M25P128 */ +    }; +    _spi_flash_log2_sector_size = log2_sector_size[_spi_flash_log2_memory_size - 22]; +} + +size_t spi_flash_log2_sector_size(void) +{ +  return _spi_flash_log2_sector_size; +} + +size_t spi_flash_sector_size(void) +{ +  return ((size_t) 1) << _spi_flash_log2_sector_size; +} + +size_t spi_flash_memory_size(void) +{ +  return ((size_t) 1) << _spi_flash_log2_memory_size;  }  void  diff --git a/firmware/zpu/usrp2p/u2p_init.c b/firmware/zpu/usrp2p/u2p_init.c new file mode 100644 index 000000000..6fe9729ac --- /dev/null +++ b/firmware/zpu/usrp2p/u2p_init.c @@ -0,0 +1,33 @@ +/* + * Copyright 2011 Ettus Research LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program.  If not, see <http://www.gnu.org/licenses/>. + */ + +#include "u2p_init.h" +#include "spi_flash.h" +#include "i2c.h" +#include "ethernet.h" + +void u2p_init(void){ +    spi_flash_init(); + +    //we do this to see if we should set a default ip addr or not +    bool safe_fw = find_safe_booted_flag(); +    set_safe_booted_flag(0); +    if (safe_fw) { +        set_default_ip_addr(); +        set_default_mac_addr(); +    } +} diff --git a/firmware/zpu/usrp2p/u2p_init.h b/firmware/zpu/usrp2p/u2p_init.h new file mode 100644 index 000000000..b0dc20f1f --- /dev/null +++ b/firmware/zpu/usrp2p/u2p_init.h @@ -0,0 +1,18 @@ +/* + * Copyright 2011 Ettus Research LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program.  If not, see <http://www.gnu.org/licenses/>. + */ + +void u2p_init(void); | 
