1
0
mirror of https://git.openwrt.org/openwrt/openwrt.git synced 2024-10-18 13:29:16 +02:00
openwrt/scripts/belkin-header.py
Markus Stockhausen d03f3dcf3b realtek: add support for Linksys LGS310C
Hardware specification
----------------------

* RTL8380M SoC, 1 MIPS 4KEc core @ 500MHz
* 256MB DRAM
* 32MB NOR Flash
* 8 x 10/100/1000BASE-T ports
* 2 x SFP ports
* Power LED, Fault LED
* Reset button on front panel
* UART (115200 8N1) via populated standard pin header marked JP1

TODO: The SFP ports use a shared SCL GPIO that the driver cannot handle.
The left SFP port (lan9) is defined and fully functional while the laser
on the right SFP port (lan10) is off by default.

UART pinout
-----------

[o]ooo|JP1
 | ||`------ GND
 | |`------- RX
 | `-------- TX
 `---------- Vcc (3V3)

Installation using OEM webinterface
-----------------------------------

1. Make sure you are running OEM firmware in secondary slot
2. Install squashfs-factory.imag to primary slot by upload via http

Installation using serial interface
-----------------------------------

1. Press "a" "c" "p" during message "Enter correct key to stop autoboot"
2. Load image with "upgrade runtime <TFTP IP>:squashfs-sysupgrade.bin" command
3. Switch to primary slot with "setsys bootpartition 0"
4. Store config with "savesys"
5. Boot the image with `boota` command

Dual-boot with stock firmware using writable u-boot-env
-------------------------------------------------------

From stock to OpenWrt / primary image 1 (CLI as admin):
   - > boot system image1
   - > reboot

From OpenWrt to stock / boot image 2: (shell as root)
   - # fw_setsys bootpartition 1
   - # reboot

Debrick using serial interface
------------------------------

1. Press "a" "c" "p" during message "Enter correct key to stop autoboot"
2. Load vendor image with "upgrade runtime <TFTP IP>:LGS310xxxxx.imag"
3. switch to primary partition "setsys bootpartition 0"
4. safe config "savesys"

Further documentation
---------------------
See https://openwrt.org/toh/linksys/lgs352c

It has been developed and tested on device with v1 revision.

Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
Link: https://github.com/openwrt/openwrt/pull/16068
[Add missing 'w' in name of firmware partition]
Signed-off-by: Sander Vanheule <sander@svanheule.net>
2024-10-02 20:15:21 +02:00

95 lines
2.7 KiB
Python
Executable File

#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright (C) 2024 OpenWrt.org
#
# ./belkin-header.py <ImageFileIn> <ImageFileOut> <BelkinHeader> <BelkinModel>
#
# This script adds an image header for Belkin devices. As of now only Realtek
# based switches of the Linksys LGS3xxC/LGS3xxMPC series are known to use this
# format. It resembles a U-Boot legacy format image header, all data in network
# byte order (aka natural aka big endian).
#
# Known values for BelkinHeader are
#
# 0x07800001 : RTL838x based switch
# 0x07600001 : RTL93xx based switch
#
# Known values for BelkinModel are
#
# BKS-RTL83xx : RTL838x based switch
# BKS-RTL93xx : RTL93xx based switch
import argparse
import os
import zlib
import array
import sys
import time
VERSION1 = 1
VERSION2 = 1
VERSION3 = 2
VERSION4 = 2
COMPANY = "belkin"
MODULE = "IMG"
def xcrc32(buf):
return (0xffffffff - zlib.crc32(buf, 0xffffffff)).to_bytes(4, 'big')
def encode_model(model):
map = " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
code = bytearray()
code.append(map.index(model[:1]))
model = model[1:]
model = model + " " * (3 - len(model) % 4)
while model != "":
b1 = map.index(model[0:1])
b2 = map.index(model[1:2])
b3 = map.index(model[2:3])
b4 = map.index(model[3:4])
model = model[4:]
code.append(b1 << 2 | b2 >> 4)
code.append((b2 & 0xf) << 4 | b3 >> 2)
code.append((b3 & 0x3) << 6 | b4)
return code
def create_header(buf, belkin_header, belkin_model):
head = bytearray(32)
head[0:4] = int(belkin_header, 0).to_bytes(4, 'big')
head[8:12] = int(time.time()).to_bytes(4, 'big')
head[12:16] = len(buf).to_bytes(4, 'big')
head[24:28] = xcrc32(buf)
head[28:29] = VERSION1.to_bytes(1)
head[29:30] = VERSION2.to_bytes(1)
head[30:31] = VERSION3.to_bytes(1)
head[31:32] = VERSION4.to_bytes(1)
head[16:16 + len(COMPANY)] = bytes(COMPANY,'ascii')
mod = MODULE + "-{:1d}.{:02d}.{:02d}.{:02d}".format(VERSION1, VERSION2, VERSION3, VERSION4)
head.extend(bytes(mod,'ascii'))
head.append(0x00)
head.extend(encode_model(belkin_model))
head.extend(bytes([0x00] * (64 - len(head))))
head[4:8] = xcrc32(head)
return head
parser = argparse.ArgumentParser(description='Generate Belkin header.')
parser.add_argument('source', type=argparse.FileType('r+b'))
parser.add_argument('dest', type=argparse.FileType('wb'))
parser.add_argument('belkin_header')
parser.add_argument('belkin_model')
args = parser.parse_args()
buf = bytearray(args.source.read())
head = create_header(buf, args.belkin_header, args.belkin_model)
args.dest.write(head)
args.dest.write(buf)