嵌入式系统BSP开发(三)
这个脚本很简单只有两句话,一个是set -e(就是说在这个set -e后面的所有代码,只要出现了返回值非零,整个脚本就会立即退出)后面一句就是包含另一个文件夹的脚本common.sh,$@后面再说,再跑到common.sh里面。我们可以通过以下一个示例来进行实验,了解#!/bin/bash的使用。除第一行外,脚本中所有以“#”开头的行都是注释。
·
一,分析r16的编译过程,然后自己移植内核和文件系统
1,编译脚本的内容说明,看下build.sh脚本的内容
#!/bin/bash
set -e
buildroot/scripts/mkcommon.sh $@
#!/bin/bash是指此脚本使用/bin/bash来解释执行。
其中,#!是一个特殊的表示符,其后,跟着解释此脚本的shell路径。
bash只是shell的一种,还有很多其它shell,如:sh,csh,ksh,tcsh,...
我们可以通过以下一个示例来进行实验,了解#!/bin/bash的使用。
除第一行外,脚本中所有以“#”开头的行都是注释。
1)#!/bin/bash只能放在第一行,如果后面还有#!,那么只能看成是注释。
#!/bin/bash
set -e
buildroot/scripts/mkcommon.sh $@
这个脚本很简单只有两句话,一个是set -e(就是说在这个set -e后面的所有代码,只要出现了返回值非零,整个脚本就会立即退出)
后面一句就是包含另一个文件夹的脚本common.sh,$@后面再说,再跑到common.sh里面
#!/bin/bash
#
# scripts/mkcommon.sh
# (c) Copyright 2013
# Allwinner Technology Co., Ltd. <www.allwinnertech.com>
# James Deng <csjamesdeng@allwinnertech.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
BR_SCRIPTS_DIR=`dirname $0`
#反引号,命令替换,就是把命令执行的结果替换到这里来
#dirname $0 buildroot/scripts
# source shflags
. ${BR_SCRIPTS_DIR}/shflags/shflags
#正常理解来看的话,有空格的点是运行的意思,跟source是一样的。如果没有空格的点是表示当前目录,..表示上一级目录
. ${BR_SCRIPTS_DIR}/mkcmd.sh
[ -f .buildconfig ] && . .buildconfig
#如果有.buildconfig文件就执行这个文件
#其实执行到这里就已经可以退出了啊
if [ "x$1" = "xconfig" ] ; then
. ${BR_SCRIPTS_DIR}/mksetup.sh
exit $?
#$? 如果我的指令的是config,那么就执行这个命令
elif [ "x$1" = "xpack" ] ; then
init_defconf #这里有几个命令是从刚导入的时候导入进来的命令的,mkcmd.sh
mkpack
exit $?
elif [ "x$1" = "xpack_debug" ] ; then
init_defconf
mkpack -d card0
exit $?
#如果我的指令是debug就执行这个
elif [ "x$1" = "xpack_dump" ] ; then
init_defconf
mkpack -m dump
exit $?
#如果我的指令是
elif [ "x$1" = "xpack_prvt" ] ; then
init_defconf
mkpack -f prvt
exit $?
elif [ $# -eq 0 ] ; then
init_defconf
mklichee
exit $?
fi
#配置这一部分,如果涉及到上面的内容就直接退出了
#其他类型的东西就在下面进行操作了
# define a 'name' command-line string flag
#DEFINE_string 'name' 'world' 'name to say hello to' 'n'
#这个是定义了一个string类型的变量,名字是name,默认值是world,说明文字是name to say hello to 缩写是 n
# define option, format:
# 'long option' 'default value' 'help message' 'short option'
DEFINE_string 'platform' '' 'platform to build, e.g. sun9iw1p1' 'p'
DEFINE_string 'kernel' 'linux-3.4' 'kernel to build, e.g. 3.3' 'k'
DEFINE_string 'board' '' 'board to build, e.g. evb' 'b'
DEFINE_string 'module' '' 'module to build, e.g. buildroot, kernel, uboot, clean' 'm'
#举例子 -p sun7i_android -k 3.4
FLAGS_HELP="Top level build script for lichee
Examples:
1. Set the config option
$ ./build.sh config
2. Build lichee using preset config value
$ ./build.sh
3. Pack a linux, dragonboard image
$ ./build.sh pack
4. Build lichee using command argument
$ ./build.sh -p <platform>
"
# parse the command-line
FLAGS "$@" || exit $?
#||的意思是如果左边的没有执行成功,就执行右边的内容,并且返回
eval set -- "${FLAGS_ARGV}"
#重新设置了$@,留下未解析的参数 ${FLAGS_ARGV}.
#
##根据传入的参数和命令来确定变量的值
##参数是: -p sun7i_android -k 3.4
chip=${FLAGS_platform%%_*} #提取出chip sun7i
platform=${FLAGS_platform##*_} #提取出平台 android
kernel=${FLAGS_kernel} #提取出内核 3.4
board=${FLAGS_board} #提取出板子 这里空
module=${FLAGS_module} #提取出模块 这里空
if [ "${platform}" = "${chip}" ] ; then #如果未指定平台,默认为linux
platform="linux"
fi
if [ -z "${module}" ] ; then #如果未指定模块,默认编译所有
module="all"
fi
if ! init_chips ${chip} || \
! init_platforms ${platform} ; then
mk_error "invalid platform '${FLAGS_platform}'"
exit 1
fi
if ! init_kern_ver ${kernel} ; then
mk_error "invalid kernel '${FLAGS_kernel}'"
exit 1
fi
if [ ${FLAGS_board} ] && \
! init_boards ${chip} ${board} ; then
mk_error "invalid board '${FLAGS_board}'"
exit 1
fi
# init default config 默认情况下的内容,这个还是很好理解的。那么下面我们按照编译手册的内容进行确定整体的步骤和环境
init_defconf
if [ ${module} = "all" ]; then
mklichee
elif [ ${module} = "boot" ] ; then
mkboot
elif [ ${module} = "buildroot" ] ; then
mkbr
elif [ ${module} = "kernel" ] ; then
mkkernel
elif [ ${module} = "clean" ] ; then
mkclean
elif [ ${module} = "distclean" ] ; then
mkdistclean
else
mk_error "invalid module '${module}'"
exit 1
fi
exit $?
更多推荐
所有评论(0)