Explorar el Código

src/cyw43_ll: Fix issue with alignment of NVRAM download.

Prior to this commit, it's possible for the NVRAM size to be aligned twice:
once to 64 bytes before the call to cyw43_download_resource(), then again
in that function to 256 bytes.  If the 256 byte alignment increases the
length then the following assertion will fail:

    assert((dest_addr&BACKPLANE_ADDR_MASK)+sz) <= (BACKPLANE_ADDR_MASK+1)

This commit fixes that by only aligning to 64, which is all that's required
for SDIO bus transfers (and aligns to 4 for SPI buses).

Signed-off-by: Damien George <dpgeorge@georgerobotics.com.au>
Damien George hace 2 años
padre
commit
b7195d8f93
Se han modificado 3 ficheros con 22 adiciones y 20 borrados
  1. 15 13
      src/cyw43_ll.c
  2. 5 5
      tests/debug_print/test.exp
  3. 2 2
      tests/sdio/test.exp

+ 15 - 13
src/cyw43_ll.c

@@ -72,6 +72,14 @@ extern bool enable_spi_packet_dumping;
 
 #define ALIGN_UINT(val, align) (((val) + (align) - 1) & ~((align) - 1))
 
+// Configure the padding needed for data sent to cyw43_write_bytes().
+// cyw43_read_bytes() also needs padding, but that's handled separately.
+#if CYW43_USE_SPI
+#define CYW43_WRITE_BYTES_PAD(len) ALIGN_UINT((len), 4)
+#else
+#define CYW43_WRITE_BYTES_PAD(len) ALIGN_UINT((len), 64)
+#endif
+
 #if CYW43_USE_STATS
 // Storage for some debug stats
 uint32_t cyw43_stats[CYW43_STAT_LAST];
@@ -380,9 +388,10 @@ static int cyw43_check_valid_chipset_firmware(cyw43_int_t *self, size_t len, uin
     return CYW43_FAIL_FAST_CHECK(-CYW43_EIO);
 }
 
-static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t raw_len, uintptr_t source) {
-    // round up len to simplify download
-    size_t len = (raw_len + 255) & ~255;
+static int cyw43_download_resource(cyw43_int_t *self, uint32_t addr, size_t len, uintptr_t source) {
+    // The calls to cyw43_write_bytes() (and cyw43_read_bytes()) require data sizes that
+    // are aligned to a certain amount.
+    assert(CYW43_WRITE_BYTES_PAD(len) == len);
 
     CYW43_VDEBUG("writing %u bytes to 0x%x\n", (uint32_t)len, (uint32_t)addr);
 
@@ -597,13 +606,6 @@ struct sdpcm_header_t {
     uint8_t reserved[2];
 };
 
-// No padding here for SPI?
-#if CYW43_USE_SPI
-#define SDPCM_PAD(A) A
-#else
-#define SDPCM_PAD(A) (A + 63) & ~63
-#endif
-
 // buf must be writable and have:
 //  - SDPCM_HEADER_LEN bytes at the start for writing the headers
 //  - readable data at the end for padding to get to 64 byte alignment
@@ -682,7 +684,7 @@ static int cyw43_sdpcm_send_common(cyw43_int_t *self, uint32_t kind, size_t len,
     self->wwd_sdpcm_packet_transmit_sequence_number += 1;
 
     // padding is taken from junk at end of buffer
-    return cyw43_write_bytes(self, WLAN_FUNCTION, 0, SDPCM_PAD(size), buf);
+    return cyw43_write_bytes(self, WLAN_FUNCTION, 0, CYW43_WRITE_BYTES_PAD(size), buf);
 }
 
 struct ioctl_header_t {
@@ -1641,13 +1643,13 @@ alp_set:
     }
 
     // Download the main WiFi firmware blob to the 43xx device.
-    ret = cyw43_download_resource(self, 0x00000000, CYW43_WIFI_FW_LEN, fw_data);
+    ret = cyw43_download_resource(self, 0x00000000, CYW43_WRITE_BYTES_PAD(CYW43_WIFI_FW_LEN), fw_data);
     if (ret != 0) {
         return ret;
     }
 
     // Download the NVRAM to the 43xx device.
-    size_t wifi_nvram_len = ALIGN_UINT(sizeof(wifi_nvram_4343), 64);
+    size_t wifi_nvram_len = CYW43_WRITE_BYTES_PAD(sizeof(wifi_nvram_4343));
     const uint8_t *wifi_nvram_data = wifi_nvram_4343;
     cyw43_download_resource(self, CYW43_RAM_SIZE - 4 - wifi_nvram_len, wifi_nvram_len, (uintptr_t)wifi_nvram_data);
     uint32_t sz = ((~(wifi_nvram_len / 4) & 0xffff) << 16) | (wifi_nvram_len / 4);

+ 5 - 5
tests/debug_print/test.exp

@@ -68,7 +68,7 @@ cyw43_sdio_transfer(cmd=52, arg=92001600)
 cyw43_sdio_transfer_cmd53(write=1, block_size=4, arg=95802004, len=4)
 cyw43_sdio_transfer_cmd53(write=1, block_size=4, arg=95808804, len=4)
 Version: 7.95.49 (2271bb6 CY) CRC: b7a28ef3 Date: Mon 2021-11-29 22:50:27 PST Ucode Ver: 1043.2162 FWID 01-c51d9400
-writing 224256 bytes to 0x0
+writing 224192 bytes to 0x0
 cyw43_sdio_transfer(cmd=52, arg=92001800)
 cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c000100, len=16384)
 cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c800100, len=16384)
