root / firmware / zpu / usrp2p / udp_fw_update.c @ 08e2432c
History | View | Annotate | Download (5.35 KB)
| 1 |
/*
|
|---|---|
| 2 |
* Copyright 2010-2012 Ettus Research LLC
|
| 3 |
*
|
| 4 |
* This program is free software: you can redistribute it and/or modify
|
| 5 |
* it under the terms of the GNU General Public License as published by
|
| 6 |
* the Free Software Foundation, either version 3 of the License, or
|
| 7 |
* (at your option) any later version.
|
| 8 |
*
|
| 9 |
* This program is distributed in the hope that it will be useful,
|
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
* GNU General Public License for more details.
|
| 13 |
*
|
| 14 |
* You should have received a copy of the GNU General Public License
|
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
*/
|
| 17 |
|
| 18 |
//Routines to handle updating the SPI Flash firmware via UDP
|
| 19 |
|
| 20 |
#include <net_common.h> |
| 21 |
#include "memory_map.h" |
| 22 |
#include "usrp2/fw_common.h" |
| 23 |
#include "spi.h" |
| 24 |
#include "spi_flash.h" |
| 25 |
#include <nonstdio.h> |
| 26 |
#include <string.h> |
| 27 |
#include "ethernet.h" |
| 28 |
#include "udp_fw_update.h" |
| 29 |
#include "xilinx_s3_icap.h" |
| 30 |
#include "i2c.h" |
| 31 |
|
| 32 |
uint16_t get_hw_rev(void) {
|
| 33 |
uint16_t tmp; |
| 34 |
eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, &tmp, sizeof(tmp));
|
| 35 |
return tmp;
|
| 36 |
} |
| 37 |
|
| 38 |
spi_flash_async_state_t spi_flash_async_state; |
| 39 |
|
| 40 |
//Firmware update packet handler
|
| 41 |
void handle_udp_fw_update_packet(struct socket_address src, struct socket_address dst, |
| 42 |
unsigned char *payload, int payload_len) { |
| 43 |
|
| 44 |
const usrp2_fw_update_data_t *update_data_in = (usrp2_fw_update_data_t *) payload;
|
| 45 |
|
| 46 |
usrp2_fw_update_data_t update_data_out; |
| 47 |
usrp2_fw_update_id_t update_data_in_id = update_data_in->id; |
| 48 |
|
| 49 |
//ensure that the protocol versions match
|
| 50 |
/* if (payload_len >= sizeof(uint32_t) && update_data_in->proto_ver != USRP2_FW_COMPAT_NUM){
|
| 51 |
printf("!Error in update packet handler: Expected compatibility number %d, but got %d\n",
|
| 52 |
USRP2_FW_COMPAT_NUM, update_data_in->proto_ver
|
| 53 |
);
|
| 54 |
update_data_in_id = USRP2_FW_UPDATE_ID_OHAI_LOL; //so we can respond
|
| 55 |
}
|
| 56 |
*/
|
| 57 |
//ensure that this is not a short packet
|
| 58 |
if (payload_len < sizeof(usrp2_fw_update_data_t)){ |
| 59 |
printf("!Error in update packet handler: Expected payload length %d, but got %d\n",
|
| 60 |
(int)sizeof(usrp2_fw_update_data_t), payload_len |
| 61 |
); |
| 62 |
update_data_in_id = USRP2_FW_UPDATE_ID_WAT; |
| 63 |
} |
| 64 |
|
| 65 |
switch(update_data_in_id) {
|
| 66 |
case USRP2_FW_UPDATE_ID_OHAI_LOL: //why hello there you handsome devil |
| 67 |
update_data_out.id = USRP2_FW_UPDATE_ID_OHAI_OMG; |
| 68 |
memcpy(&update_data_out.data.ip_addr, (void *)get_ip_addr(), sizeof(struct ip_addr)); |
| 69 |
//this is to stop streaming for the folks who think updating while streaming is a good idea
|
| 70 |
sr_rx_ctrl0->clear = 1;
|
| 71 |
sr_rx_ctrl1->clear = 1;
|
| 72 |
sr_tx_ctrl->cyc_per_up = 0;
|
| 73 |
break;
|
| 74 |
|
| 75 |
case USRP2_FW_UPDATE_ID_WATS_TEH_FLASH_INFO_LOL: //query sector size, memory size so the host can mind the boundaries |
| 76 |
update_data_out.data.flash_info_args.sector_size_bytes = spi_flash_sector_size(); |
| 77 |
update_data_out.data.flash_info_args.memory_size_bytes = spi_flash_memory_size(); |
| 78 |
update_data_out.id = USRP2_FW_UPDATE_ID_HERES_TEH_FLASH_INFO_OMG; |
| 79 |
break;
|
| 80 |
|
| 81 |
case USRP2_FW_UPDATE_ID_I_CAN_HAS_HW_REV_LOL: //get the hardware revision of the platform for validation checking |
| 82 |
update_data_out.data.hw_rev = (uint32_t) get_hw_rev(); |
| 83 |
update_data_out.id = USRP2_FW_UPDATE_ID_HERES_TEH_HW_REV_OMG; |
| 84 |
break;
|
| 85 |
|
| 86 |
case USRP2_FW_UPDATE_ID_ERASE_TEH_FLASHES_LOL: //out with the old |
| 87 |
spi_flash_async_erase_start(&spi_flash_async_state, update_data_in->data.flash_args.flash_addr, update_data_in->data.flash_args.length); |
| 88 |
update_data_out.id = USRP2_FW_UPDATE_ID_ERASING_TEH_FLASHES_OMG; |
| 89 |
break;
|
| 90 |
|
| 91 |
case USRP2_FW_UPDATE_ID_R_U_DONE_ERASING_LOL:
|
| 92 |
//poll for done, set something in the reply packet
|
| 93 |
//spi_flash_async_erase_poll() also advances the state machine, so you should call it reasonably often to get things done quicker
|
| 94 |
if(spi_flash_async_erase_poll(&spi_flash_async_state)) update_data_out.id = USRP2_FW_UPDATE_ID_IM_DONE_ERASING_OMG;
|
| 95 |
else update_data_out.id = USRP2_FW_UPDATE_ID_NOPE_NOT_DONE_ERASING_OMG;
|
| 96 |
break;
|
| 97 |
|
| 98 |
case USRP2_FW_UPDATE_ID_WRITE_TEH_FLASHES_LOL: //and in with the new |
| 99 |
//spi_flash_program() goes pretty quick compared to page erases, so we don't bother polling -- it'll come back in some milliseconds
|
| 100 |
//if it doesn't come back fast enough, we'll just write smaller packets at a time until it does
|
| 101 |
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); |
| 102 |
update_data_out.id = USRP2_FW_UPDATE_ID_WROTE_TEH_FLASHES_OMG; |
| 103 |
break;
|
| 104 |
|
| 105 |
case USRP2_FW_UPDATE_ID_READ_TEH_FLASHES_LOL: //for verify |
| 106 |
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); |
| 107 |
update_data_out.id = USRP2_FW_UPDATE_ID_KK_READ_TEH_FLASHES_OMG; |
| 108 |
break;
|
| 109 |
|
| 110 |
case USRP2_FW_UPDATE_ID_RESET_MAH_COMPUTORZ_LOL: //for if we ever get the ICAP working |
| 111 |
//should reset via icap_reload_fpga(uint32_t flash_address);
|
| 112 |
update_data_out.id = USRP2_FW_UPDATE_ID_RESETTIN_TEH_COMPUTORZ_OMG; |
| 113 |
//you should note that if you get a reply packet to this the reset has obviously failed
|
| 114 |
icap_reload_fpga(0);
|
| 115 |
break;
|
| 116 |
|
| 117 |
// case USRP2_FW_UPDATE_ID_KTHXBAI: //see ya
|
| 118 |
// break;
|
| 119 |
|
| 120 |
default: //uhhhh |
| 121 |
update_data_out.id = USRP2_FW_UPDATE_ID_WAT; |
| 122 |
} |
| 123 |
send_udp_pkt(USRP2_UDP_UPDATE_PORT, src, &update_data_out, sizeof(update_data_out));
|
| 124 |
} |