libc0607 / Realtek_switch_hacking

折腾交换机
447 stars 135 forks source link

How to compile Realtek_Unmanaged_Switch_API_V1.3.12_20171124 #23

Open Firemanpl opened 5 months ago

Firemanpl commented 5 months ago

the attached files do not talk about the general configuration and compilation of these libraries. These are only details. How to connect the interface and how to compile and create a file. I didn't read that. Is there something wrong with me? :( I trying compile firmware ASIC driver for RTL8730MB and i don't know how to do it.

Firemanpl commented 5 months ago

Thank you in advance for your help

libc0607 commented 5 months ago

@Firemanpl

Is there something wrong with me? :(

No. You're doing well, but it's the holy crab, Realtek, hides everything inside its shell.

The RTL8370 series supports multiple "modes" by configuring several pins, including SMI slave, I2C host (reading config from external EEPROM), or running some firmware from external SPI NOR flash in its internal 8051 core. If you're gonna use "Realtek_Unmanaged_Switch_API_V1.3.12_20171124", then you don't need any firmware running on RTL8370. Instead, it's working as an SMI slave.

The API is running on other SoCs (e.g. ESP32, RP2040, or whatever you love) which should be connected to RTL8370 via SMI. The hardware connection is similar to I2C. The APIs should be ported to the SoC (by implementing smi_write and smi_read, maybe you can use this as the SMI porting reference), then call the APIs on the top. The document is mainly about explaining those top APIs.

I don't know if this helps.

Firemanpl commented 5 months ago

So just design a PC board with separators and without uploading additional firmware should be used? But I want program several functions. For this purpose I would like to use the internal CPU processor to use the GPIO pins.

Firemanpl commented 5 months ago

So I used SDDM on platformio. And after I make basic configuration loop. I getting this:

`Processing Generic8051 (platform: intel_mcs51; board: Generic8051)

Verbose mode can be enabled via -v, --verbose option CONFIGURATION: https://docs.platformio.org/page/boards/intel_mcs51/Generic8051.html PLATFORM: Intel MCS-51 (8051) (2.2.0) > Generic 8051 HARDWARE: 8051 11MHz, 128B RAM, 4KB Flash PACKAGES:

int main() { //rtk_switch_init();

return 0; } `

Firemanpl commented 5 months ago

aaaaa so this 8051 is only for use instructions from SPI or SMI interface from another MCU like ESP8266 or ESP32 or external EEPROM ?

Firemanpl commented 5 months ago

so RTL8370MB does not have build-in memory ?

Firemanpl commented 5 months ago

only RAM. And RTL8370MB reading from only external EEPROM flash or another MCU like RP2040 or ESP32 or ESP8266 ?

libc0607 commented 5 months ago

@Firemanpl

As far as I know, there are at least two different SDKs for these chips. They are completely different.

One is that we all have, "Realtek_Unmanaged_Switch_API", for external SoCs utilizing the L2 functions. In that situation, the internal 8051 core is disabled by strapping pins, what the external SoCs exactly do is set the register via the SMI interface, which is most likely an HDL-hard-coded SMI slave interface. The L2 functions are implemented in hardware, and those "Unmanaged APIs" are actually wrappings of register sets & resets.

The other is called "LWS (Light Web Smart) SDK", which might be what you're looking for, is about running codes in the DW8051 core inside the RTL8370. In that case, a bootrom should be programmed into the internal 8051's ROM, then the 8051 boot from this ROM, and load the firmware (or 2nd bootloader) with web from SPI flash.

Compiling the "Realtek_Unmanaged_Switch_API" for a generic 8051 target does not make sense -- as I described above, it's not designed for it and I don't think anyone can build a minimal SDCC environment without the help from Realtek. We don't have any register-level documents. Even the LWS SDK contains a lot of pre-compiled static libraries used to operate the registers, the only thing developers in companies like TP-LINK can do with this SDK is tweak the HTTP pages (mainly CSS) and change the company logo to theirs.

Sadly, I don't know how can share the LWS SDK, and someone still selling the bootrom code for a living (see https://github.com/libc0607/Realtek_switch_hacking/issues/1#issuecomment-396489993. note that "几万" means several thousand of USD, means China’s median income for dozens of months).

What a weird business model.

But IMO you can still control the LED GPIOs on RTL8370, by using the LED APIs. See the "Modules led.h" section in the Unmanaged Switch API document.