aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/zpu
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-10 12:23:08 -0800
committerJosh Blum <josh@joshknows.com>2011-01-10 12:23:08 -0800
commit2106c6cf594866061f56b09d1396bb80df51802e (patch)
tree65c94c63d5737d88653d87e7285627650318b55a /firmware/zpu
parent916223ef3544452bee57b08f9593aa9da66212a5 (diff)
downloaduhd-2106c6cf594866061f56b09d1396bb80df51802e.tar.gz
uhd-2106c6cf594866061f56b09d1396bb80df51802e.tar.bz2
uhd-2106c6cf594866061f56b09d1396bb80df51802e.zip
usrp2: firmware pad bins to zero to deal with optimizing out the static vars that init to zero
removed the spi flash init in favor of an initialization constant at zero tweaked the cmakelists flags list added pad option to the gen binaries macro
Diffstat (limited to 'firmware/zpu')
-rw-r--r--firmware/zpu/CMakeLists.txt24
-rw-r--r--[-rwxr-xr-x]firmware/zpu/bin/bin_to_ram_macro_init.py5
-rw-r--r--firmware/zpu/usrp2/CMakeLists.txt4
-rw-r--r--firmware/zpu/usrp2p/CMakeLists.txt6
-rw-r--r--firmware/zpu/usrp2p/bootloader/CMakeLists.txt4
-rw-r--r--firmware/zpu/usrp2p/bootloader/init_bootloader.c1
-rw-r--r--firmware/zpu/usrp2p/spi_flash.h6
-rw-r--r--firmware/zpu/usrp2p/spi_flash_read.c35
-rw-r--r--firmware/zpu/usrp2p/u2p_init.c3
9 files changed, 41 insertions, 47 deletions
diff --git a/firmware/zpu/CMakeLists.txt b/firmware/zpu/CMakeLists.txt
index f79e48f8a..9a32d1834 100644
--- a/firmware/zpu/CMakeLists.txt
+++ b/firmware/zpu/CMakeLists.txt
@@ -20,6 +20,7 @@
########################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(CMAKE_C_COMPILER zpu-elf-gcc)
+#force the compiler because the check wont use the special flag below
SET(CMAKE_C_COMPILER_WORKS TRUE)
SET(CMAKE_C_COMPILER_FORCED TRUE)
PROJECT(USRP_NXXX_FW C)
@@ -40,7 +41,11 @@ INCLUDE_DIRECTORIES(
# misc flags for the gcc compiler
########################################################################
SET(CMAKE_C_FLAGS -phi) #always needed compile time and link time
-ADD_DEFINITIONS(-Os --std=gnu99 -Wall -Werror-implicit-function-declaration -ffunction-sections)
+ADD_DEFINITIONS(-Os)
+ADD_DEFINITIONS(--std=gnu99)
+ADD_DEFINITIONS(-Wall)
+ADD_DEFINITIONS(-Werror-implicit-function-declaration)
+ADD_DEFINITIONS(-ffunction-sections)
MACRO(ADD_LINKER_FLAGS flags)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flags}")
@@ -74,37 +79,32 @@ FIND_PROGRAM(HEXDUMP hexdump)
########################################################################
# helper functions to build output formats
########################################################################
-MACRO(GEN_OUTPUTS target)
+MACRO(GEN_OUTPUTS target pad)
GET_FILENAME_COMPONENT(name ${target} NAME_WE)
#command to create a map from elf
ADD_CUSTOM_COMMAND(
OUTPUT ${name}.map DEPENDS ${target}
- COMMAND ${LINKER}
- ARGS -Map ${name}.map ${target}
+ COMMAND ${LINKER} -Map ${name}.map ${target}
)
#command to create a bin from elf
ADD_CUSTOM_COMMAND(
OUTPUT ${name}.bin DEPENDS ${target}
- COMMAND ${OBJCOPY}
- ARGS -O binary ${target} ${name}.bin
+ COMMAND ${OBJCOPY} --pad-to ${pad} -O binary ${target} ${name}.bin
)
#command to create a ihx from elf
ADD_CUSTOM_COMMAND(
OUTPUT ${name}.ihx DEPENDS ${target}
- COMMAND ${OBJCOPY}
- ARGS -O ihex ${target} ${name}.ihx
+ COMMAND ${OBJCOPY} --pad-to ${pad} -O ihex ${target} ${name}.ihx
)
#command to create a dump from elf
ADD_CUSTOM_COMMAND(
OUTPUT ${name}.dump DEPENDS ${target}
- COMMAND ${OBJDUMP}
- ARGS -DSC ${target} > ${name}.dump
+ COMMAND ${OBJDUMP} -DSC ${target} > ${name}.dump
)
#command to create a rom from bin
ADD_CUSTOM_COMMAND(
OUTPUT ${name}.rom DEPENDS ${name}.bin
- COMMAND ${HEXDUMP}
- ARGS -v -e'1/1 \"%.2X\\n\"' ${name}.bin > ${name}.rom
+ COMMAND ${HEXDUMP} -v -e'1/1 \"%.2X\\n\"' ${name}.bin > ${name}.rom
)
#add a top level target for output files
ADD_CUSTOM_TARGET(
diff --git a/firmware/zpu/bin/bin_to_ram_macro_init.py b/firmware/zpu/bin/bin_to_ram_macro_init.py
index 65cf2dbdf..085045290 100755..100644
--- a/firmware/zpu/bin/bin_to_ram_macro_init.py
+++ b/firmware/zpu/bin/bin_to_ram_macro_init.py
@@ -12,8 +12,9 @@ def bin_to_ram_macro_init(bin_input_file, ram_init_output_file):
ifile = open(bin_input_file, 'rb')
ofile = open(ram_init_output_file, 'w')
idata = ifile.read()
- fmt = ">%dI" % ((len(idata) / 4),)
- words = struct.unpack(fmt, idata)
+ idata_words = len(idata) / 4
+ fmt = ">%dI"%idata_words
+ words = struct.unpack(fmt, idata[:idata_words*4])
# pad to a multiple of 8 words
r = len(words) % 8
diff --git a/firmware/zpu/usrp2/CMakeLists.txt b/firmware/zpu/usrp2/CMakeLists.txt
index ca5c6d92a..db434567d 100644
--- a/firmware/zpu/usrp2/CMakeLists.txt
+++ b/firmware/zpu/usrp2/CMakeLists.txt
@@ -28,8 +28,8 @@ ADD_LIBRARY(libusrp2fw STATIC
########################################################################
ADD_EXECUTABLE(usrp2_txrx_uhd.elf ${CMAKE_SOURCE_DIR}/apps/txrx_uhd.c)
TARGET_LINK_LIBRARIES(usrp2_txrx_uhd.elf libusrp2fw)
-GEN_OUTPUTS(usrp2_txrx_uhd.elf)
+GEN_OUTPUTS(usrp2_txrx_uhd.elf 0x3fff)
ADD_EXECUTABLE(usrp2_blinkenlights.elf ${CMAKE_SOURCE_DIR}/apps/blinkenlights.c)
TARGET_LINK_LIBRARIES(usrp2_blinkenlights.elf libusrp2fw)
-GEN_OUTPUTS(usrp2_blinkenlights.elf)
+GEN_OUTPUTS(usrp2_blinkenlights.elf 0x3fff)
diff --git a/firmware/zpu/usrp2p/CMakeLists.txt b/firmware/zpu/usrp2p/CMakeLists.txt
index 74d9e233d..f93924bc0 100644
--- a/firmware/zpu/usrp2p/CMakeLists.txt
+++ b/firmware/zpu/usrp2p/CMakeLists.txt
@@ -38,12 +38,12 @@ ADD_SUBDIRECTORY(bootloader)
########################################################################
ADD_EXECUTABLE(usrp2p_txrx_uhd.elf ${CMAKE_SOURCE_DIR}/apps/txrx_uhd.c)
TARGET_LINK_LIBRARIES(usrp2p_txrx_uhd.elf libusrp2pfw)
-GEN_OUTPUTS(usrp2p_txrx_uhd.elf)
+GEN_OUTPUTS(usrp2p_txrx_uhd.elf 0x3fff)
ADD_EXECUTABLE(usrp2p_blinkenlights.elf ${CMAKE_SOURCE_DIR}/apps/blinkenlights.c)
TARGET_LINK_LIBRARIES(usrp2p_blinkenlights.elf libusrp2pfw)
-GEN_OUTPUTS(usrp2p_blinkenlights.elf)
+GEN_OUTPUTS(usrp2p_blinkenlights.elf 0x3fff)
ADD_EXECUTABLE(usrp2p_uart_flash_loader.elf ${CMAKE_SOURCE_DIR}/apps/uart_flash_loader.c)
TARGET_LINK_LIBRARIES(usrp2p_uart_flash_loader.elf libusrp2pfw)
-GEN_OUTPUTS(usrp2p_uart_flash_loader.elf)
+GEN_OUTPUTS(usrp2p_uart_flash_loader.elf 0x3fff)
diff --git a/firmware/zpu/usrp2p/bootloader/CMakeLists.txt b/firmware/zpu/usrp2p/bootloader/CMakeLists.txt
index 41c86cc9a..26836726d 100644
--- a/firmware/zpu/usrp2p/bootloader/CMakeLists.txt
+++ b/firmware/zpu/usrp2p/bootloader/CMakeLists.txt
@@ -24,7 +24,7 @@ MACRO(GEN_RMI target)
ADD_CUSTOM_COMMAND(
OUTPUT ${name}.rmi DEPENDS ${name}.bin
COMMAND ${PYTHON_EXECUTABLE}
- ARGS ${CMAKE_SOURCE_DIR}/bin/bin_to_ram_macro_init.py ${name}.bin ${name}.rmi
+ ${CMAKE_SOURCE_DIR}/bin/bin_to_ram_macro_init.py ${name}.bin ${name}.rmi
)
#add a top level target for output files
ADD_CUSTOM_TARGET(
@@ -35,5 +35,5 @@ ENDMACRO(GEN_RMI)
########################################################################
ADD_EXECUTABLE(init_bootloader.elf init_bootloader.c)
TARGET_LINK_LIBRARIES(init_bootloader.elf libusrp2pfw)
-GEN_OUTPUTS(init_bootloader.elf)
+GEN_OUTPUTS(init_bootloader.elf 0x1fff)
GEN_RMI(init_bootloader.bin)
diff --git a/firmware/zpu/usrp2p/bootloader/init_bootloader.c b/firmware/zpu/usrp2p/bootloader/init_bootloader.c
index f71b0a7b2..e960fe474 100644
--- a/firmware/zpu/usrp2p/bootloader/init_bootloader.c
+++ b/firmware/zpu/usrp2p/bootloader/init_bootloader.c
@@ -57,7 +57,6 @@ int main(int argc, char *argv[]) {
output_regs->leds = 0x00;
hal_uart_init();
spif_init();
- spi_flash_init();
i2c_init(); //for EEPROM
puts("USRP2+ bootloader super ultra ZPU edition\n");
diff --git a/firmware/zpu/usrp2p/spi_flash.h b/firmware/zpu/usrp2p/spi_flash.h
index bfecab468..9a04df86b 100644
--- a/firmware/zpu/usrp2p/spi_flash.h
+++ b/firmware/zpu/usrp2p/spi_flash.h
@@ -31,13 +31,9 @@
uint32_t spi_flash_rdid(void); /* Read ID */
uint32_t spi_flash_rdsr(void); /* Read Status Register */
-//! call before using any spi flash utilities
-void spi_flash_init(void);
-
+size_t spi_flash_log2_memory_size(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 c65b8c1a1..47a79e7d1 100644
--- a/firmware/zpu/usrp2p/spi_flash_read.c
+++ b/firmware/zpu/usrp2p/spi_flash_read.c
@@ -27,38 +27,39 @@ spi_flash_rdid(void)
return spif_transact(SPI_TXRX, SPI_SS_FLASH, RDID_CMD << 24, 32, FLAGS) & 0xffffff;
}
-static size_t _spi_flash_log2_memory_size, _spi_flash_log2_sector_size;
-
-void spi_flash_init(void)
+size_t spi_flash_log2_memory_size(void)
{
- 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();
- _spi_flash_log2_memory_size = size;
+ static size_t _spi_flash_log2_memory_size = 0;
+ if (_spi_flash_log2_memory_size == 0){
+ uint32_t id = spi_flash_rdid();
+ uint8_t type = (id >> 8) & 0xff;
+ uint8_t size = (id >> 0) & 0xff;
+ if (type != 0x20) abort();
+ _spi_flash_log2_memory_size = size;
+ }
+ if (_spi_flash_log2_memory_size < 22 ||
+ _spi_flash_log2_memory_size > 24 ) abort();
+ return _spi_flash_log2_memory_size;
+}
+size_t spi_flash_log2_sector_size(void)
+{
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;
+ return log2_sector_size[spi_flash_log2_memory_size() - 22];
}
size_t spi_flash_sector_size(void)
{
- return ((size_t) 1) << _spi_flash_log2_sector_size;
+ 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;
+ 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
index 6fe9729ac..381987ae6 100644
--- a/firmware/zpu/usrp2p/u2p_init.c
+++ b/firmware/zpu/usrp2p/u2p_init.c
@@ -16,13 +16,10 @@
*/
#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);