buildroot使用记录.

集成的开发环境

靠 config.in 串联起来

 

         举例添加lighttpd web server

  1. Make menuconfig

 

 

 

 

Make help

 

 

Cleaning:

  clean                  - delete all files created by build

  distclean              - delete all non-source files (including .config)

 

Build:

  all                    - make world

  toolchain              - build toolchain

  sdk                    - build relocatable SDK

 

Configuration:

  menuconfig             - interactive curses-based configurator

  nconfig                - interactive ncurses-based configurator

  xconfig                - interactive Qt-based configurator

  gconfig                - interactive GTK-based configurator

  oldconfig              - resolve any unresolved symbols in .config

  silentoldconfig        - Same as oldconfig, but quietly, additionally update deps

  olddefconfig           - Same as silentoldconfig but sets new symbols to their default value

  randconfig             - New config with random answer to all options

  defconfig              - New config with default answer to all options;

                             BR2_DEFCONFIG, if set on the command line, is used as input

  savedefconfig          - Save current config to BR2_DEFCONFIG (minimal config)

  allyesconfig           - New config where all options are accepted with yes

  allnoconfig            - New config where all options are answered with no

  alldefconfig           - New config where all options are set to default

  randpackageconfig      - New config with random answer to package options

  allyespackageconfig    - New config where pkg options are accepted with yes

  allnopackageconfig     - New config where package options are answered with no

 

Package-specific:

  <pkg>                  - Build and install <pkg> and all its dependencies

  <pkg>-source           - Only download the source files for <pkg>

  <pkg>-extract          - Extract <pkg> sources

  <pkg>-patch            - Apply patches to <pkg>

  <pkg>-depends          - Build <pkg>'s dependencies

  <pkg>-configure        - Build <pkg> up to the configure step

  <pkg>-build            - Build <pkg> up to the build step

  <pkg>-show-depends     - List packages on which <pkg> depends

  <pkg>-show-rdepends    - List packages which have <pkg> as a dependency

  <pkg>-graph-depends    - Generate a graph of <pkg>'s dependencies

  <pkg>-graph-rdepends   - Generate a graph of <pkg>'s reverse dependencies

  <pkg>-dirclean         - Remove <pkg> build directory

  <pkg>-reconfigure      - Restart the build from the configure step

  <pkg>-rebuild          - Restart the build from the build step

 

busybox:

  busybox-menuconfig     - Run BusyBox menuconfig

 

uclibc:

  uclibc-menuconfig      - Run uClibc menuconfig

 

uboot:

  uboot-menuconfig       - Run U-Boot menuconfig

  uboot-savedefconfig    - Run U-Boot savedefconfig

  uboot-update-defconfig - Save the U-Boot configuration to the path specified

                             by BR2_TARGET_UBOOT_CUSTOM_CONFIG_FILE

 

linux:

  linux-menuconfig       - Run Linux kernel menuconfig

  linux-savedefconfig    - Run Linux kernel savedefconfig

  linux-update-defconfig - Save the Linux configuration to the path specified

                             by BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE

 

Documentation:

  manual                 - build manual in all formats

  manual-html            - build manual in HTML

  manual-split-html      - build manual in split HTML

  manual-pdf             - build manual in PDF

  manual-text            - build manual in text

  manual-epub            - build manual in ePub

  graph-build            - generate graphs of the build times

  graph-depends          - generate graph of the dependency tree

  graph-size             - generate stats of the filesystem size

  list-defconfigs        - list all defconfigs (pre-configured minimal systems)

 

Miscellaneous:

  source                 - download all sources needed for offline-build

  external-deps          - list external packages used

  legal-info             - generate info about license compliance

  printvars              - dump all the internal variables

 

  make V=0|1             - 0 => quiet build (default), 1 => verbose build

  make O=dir             - Locate all output files in "dir", including .config

 

make linux-rebuild

make uboot-rebuild

make linux-rebuild all

make <package> -rebuild

