From e5d23f11decb120cda7db8e33c4b21f44ea1d26b Mon Sep 17 00:00:00 2001 From: feelfree69 Date: Sun, 15 Feb 2026 13:28:31 +0100 Subject: [PATCH] Demagic FLASH_BUF_SIZE --- cmd_parser.c | 2 +- httpd/httpd.c | 2 +- rtl837x_common.h | 3 +++ rtlplayground.c | 24 ++++++++++++------------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cmd_parser.c b/cmd_parser.c index 1c4590f..3929f6a 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -33,7 +33,7 @@ extern volatile __xdata uint8_t sfr_data[4]; extern __code uint8_t * __code greeting; extern __code uint8_t * __code hex; -extern __xdata uint8_t flash_buf[512]; +extern __xdata uint8_t flash_buf[FLASH_BUF_SIZE]; extern __xdata struct flash_region_t flash_region; extern __xdata char passwd[21]; diff --git a/httpd/httpd.c b/httpd/httpd.c index 23c0b9c..fcaec36 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -29,7 +29,7 @@ extern __code char * __code mime_strings[]; extern __xdata struct flash_region_t flash_region; // Flash buffer to optimize flash writing speed, write_len is the current filling position -extern __xdata uint8_t flash_buf[512]; +extern __xdata uint8_t flash_buf[FLASH_BUF_SIZE]; __xdata uint32_t uptr; // Current flash write position __xdata uint16_t write_len; diff --git a/rtl837x_common.h b/rtl837x_common.h index 7be51fe..f6c9dd7 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -29,6 +29,9 @@ // Size of the memory area dedicated to VLAN-names #define VLAN_NAMES_SIZE 1024 +// Size of the flash buffer used for writing to flash, must be a multiple of the flash page size (0x100) +#define FLASH_BUF_SIZE 512 + // For RX data, a propriatary RTL FRAME is inserted. Instead of 0x0800 for IPv4, // the RTL_FRAME_TAG_ID is used as part of an 8-byte tag. When VLAN is activated, // the VLAN tag is inserted after the RTL tag diff --git a/rtlplayground.c b/rtlplayground.c index 51e878f..e85809b 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -99,7 +99,7 @@ extern __xdata struct flash_region_t flash_region; __code uint8_t * __code greeting = "\nA minimal prompt to explore the RTL8372:\n"; __code uint8_t * __code hex = "0123456789abcdef"; -__xdata uint8_t flash_buf[512]; +__xdata uint8_t flash_buf[FLASH_BUF_SIZE]; // NIC buffers for packet RX/TX __xdata uint8_t rx_headers[16]; // Packet header(s) on RX @@ -1073,13 +1073,13 @@ void flash_default_config(void) for (uint8_t i = 0; i < 8; i++) // 8 * 512 Byte = 4 kByte (1 sector) { flash_region.addr = source; - flash_region.len = 0x200; + flash_region.len = FLASH_BUF_SIZE; flash_read_bulk(flash_buf); flash_region.addr = dest; - flash_region.len = 0x200; + flash_region.len = FLASH_BUF_SIZE; flash_write_bytes(flash_buf); - dest += 0x200; - source += 0x200; + dest += FLASH_BUF_SIZE; + source += FLASH_BUF_SIZE; } print_string("Written default config to flash\n"); @@ -1883,13 +1883,13 @@ void check_and_flash_update_image(void) crc_value = 0x0000; for (i = 0; i < 1024; i++) { flash_region.addr = source; - flash_region.len = 0x200; + flash_region.len = FLASH_BUF_SIZE; flash_read_bulk(flash_buf); bptr = flash_buf; - for (j = 0; j < 0x200; j++) { + for (j = 0; j < FLASH_BUF_SIZE; j++) { crc16(bptr++); } - source += 0x200; + source += FLASH_BUF_SIZE; if (i%16 == 0) write_char('.'); } @@ -1903,7 +1903,7 @@ void check_and_flash_update_image(void) // print_string("Writing block: "); // print_short(dest); flash_region.addr = source; - flash_region.len = 0x200; + flash_region.len = FLASH_BUF_SIZE; flash_read_bulk(flash_buf); if (!(i & 0x7)) { flash_region.addr = dest; @@ -1911,10 +1911,10 @@ void check_and_flash_update_image(void) write_char('.'); } flash_region.addr = dest; - flash_region.len = 0x200; + flash_region.len = FLASH_BUF_SIZE; flash_write_bytes(flash_buf); - dest += 0x200; - source += 0x200; + dest += FLASH_BUF_SIZE; + source += FLASH_BUF_SIZE; } print_string("\nDeleting uploaded flash image\n"); dest = FIRMWARE_UPLOAD_START;