openwrt添加新设备支持
title: openwrt添加新设备支持
tags: openwrt
grammar_abbr: true
grammar_table: true
grammar_defList: true
grammar_emoji: true
grammar_footnote: true
grammar_ins: true
grammar_mark: true
grammar_sub: true
grammar_sup: true
grammar_checkbox: true
grammar_mathjax: true
grammar_flow: true
grammar_sequence: true
grammar_plot: true
grammar_code: true
grammar_highlight: true
grammar_html: true
grammar_linkify: true
grammar_typographer: true
grammar_video: true
grammar_audio: true
grammar_attachment: true
grammar_mermaid: true
grammar_classy: true
grammar_cjkEmphasis: true
grammar_cjkRuby: true
grammar_center: true
grammar_align: true
grammar_tableExtra: true
grammar_plantuml: true
grammar_wavedrom: true
grammar_codeChunk: true
grammar_nunjucks: true
grammar_decorate: true
grammar_attrs: true
grammar_code: true
代码修改步骤
step 1. 通过修改target/linux/ar71xx/image/Makefile 来添加新机器镜像,例如AP152-QTSA820
- diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile 
 - index 4f02be9..9371ebf 100644 
 - --- a/target/linux/ar71xx/image/Makefile 
 - +++ b/target/linux/ar71xx/image/Makefile 
 - @@ -848,6 +848,9 @@ $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP151_8M,ap151-8M,AP151,ttyS0,1152 
 -  $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP151_16M,ap151-16M,AP151,ttyS0,115200,$$(ap151_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
 -  $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_8M,ap152-8M,AP152,ttyS0,115200,$$(ap152_mtdlayout_8M),1507328,$(AR71XX_8M_ROOTFS_SIZE),RKuImage)) 
 -  $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_16M,ap152-16M,AP152,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
 - +$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_QTSA820,ap152-QTSA820,AP152-QTSA820,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
 - +$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_8200T2,ap152-8200T2,AP152-8200T2,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
 - +$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_8200R2,ap152-8200R2,AP152-8200R2,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
 -  $(eval $(call SingleProfile,AthLzma,$(fs_64k),CUS531_16M,cus531-16M,CUS531,ttyS0,115200,$$(cus531_mtdlayout_16M),1507328,14876672,RKuImage)) 
 -  $(eval $(call SingleProfile,AthLzma,$(fs_64k),CUS531_32M,cus531-32M,CUS531,ttyS0,115200,$$(cus531_mtdlayout_32M),1507328,14876672,RKuImage)) 
 -  $(eval $(call SingleProfile,AthLzma,$(fs_64k),CUS531_32M_DUAL,cus531-32M-dual,CUS531,ttyS0,115200,,1507328,14876672,RKuImage)) 
 - @@ -983,7 +986,7 @@ $(eval $(call MultiProfile,AP121,AP121_2M AP121_4M)) 
 -  $(eval $(call MultiProfile,AP143,AP143_8M AP143_16M AP143_32M AP143_32M_DUAL)) 
 -  $(eval $(call MultiProfile,AP147,AP147_16M AP147_8M)) 
 -  $(eval $(call MultiProfile,AP151,AP151_16M AP151_8M)) 
 - -$(eval $(call MultiProfile,AP152,AP152_16M AP152_8M)) 
 - +$(eval $(call MultiProfile,AP152,AP152_QTSA820 AP152_8200T2 AP152_8200R2 AP152_16M AP152_8M)) 
 -  $(eval $(call MultiProfile,CUS531,CUS531_16M CUS531_32M CUS531DUAL CUS531NAND CUS531_32M_DUAL CUS531DUAL_DUAL CUS531NAND_DUAL)) 
 -  $(eval $(call MultiProfile,EWDORIN, EWDORINAP EWDORINRT)) 
 -  $(eval $(call MultiProfile,TEW652BRP,TEW652BRP_FW TEW652BRP_RECOVERY)) 
 - @@ -1076,6 +1079,9 @@ define Image/Build/Profile/QSDK_Premium_Beeliner_Router 
 -         $(call Image/Build/Profile/AP135DUAL,$(1)) 
 -         $(call Image/Build/Profile/AP135NAND,$(1)) 
 -         $(call Image/Build/Profile/AP152_16M,$(1)) 
 - +       $(call Image/Build/Profile/AP152_QTSA820,$(1)) 
 - +       $(call Image/Build/Profile/AP152_8200T2,$(1)) 
 - +       $(call Image/Build/Profile/AP152_8200R2,$(1)) 
 -         $(call Image/Build/Profile/AP151_16M,$(1)) 
 -         $(call Image/Build/Profile/AP147_16M,$(1)) 
 -         $(call Image/Build/Profile/DB120_16M,$(1)) 
 -  
 
