打印

OpenWRT(Tina) 随笔记1 ./build.sh config 分析

[复制链接]
215|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
社畜一枚|  楼主 | 2018-10-4 10:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
虽然有些事情还没有想好,也没有个明确的方向,但现在努力总是不会错的,总比什么事情不做的好,在什么时候什么场合就做什么事情。

./build.sh config 分析
1、调用 mkcommon.sh 将参数传递进去
2、mkcomon.sh 加载 mkcmd.sh 脚本
3、删除 openwrt/.buildconfig ,该文件用来保存所选择的芯片、平台、内核、方案
4、在 mksetup()  调用 mkcmd.sh 中 select_board() 函数
5、mksetup() -> select_board() -> select_kern_ver() -> select_platform() -> select_chip()
6、mksetup() -> init_defconf()
7、mksetup() -> prepare_defconf()
8、mksetup() 分析:
------------------------------------------------------------------------------------------------------------
【1】mksetup() -> select_board() -> select_kern_ver() -> select_platform() -> select_chip()
1、select_chip() :
  1.先遍历 package\boot\uboot-sun5i\bootloader 下的所有目录,并取得除了"tools"、"boot-resource" 的目录名
  2.再遍历 package\boot\uboot-sunxi\bootloader 下的所有目录,并取得除了"tools"、"boot-resource" 的目录名
  3.显示这些目录名,获取用户选择,将用户所选保存并导出 CHIP 变量并写入 .buildconfig 文件中
2、select_platform():
  1.打印预先定义好的 platforms 变量内容:dragonboard、tina
  2.保持并导出 PLATFORM 变量,写入到 .buildconfig 文件中
3、select_kern_ver()
  1.遍历openwrt/lichee 下以 linux- 开头的所有目录并显示
  2.得到用户选择,保存并导出 KERNEL_VER,同时写入到文件.buildconfig
4、select_board()
  1.先遍历 package\boot\uboot-sun5i\bootloader\${CHIP}/configs/ 下的所有目录
  2.再遍历 package\boot\uboot-sunxi\bootloader\${CHIP}/configs/ 下的所有目录
  3.${CHIP}为用户所选的芯片,在 select_chip() 被设置
  4.显示除去 xdefault 的所有目录名
  5.获取用户所选,保存并导出 BOARD 变量,然后写入到 .buildconfig 文件中
  
【2】mksetup() -> init_defconf()
1、需要先分析 openwrt/scripts/mkrule
  chip_platform_board openwrt_defconfig kernel_defconfig
  sun8iw5p1_tina r16_defconfig r16_config-3.4
  sun8iw5p1_tina_evb r16_defconfig r16_config-3.4
  sun8iw5p1_tina_evb-8723bs r16_evb_8723bs_defconfig r16_config-3.4
  sun8iw5p1_tina_bell-one r16_bell_one_defconfig r16_config-3.4
  sun8iw5p1_dragonboard r16_defconfig r16_config-3.4
  sun5i_tina r8_defconfig r8_config-3.4
  sun5iw1p2_tina r8_defconfig r8_config-3.4
  sun5i_tina_changhong r8_changhong_config r8_config-3.4
  sun5i_dragonboard r8_defconfig r8_config-3.4
  
  格式:芯片_平台_方案   openwrt配置文件(openwrt/config)  内核配置文件
  sun5i_tina_changhong r8_changhong_config r8_config-3.4
  芯片:sun5i
  平台:tina
  方案:changhong
  openwrt配置文件:openwrt/config/r8_changhong_config
  内核配置文件: openwrt/config/r8_config-3.4 2、通过分析 openwrt\scripts\mkrule 文件来得到用户选择的方案所对应的 openwrt 配置文件和内核配置文件
  1.先将芯片、平台、方案组合之后去匹配 mkrule 里面的配置
  2.匹配成功则存入并导出 WRT_DEFCONF、KERNEL_DEFCONF
  3.匹配失败则改为 芯片、平台组合之后再去匹配,即去默认的配置,如下:
   sun5i_tina r8_defconfig r8_config-3.4
   
【3】mksetup() -> prepare_defconf()
1、调用 ./scripts/feeds install -a 来安装软件包
2、拷贝 openwrt配置文件到根目录里面的.config文件中
3、如果芯片选择的是 sun5i 则将内核配置文件覆盖 target/linux/sun5i/config-3.4
4、如果芯片选择的不是 sun5i 则覆盖到 target/linux/sunxi/config-3.4
注意:第3、4步不知道为什么被注释掉了 mksetup()【主线】
  1.调用 select_board() 获取用户选择的芯片型号、平台、内核版本、板级信息
  2.init_defconf() 分析 mkrule 文件得到 WRT_DEFCONF、KERNEL_DEFCONF
  3.prepare_defconf() 安装软件包、更新原来的openwrt配置文件和内核配置文件
