openwrt/target/linux/ramips/image/common-sercomm.mk
Mikhail Zhilkin 2d6784a033 ramips: add support for Sercomm S1500 devices
This commit adds support for following wireless routers:
 - Beeline SmartBox PRO (Serсomm S1500 AWI)
 - WiFire S1500.NBN (Serсomm S1500 BUC)

This commit is based on this PR:
 - Link: https://github.com/openwrt/openwrt/pull/4770
 - Author: Maximilian Weinmann <x1@disroot.org>
The opening of this PR was agreed with author.

My changes:
- Sorting, minor changes and some movings between dts and dtsi
- Move leds to dts when possible
- Recipes for the factory image
- Update of the installation/recovery/return to stock guides
- Add reset GPIO for the pcie1

Common specification
--------------------
SoC:        MediaTek MT7621AT (880 MHz, 2 cores)
Switch:     MediaTek MT7530 (via SoC MT7621AT)
Wireless:   2.4 GHz, MT7602EN, b/g/n, 2x2
Wireless:   5 GHz, MT7612EN, a/n/ac, 2x2
Ethernet:   5 ports - 5×GbE (WAN, LAN1-4)
Mini PCIe:  via J2 on PCB, not soldered on the board
UART:       J4 -> GND[], TX, VCC(3.3V), RX
BootLoader: U-Boot SerComm/Mediatek

Beeline SmartBox PRO specification
----------------------------------
RAM (Nanya NT5CB128M16FP): 256 MiB
NAND-Flash (ESMT F59L2G81A): 256 MiB
USB ports: 2xUSB2.0
LEDs: Status (white), WPS (blue), 2g (white), 5g (white) + 10 LED Ethernet
Buttons: 2 button (reset, wps), 1 switch button (ROUT<->REP)
Power: 12 VDC, 1.5 A
PCB Sticker: 970AWI0QW00N256SMT Ver. 1.0
CSN: SG15********
MAC LAN: 94:4A:0C:**:**:**
Manufacturer's code: 0AWI0500QW1

WiFire S1500.NBN specification
------------------------------
RAM (Nanya NT5CC64M16GP): 128 MiB
NAND-Flash (ESMT F59L1G81MA): 128 MiB
USB ports: 1xUSB2.0
LEDs: Status (white), WPS (white), 2g (white), 5g (white) + 10 LED Ethernet
Buttons: 2 button (RESET, WPS)
Power: 12 VDC, 1.0 A
PCB Sticker: 970BUC0RW00N128SMT Ver. 1.0
CSN: MH16********
MAC WAN: E0:60:66:**:**:**
Manufacturer's code: 0BUC0500RW1

MAC address table (PRO)
-----------------------
use   address   source
LAN   *:23      factory 0x1000 (label)
WAN   *:24      factory $label +1
2g    *:23      factory $label
5g    *:25      factory $label +2

MAC addresses (NBN)
-------------------
use   address   source
LAN   *:0e      factory 0x1000
WAN   *:0f      LAN +1 (label)
2g    *:0f      LAN +1
5g    *:10      LAN +2

OEM easy installation
---------------------
1. Remove all dots from the factory image filename (except the dot
   before file extension)
2. Upload and update the firmware via the original web interface
3. Two options are possible after the reboot:
   a. OpenWrt - that's OK, the mission accomplished
   b. Stock firmware - install Stock firmware (to switch booflag from
      Sercomm0 to Sercomm1) and then OpenWrt factory image.

Return to Stock
---------------
1. Change the bootflag to Sercomm1 in OpenWrt CLI and then reboot:
   printf 1 | dd bs=1 seek=7 count=1 of=/dev/mtdblock2
   reboot
2. Install stock firmware via the web OEM firmware interface

Recovery
--------
Use sercomm-recovery tool.
Link: https://github.com/danitool/sercomm-recovery