@@ -92,8 +92,8 @@ cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c800100, len=16384)
 cyw43_sdio_transfer(cmd=52, arg=92001603)
 cyw43_sdio_transfer(cmd=52, arg=92001400)
 cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c000100, len=16384)
-cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c8000b0, len=11264)
-done dnload; dt = 1 us; speed = 224256000 kbytes/sec
+cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c8000af, len=11200)
+done dnload; dt = 1 us; speed = 224192000 kbytes/sec
 cyw43_sdio_transfer(cmd=52, arg=92001600)
 cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c000100, len=16384)
 cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c800100, len=16384)
@@ -117,8 +117,8 @@ cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c800100, len=16384)
 cyw43_sdio_transfer(cmd=52, arg=92001603)
 cyw43_sdio_transfer(cmd=52, arg=92001400)
 cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c000100, len=16384)
-cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c8000b0, len=11264)
-done verify; dt = 1 us; speed = 224256000 kbytes/sec
+cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c8000af, len=11200)
+done verify; dt = 1 us; speed = 224192000 kbytes/sec
 writing 768 bytes to 0x7fcfc
 cyw43_sdio_transfer(cmd=52, arg=92001607)
 cyw43_sdio_transfer(cmd=52, arg=92001480)

+ 2 - 2
tests/sdio/test.exp

@@ -88,7 +88,7 @@ cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c800100, len=16384)
 cyw43_sdio_transfer(cmd=52, arg=92001603)
 cyw43_sdio_transfer(cmd=52, arg=92001400)
 cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c000100, len=16384)
-cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c8000b0, len=11264)
+cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9c8000af, len=11200)
 cyw43_sdio_transfer(cmd=52, arg=92001600)
 cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c000100, len=16384)
 cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c800100, len=16384)
@@ -112,7 +112,7 @@ cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c800100, len=16384)
 cyw43_sdio_transfer(cmd=52, arg=92001603)
 cyw43_sdio_transfer(cmd=52, arg=92001400)
 cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c000100, len=16384)
-cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c8000b0, len=11264)
+cyw43_sdio_transfer_cmd53(write=0, block_size=64, arg=1c8000af, len=11200)
 cyw43_sdio_transfer(cmd=52, arg=92001607)
 cyw43_sdio_transfer(cmd=52, arg=92001480)
 cyw43_sdio_transfer_cmd53(write=1, block_size=64, arg=9cf9f80c, len=768)