step 2. 创建新机器文件代码在kernel_repos/arch/mips/ath79/mach-ap152-qtsa820.c
在这里需改GPIO, Port Layout, Flash memory config, wifi, usb, watchdog timer, 等开发板特有的东西
- diff --git a/arch/mips/ath79/mach-ap152-8200r2.c b/arch/mips/ath79/mach-ap152-8200r2.c 
 - new file mode 100644 
 - index 0000000..3a6c604 
 - --- /dev/null 
 - +++ b/arch/mips/ath79/mach-ap152-8200r2.c 
 - @@ -0,0 +1,206 @@ 
 - +MIPS_MACHINE(ATH79_MACH_AP152_8200R2, "AP152-8200R2", "Qualcomm Atheros AP152-8200R2 board", 
 - +            ap152_setup); 
 - diff --git a/arch/mips/ath79/mach-ap152-8200t2.c b/arch/mips/ath79/mach-ap152-8200t2.c 
 - new file mode 100644 
 - index 0000000..323b35a 
 - --- /dev/null 
 - +++ b/arch/mips/ath79/mach-ap152-8200t2.c 
 - @@ -0,0 +1,206 @@ 
 - +MIPS_MACHINE(ATH79_MACH_AP152_8200T2, "AP152-8200T2", "Qualcomm Atheros AP152-8200T2 board", 
 - +            ap152_setup); 
 - diff --git a/arch/mips/ath79/mach-ap152-qtsa820.c b/arch/mips/ath79/mach-ap152-qtsa820.c 
 - new file mode 100644 
 - index 0000000..4b64fa1 
 - --- /dev/null 
 - +++ b/arch/mips/ath79/mach-ap152-qtsa820.c 
 - +MIPS_MACHINE(ATH79_MACH_AP152_QTSA820, "AP152-QTSA820", "Qualcomm Atheros AP152-QTSA820 board", 
 - +            ap152_setup); 
 -  
 
