diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fa2f3f9..10e9636 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,4 +18,4 @@ jobs: apt update apt install make gcc sdcc xxd python-is-python3 libjson-c-dev -y - name: Make project - run: make \ No newline at end of file + run: make MACHINE="KP_9000_6XHML_X2" \ No newline at end of file diff --git a/Makefile b/Makefile index 00519ca..fbe636d 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,11 @@ SUBDIRSCLEAN=$(addsuffix clean,$(SUBDIRS)) BUILDDIR = output/ VERSION_HEADER := version.h +ifeq ($(MACHINE),) +else + CC_FLAGS += -DMACHINE_$(MACHINE) +endif + all: create_build_dir $(VERSION_HEADER) $(SUBDIRS) $(BUILDDIR)rtlplayground.bin create_build_dir: diff --git a/doc/devices/SWTGW218AS.md b/doc/devices/SWTGW218AS.md new file mode 100644 index 0000000..c8777f2 --- /dev/null +++ b/doc/devices/SWTGW218AS.md @@ -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 + + + + + +## 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 + diff --git a/doc/devices/photos/SWTGW218AS-managed/front.png b/doc/devices/photos/SWTGW218AS-managed/front.png new file mode 100644 index 0000000..7b65678 Binary files /dev/null and b/doc/devices/photos/SWTGW218AS-managed/front.png differ diff --git a/doc/devices/photos/SWTGW218AS-managed/label.jpg b/doc/devices/photos/SWTGW218AS-managed/label.jpg new file mode 100644 index 0000000..6615dab Binary files /dev/null and b/doc/devices/photos/SWTGW218AS-managed/label.jpg differ diff --git a/machine.c b/machine.c index ca394af..d48c2d6 100644 --- a/machine.c +++ b/machine.c @@ -13,12 +13,14 @@ __code const struct machine machine = { .n_sfp = 2, .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}, - .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_los = GPIO10_LED10, .sfp_port[0].pin_tx_disable = GPIO_NA, .sfp_port[0].sds = 0, .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_los = GPIO37, .sfp_port[1].pin_tx_disable = GPIO_NA, @@ -37,9 +39,6 @@ __code const struct machine machine = { LEDS_1G | LEDS_LINK, 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) { } @@ -98,6 +97,9 @@ __code const struct machine machine = { LEDS_2G5 | LEDS_LINK | LEDS_ACT }, }, }; + +void machine_custom_init(void) { } + #elif defined MACHINE_KP_9000_9XHML_X __code const struct machine machine = { .machine_name = "keepLink KP-9000-9XHML-X", @@ -214,6 +216,40 @@ __code const struct machine machine = { 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 __code const struct machine machine = { .machine_name = "8+1 SFP Port Switch", @@ -315,4 +351,6 @@ __code const struct machine machine = { void machine_custom_init(void) { reg_bit_set(RTL837X_REG_LED_GLB_IO_EN, 6); } -#endif \ No newline at end of file +#else + #error "Please select a machine type in machine.h" +#endif diff --git a/machine.h b/machine.h index 1d4cf76..bf5aa0a 100644 --- a/machine.h +++ b/machine.h @@ -6,18 +6,18 @@ /* * 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_9XH_X_EU +// #define MACHINE_KP_9000_9XHML_X // #define MACHINE_SWGT024_V2_0 // #define MACHINE_HORACO_ZX_SG4T2 // #define MACHINE_TRENDNET_TEG_S562 // #define MACHINE_HG0402XG_V1_1 +// #define MACHINE_SWTGW218AS // #define MACHINE_HI_K0402WS // #define DEFAULT_8C_1SFP -// #define DEFAULT_5C_1SFP - typedef struct { // GPIO pins for SDA/SCL uint8_t sda; diff --git a/rtlplayground.c b/rtlplayground.c index f4767c2..37281aa 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -2037,13 +2037,92 @@ void bootloader(void) leds_dump(); + set_sys_led_state(SYS_LED_SLOW); + if (machine_detected.isRTL8373) rtl8373_init(); else rtl8372_init(); delay(1000); +<<<<<<< resetbutton 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 // This register seems to work on the RTL8373 only if also the SDS