openwrt添加新设备支持 - nicephil

时间:2024-03-08 22:31:37

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

  1. diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile 
  2. index 4f02be9..9371ebf 100644 
  3. --- a/target/linux/ar71xx/image/Makefile 
  4. +++ b/target/linux/ar71xx/image/Makefile 
  5. @@ -848,6 +848,9 @@ $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP151_8M,ap151-8M,AP151,ttyS0,1152 
  6. $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP151_16M,ap151-16M,AP151,ttyS0,115200,$$(ap151_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
  7. $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_8M,ap152-8M,AP152,ttyS0,115200,$$(ap152_mtdlayout_8M),1507328,$(AR71XX_8M_ROOTFS_SIZE),RKuImage)) 
  8. $(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_16M,ap152-16M,AP152,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
  9. +$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_QTSA820,ap152-QTSA820,AP152-QTSA820,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
  10. +$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_8200T2,ap152-8200T2,AP152-8200T2,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
  11. +$(eval $(call SingleProfile,AthLzma,$(fs_64k),AP152_8200R2,ap152-8200R2,AP152-8200R2,ttyS0,115200,$$(ap152_mtdlayout_16M),1507328,$(AR71XX_16M_ROOTFS_SIZE),RKuImage)) 
  12. $(eval $(call SingleProfile,AthLzma,$(fs_64k),CUS531_16M,cus531-16M,CUS531,ttyS0,115200,$$(cus531_mtdlayout_16M),1507328,14876672,RKuImage)) 
  13. $(eval $(call SingleProfile,AthLzma,$(fs_64k),CUS531_32M,cus531-32M,CUS531,ttyS0,115200,$$(cus531_mtdlayout_32M),1507328,14876672,RKuImage)) 
  14. $(eval $(call SingleProfile,AthLzma,$(fs_64k),CUS531_32M_DUAL,cus531-32M-dual,CUS531,ttyS0,115200,,1507328,14876672,RKuImage)) 
  15. @@ -983,7 +986,7 @@ $(eval $(call MultiProfile,AP121,AP121_2M AP121_4M)) 
  16. $(eval $(call MultiProfile,AP143,AP143_8M AP143_16M AP143_32M AP143_32M_DUAL)) 
  17. $(eval $(call MultiProfile,AP147,AP147_16M AP147_8M)) 
  18. $(eval $(call MultiProfile,AP151,AP151_16M AP151_8M)) 
  19. -$(eval $(call MultiProfile,AP152,AP152_16M AP152_8M)) 
  20. +$(eval $(call MultiProfile,AP152,AP152_QTSA820 AP152_8200T2 AP152_8200R2 AP152_16M AP152_8M)) 
  21. $(eval $(call MultiProfile,CUS531,CUS531_16M CUS531_32M CUS531DUAL CUS531NAND CUS531_32M_DUAL CUS531DUAL_DUAL CUS531NAND_DUAL)) 
  22. $(eval $(call MultiProfile,EWDORIN, EWDORINAP EWDORINRT)) 
  23. $(eval $(call MultiProfile,TEW652BRP,TEW652BRP_FW TEW652BRP_RECOVERY)) 
  24. @@ -1076,6 +1079,9 @@ define Image/Build/Profile/QSDK_Premium_Beeliner_Router 
  25. $(call Image/Build/Profile/AP135DUAL,$(1)) 
  26. $(call Image/Build/Profile/AP135NAND,$(1)) 
  27. $(call Image/Build/Profile/AP152_16M,$(1)) 
  28. + $(call Image/Build/Profile/AP152_QTSA820,$(1)) 
  29. + $(call Image/Build/Profile/AP152_8200T2,$(1)) 
  30. + $(call Image/Build/Profile/AP152_8200R2,$(1)) 
  31. $(call Image/Build/Profile/AP151_16M,$(1)) 
  32. $(call Image/Build/Profile/AP147_16M,$(1)) 
  33. $(call Image/Build/Profile/DB120_16M,$(1)) 
  34.  

step 2. 创建新机器文件代码在kernel_repos/arch/mips/ath79/mach-ap152-qtsa820.c
在这里需改GPIO, Port Layout, Flash memory config, wifi, usb, watchdog timer, 等开发板特有的东西

  1. diff --git a/arch/mips/ath79/mach-ap152-8200r2.c b/arch/mips/ath79/mach-ap152-8200r2.c 
  2. new file mode 100644 
  3. index 0000000..3a6c604 
  4. --- /dev/null 
  5. +++ b/arch/mips/ath79/mach-ap152-8200r2.c 
  6. @@ -0,0 +1,206 @@ 
  7. +MIPS_MACHINE(ATH79_MACH_AP152_8200R2, "AP152-8200R2", "Qualcomm Atheros AP152-8200R2 board", 
  8. + ap152_setup); 
  9. diff --git a/arch/mips/ath79/mach-ap152-8200t2.c b/arch/mips/ath79/mach-ap152-8200t2.c 
  10. new file mode 100644 
  11. index 0000000..323b35a 
  12. --- /dev/null 
  13. +++ b/arch/mips/ath79/mach-ap152-8200t2.c 
  14. @@ -0,0 +1,206 @@ 
  15. +MIPS_MACHINE(ATH79_MACH_AP152_8200T2, "AP152-8200T2", "Qualcomm Atheros AP152-8200T2 board", 
  16. + ap152_setup); 
  17. diff --git a/arch/mips/ath79/mach-ap152-qtsa820.c b/arch/mips/ath79/mach-ap152-qtsa820.c 
  18. new file mode 100644 
  19. index 0000000..4b64fa1 
  20. --- /dev/null 
  21. +++ b/arch/mips/ath79/mach-ap152-qtsa820.c 
  22. +MIPS_MACHINE(ATH79_MACH_AP152_QTSA820, "AP152-QTSA820", "Qualcomm Atheros AP152-QTSA820 board", 
  23. + ap152_setup); 
  24.  

step 3. 添加新机器索引到头文件kernel_repos/arch/mips/ath79/machtypes.h

  1. diff --git a/arch/mips/ath79/machtypes.h b/arch/mips/ath79/machtypes.h 
  2. index b5417a7..3712dee 100644 
  3. --- a/arch/mips/ath79/machtypes.h 
  4. +++ b/arch/mips/ath79/machtypes.h 
  5. @@ -33,6 +33,9 @@ enum ath79_mach_type { 
  6. ATH79_MACH_AP147, /* Atheros AP147 reference board */ 
  7. ATH79_MACH_AP151, /* Atheros AP151 reference board */ 
  8. ATH79_MACH_AP152, /* Atheros AP152 reference board */ 
  9. + ATH79_MACH_AP152_QTSA820,/* Atheros AP152-QTSA820 board */ 
  10. + ATH79_MACH_AP152_8200T2,/* Atheros AP152-8200T2 board */ 
  11. + ATH79_MACH_AP152_8200R2,/* Atheros AP152-8200R2 board */ 
  12. ATH79_MACH_AP81, /* Atheros AP81 reference board */ 
  13. ATH79_MACH_AP83, /* Atheros AP83 */ 
  14. ATH79_MACH_AP96, /* Atheros AP96 */ 
  15.  

step 4. 添加新机器的索引到kernel_repos/arch/mips/ath79/{Kconfig,Makefile}

  1. diff --git a/arch/mips/ath79/Kconfig b/arch/mips/ath79/Kconfig 
  2. index d092806..52e5202 100644 
  3. --- a/arch/mips/ath79/Kconfig 
  4. +++ b/arch/mips/ath79/Kconfig 
  5. @@ -176,6 +176,49 @@ config ATH79_MACH_AP152 
  6. Say \'Y\' here if you want your kernel to support the 
  7. Atheros AP152 reference board. 
  8.  
  9. +config ATH79_MACH_AP152_QTSA820 
  10. + bool "Atheros AP152-QTSA820 board" 
  11. + select SOC_QCA956X 
  12. + select ATH79_DEV_GPIO_BUTTONS 
  13. + select ATH79_DEV_LEDS_GPIO 
  14. + select ATH79_DEV_SPI 
  15. + select ATH79_DEV_USB 
  16. + select ATH79_DEV_WMAC 
  17. + select ATH79_DEV_ETH 
  18. + select ATH79_DEV_M25P80 
  19. + help 
  20. + Say \'Y\' here if you want your kernel to support the 
  21. + Atheros AP152-QTSA820 board. 
  22. + 
  23. +config ATH79_MACH_AP152_8200T2 
  24. + bool "Atheros AP152-8200T2 board" 
  25. + select SOC_QCA956X 
  26. + select ATH79_DEV_GPIO_BUTTONS 
  27. + select ATH79_DEV_LEDS_GPIO 
  28. + select ATH79_DEV_SPI 
  29. + select ATH79_DEV_USB 
  30. + select ATH79_DEV_WMAC 
  31. + select ATH79_DEV_ETH 
  32. + select ATH79_DEV_M25P80 
  33. + help 
  34. + Say \'Y\' here if you want your kernel to support the 
  35. + Atheros AP152-8200T2 board. 
  36. + 
  37. +config ATH79_MACH_AP152_8200R2 
  38. + bool "Atheros AP152-8200R2 board" 
  39. + select SOC_QCA956X 
  40. + select ATH79_DEV_GPIO_BUTTONS 
  41. + select ATH79_DEV_LEDS_GPIO 
  42. + select ATH79_DEV_SPI 
  43. + select ATH79_DEV_USB 
  44. + select ATH79_DEV_WMAC 
  45. + select ATH79_DEV_ETH 
  46. + select ATH79_DEV_M25P80 
  47. + help 
  48. + Say \'Y\' here if you want your kernel to support the 
  49. + Atheros AP152-8200R2 board. 
  50. + 
  51. + 
  52. config ATH79_MACH_AP81 
  53. bool "Atheros AP81 reference board" 
  54. select SOC_AR913X 
  55. diff --git a/arch/mips/ath79/Makefile b/arch/mips/ath79/Makefile 
  56. index 695e51c..806b46f 100644 
  57. --- a/arch/mips/ath79/Makefile 
  58. +++ b/arch/mips/ath79/Makefile 
  59. @@ -57,6 +57,9 @@ obj-$(CONFIG_ATH79_MACH_AP143) += mach-ap143.o 
  60. obj-$(CONFIG_ATH79_MACH_AP147) += mach-ap147.o 
  61. obj-$(CONFIG_ATH79_MACH_AP151) += mach-ap151.o 
  62. obj-$(CONFIG_ATH79_MACH_AP152) += mach-ap152.o 
  63. +obj-$(CONFIG_ATH79_MACH_AP152_8200R2) += mach-ap152-8200r2.o 
  64. +obj-$(CONFIG_ATH79_MACH_AP152_8200T2) += mach-ap152-8200t2.o 
  65. +obj-$(CONFIG_ATH79_MACH_AP152_QTSA820) += mach-ap152-qtsa820.o 
  66. obj-$(CONFIG_ATH79_MACH_AP81) += mach-ap81.o 
  67. obj-$(CONFIG_ATH79_MACH_AP83) += mach-ap83.o 
  68. 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/之后的用户态脚本通过它来区分板子

  1. diff --git a/ok_base-files/lib/ar71xx.sh b/ok_base-files/lib/ar71xx.sh 
  2. index 91abca1..dedf81a 100755 
  3. --- a/ok_base-files/lib/ar71xx.sh 
  4. +++ b/ok_base-files/lib/ar71xx.sh 
  5. @@ -205,6 +205,12 @@ ar71xx_board_detect() { 
  6. + *"AP152-QTSA820 board") 
  7. + name="ap152" 
  8. + ;; 
  9. + *"AP152-8200T2 board") 
  10. + name="ap152" 
  11. + ;; 
  12. + *"AP152-8200R2 board") 
  13. + name="ap152" 
  14. + ;; 
  15. *AP81) 
  16. name="ap81" 
  17. ;; 
  1. root@oakridge:/tmp/sysinfo# cat /tmp/sysinfo/board_name 
  2. ap152 
  3. root@oakridge:/tmp/sysinfo# cat /tmp/sysinfo/model 
  4. Qualcomm Atheros AP152-QTSA820 board 

