Merge branch 'main' into resetbutton

This commit is contained in:
feelfree69
2026-02-15 12:34:46 +01:00
committed by GitHub
8 changed files with 155 additions and 9 deletions
+1 -1
View File
@@ -18,4 +18,4 @@ jobs:
apt update apt update
apt install make gcc sdcc xxd python-is-python3 libjson-c-dev -y apt install make gcc sdcc xxd python-is-python3 libjson-c-dev -y
- name: Make project - name: Make project
run: make run: make MACHINE="KP_9000_6XHML_X2"
+5
View File
@@ -17,6 +17,11 @@ SUBDIRSCLEAN=$(addsuffix clean,$(SUBDIRS))
BUILDDIR = output/ BUILDDIR = output/
VERSION_HEADER := version.h VERSION_HEADER := version.h
ifeq ($(MACHINE),)
else
CC_FLAGS += -DMACHINE_$(MACHINE)
endif
all: create_build_dir $(VERSION_HEADER) $(SUBDIRS) $(BUILDDIR)rtlplayground.bin all: create_build_dir $(VERSION_HEADER) $(SUBDIRS) $(BUILDDIR)rtlplayground.bin
create_build_dir: create_build_dir:
+24
View File
@@ -0,0 +1,24 @@
### ZX-SWTGW218AS
## Brands
|Brand|Type|Managed|PCB|Flash|Chip RTL|
|---|---|---|---|---|---|
| Mokerlink | ZX-SWTGW218AS | Yes| SWTG118AS-V2.0-16029 | 2MB (FM25Q16A)| 8273N + 8224N |
| Sodola | | | | | |
| Horaco | | | | | |
## Photos
<img src="photos/SWTGW218AS-managed/front.png" width="800" />
<img src="photos/SWTGW218AS-managed/label.jpg" width="800" />
## PCB
See up'n'atom's Repo:
https://github.com/up-n-atom/SWTG118AS/blob/main/photos/SWTG118AS-v2.0/SWTG118AS-v2.0-pcb-top.JPG
https://github.com/up-n-atom/SWTG118AS/blob/main/photos/SWTG118AS-v2.0/SWTG118AS-v2.0-pcb-bottom.JPG
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 KiB