step 3. 添加新机器索引到头文件kernel_repos/arch/mips/ath79/machtypes.h
- diff --git a/arch/mips/ath79/machtypes.h b/arch/mips/ath79/machtypes.h 
 - index b5417a7..3712dee 100644 
 - --- a/arch/mips/ath79/machtypes.h 
 - +++ b/arch/mips/ath79/machtypes.h 
 - @@ -33,6 +33,9 @@ enum ath79_mach_type { 
 -         ATH79_MACH_AP147,               /* Atheros AP147 reference board */ 
 -         ATH79_MACH_AP151,               /* Atheros AP151 reference board */ 
 -         ATH79_MACH_AP152,               /* Atheros AP152 reference board */ 
 - +       ATH79_MACH_AP152_QTSA820,/* Atheros AP152-QTSA820 board */ 
 - +       ATH79_MACH_AP152_8200T2,/* Atheros AP152-8200T2 board */ 
 - +       ATH79_MACH_AP152_8200R2,/* Atheros AP152-8200R2 board */ 
 -         ATH79_MACH_AP81,                /* Atheros AP81 reference board */ 
 -         ATH79_MACH_AP83,                /* Atheros AP83 */ 
 -         ATH79_MACH_AP96,                /* Atheros AP96 */ 
 -  
 
step 4. 添加新机器的索引到kernel_repos/arch/mips/ath79/{Kconfig,Makefile}
- diff --git a/arch/mips/ath79/Kconfig b/arch/mips/ath79/Kconfig 
 - index d092806..52e5202 100644 
 - --- a/arch/mips/ath79/Kconfig 
 - +++ b/arch/mips/ath79/Kconfig 
 - @@ -176,6 +176,49 @@ config ATH79_MACH_AP152 
 -           Say 'Y' here if you want your kernel to support the 
 -           Atheros AP152 reference board. 
 -   
 - +config ATH79_MACH_AP152_QTSA820 
 - +       bool "Atheros AP152-QTSA820 board" 
 - +       select SOC_QCA956X 
 - +       select ATH79_DEV_GPIO_BUTTONS 
 - +       select ATH79_DEV_LEDS_GPIO 
 - +       select ATH79_DEV_SPI 
 - +       select ATH79_DEV_USB 
 - +       select ATH79_DEV_WMAC 
 - +       select ATH79_DEV_ETH 
 - +       select ATH79_DEV_M25P80 
 - +       help 
 - +         Say 'Y' here if you want your kernel to support the 
 - +         Atheros AP152-QTSA820 board. 
 - + 
 - +config ATH79_MACH_AP152_8200T2 
 - +       bool "Atheros AP152-8200T2 board" 
 - +       select SOC_QCA956X 
 - +       select ATH79_DEV_GPIO_BUTTONS 
 - +       select ATH79_DEV_LEDS_GPIO 
 - +       select ATH79_DEV_SPI 
 - +       select ATH79_DEV_USB 
 - +       select ATH79_DEV_WMAC 
 - +       select ATH79_DEV_ETH 
 - +       select ATH79_DEV_M25P80 
 - +       help 
 - +         Say 'Y' here if you want your kernel to support the 
 - +         Atheros AP152-8200T2 board. 
 - + 
 - +config ATH79_MACH_AP152_8200R2 
 - +       bool "Atheros AP152-8200R2 board" 
 - +       select SOC_QCA956X 
 - +       select ATH79_DEV_GPIO_BUTTONS 
 - +       select ATH79_DEV_LEDS_GPIO 
 - +       select ATH79_DEV_SPI 
 - +       select ATH79_DEV_USB 
 - +       select ATH79_DEV_WMAC 
 - +       select ATH79_DEV_ETH 
 - +       select ATH79_DEV_M25P80 
 - +       help 
 - +         Say 'Y' here if you want your kernel to support the 
 - +         Atheros AP152-8200R2 board. 
 - + 
 - + 
 -  config ATH79_MACH_AP81 
 -         bool "Atheros AP81 reference board" 
 -         select SOC_AR913X 
 - diff --git a/arch/mips/ath79/Makefile b/arch/mips/ath79/Makefile 
 - index 695e51c..806b46f 100644 
 - --- a/arch/mips/ath79/Makefile 
 - +++ b/arch/mips/ath79/Makefile 
 - @@ -57,6 +57,9 @@ obj-$(CONFIG_ATH79_MACH_AP143)                += mach-ap143.o 
 -  obj-$(CONFIG_ATH79_MACH_AP147)         += mach-ap147.o 
 -  obj-$(CONFIG_ATH79_MACH_AP151)         += mach-ap151.o 
 -  obj-$(CONFIG_ATH79_MACH_AP152)         += mach-ap152.o 
 - +obj-$(CONFIG_ATH79_MACH_AP152_8200R2)          += mach-ap152-8200r2.o 
 - +obj-$(CONFIG_ATH79_MACH_AP152_8200T2)          += mach-ap152-8200t2.o 
 - +obj-$(CONFIG_ATH79_MACH_AP152_QTSA820)         += mach-ap152-qtsa820.o 
 -  obj-$(CONFIG_ATH79_MACH_AP81)          += mach-ap81.o 
 -  obj-$(CONFIG_ATH79_MACH_AP83)          += mach-ap83.o 
 -  obj-$(CONFIG_ATH79_MACH_AP96)          += mach-ap96.o 
 
step 5. 用户态脚本package_repos/ok_base-files/lib/ar71xx.sh,通过解析/proc/cpuinfo来初始化board_name,model,放到/tmp/sysinfo/之后的用户态脚本通过它来区分板子
- diff --git a/ok_base-files/lib/ar71xx.sh b/ok_base-files/lib/ar71xx.sh 
 - index 91abca1..dedf81a 100755 
 - --- a/ok_base-files/lib/ar71xx.sh 
 - +++ b/ok_base-files/lib/ar71xx.sh 
 - @@ -205,6 +205,12 @@ ar71xx_board_detect() { 
 - +       *"AP152-QTSA820 board") 
 - +               name="ap152" 
 - +               ;; 
 - +       *"AP152-8200T2 board") 
 - +               name="ap152" 
 - +               ;; 
 - +       *"AP152-8200R2 board") 
 - +               name="ap152" 
 - +               ;; 
 -         *AP81) 
 -                 name="ap81" 
 -                 ;; 
 
- root@oakridge:/tmp/sysinfo# cat /tmp/sysinfo/board_name 
 - ap152 
 - root@oakridge:/tmp/sysinfo# cat /tmp/sysinfo/model 
 - Qualcomm Atheros AP152-QTSA820 board 
 