make <package> -reconfigure

make <package>

 

make --debug=all

 

make -p MAKE_LOCAL

 

make libopenssl-rebuild

 

 

make source:只载以前在配置器(menuconfig,nconfig,xconfig或gconfig)中选择的所有源

模块编译裁剪举例(openssl)

       在嵌入式平台上,如果使用openssl的标准方法,编译出来的libcrypto.solibssl.so会比较大,大约为2.1M多和436K,为了节省空间,可以使用如下方法进行裁剪:
 

1、静态库:
./config--prefix=/home/zqjun/openssl5350 no-shared no-zlib no-asm no-threads no-sse2no-compno-dso no-gmp no-rfc3779 no-krb5 no-rc5 no-zlib-dynamic
 no-hw no-cipherno-md2 no-md4 no-mdc2 no-rc2 no-idea no-camellia no-ec no-ecdsa no-ecdhno-store no-ripemd no-des no-rc4 no-bf no-cast no-dsa no-dh no-ssl no-ssl2 no-ssl3 no-tls no-perlasm
 
2
、动态库:
.config--prefic=/home/zqjun/openssl5350
shared no-zlib no-asm no-threads no-sse2 no-compno-gmp no-rfc3779 no-krb5 no-rc5 no-zlib-dynamic no-hw no-cipher no-md2 no-md4 no-mdc2no-rc2 no-idea no-camellia no-ec no-ecdsa no-ecdh no-store no-ripemd no-des no-rc4no-bf no-cast no-dsa no-dh no-ssl
 no-ssl2 no-ssl3 no-tls no-perlasm

注意:
1、动态编译时不能出现no-dso参数,因为编译过程中有些函数需要链接相应动态库。
2、编译完成后使用XXX-strip把相应的符号去掉,安装后的库会更小一些。
创建出Makefile后,再按照上面编译时的修改方法修改makefile中相应的参数值就可以了

 

 

修改libopenssl.mk

 

补丁文件的生成:

diff -uprN  a/xxx.h b/xxx.h > xxx.patch

 

buildroot工作原理

  Buildroot原则上是一个自动构建框架,虽然说u-boot、linux kernel这些经典的开源软件包的构建脚本,官方社区都在帮你实现了,但是有时候你还是需要加入你自己特有的app_pkg软件包,用以构建自己的应用。

 

  buildroot的编译流程是先从dl/xxx.tar下解压出源码到output/build/xxx,然后它利用本身的配置文件(如果有的话)覆盖output/build/xxx下的配置文件,在开始编译连接完成后安装到output/相应文件夹下。

 

  Buildroot提供了函数框架和变量命令框架,采用它的框架编写的app_pkg.mk这种Makefile格式的自动构建脚本,将被package/pkg-generic.mk 这个核心脚本展开填充到buildroot主目录下的Makefile中去。最后make all执行Buildroot主目录下的Makefile,生成你想要的image。

 

  package/pkg-generic.mk中通过调用同目录下的pkg-download.mk、pkg-utils.mk文件,已经帮你自动实现了下载、解压、依赖包下载编译等一系列机械化的流程。你只要需要按照格式写Makefile脚app_pkg.mk,填充下载地址,链接依赖库的名字等一些特有的构建细节即可。

 

  总而言之,Buildroot本身提供构建流程的框架,开发者按照格式写脚本,提供必要的构建细节,配置整个系统,最后自动构建出你的系统。

  

  buildroot/packages里面有丰富的应用软件的配置文件,可以通过make menuconfig,出现图形化界面进行选择丰富的开源软件包的编译和构建。

  对buildroot的配置通过Config.in串联起来,起点在根目录Config.in中:

 

配置选项   Config.in位置

Target options  arch/Config.in

Build options   Config.in

Toolchain toolchain/Config.in

System configuration  system/Config.in

Kernel linux/Config.in

Target packages package/Config.in

Target packages->Busybox

Filesystem images  fs/Config.in

