diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 45b2e84..9769311 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -17,6 +17,7 @@ // #define DEBUG #include "debug.h" + #define L2_MAX_TRANSFER 30 #pragma codeseg BANK1 @@ -96,6 +97,10 @@ void itoa_html(uint8_t v) char_to_html('0' + (v % 10)); } +void string_to_html(register char *s) +{ + while (*s) char_to_html(*s++); +} uint16_t stat_content(void) { @@ -234,6 +239,9 @@ void send_basic_info(void) slen += strtox(outbuf + slen, BUILD_DATE); slen += strtox(outbuf + slen, "\",\"hw_ver\":\""); slen += strtox(outbuf + slen, machine.machine_name); + slen += strtox(outbuf + slen, "\",\"flash_size\":\""); + string_to_html(get_flash_size_str()); + slen += strtox(outbuf + slen, "\",\"sfp_slot_0\":\""); send_sfp_info(0); char_to_html('"'); diff --git a/rtl837x_common.h b/rtl837x_common.h index b6ec58e..8fe6764 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -131,6 +131,7 @@ void memset(register __xdata uint8_t *dst, register __xdata uint8_t v, register uint16_t strlen(register __code const char *s); uint16_t strlen_x(register __xdata const char *s); uint16_t strtox(register __xdata uint8_t *dst, register __code const char *s); +uint16_t strcpy(register __xdata uint8_t *dst, register const char *s); void tcpip_output(void); uint8_t read_flash(uint8_t bank, __code uint8_t *addr); void get_random_32(void); diff --git a/rtl837x_flash.c b/rtl837x_flash.c index 76c6eb3..8845375 100644 --- a/rtl837x_flash.c +++ b/rtl837x_flash.c @@ -9,7 +9,9 @@ __xdata uint8_t dio_enabled; __xdata struct flash_region_t flash_region; + __xdata uint32_t flash_size; +__xdata uint8_t flash_capacity_code; // For the flash commands, see e.g. Windbond W25Q32JV datasheet #define CMD_WRITE_STATUS 0x01 @@ -134,6 +136,19 @@ void flash_read_uid(void) flash_configure_mmio(); } +__code char* get_flash_size_str(void) +{ + switch (flash_capacity_code) { + case 0x12: return "256 KB"; + case 0x13: return "512 KB"; + case 0x14: return "1 MB"; + case 0x15: return "2 MB"; + case 0x16: return "4 MB"; + case 0x17: return "8 MB"; + case 0x18: return "16 MB"; + default: return "unknown"; + } +} void flash_read_jedecid(void) { @@ -150,17 +165,16 @@ void flash_read_jedecid(void) SFR_FLASH_EXEC_GO = 1; while(SFR_FLASH_EXEC_BUSY); - print_string("Maufacturer ID: 0x"); + print_string("Flash information:\n"); + print_string(" Manufacturer ID: 0x"); print_byte(SFR_FLASH_DATA0); - print_string("\nMemory Type: 0x"); + print_string("\n Memory Type: 0x"); print_byte(SFR_FLASH_DATA8); - print_string("\nCapacity: 0x"); - uint8_t cap = SFR_FLASH_DATA16; - flash_size = 1UL << cap; - print_byte(cap); - print_string(" = "); - print_long(flash_size); - print_string(" Bytes\n"); + print_string("\n Capacity: 0x"); + flash_capacity_code = SFR_FLASH_DATA16; + flash_size = 1UL << flash_capacity_code; + print_byte(flash_capacity_code); + print_string(" = "); print_string(get_flash_size_str()); write_char('\n'); flash_configure_mmio(); } diff --git a/rtl837x_flash.h b/rtl837x_flash.h index cad66b0..2267b23 100644 --- a/rtl837x_flash.h +++ b/rtl837x_flash.h @@ -10,4 +10,6 @@ void flash_read_security(void); void flash_sector_erase(void); void flash_read_bulk(__xdata uint8_t *dst); void flash_write_bytes(__xdata uint8_t *ptr); +__code char* get_flash_size_str(void); + #endif diff --git a/rtlplayground.c b/rtlplayground.c index 9c08837..84a8ab7 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -240,6 +240,7 @@ uint16_t strtox(register __xdata uint8_t *dst, register __code const char *s) return dst - b; } + uint16_t strlen(register __code const char *s) { uint16_t l = 0; @@ -1872,17 +1873,13 @@ void check_and_flash_update_image(void) { flash_read_jedecid(); // This initializes also __xdata flash_size variable - print_long(flash_size); print_string(" flash size detected.\n"); - print_long(FIRMWARE_UPLOAD_START*2); print_string(" bytes needed for update.\n"); + print_string(get_flash_size_str()); print_string(" flash size detected. (1 MB is needed for image updating)\n"); if (flash_size < FIRMWARE_UPLOAD_START*2) { print_string("Flash too small for updating; skipping update check\n"); return; } - else { - print_string("Flash size ok.\n"); - } - + print_string("Checking for update image in flash... "); // Check if an update image is in flash flash_region.addr = FIRMWARE_UPLOAD_START; flash_region.len = 0x100; @@ -1895,7 +1892,7 @@ void check_and_flash_update_image(void) __xdata uint16_t i = 0; __xdata uint16_t j = 0; __xdata uint8_t * __xdata bptr; - print_string("Identified update image. Checking integrity"); + print_string("found update image! Checking integrity"); flash_init(0); // Re-initialize flash for non-DIO operation, otherwise flashing will fail set_sys_led_state(SYS_LED_FAST); crc_value = 0x0000; @@ -1951,6 +1948,10 @@ void check_and_flash_update_image(void) dest += 0x1000; } } + else + { + print_string("no update image found.\n"); + } } void main(void)