logo elektroda
logo elektroda
X
logo elektroda

Flashing OpenBeken Firmware on WL2S Module with Lightning LN882HK Chip for ELIVCO LSPA9

sithyoda 33840 180
ADVERTISEMENT
  • #61 20891549
    sweetlilmre
    Level 9  

    I wrote a Python script to dump the original firmware (very slowly). I then reflashed the firmware, which booted, but I didn't save the OTP area and it failed to work properly. I will share the script when I'm back at home and also some other instructions which I think you should execute to dump OTP and other bits before flashing anything new. I'll also see if I can optimize the script.
  • ADVERTISEMENT
  • #62 20891585
    p.kaczmarek2
    Moderator Smart Home
    It's a shame this device has no external SPI memory, it would make things easier.

    Or maybe is it possible to access it in SPI mode like we do with Beken?
    BK7231 programming via SPI in flash memory mode - Python and Banana Pi
    Helpful post? Buy me a coffee.
  • #63 20891632
    sweetlilmre
    Level 9  

    I doubt it, but don't know. Basically, a chunk of binary code is loaded into RAM, and then that is used to program the flash. It's very weird. I want to reverse engineer the flashing code at some point and see what it does.
  • #64 20897719
    sweetlilmre
    Level 9  
    Hi,

    The Python script I wrote for dumping the firmware can be found here:
    https://github.com/sweetlilmre/ln882h/blob/master/project/OpenBeken/LN882H_Flash_Dumper.py

    Usage is detailed if you run it without arguments, e.g.

    python LN882H_Flash_Dumper.py
    
    LN882H flash dump tool v1.1
    Usage: python LN882H_Flash_Dumper.py port filename <length>
           port: e.g. COM6
           filename: any simple name, e.g. test
                     otp_ and flash_ files will be created as:
                     otp_filename.bin
                     flash_filename.bin
           length: optional: the amount of flash to dump. This MUST be a hex value.
                   e.g. 0x00040000 (256 KB)
                   If length is omitted, it will default to 0x200000.
                   OTP is fixed size and will always dump 1KB.
    


    If anyone has a module that is stock (has not been flashed with anything custom yet) and could run a dump and post the OTP and Flash files, that would be great. Otherwise, I'm going to have to break open another smart plug.

    This script takes a very long time to dump flash as the command tool is slow.
    You will need to run it in the same directory as you extracted the LN882H_CMD_Tool.exe and dependencies.
    Connect to RX0 / TX0 appropriately and connect GPIOA9 to GND before attaching your USB-UART device.
    Let the device settle for a short while before running the script.

    @p.kaczmarek2 I've got some repos set up and will start pushing changes to them when I get a chance. If you have Discord, could you PM me your details as it would probably be easier to correspond there over firmware.

    Thanks
    -(e)
  • ADVERTISEMENT
  • #65 20897739
    divadiow
    Level 35  

    I have a couple of unadulterated LN8825s at home. I will check them after work.
  • #66 20898248
    p.kaczmarek2
    Moderator Smart Home
    Ok I am looking into porting with @sweetlilmre right now, we will let you know once there is some progress.
    Helpful post? Buy me a coffee.
  • #67 20898972
    divadiow
    Level 35  
    @sweetlilmre is there a uart output of any kind when A9 is pulled low on boot to indicate the chip is in uart download mode?
  • #68 20899019
    sweetlilmre
    Level 9  

    divadiow wrote:
    @sweetlilmre is there a UART output of any kind when A9 is pulled low on boot to indicate the chip is in UART download mode?


    There is no output from what I can remember.
    I keep A9 pulled low throughout the flash dumping process (I've wired a jumper to GND and another to A9 and connect them before plugging in the USB UART).

    I assume you're getting failures of some kind when trying the script?

    Sorry for the late response, we've been deep in porting code.

    Added after 1 [minutes]:

    Also, I don't know if the ln8825 is compatible with the download tool?
  • #69 20899058
    divadiow
    Level 35  
    no apologies necessary!

    me neither on whether it's compatible. I kinda hoped LN882X covered all variations, including LN8825B. I see now in the boot that ln882x is mentioned on this LN8825B device https://www.elektroda.com/rtvforum/topic4023264.html#20898850

    The trouble is this PCB doesn't have an obvious A9 pad. I *think* I've continuity (my multimeter probes are a bit fat) from what appears to be A9 pin on the chip and the hole circled yellow next to GND. Using this IC pinout diagram as a reference, the RX0/TX0/CEN/A4 all seem to match the LN882H pinout I found here http://www.scanway-tech.com/product/detail/47.html

    Close-up of a PCB with an LN8825B chip and wires.

    Diagram of the LN882H integrated circuit with labeled pins.

    I just get the standard boot output when it's grounded and this when trying flasher script

    LN882H flash dump tool v1.0
    Loading RAMCode...
    Error: Fail. Could not go in download mode.
  • #70 20899073
    sweetlilmre
    Level 9  

    Your pinout and via connection look correct.
    This could be many things, incompatible software, different I/O used for boot mode, etc. I'm not sure. I guess we'll have to wait until some more info surfaces.
  • #71 20899077
    divadiow
    Level 35  
    Yes. I'm sure all will be clear in time
  • ADVERTISEMENT
  • #73 20899251
    p.kaczmarek2
    Moderator Smart Home
    OBK compiles on my side, with Main_Init and Main_OnEverySecond included. Of course, it doesn't mean that it works, but we'll see about that soon. I am unable to test yet as I don't have hardware but we will test with @sweetlilmre
    Console with the build process of the OpenBeken project on the LN882H platform.

    Added after 6 [hours] 14 [minutes]:

    We've got a first signs of life, OBK boot log on LN882H:
    
    ------  wifi_mcu_basic_example  ------
    TCP/IP initialized.
    LN882H SDK Ver: 2.1_rc1 [build time:Jan  9 2024 10:41:43][0x02010001]
    psk value :
    00000000:  22 8E A8 71 2B 82 E2 01  5A F7 3E F7 5C 90 A4 7E  "..q+...Z.>.\..~
    00000010:  89 AA C7 D5 6D 05 2A C1  29 EC 34 1E BB F4 A8 FF  ....m.*.).4.....
    00000020:  E3 E5 0A B8 BD 9E 97 F7                           ........
    [WLIB_I]LN882H WiFi Lib Ver: 1.3.0 [build time:Aug  7 2023 17:32:24][0x010300ff]
    [WLIB_I]SoftAP_Startup.
    SoftAP startup!
    +--------------- net device info ------------+
    |netif hostname: ln_softap                   |
    |netif ip      = 192.168.4.1                 |
    |netif mask    = 255.255.255.0               |
    |netif gateway = 192.168.4.1                 |
    |netif mac     : [00:50:C2:5E:88:99]         |
    +--------------------------------------------+
    [WLIB_E]HwEr:UKI:0
    [WLIB_I]Channel scanning not needed
    [WLIB_I]User Preferred channel idx 0-0
    [WLIB_I]Selecting 20MHz ch from One of ... 0
    [WLIB_I]Selected Channel Tbl Idx 0-0
    [WLIB_I]AP: Starting network in 0-0
    [WLIB_I]Connected.
    [WLIB_I]sta_conn_step_set: CONNECTED
    [WLIB_I]Status: Start Successful. Entering Enable State.
    [WLIB_I]Disconnected.
    [WLIB_I]Channel scanning not needed
    [WLIB_I]User Preferred channel idx 5-0
    [WLIB_I]Selecting 20MHz ch from One of ... 0 1 2 3 4 5
    [WLIB_I]Selected Channel Tbl Idx 5-0
    [WLIB_I]AP: Starting network in 5-0
    [WLIB_I]Connected.
    [WLIB_I]sta_conn_step_set: CONNECTED
    [WLIB_I]Status: Start Successful. Entering Enable State.
    Entering initLog()...
    Commands registered!
    initLog() done!
    
    Main_Init_Before_Delay done
    
    Main_Init_Delay
    
    Main_Init_Delay done
    Info:MAIN:Main_Init_Before_Delay
    Warn:CFG:CFG_InitAndLoad: Config crc or ident mismatch. Default config will be loaded.
    Info:CFG:CFG_SetDefaultLEDCorrectionTable: setting defaults
    Info:GEN:PIN_SetupPins pins have been set up.
    Info:MAIN:Main_Init_Before_Delay done
    Info:MAIN:Main_Init_Delay
    Info:MAIN:Main_Init_Delay done
    Info:MAIN:Main_Init_After_Delay
    Info:MAIN:Using SSID []
    Info:MAIN:Using Pass []
    Info:MQTT:MQTT_RegisterCallback called for bT ln882h00000000/ subT ln882h00000000/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT obks/ subT obks/+/set
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/ln882h00000000/ subT cmnd/ln882h00000000/+
    Info:MQTT:MQTT_RegisterCallback called for bT cmnd/obks/ subT cmnd/obks/+
    Info:MQTT:MQTT_RegisterCallback called for bT ln882h00000000/ subT ln882h00000000/+/get
    Error:CMD:cmd startScript NOT found (args autoexec.bat)
    Info:MAIN:Main_Init_After_Delay done
    Info:MAIN:Time 1, idle 0/s, free 106160, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0
    Info:MAIN:Time 2, idle 0/s, free 106160, MQTT 0(0), bWifi 0, secondsWithNoPing -1, socks 0/0
    

    Who can help with testing?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #74 20899557
    sithyoda
    Level 7  

    Very cool development! Thanks guys!
    Really looking forward to the 1st OBK build that I can try to install.

    Of course, I would like to give it a shot on my board.
  • #76 20899787
    sweetlilmre
    Level 9  
    First test image.
    Unzip it and flash with the download tool:

    LN882H_CMD_Tool.exe COM6 download flash 2000000 0x0 flashimage.bin

    (obv. replacing with your comport)

    Once the chip is reset you should see an AP:
    ssid: "LN_AP_8899"
    pwd: "12345678"

    You can connect and get to the OBK webpage on the default IP: 192.168.4.1

    Still a long way to go.
    -(e)
  • #77 20900346
    p.kaczmarek2
    Moderator Smart Home
    I still don't have device to test it, but results are very promising. Who can help testing?

    Here is a screenshot from @sweetlilmre
    Screenshot of the OpenLN882H user interface with options for configuration and restart.
    Helpful post? Buy me a coffee.
  • #78 20901556
    p.kaczmarek2
    Moderator Smart Home
    I've did an information dump about LN882 in this thread:
    https://www.elektroda.com/rtvforum/topic4027545.html
    I will try to maintain that thread with all the info we can find. Please let me know if you have something to add there.
    Helpful post? Buy me a coffee.
  • #79 20901633
    divadiow
    Level 35  
    sweetlilmre wrote:
    but there also seems to be a different tool


    thank you. Where in this doc are you seeing reference to a different tool? I've trawled through the LN882X areas looking for an exe but there only seems to be mkimage.exe, which appears to be for something else.
  • #80 20901738
    sithyoda
    Level 7  

    Still struggling with uploading binary via UART mode to my WL2S module.
    I connected 3.3V, GND, RX, and TX to USB-TTL converter, GPIO A9 to GND (during start). But I get "Fail. Could not go in download mode" all the time.
    Can I simply flash this binary with J-Flash as well?
  • #81 20901870
    sweetlilmre
    Level 9  
    divadiow wrote:
    sweetlilmre wrote:
    but there also seems to be a different tool


    thank you. Where in this doc are you seeing reference to a different tool? I've trawled through the LN882X areas looking for an exe but there only seems to be mkimage.exe, which appears to be for something else.


    I had a look couldn't remember and then found this doc. This looks like it may be the other burning tool found in the gitee repos posted about above: ln882h-document-collection

    Burning mode GPIO configuration is definitely different.

    Also, having a look, this is definitely a different chip, smaller flash size etc, so I'm not sure how far you'll get with the LN882H firmware, but it will be interesting to see. Definitely see if you can get the flash back up first!
    -(e)
  • #82 20901873
    sweetlilmre
    Level 9  
    sithyoda wrote:
    Still struggling with uploading binary via UART mode to my WL2S module.
    I connected 3v3, GND, RX and TX to USB-TTL converter, GPIO A9 to GND (during start). But I get "Fail. Could not go in download mode" all the time.
    Can I simply flash this binary with J-Flash as well?


    You should be able to flash with SWD no problem. AFAIK you need to keep A9 connected to GND the whole time (before connecting UART and during the process, this is why I have soldered connectable jumpers to A9 and GND).

    Just to be sure, you are connecting RX0 and TX0, not RX1 and TX1?

    -(e)
  • #83 20902158
    divadiow
    Level 35  

    >>20901870
    Thank you.

    I'll have a go at it. I'm just downloading everything from that FTP site also, but maybe it's the same as Gitee.

    ftp://sh.lightningsemi.cn:8621
    LN_Customer02
    111111

    I don't have any J-Link stuff, but I notice this device is shown in a couple of the PDFs
    Circuit board with connected cables and a blue USB module.

    Image of an electronic device with a microcontroller and cable connector.

    It looks suspiciously like https://www.aliexpress.com/item/1005005773672204.html

    And for £2 delivered, maybe I'll have a play with that too.
  • #84 20902169
    sweetlilmre
    Level 9  

    Any compatible SWD programmer should do it, so that will probably work.

    Are you managing to download off of that FTP server?
    It keeps dropping the connection for me.
    If you can grab them, please PM me a link?

    -(e)
  • #85 20902206
    @GUTEK@
    Level 31  
    p.kaczmarek2 wrote:
    I don't have a device to test this yet, but the results are very promising. Who can help with testing?
    I have an aftermarket switch on this chip, to be exact:
    Close-up of a circuit board with visible electronic components. With programming this I won't help, but once you have something ready I can upload and test it.
  • #86 20902172
    divadiow
    Level 35  
    sweetlilmre wrote:
    Are you managing to download off of that FTP server?
    It keeps dropping the connection for me.
    If you can grab them, please PM me a link?


    No stopping yet but very slow. Will make available if I get it all

    Screenshot of a download progress window for a file named SDK-LN8825-v0.7.1.7z, downloaded to a location on a computer. The download is at 23% with a speed of 28.8 KB/s.


    Added after 27 [minutes]:

    sweetlilmre wrote:
    this is definitely a different chip, smaller flash size etc, so I'm not sure how far you'll get with the LN882H firmware,


    the LN8825A looks to have 1mb but the LN8825B is 2mb. this would be OK?

    Comparison table of two chipsets, LN8825A and LN8825B, with different SIP Flash storage capacities. Memory map of LN8825A showing ROM, FLASH, and SRAM. Memory map of LN8825B showing sections like ROM, FLASH memory, SRAM, and others.

    Added after 42 [minutes]:

    interesting. there's another FTP and it has this tool

    Screenshot of the LN882X tools folder with files. Screenshot of FactoryDownloadTool - 20191227 - v1.1 with a list of COM ports and download status
  • #87 20902370
    p.kaczmarek2
    Moderator Smart Home
    I think I've got whole this FTP downloaded. Which files do you need?
    Helpful post? Buy me a coffee.
  • #89 20902407
    sweetlilmre
    Level 9  

    @p.kaczmarek2

    I'd like to take a look through everything. Could you share the lot on a Google Drive link or similar?

    @divadiow
    2MB should be enough, but a port to this new platform will have to follow the Ln882h I think.
    When you say "new FTP," do you mean another server?
    If so, can you share what you have?

    -(e)
  • #90 20902416
    divadiow
    Level 35  

    I've PM'd you ftp1 dump.

    I'm downloading this second one.

    ftp://sh.lightningsemi.cn:8621
    Username: LN_Customer
    Password: forcus123*()

    Added after 1 [minutes]:

    Details are seen in doc "..SDKtuyaty_iot_wf_rtos_sdk_ln882x使用说明.pdf"

    Added after 19 [minutes]:

    >>20902394

    lol. It's here https://gitee.com/lightningsemi/pc-tool-release/tree/master

Topic summary

The discussion revolves around flashing OpenBeken firmware on the ELIVCO LSPA9 module, which utilizes the WL2S microcontroller and the LIGHTNING LN882HK chip. Users share their experiences with UART and JTAG flashing methods, debugging issues, and the challenges of obtaining and compiling the necessary firmware. Several users successfully managed to flash the firmware, enabling functionalities such as WiFi connectivity and relay control. The conversation also touches on power consumption, temperature management, and the implementation of power-saving features. Additionally, users discuss the integration of the BL0937 power metering chip and the development of a comprehensive template for the device.
Summary generated by the language model.
ADVERTISEMENT