setp 6. 修改各个用户态脚本来支持新的

  1. llwang@VM2~/repos/osdk_repos/package_repos/ok_base-files $ grep -rin ap152 * 
  2. etc/uci-defaults/network:112:ap152) 
  3. etc/diag.sh:50: ap152) 
  4. etc/diag.sh:51: status_led="ap152:green:status" 
  5. lib/wifi/qcawifi.sh:356: ap152 | ap147 | ap151 | ap135 | ap137) 
  6. lib/upgrade/ap135.sh:77: "ap152" |\ 
  7. lib/upgrade/ap135.sh:126: "ap152" |\ 
  8. lib/upgrade/platform.sh:110: ap152 |\ 
  9. lib/upgrade/platform.sh:329: ap152 |\ 
  10. lib/ar71xx.sh:202: *"AP152 reference board"
  11. lib/ar71xx.sh:203: name="ap152" 
  12. lib/ar71xx.sh:205: *"AP152-QTSA820 board"
  13. lib/ar71xx.sh:206: name="ap152" 
  14. lib/preinit/81_load_wifi_board_bin:16: ap152) 
  15.  

step 7. 使用make kernel_menuconfig选中新加入的machine type,保存到targe/linux/config-3.3然后编译

  1. $ make kenerl_menuconfig 
  2. Machine selection ---> Atheros AR71xx/AR724xx/AR913X machine selection ---> Atheros AP52-QTSA820 board 
  1. diff --git a/target/linux/ar71xx/config-3.3 b/target/linux/ar71xx/config-3.3 
  2. index 95a892c..e158692 100644 
  3. --- a/target/linux/ar71xx/config-3.3 
  4. +++ b/target/linux/ar71xx/config-3.3 
  5. @@ -38,6 +38,8 @@ CONFIG_ATH79_DEV_WMAC=y 
  6. # CONFIG_ATH79_MACH_AP147 is not set 
  7. # CONFIG_ATH79_MACH_AP151 is not set 
  8. CONFIG_ATH79_MACH_AP152=y 
  9. +CONFIG_ATH79_MACH_AP152_8200R2=y 
  10. +CONFIG_ATH79_MACH_AP152_8200T2=y 
  11. +CONFIG_ATH79_MACH_AP152_QTSA820=y 
  12. # CONFIG_ATH79_MACH_AP81 is not set 
  13. # CONFIG_ATH79_MACH_AP83 is not set 