------------------------------------------------------------------------------------------------------------总结:
./build.sh config 关注的地方:

1.选择芯片时涉及到的目录
  package\boot\uboot-sun5i\bootloader
  package\boot\uboot-sun5i\bootloader
  取以上目录内子目录的目录名作为芯片选项("tools"、"boot-resource" 除外)
  
2.选择平台时涉及到的字符串
  platforms:dragonboard、tina
  
3.选择内核时涉及到的目录
  openwrt/lichee 以内中 "linux-" 开头的目录名作为内核选项
  
4.板级选项(方案选项)
  package\boot\uboot-sun5i\bootloader\${CHIP}/configs/
  package\boot\uboot-sunxi\bootloader\${CHIP}/configs/
  取以上目录内子目录的目录名作为方案选项("default" 例外)
  
5.以上 1~4 的选择将保存到 openwrt/.buildconfig 文件中

6.用于关联芯片、平台、方案与 openwrt配置、内核配置文件的文件
  openwrt/scripts/mkrule
  格式:
   芯片_平台_方案   openwrt配置文件(openwrt/config)  内核配置文件
   芯片_平台     openwrt配置文件(openwrt/config)  内核配置文件


创建新的方案(芯片:sun5i 平台:tina 内核:linux-3.4)

1、在 package\boot\uboot-sun5i\bootloader\sun5i/configs/ 建立新的板级文件
  最简单方式是拷贝 evb 文件夹为新的方案名
  cp package\boot\uboot-sun5i\bootloader\sun5i/configs/evb package\boot\uboot-sun5i\bootloader\sun5i/configs/Baymin
  
  文件夹内文件如下:
   sys_config.fex为系统模块的配置文件
   sys_partition.fex为系统分区配置文件
   test_config.fex为办卡测试配置文件,可选
   env.cfg为uboot中的env配置文件,可选  修改 Baymin 中的 sys_config.fex 文件
  [product] -> machine = "R8-BAYMIN-V1.0"
  
2、修改 openwrt/package/boot/uboot-sun5i/Makefile 文件增加OpenWrt配置选项
  加入一个选项菜单
  define uboot/R8-Baymin-Board
    TITLE:=U-Boot 2011.09 Pre-Built for R8 // 显示在menuconfig中的名称
    CONFIG:=sun5i        // 为IC的代号,R16为sun8iw5p1,R8为sun5i
    PROFILE:=Baymin       // 板子名字
  endef
  
  加入到 UBOOTS 变量中
  UBOOTS:=R8M-Evb-Board \
   R8-NextThing-Board \
   R8-ChangHong-Board \
   R8-Slbh-Board \
   R8-Evb-Board \
   R8-Baymin-Board  // 新增加

3、在 openwrt/target/linux/sun5i/profiles/ 建立新的mk文件
  最简单的方式是拷贝 evb 方案的文件
  cp openwrt/target/linux/sun5i/profiles/r8-evb.mk openwrt/target/linux/sun5i/profiles/r8-Baymin.mk
  
  修改该文件:
  define Profile/R8-Baymin-Board
   NAME:=R8 Baymin Board     // menuconfig中显示的Profile的名称
   PACKAGES := uboot-sun5i-R8-Baymin-Board // 选择的软件包 ???
  endef  define Profile/R8-Baymin-Board/Description // Profile描述信息
   Package set optimized for the R8 dev board
  endef  $(eval $(call Profile,R8-Baymin-Board))
   
4、修改 openwrt\scripts\mkrule 文件
  增加:sun5i_tina_Baymin r8_Baymin_config r8_config-3.4
  
5、新增 OpenWRT 配置文件
  cp openwrt/config/r8_defconfig openwrt/config/r8_Baymin_config
   
6、修改 openwrt/target/linux/sun5i/image/make   
  BOARDS:= \
   R8M-Evb-Board \
   R8-NextThing-Board \
   R8-ChangHong-Board \
   R8-Slbh-Board \
   R8-Baymin-Board  // 增加
   
  // 增加
  define Image/Build/Profile/R8-Baymin-Board
   $(call Image/Build/FirmWare,$(1),sun5i, uart0, Baymin)
  endef
   
7、make menuconfig 配置
  make menuconfig -> Target Profile -> Baymin
  make menuconfig -> Boot Loader -> Baymin  // 由于 demo 板是 R8M 的,开发板就不要选择这项。
  然后将 openwrt/.config 文件的内容直接覆盖 r8_Baymin_config
  这一步也可以直接在第5步骤去修改 r8_Baymin_config 文件,那么第7步就可以省略了
  