setp 6. 修改各个用户态脚本来支持新的
- llwang@VM2~/repos/osdk_repos/package_repos/ok_base-files $ grep -rin ap152 * 
 - etc/uci-defaults/network:112:ap152) 
 - etc/diag.sh:50: ap152) 
 - etc/diag.sh:51:         status_led="ap152:green:status" 
 - lib/wifi/qcawifi.sh:356:                ap152 | ap147 | ap151 | ap135 | ap137) 
 - lib/upgrade/ap135.sh:77:        "ap152" |\ 
 - lib/upgrade/ap135.sh:126:       "ap152" |\ 
 - lib/upgrade/platform.sh:110:    ap152 |\ 
 - lib/upgrade/platform.sh:329:    ap152 |\ 
 - lib/ar71xx.sh:202:      *"AP152 reference board") 
 - lib/ar71xx.sh:203:              name="ap152" 
 - lib/ar71xx.sh:205:      *"AP152-QTSA820 board") 
 - lib/ar71xx.sh:206:              name="ap152" 
 - lib/preinit/81_load_wifi_board_bin:16:         ap152) 
 -  
 
step 7. 使用make kernel_menuconfig选中新加入的machine type,保存到targe/linux/config-3.3然后编译
- $ make kenerl_menuconfig 
 - Machine selection ---> Atheros AR71xx/AR724xx/AR913X machine selection ---> Atheros AP52-QTSA820 board 
 
- diff --git a/target/linux/ar71xx/config-3.3 b/target/linux/ar71xx/config-3.3 
 - index 95a892c..e158692 100644 
 - --- a/target/linux/ar71xx/config-3.3 
 - +++ b/target/linux/ar71xx/config-3.3 
 - @@ -38,6 +38,8 @@ CONFIG_ATH79_DEV_WMAC=y 
 -  # CONFIG_ATH79_MACH_AP147 is not set 
 -  # CONFIG_ATH79_MACH_AP151 is not set 
 -  CONFIG_ATH79_MACH_AP152=y 
 - +CONFIG_ATH79_MACH_AP152_8200R2=y 
 - +CONFIG_ATH79_MACH_AP152_8200T2=y 
 - +CONFIG_ATH79_MACH_AP152_QTSA820=y 
 -  # CONFIG_ATH79_MACH_AP81 is not set 
 -  # CONFIG_ATH79_MACH_AP83 is not set 
 
程序流程
- Image Generator将board identifier放到内核的command line
 - 内核命令行通过BOARD=MY_BOARD来执行
 - 内核代码查找板子类型和机器类型相关代码
 - /lib/ar71xx.sh从/proc/cpuinfo中读取板子名称放入/tmp/sysinfo/{board_name,model}
 - 一些脚本使用这个名字来区分板子
 
通用步骤
- 详细的列出设备上的芯片,关注processor,flash,ethernet,wireless。
 - 确定串口和uboot能访问
 - 准备和安装固件,查看bootlog的问题和错误
 - 核实flash分区,LED和buttons
 
GPIO
GPIO LED Testing
- #!/bin/sh 
 - GPIOCHIP=0 
 - BASE=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/base) 
 - NGPIO=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/ngpio) 
 - max=$(($BASE+$NGPIO)) 
 - gpio=$BASE 
 - while [ $gpio -lt $max ] ; do 
 - 	echo $gpio > /sys/class/gpio/export 
 - 	[ -d /sys/class/gpio/gpio${gpio} ] && { 
 - 		echo out > /sys/class/gpio/gpio$gpio/direction 
 -  
 - 		echo "[GPIO$gpio] Trying value 0" 
 - 		echo 0 > /sys/class/gpio/gpio$gpio/value 
 - 		sleep 3s 
 -  
 - 		echo "[GPIO$gpio] Trying value 1" 
 - 		echo 1 > /sys/class/gpio/gpio$gpio/value 
 - 		sleep 3s 
 -  
 - 		echo $gpio > /sys/class/gpio/unexport 
 - 	} 
 - 	gpio=$((gpio+1)) 
 - done 
 
GPIO Button Testing
- #!/bin/sh 
 - GPIOCHIP=0 
 - BASE=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/base) 
 - NGPIO=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/ngpio) 
 - max=$(($BASE+$NGPIO)) 
 - gpio=$BASE 
 - while [ $gpio -lt $max ] ; do 
 - 	echo $gpio > /sys/class/gpio/export 
 - 	[ -d /sys/class/gpio/gpio${gpio} ] && { 
 - 		echo in > /sys/class/gpio/gpio${gpio}/direction 
 - 		echo "[GPIO${gpio}] value $(cat /sys/class/gpio/gpio${gpio}/value)" 
 - 		echo ${gpio} > /sys/class/gpio/unexport 
 - 	} 
 - 	gpio=$((gpio+1)) 
 - done 
 
                    
                
                
            
        
浙公网安备 33010602011771号