程序流程

  1. Image Generator将board identifier放到内核的command line
  2. 内核命令行通过BOARD=MY_BOARD来执行
  3. 内核代码查找板子类型和机器类型相关代码
  4. /lib/ar71xx.sh从/proc/cpuinfo中读取板子名称放入/tmp/sysinfo/{board_name,model}
  5. 一些脚本使用这个名字来区分板子

通用步骤

  1. 详细的列出设备上的芯片,关注processor,flash,ethernet,wireless。
  2. 确定串口和uboot能访问
  3. 准备和安装固件,查看bootlog的问题和错误
  4. 核实flash分区,LED和buttons

GPIO

GPIO LED Testing

  1. #!/bin/sh 
  2. GPIOCHIP=0 
  3. BASE=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/base) 
  4. NGPIO=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/ngpio) 
  5. max=$(($BASE+$NGPIO)) 
  6. gpio=$BASE 
  7. while [ $gpio -lt $max ] ; do 
  8. echo $gpio > /sys/class/gpio/export 
  9. [ -d /sys/class/gpio/gpio${gpio} ] && { 
  10. echo out > /sys/class/gpio/gpio$gpio/direction 
  11.  
  12. echo "[GPIO$gpio] Trying value 0" 
  13. echo 0 > /sys/class/gpio/gpio$gpio/value 
  14. sleep 3
  15.  
  16. echo "[GPIO$gpio] Trying value 1" 
  17. echo 1 > /sys/class/gpio/gpio$gpio/value 
  18. sleep 3
  19.  
  20. echo $gpio > /sys/class/gpio/unexport 

  21. gpio=$((gpio+1)) 
  22. done 

GPIO Button Testing

  1. #!/bin/sh 
  2. GPIOCHIP=0 
  3. BASE=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/base) 
  4. NGPIO=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/ngpio) 
  5. max=$(($BASE+$NGPIO)) 
  6. gpio=$BASE 
  7. while [ $gpio -lt $max ] ; do 
  8. echo $gpio > /sys/class/gpio/export 
  9. [ -d /sys/class/gpio/gpio${gpio} ] && { 
  10. echo in > /sys/class/gpio/gpio${gpio}/direction 
  11. echo "[GPIO${gpio}] value $(cat /sys/class/gpio/gpio${gpio}/value)" 
  12. echo ${gpio} > /sys/class/gpio/unexport 

  13. gpio=$((gpio+1)) 
  14. done 

Reference

add new device


nicephil@gmail.com