[OpenWrt-Devel] [PATCH][RFC] ramips:Add support for HiWiFi HC5761.

郭传鈜 gch981213 at gmail.com
Sun Apr 19 00:29:54 EDT 2015


Sorry...The EEPROM script is not working correctly because I forgot to
include /lib/functions/system.sh...
But I still want some suggestions about the script:-)

2015-04-19 0:02 GMT+08:00 郭传鈜 <gch981213 at gmail.com>:
> Hi,all!
>   I'm trying to add support for HiWiFi HC5761 router,This patch works fine.Because the mac address is not saved in factory partition and I think my way to deal with this problem is not so good,I hope I could get some suggestions for this patch.
>   HiWiFi HC5761 is a dual band router with mt7620a SoC.It has 3 network interface,SD card and USB.
> There is an MT7610E for 5G wireless but there is no open-source driver to support this.I enabled the PCI-E interface so that I could use the proprietary driver from MTK.
> MAC address is not in factory partition.It is defined in bdinfo partition in ascii format.
> With 'strings' command we could see such a line:Vfac_mac = XX:XX:XX:XX:XX:XX
> There is a space between 'Vfac_mac' and '=' so 'mtd_get_mac_ascii' function in /lib/functions/system.sh doesn't work.I copied the function and added a space in the sed command.
> Because of the mac address,the calibration data for wireless should't be read from mtd partition directly.I used the hotplug script to generate the calibration data for the wireless driver.
> I think I added too much code for the MAC address:-( I wonder if there is a better way to do this.
>     Best regards.
>     Guo Chuanhong
>
> Signed-off-by: 郭传鈜 <gch981213 at gmail.com>
> ---
>  target/linux/ramips/base-files/etc/board.d/01_leds |   5 +
>  .../linux/ramips/base-files/etc/board.d/02_network |  20 +++
>  target/linux/ramips/base-files/etc/diag.sh         |   3 +
>  .../etc/hotplug.d/firmware/10-rt2x00-eeprom        |  39 +++++-
>  target/linux/ramips/base-files/lib/ramips.sh       |   3 +
>  .../ramips/base-files/lib/upgrade/platform.sh      |   1 +
>  target/linux/ramips/dts/HiWiFi-HC5761.dts          | 155 +++++++++++++++++++++
>  target/linux/ramips/image/Makefile                 |   3 +
>  8 files changed, 228 insertions(+), 1 deletion(-)
>  create mode 100644 target/linux/ramips/dts/HiWiFi-HC5761.dts
>
> diff --git a/target/linux/ramips/base-files/etc/board.d/01_leds b/target/linux/ramips/base-files/etc/board.d/01_leds
> index 56ba3b7..e20732d 100755
> --- a/target/linux/ramips/base-files/etc/board.d/01_leds
> +++ b/target/linux/ramips/base-files/etc/board.d/01_leds
> @@ -222,6 +222,11 @@ case $board in
>                 set_usb_led "wr8305rt:usb"
>                 set_wifi_led "wr8305rt:wifi"
>                 ;;
> +       hiwifi-hc5761)
> +               ucidef_set_led_default "system" "system" "hiwifi:blue:system" "1"
> +               ucidef_set_led_netdev "internet" "internet" "hiwifi:blue:internet" "eth0.2"
> +               set_wifi_led "hiwifi:blue:wlan-2p4"
> +               ;;
>         wt1520)
>                 set_wifi_led "rt2800pci-phy0::radio"
>                 ;;
> diff --git a/target/linux/ramips/base-files/etc/board.d/02_network b/target/linux/ramips/base-files/etc/board.d/02_network
> index 24e1ba8..615baa4 100755
> --- a/target/linux/ramips/base-files/etc/board.d/02_network
> +++ b/target/linux/ramips/base-files/etc/board.d/02_network
> @@ -223,6 +223,7 @@ ramips_setup_interfaces()
>                 ucidef_add_switch_vlan "switch0" "2" "4 6t"
>                 ;;
>
> +       hiwifi-hc5761 | \
>         y1s)
>                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
>                 ucidef_add_switch "switch0" "1" "1"
> @@ -288,6 +289,25 @@ ramips_setup_macs()
>                 wan_mac=$(macaddr_add "$lan_mac" 4)
>                 ;;
>
> +       hiwifi-hc5761)
> +               local part
> +               local mac_dirty
> +
> +               part=$(find_mtd_part "bdinfo")
> +               if [ -z "$part" ]; then
> +                       echo "hiwifi_get_mac: partition bdinfo not found!" >&2
> +                       return
> +               fi
> +
> +               mac_dirty=$(strings "$part" | sed -n 's/^'"Vfac_mac "'=//p')
> +
> +               # "canonicalize" mac
> +               [ -n "$mac_dirty" ] && {
> +                               lan_mac=$(macaddr_canonicalize "$mac_dirty")
> +               }
> +               wan_mac=$(macaddr_add "$lan_mac" 1)
> +               ;;
> +
>         m3 |\
>         m4 |\
>         x5 |\
> diff --git a/target/linux/ramips/base-files/etc/diag.sh b/target/linux/ramips/base-files/etc/diag.sh
> index 5301593..e66336f 100644
> --- a/target/linux/ramips/base-files/etc/diag.sh
> +++ b/target/linux/ramips/base-files/etc/diag.sh
> @@ -220,6 +220,9 @@ get_status_led() {
>         na930)
>                 status_led="na930:blue:power"
>                 ;;
> +       hiwifi-hc5761)
> +               status_led="hiwifi:blue:system"
> +       ;;
>         y1 | \
>         y1s)
>                 status_led="lenovo:blue:power"
> diff --git a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
> index 0cd95a5..ce7171c 100644
> --- a/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
> +++ b/target/linux/ramips/base-files/etc/hotplug.d/firmware/10-rt2x00-eeprom
> @@ -21,6 +21,37 @@ rt2x00_eeprom_extract() {
>                 rt2x00_eeprom_die "failed to extract from $mtd"
>  }
>
> +hiwifi_eeprom_extract() {
> +       local part=$1
> +       local offset=$2
> +       local mac_addr=$3
> +       local mtd
> +
> +       . /lib/functions.sh
> +       . /lib/functions/system.sh
> +       mtd=$(find_mtd_part $part)
> +       [ -n "$mtd" ] || exit 1
> +       dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=4
> +       macaddr_2bin $mac_addr >> /lib/firmware/$FIRMWARE
> +       dd if=$mtd bs=1 skip=$(echo $offset | awk '{print $1+10}') count=502 >> /lib/firmware/$FIRMWARE
> +}
> +
> +hiwifi_get_mac()
> +{
> +       local part
> +       local mac_dirty
> +       part=$(find_mtd_part "bdinfo")
> +       if [ -z "$part" ]; then
> +               echo "hiwifi_get_mac: partition bdinfo not found!" >&2
> +               return
> +       fi
> +       mac_dirty=$(strings "$part" | sed -n 's/^'"Vfac_mac "'=//p')
> +       # "canonicalize" mac
> +       [ -n "$mac_dirty" ] && {
> +               macaddr_canonicalize "$mac_dirty"
> +       }
> +}
> +
>  FW="/lib/firmware/$FIRMWARE"
>  [ -e "$FW" ] && exit 0
>
> @@ -36,7 +67,13 @@ case "$FIRMWARE" in
>                 ;;
>         esac
>         ;;
> -
> +"hiwifi_wlan24_caldata.eeprom")
> +       case $board in
> +       hiwifi-hc5761)
> +               hiwifi_eeprom_extract "factory" 0 $(hiwifi_get_mac)
> +               ;;
> +       esac
> +       ;;
>  "rt2x00pci_1_0.eeprom")
>         case $board in
>         cy-swr1100)
> diff --git a/target/linux/ramips/base-files/lib/ramips.sh b/target/linux/ramips/base-files/lib/ramips.sh
> index 616f4a1..0509678 100755
> --- a/target/linux/ramips/base-files/lib/ramips.sh
> +++ b/target/linux/ramips/base-files/lib/ramips.sh
> @@ -385,6 +385,9 @@ ramips_board_detect() {
>         *"ZTE Q7")
>                 name="zte-q7"
>                 ;;
> +       *"HiWiFi HC5761")
> +               name="hiwifi-hc5761"
> +               ;;
>         *"Lenovo Y1")
>                 name="y1"
>                 ;;
> diff --git a/target/linux/ramips/base-files/lib/upgrade/platform.sh b/target/linux/ramips/base-files/lib/upgrade/platform.sh
> index 17b456b..463ed94 100755
> --- a/target/linux/ramips/base-files/lib/upgrade/platform.sh
> +++ b/target/linux/ramips/base-files/lib/upgrade/platform.sh
> @@ -53,6 +53,7 @@ platform_check_image() {
>         freestation5 | \
>         firewrt |\
>         hg255d | \
> +       hiwifi-hc5761 |\
>         hlk-rm04 | \
>         ht-tm02 | \
>         hw550-3g | \
> diff --git a/target/linux/ramips/dts/HiWiFi-HC5761.dts b/target/linux/ramips/dts/HiWiFi-HC5761.dts
> new file mode 100644
> index 0000000..2c6c4d7
> --- /dev/null
> +++ b/target/linux/ramips/dts/HiWiFi-HC5761.dts
> @@ -0,0 +1,155 @@
> +/dts-v1/;
> +
> +/include/ "mt7620a.dtsi"
> +
> +/ {
> +       compatible = "HiWiFi-HC5761", "ralink,mt7620a-soc";
> +       model = "HiWiFi HC5761";
> +
> +       chosen {
> +               bootargs = "console=ttyS0,115200";
> +       };
> +
> +       palmbus at 10000000 {
> +               sysc at 0 {
> +                       ralink,gpiomux = "i2c", "jtag";
> +                       ralink,uartmux = "gpio";
> +                       ralink,wdtmux = <1>;
> +               };
> +               gpio0: gpio at 600 {
> +                       status = "okay";
> +               };
> +               gpio3: gpio at 688 {
> +                       status = "okay";
> +               };
> +
> +               spi at b00 {
> +                       status = "okay";
> +
> +                       m25p80 at 0 {
> +                               #address-cells = <1>;
> +                               #size-cells = <1>;
> +                               compatible = "w25q128";
> +                               reg = <0 0>;
> +                               linux,modalias = "m25p80", "w25q128";
> +                               spi-max-frequency = <10000000>;
> +
> +                               partition at 0 {
> +                                       label = "u-boot";
> +                                       reg = <0x0 0x30000>;
> +                                       read-only;
> +                               };
> +
> +                               partition at 30000 {
> +                                       label = "u-boot-env";
> +                                       reg = <0x30000 0x10000>;
> +                                       read-only;
> +                               };
> +
> +                               factory: partition at 40000 {
> +                                       label = "factory";
> +                                       reg = <0x40000 0x10000>;
> +                                       read-only;
> +                               };
> +
> +                               partition at 50000 {
> +                                       label = "firmware";
> +                                       reg = <0x50000 0xf80000>;
> +                               };
> +
> +                               partition at fd0000 {
> +                                       label = "hwf_config";
> +                                       reg = <0xfd0000 0x10000>;
> +                               };
> +
> +                               partition at fe0000 {
> +                                       label = "bdinfo";
> +                                       reg = <0xfe0000 0x10000>;
> +                               };
> +
> +                               partition at ff0000 {
> +                                       label = "backup";
> +                                       reg = <0xff0000 0x10000>;
> +                               };
> +                       };
> +               };
> +       };
> +
> +       ehci at 101c0000 {
> +               status = "okay";
> +       };
> +
> +       ohci at 101c1000 {
> +               status = "okay";
> +       };
> +
> +       sdhci at 10130000 {
> +               status = "okay";
> +       };
> +
> +       pcie at 10140000 {
> +               status = "okay";
> +       };
> +
> +       wmac at 10180000 {
> +               ralink,eeprom = "hiwifi_wlan24_caldata.eeprom";
> +       };
> +
> +       pinctrl {
> +               state_default: pinctrl0 {
> +                       gpio {
> +                               ralink,group = "uartf", "wled", "nd_sd";
> +                               ralink,function = "gpio";
> +                       };
> +               };
> +       };
> +
> +       ethernet at 10100000 {
> +               pinctrl-names = "default";
> +               pinctrl-0 = <&ephy_pins>;
> +               ralink,port-map = "llllw";
> +       };
> +
> +       gpio-keys-polled {
> +               compatible = "gpio-keys-polled";
> +               #address-cells = <1>;
> +               #size-cells = <0>;
> +               poll-interval = <20>;
> +               reset {
> +                       label = "reset";
> +                       gpios = <&gpio0 12 1>;
> +                       linux,code = <0x198>;
> +               };
> +       };
> +
> +       gpio-leds {
> +               compatible = "gpio-leds";
> +               system {
> +                       label = "hiwifi:blue:system";
> +                       gpios = <&gpio0 9 1>;
> +               };
> +               internet {
> +                       label = "hiwifi:blue:internet";
> +                       gpios = <&gpio0 11 1>;
> +               };
> +               wlan2p4 {
> +                       label = "hiwifi:blue:wlan-2p4";
> +                       gpios = <&gpio3 0 1>;
> +               };
> +               wlan5p {
> +                       label = "hiwifi:blue:wlan-5p";
> +                       gpios = <&gpio0 7 1>;
> +               };
> +       };
> +
> +       gpio_export {
> +               compatible = "gpio-export";
> +               #size-cells = <0>;
> +               usbpower {
> +                       gpio-export,name = "usbpower";
> +                       gpio-export,output = <1>;
> +                       gpios = <&gpio0 13 0>;
> +               };
> +       };
> +
> +};
> diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile
> index e6b5112..5a29447 100644
> --- a/target/linux/ramips/image/Makefile
> +++ b/target/linux/ramips/image/Makefile
> @@ -852,6 +852,8 @@ Image/Build/Profile/DIR-810L=$(call BuildFirmware/CustomFlash/$(1),$(1),dir-810l
>  na930_mtd_size=20971520
>  Image/Build/Profile/NA930=$(call BuildFirmware/CustomFlash/$(1),$(1),na930,NA930,$(na930_mtd_size))
>  Image/Build/Profile/MZK-750DHP=$(call BuildFirmware/Default8M/$(1),$(1),mzk-750dhp,MZK-750DHP)
> +hiwifi_16m_mtd_size=16252928
> +Image/Build/Profile/HiWiFi-HC5761=$(call BuildFirmware/CustomFlash/$(1),$(1),hiwifi-hc5761,HiWiFi-HC5761,$(hiwifi_16m_mtd_size))
>  Image/Build/Profile/Y1=$(call BuildFirmware/Default16M/$(1),$(1),Lenovo-y1,Y1)
>  Image/Build/Profile/Y1S=$(call BuildFirmware/Default16M/$(1),$(1),Lenovo-y1s,Y1S)
>  Image/Build/Profile/MLW221=$(call BuildFirmware/Default16M/$(1),$(1),mlw221,MLW221)
> @@ -884,6 +886,7 @@ define Image/Build/Profile/Default
>         $(call Image/Build/Profile/WHR1166D,$(1))
>         $(call Image/Build/Profile/MZK-750DHP,$(1))
>         $(call Image/Build/Profile/NA930,$(1))
> +       $(call Image/Build/Profile/HiWiFi-HC5761,$(1))
>         $(call Image/Build/Profile/Y1,$(1))
>         $(call Image/Build/Profile/Y1S,$(1))
>         $(call Image/Build/Profile/MLW221,$(1))
> --
> 2.1.0
>
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list