summaryrefslogtreecommitdiffstats
path: root/firmware/microblaze/usrp2p
diff options
context:
space:
mode:
authorNick Foster <nick@nerdnetworks.org>2010-08-17 18:35:11 -0700
committerNick Foster <nick@nerdnetworks.org>2010-08-17 18:35:11 -0700
commit9d10efa5f0f81e1a971e92b28ba7f38e0384fdab (patch)
tree7b797016a4da8625dabc41c9bcc9ee0216092507 /firmware/microblaze/usrp2p
parent40faee2e6d87f7364a0c0c2cf310f1483c0331cf (diff)
downloaduhd-9d10efa5f0f81e1a971e92b28ba7f38e0384fdab.tar.gz
uhd-9d10efa5f0f81e1a971e92b28ba7f38e0384fdab.tar.bz2
uhd-9d10efa5f0f81e1a971e92b28ba7f38e0384fdab.zip
UDP firmware update support for USRP2P.
The hooks are in there for USRP2, but without CPLD changes it won't support it. Added an app host/utils/usrp2p_fw_update.py to write to USRP2P over the wire. Lots of TODOs in that file. Caveat -- fw_common.h, bootloader_utils.h, and the .py app MUST ALL AGREE!
Diffstat (limited to 'firmware/microblaze/usrp2p')
-rw-r--r--firmware/microblaze/usrp2p/Makefile.am4
-rw-r--r--firmware/microblaze/usrp2p/spi_flash.h7
-rw-r--r--firmware/microblaze/usrp2p/spi_flash_read.c19
-rw-r--r--firmware/microblaze/usrp2p/udp_fw_update.c116
-rw-r--r--firmware/microblaze/usrp2p/udp_fw_update.h22
5 files changed, 167 insertions, 1 deletions
diff --git a/firmware/microblaze/usrp2p/Makefile.am b/firmware/microblaze/usrp2p/Makefile.am
index ddc7006ca..c9ed3b99b 100644
--- a/firmware/microblaze/usrp2p/Makefile.am
+++ b/firmware/microblaze/usrp2p/Makefile.am
@@ -32,6 +32,7 @@ COMMON_IHX_ARGS = \
--change-section-address .vectors.hw_exception+0x8000 \
--change-section-address .vectors.interrupt+0x8000 \
--change-section-address .vectors.reset+0x8000
+
# $(MB_OBJCOPY) -O ihex $< $@
# the below would work if objcopy weren't written by apes
# $(MB_OBJCOPY) -O ihex -w --change-section-address .vectors*+0x8000 $< $@
@@ -49,7 +50,8 @@ libusrp2p_a_SOURCES = \
spi_flash.c \
spi_flash_read.c \
bootloader_utils.c \
- ethernet.c
+ ethernet.c \
+ udp_fw_update.c
noinst_PROGRAMS = \
usrp2p_txrx_uhd.elf \
diff --git a/firmware/microblaze/usrp2p/spi_flash.h b/firmware/microblaze/usrp2p/spi_flash.h
index f65f28477..bbe7b650d 100644
--- a/firmware/microblaze/usrp2p/spi_flash.h
+++ b/firmware/microblaze/usrp2p/spi_flash.h
@@ -31,6 +31,7 @@
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)
@@ -38,6 +39,12 @@ 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();
+}
+
void spi_flash_read(uint32_t flash_addr, size_t nbytes, void *buf);
/*
diff --git a/firmware/microblaze/usrp2p/spi_flash_read.c b/firmware/microblaze/usrp2p/spi_flash_read.c
index 1c65350f7..4682c5fe6 100644
--- a/firmware/microblaze/usrp2p/spi_flash_read.c
+++ b/firmware/microblaze/usrp2p/spi_flash_read.c
@@ -20,6 +20,8 @@
#include "spi_flash_private.h"
#include <stdlib.h> // abort
+static size_t _spi_flash_log2_memory_size;
+
uint32_t
spi_flash_rdid(void)
{
@@ -48,9 +50,26 @@ spi_flash_log2_sector_size(void)
};
_spi_flash_log2_sector_size = log2_sector_size[size - 22];
+ _spi_flash_log2_memory_size = size; //while we're at it
return _spi_flash_log2_sector_size;
}
+size_t
+spi_flash_log2_memory_size(void)
+{
+ if (_spi_flash_log2_memory_size != 0)
+ return _spi_flash_log2_memory_size;
+
+ uint32_t id = spi_flash_rdid();
+ int type = (id >> 8) & 0xff;
+ int size = id & 0xff;
+ if (type != 0x20 || size < 22 || size > 24)
+ abort();
+
+ _spi_flash_log2_memory_size = size;
+ return _spi_flash_log2_memory_size;
+}
+
void
spi_flash_read(uint32_t flash_addr, size_t nbytes, void *buf)
{
diff --git a/firmware/microblaze/usrp2p/udp_fw_update.c b/firmware/microblaze/usrp2p/udp_fw_update.c
new file mode 100644
index 000000000..6b860007a
--- /dev/null
+++ b/firmware/microblaze/usrp2p/udp_fw_update.c
@@ -0,0 +1,116 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010 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/>.
+ */
+
+//Routines to handle updating the SPI Flash firmware via UDP
+
+#include <net_common.h>
+#include "usrp2/fw_common.h"
+#include "spi.h"
+#include "spi_flash.h"
+#include "udp_fw_update.h"
+#include <nonstdio.h>
+#include <string.h>
+#include "ethernet.h"
+
+//Firmware update packet handler
+void handle_udp_fw_update_packet(struct socket_address src, struct socket_address dst,
+ unsigned char *payload, int payload_len) {
+//okay, we can do this ANY NUMBER of ways. we have up to ~1500 bytes to play with -- we don't handle
+//fragmentation, so limit it to <MTU. let's say 1K. remember that SPI Flash page writes can only be up to 256B(?) long,
+//so if your SPI Flash write routine doesn't handle that, you will have to on the host side (or in here).
+//so here are your options:
+
+//IHEX -- 16 bytes at a time, relocated for you. parser is already written. possibly extra slow due to the small packet size.
+//custom struct -- addr, data, len. you can checksum this if you like, but it is already checksummed in UDP (as well as on the wire).
+// this option needs minimal parsing on the device side and is a straight Flash write. no interpretation required. all the brains
+// go on the host side. how is relocation handled? well, your fw images are supposed to be "fully relocated" such that you can just
+// stick 'em anywhere, so a .bin (provided it's relocated to 0 for the wire) plus a location is good enough. let's go this route.
+
+ const udp_fw_update_data_t *update_data_in = (udp_fw_update_data_t *) payload;
+
+ udp_fw_update_data_t update_data_out;
+ usrp2_fw_update_id_t update_data_in_id = update_data_in->id;
+
+ //ensure that the protocol versions match
+ if (payload_len >= sizeof(uint32_t) && update_data_in->proto_ver != USRP2_FW_COMPAT_NUM){
+ printf("!Error in update packet handler: Expected compatibility number %d, but got %d\n",
+ USRP2_FW_COMPAT_NUM, update_data_in->proto_ver
+ );
+ update_data_in_id = USRP2_FW_UPDATE_ID_OHAI_LOL; //so we can respond
+ }
+
+ //ensure that this is not a short packet
+ if (payload_len < sizeof(udp_fw_update_data_t)){
+ printf("!Error in update packet handler: Expected payload length %d, but got %d\n",
+ (int)sizeof(udp_fw_update_data_t), payload_len
+ );
+ update_data_in_id = USRP2_FW_UPDATE_ID_WAT;
+ }
+
+ spi_flash_async_state_t spi_flash_async_state;
+
+ switch(update_data_in_id) {
+ case USRP2_FW_UPDATE_ID_OHAI_LOL: //why hello there you handsome devil
+ update_data_out.id = USRP2_FW_UPDATE_ID_OHAI_OMG;
+ memcpy(&update_data_out.data.ip_addr, (void *)get_ip_addr(), sizeof(struct ip_addr));
+ break;
+
+ case USRP2_FW_UPDATE_ID_WATS_TEH_FLASH_INFO_LOL: //query sector size, memory size so the host can mind the boundaries
+ update_data_out.data.flash_info_args.sector_size_bytes = spi_flash_sector_size();
+ update_data_out.data.flash_info_args.memory_size_bytes = spi_flash_memory_size();
+ update_data_out.id = USRP2_FW_UPDATE_ID_HERES_TEH_FLASH_INFO_OMG;
+ break;
+
+ case USRP2_FW_UPDATE_ID_ERASE_TEH_FLASHES_LOL: //out with the old
+ spi_flash_async_erase_start(&spi_flash_async_state, update_data_in->data.flash_args.flash_addr, update_data_in->data.flash_args.length);
+ update_data_out.id = USRP2_FW_UPDATE_ID_ERASING_TEH_FLASHES_OMG;
+ break;
+
+ case USRP2_FW_UPDATE_ID_R_U_DONE_ERASING_LOL:
+ //poll for done, set something in the reply packet
+ //spi_flash_async_erase_poll() also advances the state machine, so you should call it reasonably often to get things done quicker
+ if(spi_flash_async_erase_poll(&spi_flash_async_state)) update_data_out.id = USRP2_FW_UPDATE_ID_IM_DONE_ERASING_OMG;
+ else update_data_out.id = USRP2_FW_UPDATE_ID_NOPE_NOT_DONE_ERASING_OMG;
+ break;
+
+ case USRP2_FW_UPDATE_ID_WRITE_TEH_FLASHES_LOL: //and in with the new
+ //spi_flash_program() goes pretty quick compared to page erases, so we don't bother polling -- it'll come back in some milliseconds
+ //if it doesn't come back fast enough, we'll just write smaller packets at a time until it does
+ spi_flash_program(update_data_in->data.flash_args.flash_addr, update_data_in->data.flash_args.length, update_data_in->data.flash_args.data);
+ update_data_out.id = USRP2_FW_UPDATE_ID_WROTE_TEH_FLASHES_OMG;
+ break;
+
+ case USRP2_FW_UPDATE_ID_READ_TEH_FLASHES_LOL: //for verify
+ spi_flash_read(update_data_in->data.flash_args.flash_addr, update_data_in->data.flash_args.length, update_data_out.data.flash_args.data);
+ update_data_out.id = USRP2_FW_UPDATE_ID_KK_READ_TEH_FLASHES_OMG;
+ break;
+
+ case USRP2_FW_UPDATE_ID_RESET_MAH_COMPUTORZ_LOL: //for if we ever get the ICAP working
+ //should reset via icap_reload_fpga(uint32_t flash_address);
+ update_data_out.id = USRP2_FW_UPDATE_ID_RESETTIN_TEH_COMPUTORZ_OMG;
+ //you should note that if you get a reply packet to this the reset has obviously failed
+ break;
+
+// case USRP2_FW_UPDATE_ID_KTHXBAI: //see ya
+// break;
+
+ default: //uhhhh
+ update_data_out.id = USRP2_FW_UPDATE_ID_WAT;
+ }
+ send_udp_pkt(USRP2_UDP_UPDATE_PORT, src, &update_data_out, sizeof(update_data_out));
+}
diff --git a/firmware/microblaze/usrp2p/udp_fw_update.h b/firmware/microblaze/usrp2p/udp_fw_update.h
new file mode 100644
index 000000000..dcf44bc42
--- /dev/null
+++ b/firmware/microblaze/usrp2p/udp_fw_update.h
@@ -0,0 +1,22 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2010 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 "net_common.h"
+
+void handle_udp_fw_update_packet(struct socket_address src, struct socket_address dst,
+ unsigned char *payload, int payload_len);