8、注意事项
  1、如果 ./build.sh config 之后没有 make menuconfig 编译会报如下警告
   WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!
   
  2、R8M 板子中在烧录过程中发现弹出了格式化对话框,但是一直没有反应,那就是 Boot Loader 没有选择 R8M 的 uboot
  
  3、保存配置
   由于这份源码还不够完善,所以当要切换方案时,一定要注意将 OpenWRT/.config 覆盖到当前方案名的配置文件
   cp openwrt/.config openwrt/r8_Baymin_config
   否则,针对该方案的配置信息将会全部丢失------------------------------------------------------------------------------------------------------------   

脚本分析:

./build.sh config 命令分析:
========================================
-> build.sh
---------------------------------------
#!/bin/bashset -escripts/mkcommon.sh $@ // 将参数传递给 mkcommon.sh========================================
-> mkcommon.sh
---------------------------------------
if [ "x$1" = "xconfig" ] ; then
. ${SCRIPTS_DIR}/mksetup.sh // 1.加载该脚本
exit $?
========================================
-> mksetup.sh
---------------------------------------
. scripts/mkcmd.sh  // 1.加载该脚本function mksetup()  // 3.被调用
{
    rm -f .buildconfig // 4.删掉 .buildconfig 文件
    printf "\n"   // 5.打印提示信息
    printf "Welcome to mkscript setup progress\n"    select_board  // 设置 芯片型号、平台、内核版本、板级信息    init_defconf  //25.分析 mkrule 文件得到 WRT_DEFCONF、KERNEL_DEFCONF
    prepare_defconf  //30.正式设置
}# Setup all variables in setup.
mksetup  // 2.执行
----------
.buildconfig:用于存储所选择的芯片、平台、内核、方案名称,这里删除是因为要新建立新配置========================================
-> mkcmd.sh
---------------------------------------
TOP_DIR=`pwd`
SUNXI_BOOT_DIR=${TOP_DIR}/package/boot/uboot-sunxi
SUN5I_BOOT_DIR=${TOP_DIR}/package/boot/uboot-sun5i
KERNEL_DIR=${TOP_DIR}/lichee/linux-3.4
function select_board() // 1.被调用
{
local cnt=0
local choice select_kern_ver  // 2.设置 printf "All available boards:\n"
// 20.先遍历 package\boot\uboot-sun5i\bootloader\${CHIP}/configs/ 下的所有目录并显示
for boarddir in ${SUN5I_BOOT_DIR}/bootloader/${CHIP}/configs/* ; do
  boards[$cnt]=`basename $boarddir`
  
  if [ "x${boards[$cnt]}" = "x*" ] ; then
   break
  fi
  // 除却 default 目录名
  if [ "x${boards[$cnt]}" = "xdefault" ] ; then
   continue
  fi
  
  printf "%4d. %s\n" $cnt ${boards[$cnt]}
  ((cnt+=1))
done
// 23.再遍历 package\boot\uboot-sun5i\bootloader\${CHIP}/configs/ 下的所有目录并显示
for boarddir in ${SUNXI_BOOT_DIR}/bootloader/${CHIP}/configs/* ; do
  boards[$cnt]=`basename $boarddir`
  if [ "x${boards[$cnt]}" = "x*" ] ; then
   break
  fi
  // 除却 default 目录名
  if [ "x${boards[$cnt]}" = "xdefault" ] ; then
   continue
  fi
  printf "%4d. %s\n" $cnt ${boards[$cnt]}
  ((cnt+=1))
done //24.获取用户所选,保存并导出 BOARD 变量,然后写入到 .buildconfig 文件中
while true ; do
  read -p "Choice: " choice
  if [ -z "${choice}" ] ; then
   continue
  fi  if [ -z "${choice//[0-9]/}" ] ; then
   if [ $choice -ge 0 -a $choice -lt $cnt ] ; then
    export BOARD="${boards[$choice]}"
    echo "export BOARD=${boards[$choice]}" >> .buildconfig
    break
   fi
  fi
  printf "Invalid input ...\n"
done
}
function select_kern_ver()  // 3.select_board() Call
{
local cnt=0
local choice select_platform    // 4.设置平台
printf "All available kernel:\n"
for kern_dir in ${TOP_DIR}/lichee/linux-* ; do //16.遍历openwrt/lichee/linux-* 目录
  kern_vers[$cnt]=`basename $kern_dir`  //17.取得目录名
  printf "%4d. %s\n" $cnt ${kern_vers[$cnt]} //18.显示
  ((cnt+=1))
done
// 19.得到用户选择,保存并导出 KERNEL_VER,同时写入到文件.buildconfig
while true ; do
  read -p "Choice: " choice
  if [ -z "${choice}" ] ; then
   continue
  fi  if [ -z "${choice//[0-9]/}" ] ; then
   if [ $choice -ge 0 -a $choice -lt $cnt ] ; then
    export KERNEL_VER="${kern_vers[$choice]}"
    echo "export KERNEL_VER=${kern_vers[$choice]}" >> .buildconfig
    break
   fi
  fi
  printf "Invalid input ...\n"
done
}
function select_platform()  // 5.select_kern_ver() Call
{
local cnt=0
local choice
local call=$1 select_chip     // 6.设置芯片 printf "All available platforms:\n"
for platform in ${platforms[@]} ; do  // 13.打印  platforms 里的内容:dragonboard、tina
  printf "%4d. %s\n" $cnt $platform
  ((cnt+=1))
done while true ; do
  read -p "Choice: " choice
  if [ -z "${choice}" ] ; then
   continue
  fi  if [ -z "${choice//[0-9]/}" ] ; then
   if [ $choice -ge 0 -a $choice -lt $cnt ] ; then
    export PLATFORM="${platforms[$choice]}" // 14.保存用户所选
    echo "export PLATFORM=${platforms[$choice]}" >> .buildconfig // 15.写入到文件中
    break
   fi
  fi
  printf "Invalid input ...\n"
done
}
function select_chip()  //7.select_platform()
{
local cnt=0
local choice
local call=$1 printf "All available chips:\n"
//8. 遍历 package\boot\uboot-sun5i\bootloader 下的所有目录
for chipdir in ${SUN5I_BOOT_DIR}/bootloader/* ; do
  chips[$cnt]=`basename $chipdir`   // 取目录名
  if [ "x${chips[$cnt]}" = "xtools" -o \
   "x${chips[$cnt]}" = "xboot-resource" ] ; then
   continue       // tools、boot-resource 排除
  fi
  printf "%4d. %s\n" $cnt ${chips[$cnt]}
  ((cnt+=1))
done
//9. 遍历 package\boot\uboot-sunxi\bootloader 下的所有目录
for chipdir in ${SUNXI_BOOT_DIR}/bootloader/* ; do
  chips[$cnt]=`basename $chipdir`
  if [ "x${chips[$cnt]}" = "xtools" -o \
   "x${chips[$cnt]}" = "xboot-resource" ] ; then
   continue      // tools、boot-resource 排除
  fi
  printf "%4d. %s\n" $cnt ${chips[$cnt]}
  ((cnt+=1))
done
//10. 让用户选择这些目录
while true ; do
  read -p "Choice: " choice
  if [ -z "${choice}" ] ; then
   continue
  fi
  export CHIP="${chips[$choice]}"
  if [ -z "${choice//[0-9]/}" ] ; then
   if [ $choice -ge 0 -a $choice -lt $cnt ] ; then
    export CHIP="${chips[$choice]}"  //11. 保存 CHIP 为全局变量,让其他的sh文件可以访问
    echo "export CHIP=${chips[$choice]}" >> .buildconfig //12. 将用户所选写入到文件中
    break
   fi
  fi
  printf "Invalid input ...\n"
done
}
function init_defconf()  // 26.mksetup() CALL init_defconf()
{
local pattern
local defconf check_env pattern="${CHIP}_${PLATFORM}_${BOARD}"
defconf=`awk '$1=="'$pattern'" {print $2,$3}' scripts/mkrule`

if [ -n "${defconf}" ] ; then // 27.判断 defconf 判断是否不为空
  export WRT_DEFCONF=`echo ${defconf} | awk '{print $1}'`
  export KERNEL_DEFCONF=`echo ${defconf} | awk '{print $2}'`
else // 28.为空则换一种方法,即取消方案名,以芯片和平台去取方案,实际上是取默认的配置文件
  pattern="${CHIP}_${PLATFORM}"
  defconf=`awk '$1=="'$pattern'" {print $2,$3}' scripts/mkrule`
  if [ -n "${defconf}" ] ; then // 29.将匹配到的信息存入并导出 WRT_DEFCONF、KERNEL_DEFCONF
   export WRT_DEFCONF=`echo ${defconf} | awk '{print $1}'`
   export KERNEL_DEFCONF=`echo ${defconf} | awk '{print $2}'`
  fi
fi}
function prepare_defconf() // 31.mksetup() CALL prepare_defconf()
{
./scripts/feeds install -a // 32.安装软件包
cp config/${WRT_DEFCONF} .config
// 下面怎么注释了???
#if [ "x${CHIP} = "xsun5i" ]
# cp config/${KERNEL_DEFCONF} target/linux/sun5i/config-3.4
#else
# cp config/${KERNEL_DEFCONF} target/linux/sunxi/config-3.4
#fi
}
================================================================================

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

397

主题

401

帖子

0

粉丝