aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/mediatek/base-files
diff options
context:
space:
mode:
authorKristian Evensen <kristian.evensen@gmail.com>2018-06-20 01:17:40 +0200
committerJohn Crispin <john@phrozen.org>2018-06-22 11:25:52 +0200
commit4def81f30f2e89eeecc6ec06e3091f1dd6b3c3d9 (patch)
tree5258167901e2ad9117e0fe887501c5484b11229f /target/linux/mediatek/base-files
parente317bb06fdfb46cf0c6496e3db4eb020ea28b656 (diff)
downloadupstream-4def81f30f2e89eeecc6ec06e3091f1dd6b3c3d9.tar.gz
upstream-4def81f30f2e89eeecc6ec06e3091f1dd6b3c3d9.tar.bz2
upstream-4def81f30f2e89eeecc6ec06e3091f1dd6b3c3d9.zip
mediatek: Add support for the UniElec U7623-02
This commit adds support for the MT7623A-based UniElec U7623-02 router, with eMMC storage and 512MB RAM. The router can be delivered with NAND Flash and more memory, but I only have access to the one configuration. The DTS is structured in such a way that adding support for more/different storage/memory should be straight forward. The device has the following specifications: * MT7623A (quad-core, 1.3 GHz) * 512MB RAM (DDR3) * 8GB storage (eMMC 4.5) * 2x normal miniPCIe slots * 1x miniPCIe slot that is connected via an internal USB OTG port * 5x 1Gbps Ethernet (MT7530 switch) * 1x UART header * 1x USB 3.0 port * 1x SATA 3.0 * 1x 40P*0.5mm FPC for MIPI LCD * 1x SIM slot * 12x LEDs (2 GPIO controlled) * 1x reset button * 1x DC jack for main power (12V) The following has been tested and is working: * Ethernet switch * miniPCIe slots (tested with Wi-Fi cards) * USB 3.0 port * sysupgrade * reset button Not working: * The miniPCIe connected via USB OTG. For the port to work, some MUSB glue must be added. I am currently in the process of porting the glue from the vendor SDK. Not tested: * SATA 3.0 * MIPI LCD Installation: The board ships with u-boot, and the first installation needs to be done via the bootloader using tftp. Step number one is to update the MBR of the eMMC, as the one that ships with the device is broken. Since the device can ship with different storage sizes, I will not provide the exact steps for creating a valid MBR. However, I have made some assumptions about the disk layout - there must be one 8MB recovery partition (FAT32) and a partition for the rootfs (Linux). The board loads the kernel from block 0xA00 (2560) and I have reserved 32MB for the kernel (65536 blocks). I have aligned the partitions on the erase block size (4096 byte), so the recovery partition must start on block 69632 and end on 86016 (16385 sectors). The rootfs is assumed to start on sector 90112. In order to install the mbr, you run the following commands from the u-boot command line: * tftpboot ${loadaddr} <name of mbr file> * mmc device 0 * mmc write ${loadaddr} 0x00 1 Run the following commands to install + boot OpenWRT: * tftpboot ${loadaddr} openwrt-mediatek-mt7623-7623a-unielec-u7623-02-emmc-512m-squashfs-sysupgrade-emmc.bin.gz * run boot_wr_img * run boot_rd_img * bootm Recovery: In order to recover the router, you need to follow the installation steps above (no need to replace MBR). Notes: * F2FS is used as the overlay filesystem. * The device does not ship with any valid MAC address, so a random address has to be generated. As a work-around, I write the initial random MAC to a file on the recovery partition. The MAC of the WAN interface is set to the MAC-address contained in this file on each boot, and the address of the LAN-interfaces are WAN + 1. The MAC file is kept across sysupgrade/firstboot. My approach is slightly different than what the stock image does. The first fives bytes of the MAC addresses in the stock image are static, and then the last byte is random. I believe it is better to create fully random MAC addresses. * In order to support the miniPCIe-slots, I needed to add missing pcie-nodes to mt7623.dtsi. The nodes are just c&p from the upstream dtsi. * One of the USB3.0 phys (u3phy2) on the board can be used as either USB or PCI, and one of the wifi-cards is connected to this phy. In order to support switching the phy from USB to PCI, I needed to patch the phy-driver. The patch is based on a rejected (at least last time I checked) PCI-driver submitted to the linux-mediatek mailing list. * The eMMC is configured to boot from the user area, and according to the data sheet of the eMMC this value can't be changed. * I tried to structure the MBR more nicely and use for example a FAT32-parition for the kernel, so that we don't need to write/read from some offset. The bootloader does not support reading from FAT32-paritions. While the command (fatload) is there, it just throws an error when I try to use it. * I will submit and hope to get the DTS for the device accepted upstream. If and when that happens, I will update the patches accordingly. Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com>
Diffstat (limited to 'target/linux/mediatek/base-files')
-rwxr-xr-xtarget/linux/mediatek/base-files/etc/board.d/02_network19
-rw-r--r--target/linux/mediatek/base-files/lib/preinit/07_set_iface_mac47
-rw-r--r--target/linux/mediatek/base-files/lib/preinit/79_move_config19
-rwxr-xr-xtarget/linux/mediatek/base-files/lib/upgrade/platform.sh47
4 files changed, 125 insertions, 7 deletions
diff --git a/target/linux/mediatek/base-files/etc/board.d/02_network b/target/linux/mediatek/base-files/etc/board.d/02_network
index 8015cf3cc2..faa2434241 100755
--- a/target/linux/mediatek/base-files/etc/board.d/02_network
+++ b/target/linux/mediatek/base-files/etc/board.d/02_network
@@ -13,9 +13,21 @@ mediatek_setup_interfaces()
ucidef_set_interface_lan "lan0 lan1 lan2 lan3"
ucidef_set_interface_wan eth1
;;
- 'bananapi,bpi-r2')
- ucidef_set_interface_lan "lan0 lan1 lan2 lan3"
- ucidef_set_interface_wan wan
+ 'bananapi,bpi-r2'|\
+ "unielec,u7623"*)
+ ucidef_set_interfaces_lan_wan "lan0 lan1 lan2 lan3" "wan"
+ ;;
+ esac
+}
+
+mediatek_setup_macs()
+{
+ local board="$1"
+
+ case $board in
+ "unielec,u7623"*)
+ mac=$(cat /sys/class/net/wan/address)
+ ucidef_set_interface_macaddr "wan" $mac
;;
esac
}
@@ -23,6 +35,7 @@ mediatek_setup_interfaces()
board_config_update
board=$(board_name)
mediatek_setup_interfaces $board
+mediatek_setup_macs $board
board_config_flush
exit 0
diff --git a/target/linux/mediatek/base-files/lib/preinit/07_set_iface_mac b/target/linux/mediatek/base-files/lib/preinit/07_set_iface_mac
new file mode 100644
index 0000000000..3d04000738
--- /dev/null
+++ b/target/linux/mediatek/base-files/lib/preinit/07_set_iface_mac
@@ -0,0 +1,47 @@
+#!/bin/sh
+# Copyright (C) 2018 OpenWrt.org
+
+RECOVERY_PART=/dev/mmcblk0p1
+
+preinit_set_mac_address() {
+ local mac
+
+ . /lib/functions.sh
+ . /lib/functions/system.sh
+
+ case $(board_name) in
+ "unielec,u7623"*)
+ if [ -b $RECOVERY_PART ]; then
+ insmod nls_cp437
+ insmod nls_iso8859-1
+ insmod fat
+ insmod vfat
+ mkdir -p /tmp/recovery
+ mount -o rw,noatime $RECOVERY_PART /tmp/recovery
+
+ if [ -f "/tmp/recovery/mac_addr" ];
+ then
+ mac=$(cat /tmp/recovery/mac_addr)
+ else
+ mac=$(cat /sys/class/net/eth0/address)
+ echo "$mac" > /tmp/recovery/mac_addr
+ fi
+
+ sync
+ umount /tmp/recovery
+ rm -rf /tmp/recovery
+ fi
+
+ ip link set dev wan address $mac 2> /dev/null
+
+ mac=$(macaddr_add $mac 1)
+
+ ip link set dev lan0 address $mac 2>/dev/null
+ ip link set dev lan1 address $mac 2>/dev/null
+ ip link set dev lan2 address $mac 2>/dev/null
+ ip link set dev lan3 address $mac 2>/dev/null
+ ;;
+ esac
+}
+
+boot_hook_add preinit_main preinit_set_mac_address
diff --git a/target/linux/mediatek/base-files/lib/preinit/79_move_config b/target/linux/mediatek/base-files/lib/preinit/79_move_config
new file mode 100644
index 0000000000..e8e62883dc
--- /dev/null
+++ b/target/linux/mediatek/base-files/lib/preinit/79_move_config
@@ -0,0 +1,19 @@
+#!/bin/sh
+# Copyright (C) 2015 OpenWrt.org
+
+RECOVERY_PART=/dev/mmcblk0p1
+
+move_config() {
+ if [ -b $RECOVERY_PART ]; then
+ insmod nls_cp437
+ insmod nls_iso8859-1
+ insmod fat
+ insmod vfat
+ mkdir -p /recovery
+ mount -o rw,noatime $RECOVERY_PART /recovery
+ [ -f /recovery/sysupgrade.tgz ] && mv -f /recovery/sysupgrade.tgz /
+ umount /recovery
+ fi
+}
+
+boot_hook_add preinit_mount_root move_config
diff --git a/target/linux/mediatek/base-files/lib/upgrade/platform.sh b/target/linux/mediatek/base-files/lib/upgrade/platform.sh
index 646ce0dc53..487a262dc2 100755
--- a/target/linux/mediatek/base-files/lib/upgrade/platform.sh
+++ b/target/linux/mediatek/base-files/lib/upgrade/platform.sh
@@ -1,6 +1,28 @@
platform_do_upgrade() {
- default_do_upgrade "$ARGV"
-}
+ local board=$(board_name)
+ case "$board" in
+ "unielec,u7623"*)
+ #Keep the persisten random mac address (if it exists)
+ mkdir -p /tmp/recovery
+ mount -o rw,noatime /dev/mmcblk0p1 /tmp/recovery
+ [ -f "/tmp/recovery/mac_addr" ] && \
+ mv -f /tmp/recovery/mac_addr /tmp/
+ umount /tmp/recovery
+
+ #1310720 is the offset in bytes from the start of eMMC and to
+ #the location of the kernel (2560 512 byte sectors)
+ get_image "$1" | dd of=/dev/mmcblk0 bs=1310720 seek=1 conv=fsync
+
+ mount -o rw,noatime /dev/mmcblk0p1 /tmp/recovery
+ [ -f "/tmp/mac_addr" ] && mv -f /tmp/mac_addr /tmp/recovery
+ sync
+ umount /tmp/recovery
+ ;;
+ *)
+ default_do_upgrade "$ARGV"
+ ;;
+ esac
+}
PART_NAME=firmware
@@ -11,7 +33,8 @@ platform_check_image() {
[ "$#" -gt 1 ] && return 1
case "$board" in
- bananapi,bpi-r2)
+ bananapi,bpi-r2|\
+ "unielec,u7623"*)
[ "$magic" != "27051956" ] && {
echo "Invalid image type."
return 1
@@ -26,4 +49,20 @@ platform_check_image() {
esac
return 0
-}
+}
+
+platform_copy_config_emmc() {
+ mkdir -p /recovery
+ mount -o rw,noatime /dev/mmcblk0p1 /recovery
+ cp -af "$CONF_TAR" /recovery/
+ sync
+ umount /recovery
+}
+
+platform_copy_config() {
+ case "$(board_name)" in
+ "unielec,u7623"*)
+ platform_copy_config_emmc
+ ;;
+ esac
+}