learning armbian steps(9) ----- armbian 源码分析(四)
在上一节的分析当中,我们知道是通过对话框来选择到底编译的是哪块板子,基于什么样的配置。
接下来我们来拿一个实例来分析一下具体的案例,我们会选中如下所示的版本
iotx-3 AM335X 1Gb SoC eMMC
相当于BOARD=iotx-3 BOARD_TYPE=conf
接下来还是回到lib/main.sh当中
169 source $SRC/config/boards/${BOARD}.${BOARD_TYPE} 170 LINUXFAMILY="${BOARDFAMILY}"
169行 相当于获取$SRC/config/boards/iotx-3.conf 当中设置的变量
170行 相当于设置LINUXFAMILY=cloudwsn,这个和iotx-3.conf内部的配置有关
来看一下iotx-3.conf的内容:
# AM335X 1Gb SoC eMMC BOARD_NAME="IOTX-3" BOARDFAMILY="cloudwsn" BOOTCONFIG="am335x_iotx3_config" MODULES="hci_uart gpio_sunxi rfcomm hidp bonding spi_sun7i" MODULES_NEXT="bonding" # KERNEL_TARGET="default,dev" CLI_TARGET="stretch,xenial:next" DESKTOP_TARGET="xenial:default,next" # CLI_BETA_TARGET="" uboot_custom_postprocess() { local tftpdir="/tftpboot" if [ -f MLO -a -e ${tftpdir} ];then cp MLO ${tftpdir}/cloudwsn-IOTX3-runtime-uboot.MLO fi if [ -f u-boot.img -a -e ${tftpdir} ];then cp u-boot.img ${tftpdir}/cloudwsn-IOTX3-runtime-uboot.img fi } BOOTENV_FILE="cloudwsn-default.txt"
第一行板子的具体描述,接下来设置了相关的变量,后续我们会看到这些变量使用的地放。
继续回到lib/main.sh当中
172 [[ -z $KERNEL_TARGET ]] && exit_with_error "Board configuration does not define valid kernel config"
172行 说明KERNEL_TARGET 变量是必须存在于iotx-3.conf 文件当中的,如果新增一块板子该变量是必须存在的,否则会报错。
继续阅读lib/main.sh脚本:
174 if [[ -z $BRANCH ]]; then 175 options=() 176 [[ $KERNEL_TARGET == *default* ]] && options+=("default" "Vendor provided / legacy (3.4.x - 4.4.x)") 177 [[ $KERNEL_TARGET == *next* ]] && options+=("next" "Mainline (@kernel.org) (4.x)") 178 [[ $KERNEL_TARGET == *dev* && $EXPERT = yes ]] && options+=("dev" "\Z1Development version (4.x)\Zn") 179 # do not display selection dialog if only one kernel branch is available 180 if [[ "${#options[@]}" == 2 ]]; then 181 BRANCH="${options[0]}" 182 else 183 BRANCH=$(dialog --stdout --title "Choose a kernel" --backtitle "$backtitle" --colors \ 184 --menu "Select the target kernel branch\nExact kernel versions depend on selected board" \ 185 $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") 186 fi 187 unset options 188 [[ -z $BRANCH ]] && exit_with_error "No kernel branch selected" 189 [[ $BRANCH == dev && $SHOW_WARNING == yes ]] && show_developer_warning 190 else 191 [[ $KERNEL_TARGET != *$BRANCH* ]] && exit_with_error "Kernel branch not defined for this board" "$BRANCH" 192 fi
174-192行, 执行的结果就是设置 BRANCH=default
继续阅读lib/main.sh
194 if [[ $KERNEL_ONLY != yes && -z $RELEASE ]]; then 195 options=() 196 options+=("jessie" "Debian 8 Jessie") 197 options+=("stretch" "Debian 9 Stretch") 198 options+=("xenial" "Ubuntu Xenial 16.04 LTS") 199 [[ $EXPERT = yes ]] && options+=("bionic" "Ubuntu Bionic 18.04 LTS") 200 RELEASE=$(dialog --stdout --title "Choose a release" --backtitle "$backtitle" --menu "Select the target OS release" \ 201 $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") 202 unset options 203 [[ -z $RELEASE ]] && exit_with_error "No release selected" 204 fi 205 206 if [[ $KERNEL_ONLY != yes && -z $BUILD_DESKTOP ]]; then 207 options=() 208 options+=("no" "Image with console interface (server)") 209 options+=("yes" "Image with desktop environment") 210 BUILD_DESKTOP=$(dialog --stdout --title "Choose image type" --backtitle "$backtitle" --no-tags --menu "Select the target image type" \ 211 $TTY_Y $TTY_X $(($TTY_Y - 8)) "${options[@]}") 212 unset options 213 [[ -z $BUILD_DESKTOP ]] && exit_with_error "No option selected" 214 fi 215
194-204行会弹出如下内容,在这里选择rootfs发行版本,在这里假设我们选择xenial , 即设置RELEASE=xenial,该变量会在后续被使用
jessie Debian 8 Jessie stretch Debian 9 Stretch xenial Ubuntu Xenial 16.04 LTS
206-215行 会弹出选择的发行版本,是否带桌面功能的版本,在这里我们选择Image with console interface, 即设置BUILD_DESKTOP=no,该变量会在后续被使用。
Image with console interface (server) Image with desktop environment
继续回到/ib/mian.sh当中
216 source $SRC/lib/configuration.sh
这里面的内容很多,我们来具体分析一下该脚本到底做了什么事情,对于新增一块板子也是有帮助的。
我们先跳到$SRC/lib/configuration.sh,,分析完了之后,再回到lib/main.sh
整个的configuration.sh,最终的目地就是获取uboot/kernel 的 git repository和branch 及对应的配置以便于后续的编译。
主功的功能有:
设置主机名
HOST=iotx
设置其初始密码
BOOTPWD=1234
设置其文件系统格式
ROOTFS_TYPE=ext4
设置其时区
TZDATA=Asia/Shanghan
设置其版本REVISION
REVISION=5.59
设置如下相关的变量
UBOOT_USE_GCC=> 5.0
KERNEL_USE_GCC=> 5.0
ARCH=armhf
QEMU_BINARY=qemu-arm-static // 该变量会用于本地挂载arm rootfs当中
ARCHITECTURE=arm
KERNEL_COMPILER=arm-linux-gnueabihf-
UBOOT_COMPILER=arm-linux-gnueabihf-
INITRD_ARCH=arm
BOOTCONFIG_VAR_NAME=BOOTCONFIG_DEFAULT
BOOTCONFIG=am335x_iotx3_config // uboot configure
LINUXCONFIG=linux-cloudwsn-default // kernel configure
BOOTPATCHDIR=u-boot-cloudwsn
KERNELPATCHDIR=cloudwsn-default
DISTRUBUTION=Ubuntu
在其output/debug/output.log 可以找到如下信息
## BUILD CONFIGURATION Build target: Board: iotx-3 Branch: default Desktop: Kernel configuration: Repository: git://git.ti.com/processor-sdk/processor-sdk-linux.git Branch: branch:processor-sdk-linux-04.03.00 Config file: linux-cloudwsn-default U-boot configuration: Repository: git://git.ti.com/ti-u-boot/ti-u-boot.git Branch: branch:ti-u-boot-2017.01 Config file: am335x_iotx3_config Partitioning configuration: Root partition type: ext4 Boot partition type: (none) User provided boot partition size: 0 Offset: 4 CPU configuration: - with interactive Displaying message: Downloading sources info Displaying message: Checking git sources u-boot-am335x ti-u-boot-2017.01 info
我们再次总结一下当前变量的值:
BOARD=iotx-3
BRANCH=default
BUILD_DESKTOP=no
KERNELSOURCE=git://git.ti.com/processor-sdk/processor-sdk-linux.git
KERNELBRANCH=branch:processor-sdk-linux-04.03.00
LINUXCONFIG=linux-cloudwsn-default
有了如上变量就可以用来编译kernel,加上KERNEL_COMPILER KERNEL_USE_GCC
如下是uboot相关的变量
BOOTSOURCE=git://git.ti.com/ti-u-boot/ti-u-boot.git
BOOTBRANCH=branch:ti-u-boot-2017.01
BOOTCONFIG=am335x_iotx3_config
ROOTFS_TYPE=ext4
BOOTSIZE=0
OFFSET=4
经过上面的初始化之后,接下来就是要开始编译uboot kernel,及构建rootfs.打包镜像。
我们回到 lib/main.sh 216行,在后续我们继续分析编译脚本。