Revision ef9ca5f9

b/firmware/zpu/usrp2p/spi_flash.c
51 51
spi_flash_erase_sector_start(uint32_t flash_addr)
52 52
{
53 53
  //uprintf(UART_DEBUG, "spi_flash_erase_sector_start: addr = 0x%x\n", flash_addr);
54
  if(flash_addr > spi_flash_memory_size())
55
    return;
54 56

  
55 57
  spi_flash_wait();
56 58
  spi_flash_write_enable();
......
65 67
  if (nbytes == 0 || nbytes > SPI_FLASH_PAGE_SIZE)
66 68
    return false;
67 69

  
70
  //please to not be writing past the end of the device
71
  if ((flash_addr + nbytes) > spi_flash_memory_size())
72
    return false;
73

  
68 74
  uint32_t local_buf[SPI_FLASH_PAGE_SIZE / sizeof(uint32_t)];
69 75
  memset(local_buf, 0xff, sizeof(local_buf));	// init to 0xff (nops when programming)
70 76
  memcpy(local_buf, buf, nbytes);
......
130 136
  const unsigned char *p = (const unsigned char *) buf;
131 137
  size_t n;
132 138

  
139
  if ((nbytes + flash_addr) > spi_flash_memory_size())
140
    return false;
133 141
  if (nbytes == 0)
134 142
    return true;
135 143

  
......
158 166
spi_flash_async_erase_start(spi_flash_async_state_t *s,
159 167
			    uint32_t flash_addr, size_t nbytes)
160 168
{
161
  if (nbytes == 0){
169
  if ((nbytes == 0) || ((flash_addr + nbytes) > spi_flash_memory_size())){
162 170
    s->first = s->last = s->current = 0;
163 171
    return;
164 172
  }
b/host/utils/usrp_n2xx_net_burner.py
139 139

  
140 140
        #  print "Incoming:\n\tVer: %i\n\tID: %c\n\tSeq: %i\n\tIP: %i\n" % (proto_ver, chr(pktid), rxseq, ip_addr)
141 141

  
142
    memory_size_bytes = 0
143
    sector_size_bytes = 0
142 144
    def get_flash_info(self):
145
        if (self.memory_size_bytes != 0) and (self.sector_size_bytes != 0):
146
            return (self.memory_size_bytes, self.sector_size_bytes)
147
            
143 148
        out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_WATS_TEH_FLASH_INFO_LOL, seq(), 0, 0)
144 149
        in_pkt = self.send_and_recv(out_pkt)
145 150

  
146
        (proto_ver, pktid, rxseq, sector_size_bytes, memory_size_bytes) = unpack_flash_info_fmt(in_pkt)
151
        (proto_ver, pktid, rxseq, self.sector_size_bytes, self.memory_size_bytes) = unpack_flash_info_fmt(in_pkt)
147 152

  
148 153
        if pktid != update_id_t.USRP2_FW_UPDATE_ID_HERES_TEH_FLASH_INFO_OMG:
149 154
            raise Exception("Invalid reply %c from device." % (chr(pktid)))
150 155

  
151
        return (memory_size_bytes, sector_size_bytes)
156
        return (self.memory_size_bytes, self.sector_size_bytes)
152 157

  
153 158
    def burn_fw(self, fw, fpga, reset, safe):
154 159
        (flash_size, sector_size) = self.get_flash_info()
......
167 172

  
168 173
            if not is_valid_fpga_image(fpga_image):
169 174
                raise Exception("Error: Invalid FPGA image file.")
175
                
176
            if (len(fpga_image) + image_location) > flash_size:
177
                raise Exception("Error: Cannot write past end of device")
170 178

  
171 179
            print("Begin FPGA write: this should take about 1 minute...")
172 180
            start_time = time.time()
......
188 196

  
189 197
            if not is_valid_fw_image(fw_image):
190 198
                raise Exception("Error: Invalid firmware image file.")
199
                
200
            if (len(fw_image) + image_location) > flash_size:
201
                raise Exception("Error: Cannot write past end of device")
191 202

  
192 203
            print("Begin firmware write: this should take about 1 second...")
193 204
            start_time = time.time()
......
204 215
        self._status_cb("Writing")
205 216
        writedata = image
206 217
        #we split the image into smaller (256B) bits and send them down the wire
218
        (mem_size, sector_size) = self.get_flash_info()
219
        if (addr + len(writedata)) > mem_size:
220
            raise Exception("Error: Cannot write past end of device")
221
            
207 222
        while writedata:
208 223
            out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_WRITE_TEH_FLASHES_LOL, seq(), addr, FLASH_DATA_PACKET_SIZE, writedata[:FLASH_DATA_PACKET_SIZE])
209 224
            in_pkt = self.send_and_recv(out_pkt)
......
287 302
    def erase_image(self, addr, length):
288 303
        self._status_cb("Erasing")
289 304
        #get flash info first
305
        (flash_size, sector_size) = self.get_flash_info()
306
        if (addr + length) > flash_size:
307
            raise Exception("Cannot erase past end of device")
308
            
290 309
        out_pkt = pack_flash_args_fmt(USRP2_FW_PROTO_VERSION, update_id_t.USRP2_FW_UPDATE_ID_ERASE_TEH_FLASHES_LOL, seq(), addr, length)
291 310
        in_pkt = self.send_and_recv(out_pkt)
292 311

  

Also available in: Unified diff