Merge pull request #90 from feelfree69/fix-FW-Upload

make fw upload working; nicer debug outputs for console
This commit is contained in:
logicog
2026-01-24 09:54:07 +01:00
committed by GitHub
6 changed files with 48 additions and 18 deletions
+1
View File
@@ -692,6 +692,7 @@ void print_gpio_status(void) {
void print_sw_version(void) __banked {
print_string("Software version: ");
print_string(VERSION_SW);
print_string("\nBuild: " __DATE__ " " __TIME__);
print_string("\nHardware: ");
print_string(machine.machine_name);
write_char('\n');
+8 -3
View File
@@ -296,11 +296,11 @@ uint8_t stream_upload(uint16_t bptr)
if (verify_crc) {
dbg_string("CRC16: "); dbg_short(crc_final); dbg_char('\n');
if (crc_final == 0xb001) {
dbg_string("Checksum OK.");
print_string("Checksum OK.");
} else {
dbg_string("Checksum incorrect!");
print_string("Checksum incorrect!");
}
dbg_string("Upload to flash done, will reset!\n");
print_string("\nUpload to flash done, will reset!\n");
reset_chip();
}
// Make sure there is a 0 at the end of the uploaded data
@@ -424,6 +424,7 @@ void handle_post(void)
p += 4; // Skip \r\n\r\n sequence at end of preamble of part
if (is_word(request_path, "upload")) {
print_string("Firmware upload started.");
uptr = FIRMWARE_UPLOAD_START;
verify_crc = 1;
max_upload = 1024576;
@@ -435,6 +436,9 @@ void handle_post(void)
flash_region.addr = CONFIG_START;
flash_sector_erase();
}
flash_init(0); // Re-initialize flash for non-DIO operation, otherwise flashing fails
set_sys_led_state(SYS_LED_FAST);
crc_value = 0;
bindex = 0;
write_len = 0;
@@ -514,6 +518,7 @@ void httpd_appcall(void)
// Check here maxupload by subtracting uip_len and close socekt if fails!
if (max_upload - uip_len > 0) {
stream_upload(0);
write_char('.');
} else {
send_bad_request();
goto do_send;
+1
View File
@@ -124,5 +124,6 @@ void get_random_32(void);
void read_reg_timer(uint32_t * tmr);
void sfp_print_info(uint8_t sfp);
bool gpio_pin_test(uint8_t pin);
void set_sys_led_state(uint8_t state);
#endif
+2 -3
View File
@@ -342,8 +342,8 @@ void flash_sector_erase(void)
void flash_write_bytes(__xdata uint8_t *ptr)
{
write_char('>'); print_long(flash_region.addr); write_char(':'); print_short(flash_region.len); write_char('-'); print_byte(*ptr); write_char('\n');
while(1) {
// write_char('\n'); write_char('>'); print_long(flash_region.addr); write_char(':'); print_short(flash_region.len); write_char('-'); print_byte(*ptr); // write_char('\n');
while(1) {
flash_write_enable();
SFR_FLASH_CMD = CMD_PAGE_PROGRAM;
SFR_FLASH_TCONF = 0x40 | 8 | 4; // Bytes written is 4, 8 enables write, 0x40 is unknown
@@ -369,7 +369,6 @@ void flash_write_bytes(__xdata uint8_t *ptr)
flash_region.len -= 4;
flash_region.addr += 4;
};
while (flash_read_status() & 0x1);
flash_configure_mmio();
}
+5
View File
@@ -9,6 +9,11 @@
#define RTL837X_REG_HW_CONF 0x6040
// Bits 4 & 5: CLOCK DIVIDER from 125MHz for Timer
#define SYS_LED_OFF 0
#define SYS_LED_FAST 1
#define SYS_LED_SLOW 2
#define SYS_LED_ON 3
#define RTL837X_REG_LED_MODE 0x6520
// Defines the LED Mode for steering the Port LEDS and the System LED
// BIT 17 set: LED solid on
+31 -12
View File
@@ -1416,6 +1416,9 @@ void led_config_9xh(void)
sfr_mask_data(0, 0xe0, 0xa0);
reg_write_m(RTL837X_REG_LED_MODE);
// Set LED blink rate to slow during booting
set_sys_led_state(SYS_LED_SLOW);
// Disable RLDP (Realtek Loop Detection Protocol) LEDs on loop detection
reg_read_m(RTL837X_REG_LED_RLDP_1);
sfr_mask_data(0, 0, 0x3);
@@ -1442,6 +1445,12 @@ void led_config_9xh(void)
reg_write_m(RTL837X_REG_LED3_0_SET1);
}
void set_sys_led_state(uint8_t state)
{
reg_read_m(RTL837X_REG_LED_MODE);
sfr_mask_data(2, 0x03, state);
reg_write_m(RTL837X_REG_LED_MODE);
}
void led_config(void)
{
@@ -1848,7 +1857,10 @@ void bootloader(void)
__xdata uint16_t i = 0;
__xdata uint16_t j = 0;
__xdata uint8_t * __xdata bptr;
print_string("Identified update image. Checking integrity...\n");
print_string("Identified 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;
for (i = 0; i < 1024; i++) {
@@ -1857,28 +1869,31 @@ void bootloader(void)
flash_read_bulk(flash_buf);
bptr = flash_buf;
for (j = 0; j < 0x200; j++) {
print_byte(*bptr); write_char(' ');
// print_byte(*bptr); write_char(' ');
crc16(bptr++);
print_short(crc_value); write_char(':');
// print_short(crc_value); write_char(':');
}
source += 0x200;
write_char('\n'); print_short(crc_value); write_char(' ');
// write_char('\n'); print_short(crc_value); write_char(' ');
if (i%16 == 0)
write_char('.');
}
if (crc_value == 0xb001) {
print_string("Checksum OK\n");
print_string("Update in progress, moving firmware to start of FLASH!\n");
print_string("\nChecksum OK\n");
print_string("Update in progress, moving firmware to start of FLASH.");
source = FIRMWARE_UPLOAD_START;
// A 512kByte = 4MBit Flash has 128*8=1024 512k blocks, we copy only 120
for (i = 0; i < 960; i++) {
print_string("Writing block: ");
print_short(dest);
// A 512kByte = 4MBit Flash has 128*8=1024 512byte blocks, we copy only 896
// (don't overwrite config @ 0x700000)
for (i = 0; i < 896; i++) {
// print_string("Writing block: ");
// print_short(dest);
flash_region.addr = source;
flash_region.len = 0x200;
flash_read_bulk(flash_buf);
write_char('\n');
if (!(i & 0x7)) {
flash_region.addr = dest;
flash_sector_erase();
write_char('.');
}
flash_region.addr = dest;
flash_region.len = 0x200;
@@ -1886,7 +1901,7 @@ void bootloader(void)
dest += 0x200;
source += 0x200;
}
print_string("Deleting uploaded flash image\n");
print_string("\nDeleting uploaded flash image\n");
dest = FIRMWARE_UPLOAD_START;
for (register uint8_t i=0; i < 128; i++) {
flash_region.addr = dest;
@@ -1907,6 +1922,8 @@ void bootloader(void)
}
}
set_sys_led_state(SYS_LED_SLOW);
#ifdef DEBUG
// This register seems to work on the RTL8373 only if also the SDS
// Is correctly configured. Therefore, we can test it, here...
@@ -1952,6 +1969,8 @@ void bootloader(void)
print_string("\n> ");
idle_ready = 1;
set_sys_led_state(SYS_LED_ON);
// Wait for commands on serial connection
// sbuf_ptr is moved forward by serial interrupt, l is the position until we have already
// printed out the entered characters