Tested-by: Pavel Ivanov <pi635v@gmail.com>
Tested-by: Denis Myshaev <denis.myshaev@gmail.com>
Tested-by: Oleg Galeev <olegingaleev@gmail.com>
Tested-By: Ivan Pavlov <AuthorReflex@gmail.com>
Co-authored-by: Maximilian Weinmann <x1@disroot.org>
Signed-off-by: Mikhail Zhilkin <csharper2005@gmail.com>
2023-07-01 16:05:01 +02:00

172 lines
5.0 KiB
Makefile

DEVICE_VARS += SERCOMM_KERNEL_OFFSET SERCOMM_ROOTFS_OFFSET
DEVICE_VARS += SERCOMM_KERNEL2_OFFSET SERCOMM_ROOTFS2_OFFSET
define Build/sercomm-append-tail
printf 16 | dd seek=$$((0x90)) of=$@ bs=1 conv=notrunc 2>/dev/null
printf 11223344556677889900112233445566 | \
sed 's/../\\x&/g' | xargs -d . printf >> $@
endef
define Build/sercomm-crypto
$(TOPDIR)/scripts/sercomm-crypto.py \
--input-file $@ \
--key-file $@.key \
--output-file $@.ser \
--version $(SERCOMM_SWVER)
$(STAGING_DIR_HOST)/bin/openssl enc -md md5 -aes-256-cbc \
-in $@ \
-out $@.enc \
-K `cat $@.key` \
-iv 00000000000000000000000000000000
dd if=$@.enc >> $@.ser 2>/dev/null
mv $@.ser $@
rm -f $@.enc $@.key
endef
define Build/sercomm-factory-cqr
$(TOPDIR)/scripts/sercomm-pid.py \
--hw-version $(SERCOMM_HWVER) \
--hw-id $(SERCOMM_HWID) \
--sw-version $(SERCOMM_SWVER) \
--pid-file $@.fhdr \
--extra-padding-size 0x190
printf $$(stat -c%s $(IMAGE_KERNEL)) | \
dd seek=$$((0x70)) of=$@.fhdr bs=1 conv=notrunc 2>/dev/null
printf $$(($$(stat -c%s $@)-$$(stat -c%s $(IMAGE_KERNEL))-$$((0x200)))) | \
dd seek=$$((0x80)) of=$@.fhdr bs=1 conv=notrunc 2>/dev/null
dd if=$@ >> $@.fhdr 2>/dev/null
mv $@.fhdr $@
endef
define Build/sercomm-fix-buc-pid
printf 1 | dd seek=$$((0x13)) of=$@ bs=1 conv=notrunc 2>/dev/null
endef
define Build/sercomm-kernel
$(TOPDIR)/scripts/sercomm-kernel-header.py \
--kernel-image $@ \
--kernel-offset $(SERCOMM_KERNEL_OFFSET) \
--rootfs-offset $(SERCOMM_ROOTFS_OFFSET) \
--output-header $@.hdr
dd if=$@ >> $@.hdr 2>/dev/null
mv $@.hdr $@
endef
define Build/sercomm-kernel-factory
$(TOPDIR)/scripts/sercomm-kernel-header.py \
--kernel-image $@ \
--kernel-offset $(SERCOMM_KERNEL_OFFSET) \
--rootfs-offset $(SERCOMM_ROOTFS_OFFSET) \
--output-header $@.khdr1
$(TOPDIR)/scripts/sercomm-kernel-header.py \
--kernel-image $@ \
--kernel-offset $(SERCOMM_KERNEL2_OFFSET) \
--rootfs-offset $(SERCOMM_ROOTFS2_OFFSET) \
--output-header $@.khdr2
cat $@.khdr1 $@.khdr2 > $@.khdr
dd if=$@ >> $@.khdr 2>/dev/null
mv $@.khdr $@
endef
define Build/sercomm-mkhash
dd bs=$$((0x400)) skip=1 if=$@ conv=notrunc 2>/dev/null | \
$(MKHASH) md5 | awk '{print $$1}' | tr -d '\n' | \
dd seek=$$((0x1e0)) of=$@ bs=1 conv=notrunc 2>/dev/null
endef
define Build/sercomm-part-tag
$(call Build/sercomm-part-tag-common,$(word 1,$(1)) $@)
endef
define Build/sercomm-part-tag-common
$(eval file=$(word 2,$(1)))
$(TOPDIR)/scripts/sercomm-partition-tag.py \
--input-file $(file) \
--output-file $(file).tmp \
--part-name $(word 1,$(1)) \
--part-version $(SERCOMM_SWVER)
mv $(file).tmp $(file)
endef
define Build/sercomm-payload
$(TOPDIR)/scripts/sercomm-pid.py \
--hw-version $(SERCOMM_HWVER) \
--hw-id $(SERCOMM_HWID) \
--sw-version $(SERCOMM_SWVER) \
--pid-file $@.pid \
--extra-padding-size 0x10 \
--extra-padding-first-byte 0x0a
$(TOPDIR)/scripts/sercomm-payload.py \
--input-file $@ \
--output-file $@.tmp \
--pid-file $@.pid
mv $@.tmp $@
rm $@.pid
endef
define Build/sercomm-prepend-tagged-kernel
$(CP) $(IMAGE_KERNEL) $(IMAGE_KERNEL).tagged
$(call Build/sercomm-part-tag-common,$(word 1,$(1)) \
$(IMAGE_KERNEL).tagged)
dd if=$@ >> $(IMAGE_KERNEL).tagged 2>/dev/null
mv $(IMAGE_KERNEL).tagged $@
endef
define Build/sercomm-reset-slot1-chksum
printf "\xff\xff\xff\xff" | \
dd of=$@ seek=$$((0x118)) bs=1 conv=notrunc 2>/dev/null
endef
define Device/sercomm
$(Device/nand)
LOADER_TYPE := bin
IMAGES += factory.img
endef
define Device/sercomm_cxx_dxx
$(Device/sercomm)
KERNEL_SIZE := 6144k
KERNEL_LOADADDR := 0x81001000
LZMA_TEXT_START := 0x82800000
SERCOMM_KERNEL_OFFSET := 0x400100
SERCOMM_ROOTFS_OFFSET := 0x1000000
endef
define Device/sercomm_cxx
$(Device/sercomm_cxx_dxx)
SERCOMM_KERNEL2_OFFSET := 0xa00100
SERCOMM_ROOTFS2_OFFSET := 0x3000000
KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | lzma -a0 | \
uImage lzma
IMAGE/sysupgrade.bin := append-kernel | sercomm-kernel | \
sysupgrade-tar kernel=$$$$@ | append-metadata
IMAGE/factory.img := append-kernel | sercomm-kernel-factory | \
append-ubi | sercomm-factory-cqr | sercomm-mkhash
endef
define Device/sercomm_dxx
$(Device/sercomm_cxx_dxx)
KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | lzma -a0 | \
uImage lzma | sercomm-kernel
KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel | \
lzma -a0 | uImage lzma
IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
IMAGE/factory.img := append-ubi | check-size | \
sercomm-part-tag rootfs | sercomm-prepend-tagged-kernel kernel | \
gzip | sercomm-payload | sercomm-crypto
endef
define Device/sercomm_s1500
$(Device/sercomm)
SERCOMM_KERNEL_OFFSET := 0x1700100
SERCOMM_ROOTFS_OFFSET := 0x1f00000
SERCOMM_KERNEL2_OFFSET := 0x1b00100
KERNEL := kernel-bin | append-dtb | lzma | loader-kernel | lzma -a0 | \
uImage lzma
KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | loader-kernel | \
lzma -a0 | uImage lzma
IMAGE/sysupgrade.bin := append-kernel | sercomm-kernel | \
sysupgrade-tar kernel=$$$$@ | append-metadata
DEVICE_PACKAGES := kmod-mt76x2 kmod-usb3
endef