Bootloaders  boot/Config.in

Host utilities  package/Config.in.host

Legacy config options Config.in.legacy

配置Kernel内核

  对Linux内核的配置包括两部分:通过make menuconfig进入Kernel对内核进行选择,通过make linux-menuconfig对内核内部进行配置。

 

内核配置

  进入buildroot目录,输入make menuconfig,选然后选择Kernel进行配置,如图:

 

 

“Kernel version”选择内核的版本;

“Defconfig name”选择内核config文件;

“Kernel binary formant”选择内核格式;

“Device tree source file names”选择DT文件;

“Linux Kernel Tools”中选择内核自带的工具,比如perf;

可以选择“Custom Git repository”来指定自己的Git库,在“Custom repository version”中指定branch名称。

选择“Using an in-tree defconfig file”,在“Defconfig name”中输入defconfig名称,注意不需要末尾_defconfig。

选择“Use a device tree present in the kernel”,在“Device Tree Source file names”中输入dts名称,不需要.dts扩展名。

“Kernel binary format”可以选择vmlinux或者uImage。

uImage是uboot专用的映像文件,它是在zImage之前加上一个长度为64字节的“头”,说明这个内核的版本、加载位置、生成时间、大小等信息;其0x40之后与zImage没区别。

zImage是ARM Linux常用的一种压缩映像文件,uImage是U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的“头”,说明这个映像文件的类型、加载位置、生成时间、大小等信息。

vmlinux编译出来的最原始的内核elf文件,未压缩。

zImage是vmlinux经过objcopy gzip压缩后的文件, objcopy实现由vmlinux的elf文件拷贝成纯二进制数据文件。

uImage是U-boot专用的映像文件,它是在zImage之前加上一个长度为0x40的tag。

选择vmlinux和uImage的区别在于:

   PATH="/bin..."

   BR_BINARIES_DIR=/home/.../output/images /usr/bin/make -j9

   HOSTCC="/usr/bin/gcc"

   HOSTCFLAGS=""

   ARCH=csky

   INSTALL_MOD_PATH=/home/.../output/target

   CROSS_COMPILE="/home/.../output/host/bin/csky-abiv2-linux-"

   DEPMOD=/home/.../output/host/sbin/depmod

   INSTALL_MOD_STRIP=1 -C /home/.../linux uImage

1

 

  如果是vmlinux,在结尾就是vmlinux。

 

内核内部配置

  通过make linux-menuconfig可以对内核内部细节进行配置。

  让Linux内核带符号表:

 

    CONFIG_COMPILE_TEST is not set

    CONFIG_DEBUG_INFO=y

1

2

配置文件系统

对目标板文件系统内容进行配置主要通过make menuconfig进入Target packages进行。

在Filesystem images中配置文件系统采用的格式,以及是否使用RAM fs。

配置Uboot

  使用uboot作为bootloader,需要进行一些配置。

  在选中U-boot作为bootloader之后,会弹出一系列相关配置。

 

“U-Boot board name”配置configs的defconfig名称。

“U-Boot Version”选择Custom Git repository,然后在“URL of custom repository”中选择自己的git地址,并在“Custom repository version”中选择git的分支。

在“U-Boot binary format”中选择想要输出的image格式,比如u-boot.img或者u-image.bin。

还可以选择“Intall U-Boot SPL binary image”,选择合适的SPL。

 

buildroot编译出来的目标文件大多是stripped的。

buildroot/Config.in

注意 BR2_STRIP_strip 默认是选中的

makemenuconfig 可以看到选项情况

第3行定义 BR2_STRIP_strip ,你的buildroot使能了strip

第4行定义 BR2_STRIP_EXCLUDE_DIRS , test目录是strip的例外目录

 

编译时判断的6个标识文件,需要重新执行对应步骤时删除。

.stamp_built

.stamp_configured

.stamp_downloaded

.stamp_extracted

.stamp_patched

.stamp_target_installed

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值