+43 -5
View File
@@ -13,12 +13,14 @@ __code const struct machine machine = {
.n_sfp = 2, .n_sfp = 2,
.log_to_phys_port = {0, 0, 0, 5, 1, 2, 3, 4, 6}, .log_to_phys_port = {0, 0, 0, 5, 1, 2, 3, 4, 6},
.phys_to_log_port = {4, 5, 6, 7, 3, 8, 0, 0, 0}, .phys_to_log_port = {4, 5, 6, 7, 3, 8, 0, 0, 0},
.is_sfp = {0, 0, 0, 2, 0, 0, 0, 0, 1}, .is_sfp = {0, 0, 0, 1, 0, 0, 0, 0, 2},
// Left SFP port (5)
.sfp_port[0].pin_detect = GPIO50_I2C_SCL2_UART1_TX, .sfp_port[0].pin_detect = GPIO50_I2C_SCL2_UART1_TX,
.sfp_port[0].pin_los = GPIO10_LED10, .sfp_port[0].pin_los = GPIO10_LED10,
.sfp_port[0].pin_tx_disable = GPIO_NA, .sfp_port[0].pin_tx_disable = GPIO_NA,
.sfp_port[0].sds = 0, .sfp_port[0].sds = 0,
.sfp_port[0].i2c = { .sda = GPIO41_I2C_SDA3_MDIO1, .scl = GPIO40_I2C_SCL3_MDC1 }, .sfp_port[0].i2c = { .sda = GPIO41_I2C_SDA3_MDIO1, .scl = GPIO40_I2C_SCL3_MDC1 },
// Right SFP port (6)
.sfp_port[1].pin_detect = GPIO30_ACL_BIT3_EN, .sfp_port[1].pin_detect = GPIO30_ACL_BIT3_EN,
.sfp_port[1].pin_los = GPIO37, .sfp_port[1].pin_los = GPIO37,
.sfp_port[1].pin_tx_disable = GPIO_NA, .sfp_port[1].pin_tx_disable = GPIO_NA,
@@ -37,9 +39,6 @@ __code const struct machine machine = {
LEDS_1G | LEDS_LINK, LEDS_1G | LEDS_LINK,
0 }, 0 },
}, },
.led_mux_custom = 1,
.led_mux = {0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x0f, 0x0c, 0x0d, 0x0e, 0x10, 0x11, 0x12, 0x14,
0x15, 0x16, 0x18, 0x19, 0x1a, 0x1c, 0x1d, 0x1e, 0x20, 0x21, 0x22, 0x23 },
}; };
void machine_custom_init(void) { } void machine_custom_init(void) { }
@@ -98,6 +97,9 @@ __code const struct machine machine = {
LEDS_2G5 | LEDS_LINK | LEDS_ACT }, LEDS_2G5 | LEDS_LINK | LEDS_ACT },
}, },
}; };
void machine_custom_init(void) { }
#elif defined MACHINE_KP_9000_9XHML_X #elif defined MACHINE_KP_9000_9XHML_X
__code const struct machine machine = { __code const struct machine machine = {
.machine_name = "keepLink KP-9000-9XHML-X", .machine_name = "keepLink KP-9000-9XHML-X",
@@ -214,6 +216,40 @@ __code const struct machine machine = {
void machine_custom_init(void) { } void machine_custom_init(void) { }
#elif defined MACHINE_SWTGW218AS
__code const struct machine machine = {
.machine_name = "SWTGW218AS 8+1 Managed Switch",
.isRTL8373 = 1,
.min_port = 0,
.max_port = 8,
.n_sfp = 1,
.log_to_phys_port = {1, 2, 3, 4, 5, 6, 7, 8, 9},
.phys_to_log_port = {0, 1, 2, 3, 4, 5, 6, 7, 8},
.is_sfp = {0, 0, 0, 0, 0, 0, 0, 0, 1},
.sfp_port[0].pin_detect = GPIO30_ACL_BIT3_EN,
.sfp_port[0].pin_los = GPIO37,
.sfp_port[0].pin_tx_disable = GPIO_NA,
.sfp_port[0].sds = 1,
.sfp_port[0].i2c = { .sda = GPIO39_I2C_SDA4, .scl = GPIO40_I2C_SCL3_MDC1 },
.reset_pin = GPIO54_ACL_BIT2_EN,
.high_leds = { .mux = LED_27 | LED_28 | LED_29, .enable = LED_28 | LED_29 },
.port_led_set = { 0, 0, 0, 0, 0, 0, 0, 0, 1},
.led_sets = { { LEDS_2G5 | LEDS_LINK | LEDS_ACT, // Green LED (right)
0, // unused
LEDS_1G | LEDS_100M | LEDS_10M | LEDS_LINK | LEDS_ACT, // Amber LED (left)
0
}, // unused
{ LEDS_10G | LEDS_5G | LEDS_2G5 | LEDS_1G | LEDS_100M | LEDS_LINK | LEDS_ACT, // SFP LED
0, // unused
0, // unused
0
}, // unused },
},
};
void machine_custom_init(void) { }
#elif defined DEFAULT_8C_1SFP #elif defined DEFAULT_8C_1SFP
__code const struct machine machine = { __code const struct machine machine = {
.machine_name = "8+1 SFP Port Switch", .machine_name = "8+1 SFP Port Switch",
@@ -315,4 +351,6 @@ __code const struct machine machine = {
void machine_custom_init(void) { void machine_custom_init(void) {
reg_bit_set(RTL837X_REG_LED_GLB_IO_EN, 6); reg_bit_set(RTL837X_REG_LED_GLB_IO_EN, 6);
} }
#endif #else
#error "Please select a machine type in machine.h"
#endif
+3 -3
View File
@@ -6,18 +6,18 @@
/* /*
* Select your machine type below * Select your machine type below
*/ */
#define MACHINE_KP_9000_6XHML_X2 // #define MACHINE_KP_9000_6XHML_X2
// #define MACHINE_KP_9000_6XH_X // #define MACHINE_KP_9000_6XH_X
// #define MACHINE_KP_9000_9XH_X_EU // #define MACHINE_KP_9000_9XH_X_EU
// #define MACHINE_KP_9000_9XHML_X
// #define MACHINE_SWGT024_V2_0 // #define MACHINE_SWGT024_V2_0
// #define MACHINE_HORACO_ZX_SG4T2 // #define MACHINE_HORACO_ZX_SG4T2
// #define MACHINE_TRENDNET_TEG_S562 // #define MACHINE_TRENDNET_TEG_S562
// #define MACHINE_HG0402XG_V1_1 // #define MACHINE_HG0402XG_V1_1
// #define MACHINE_SWTGW218AS
// #define MACHINE_HI_K0402WS // #define MACHINE_HI_K0402WS
// #define DEFAULT_8C_1SFP // #define DEFAULT_8C_1SFP
// #define DEFAULT_5C_1SFP
typedef struct { typedef struct {
// GPIO pins for SDA/SCL // GPIO pins for SDA/SCL
uint8_t sda; uint8_t sda;
+79
View File
@@ -2037,13 +2037,92 @@ void bootloader(void)
leds_dump(); leds_dump();
set_sys_led_state(SYS_LED_SLOW);
if (machine_detected.isRTL8373) if (machine_detected.isRTL8373)
rtl8373_init(); rtl8373_init();
else else
rtl8372_init(); rtl8372_init();
delay(1000); delay(1000);
<<<<<<< resetbutton
check_and_flash_update_image(); check_and_flash_update_image();
=======
// Check update in progress and move blocks
flash_region.addr = FIRMWARE_UPLOAD_START;
flash_region.len = 0x100;
flash_read_bulk(flash_buf);
if (flash_buf[0] == 0x00 && flash_buf[1] == 0x40) {
__xdata uint32_t dest = 0x0;
__xdata uint32_t source = FIRMWARE_UPLOAD_START;
__xdata uint16_t i = 0;
__xdata uint16_t j = 0;
__xdata uint8_t * __xdata bptr;
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++) {
flash_region.addr = source;
flash_region.len = 0x200;
flash_read_bulk(flash_buf);
bptr = flash_buf;
for (j = 0; j < 0x200; j++) {
// print_byte(*bptr); write_char(' ');
crc16(bptr++);
// print_short(crc_value); write_char(':');
}
source += 0x200;
// write_char('\n'); print_short(crc_value); write_char(' ');
if (i%16 == 0)
write_char('.');
}
if (crc_value == 0xb001) {
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 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);
if (!(i & 0x7)) {
flash_region.addr = dest;
flash_sector_erase();
write_char('.');
}
flash_region.addr = dest;
flash_region.len = 0x200;
flash_write_bytes(flash_buf);
dest += 0x200;
source += 0x200;
}
print_string("\nDeleting uploaded flash image\n");
dest = FIRMWARE_UPLOAD_START;
for (register uint8_t i=0; i < 128; i++) {
flash_region.addr = dest;
flash_sector_erase();
dest += 0x1000;
}
print_string("Resetting now");
delay(200);
reset_chip();
}
print_string("Checksum incorrect, please upload the image again\n");
print_string("Erasing bad uploaded flash image\n");
dest = FIRMWARE_UPLOAD_START;
for (register uint8_t i=0; i < 128; i++) {
flash_region.addr = dest;
flash_sector_erase();
dest += 0x1000;
}
}
>>>>>>> main
#ifdef DEBUG #ifdef DEBUG
// This register seems to work on the RTL8373 only if also the SDS // This register seems to work on the RTL8373 only if also the SDS