forked from Openwrt-EcoNet/openwrt
The SmartFiber XP8421-B is a fiber modem which is available for $20 online and has 512MB of memory, 256MB of SPI NAND flash and 2 USB 2.0 ports in addition to ethernet, wifi and XPON. Because EcoNet is not currently producing evaluation boards, the XP8421-B stands in as a convenient, low cost, off-the-shelf, representitive example of the capabilities of the EN751221 econet processor. This is also the example board that is included in the upstream Linux patchset. The XP8421-B, and apparently many other devices of this platform, use a dual-image layout. I have chosen to reuse this to support dual-boot between OpenWRT and the factory firmware. Certain design decisions were made with the goal of not overwriting data that is used by the factory OS. This commit also introduces a utility for switching between OS_A and OS_B which are used for OpenWRT and Factory OS respectively. Flashing instructions (from bootloader): Build and then locate the squashfs-tclinux.trx image file Get the length of that file in hex: printf '%X\n' "$(stat -c%s the-file-squashfs-tclinux.trx)" Connect to device with xmodem capability, e.g. picocom --send-cmd lsx -vv -b 115200 /dev/ttyUSB0 Switch device on and press a key within 3 seconds Enter bootloader username and password: telecomadmin nE7jA%5m Type: xmdm 80020000 <file length hex> Quickly start xmodem and send the file, in picocom that is ctrl+a ctrl+s <paste-the-file-name> enter If the transfer fails to start, wait 30 seconds to a minute for the bootloader prompt to return and then try the command again. Once the transfer has completed successfully, type the following flash 80000 80020000 <file length hex> Type go or simply restart the device to boot into OpenWRT Signed-off-by: Caleb James DeLisle <cjd@cjdns.fr>
113 lines
2.7 KiB
Bash
Executable File
113 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
set -e
|
|
|
|
part=
|
|
offset_blocks=
|
|
block_size=
|
|
code_openwrt=
|
|
code_factory=
|
|
code_offset=
|
|
|
|
read_nand() {
|
|
dd "if=$part" "of=$file" "bs=$block_size" "skip=$offset_blocks" count=1 2>/dev/null
|
|
}
|
|
|
|
write_nand() {
|
|
flash_erase -N -q "$part" $((offset_blocks * block_size)) 1
|
|
dd "if=$file" "of=$part" "bs=$block_size" "seek=$offset_blocks" count=1 2>/dev/null
|
|
}
|
|
|
|
part_named() {
|
|
name=$1
|
|
pn=$(grep "$name" < /proc/mtd | sed 's/:.*//')
|
|
if [ -z "$pn" ]; then
|
|
echo "Partition not found: $name"
|
|
exit 1
|
|
fi
|
|
echo "/dev/$pn"
|
|
}
|
|
|
|
to_hex() {
|
|
hexdump -v -e '1/1 "%02x"'
|
|
}
|
|
|
|
from_hex() {
|
|
sed 's/\([0-9a-fA-F]\{2\}\)/echo -n -e "\\x\1"\n/g' | sh
|
|
}
|
|
|
|
check() {
|
|
stored_code=$(dd \
|
|
"if=$part" \
|
|
bs=1 \
|
|
skip=$((offset_blocks * block_size + code_offset)) \
|
|
count=$((${#code_openwrt} / 2)) \
|
|
2>/dev/null | to_hex
|
|
)
|
|
if [ "$stored_code" = "$code_openwrt" ]; then
|
|
echo "Current boot flag set to OS A (OpenWrt)"
|
|
elif [ "$stored_code" = "$code_factory" ]; then
|
|
echo "Current boot flag set to OS B (Factory)"
|
|
else
|
|
echo "Current boot flag unknown: $stored_code"
|
|
fi
|
|
}
|
|
|
|
switch() {
|
|
switch_to=$1
|
|
|
|
echo "Switching boot flag to $switch_to"
|
|
file=$(mktemp)
|
|
read_nand
|
|
if [ "$switch_to" = "factory" ]; then
|
|
echo "$code_factory" | from_hex | \
|
|
dd "of=$file" bs=1 "seek=$code_offset" conv=notrunc 2>/dev/null
|
|
elif [ "$switch_to" = "openwrt" ]; then
|
|
echo "$code_openwrt" | from_hex | \
|
|
dd "of=$file" bs=1 "seek=$code_offset" conv=notrunc 2>/dev/null
|
|
else
|
|
echo "Invalid switch_to: $switch_to"
|
|
exit 1
|
|
fi
|
|
write_nand
|
|
rm "$file"
|
|
echo "Flash write complete"
|
|
check
|
|
}
|
|
|
|
main() {
|
|
machine=$(sed -n -e 's/^machine\s\+:\s\+//p' < /proc/cpuinfo)
|
|
if [ "$machine" = "TP-Link Archer VR1200v (v2)" ]; then
|
|
# 03fe0000
|
|
part=$(part_named '"reserve"')
|
|
offset_blocks=0
|
|
block_size=$((1024 * 128))
|
|
code_offset=0
|
|
code_openwrt=0000000101000002
|
|
code_factory=0000000101010003
|
|
elif [ "$machine" = "SmartFiber XP8421-B" ]; then
|
|
# 0dfc0000
|
|
part=$(part_named '"reservearea"')
|
|
offset_blocks=12
|
|
block_size=$((1024 * 128))
|
|
code_offset=0
|
|
code_openwrt=30000000
|
|
code_factory=31000000
|
|
else
|
|
echo "Unsupported machine: $machine"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$1" = "factory" ]; then
|
|
switch factory
|
|
elif [ "$1" = "openwrt" ]; then
|
|
switch openwrt
|
|
else
|
|
echo "Usage: $0 factory|openwrt # Change boot flag to Factory OS or OpenWrt"
|
|
check
|
|
exit 1
|
|
fi
|
|
}
|
|
main "$@"
|