嵌入式Linux內核+根文件系統構建工具-Buildroot 快速入手指導【轉】

本文轉載自:https://my.oschina.net/freeblues/blog/596448php

嵌入式Linux內核+根文件系統構建工具-Buildroot 快速入手指導

buildroot 是一款專門用來定製嵌入式 Linux 的內核和根文件系統(rootfs) 的開源工具, 很是強大兼方便, 不過對於新手來講, 過多的配置項明顯有些難度, 本文的目標就是簡要介紹這款工具, 讓新手迅速入門.linux

目標:nginx

  • 1 新手須要瞭解的2個目錄和1個文件
  • 2 熟悉該工具的基本命令 ;
  • 3 構建出一個內核和一個根文件系統

練習:git

  • 1 查看針對特定開發板的典型配置文件的選項
  • 2 利用工具自帶的配置文件生成一個 Linux 內核和根文件系統;

首先是獲取該工具, 在 github 上, 命令以下:github

git clone https://github.com/buildroot/buildroot 

進入目錄, 查看:express

pi@rpi /opt/github/buildroot $ ls -al
total 420
drwxr-xr-x   15 root root   4096 Dec 24 21:18 .
drwxr-xr-x   73 git  git    4096 Jan  3 08:01 ..
drwxr-xr-x    2 root root   4096 Dec 24 21:15 arch
drwxr-xr-x   25 root root   4096 Dec 24 21:15 board
drwxr-xr-x   15 root root   4096 Dec 24 21:15 boot
-rw-r--r-- 1 root root 146433 Dec 24 21:15 CHANGES -rw-r--r-- 1 root root 44501 Dec 24 21:16 .config -rw-r--r-- 1 root root 19111 Dec 24 21:15 Config.in -rw-r--r-- 1 root root 42879 Dec 24 21:15 Config.in.legacy drwxr-xr-x 2 root root 4096 Dec 24 21:15 configs -rw-r--r-- 1 root root 17987 Dec 24 21:15 COPYING -rw-r--r-- 1 root root 1246 Dec 24 21:15 .defconfig drwxr-xr-x 5 root root 4096 Dec 24 21:15 docs drwxr-xr-x 15 root root 4096 Dec 24 21:15 fs drwxr-xr-x 8 root root 4096 Dec 24 21:18 .git -rw-r--r-- 1 root root 125 Dec 24 21:15 .gitignore drwxr-xr-x 2 root root 4096 Dec 24 21:15 linux -rw-r--r-- 1 root root 34899 Dec 24 21:15 Makefile -rw-r--r-- 1 root root 2432 Dec 2421:15 Makefile.legacy drwxr-xr-x 3 root root 4096 Dec 24 21:18 output drwxr-xr-x 1266 root root 36864 Dec 24 21:15 package -rw-r--r-- 1 root root 972 Dec 2421:15 README drwxr-xr-x 11 root root 4096 Dec 24 21:15 support drwxr-xr-x 3 root root 4096 Dec 24 21:15 system drwxr-xr-x 5 root root 4096 Dec 24 21:15 toolchain pi@rpi /opt/github/buildroot $ 

1. 新手須要瞭解的2個目錄和1個文件

先說目錄:

  • 目錄1: configs

一個是 configs 目錄, 存放着工具提供的一些特定系統的構建配置, 換句話說就是一些使用比較普遍的 Linux 嵌入式系統的構建配置文件, 例如, 咱們熟悉的樹莓派1 raspberrypi_defconfig 和2 raspberrypi2_defconfig 的構建配置文件就在其中, 咱們能夠看一下內容:ruby

pi@rpi /opt/github/buildroot $ ls ./configs altera_sockit_defconfig calao_usb_a9g20_lpw_defconfig minnowboard_defconfig qemu_ppc_virtex_ml507_defconfig armadeus_apf27_defconfig ci20_defconfig minnowboard_max_defconfig qemu_sh4_r2d_defconfig armadeus_apf28_defconfig cubieboard2_defconfig mx53loco_defconfig qemu_sparc_ss10_defconfig armadeus_apf51_defconfig cubieboard_defconfig nitrogen6x_defconfig qemu_x86_64_defconfig armadeus_apf9328_defconfig freescale_imx28evk_defconfig olimex_imx233_olinuxino_defconfig qemu_x86_defconfig arm_foundationv8_defconfig freescale_imx31_3stack_defconfig openblocks_a6_defconfig qemu_xtensa_lx60_defconfig at91rm9200df_defconfig freescale_imx6dlsabreauto_defconfig pandaboard_defconfig qmx6_defconfig at91sam9260dfc_defconfig freescale_imx6dlsabresd_defconfig qemu_aarch64_virt_defconfig raspberrypi2_defconfig at91sam9260eknf_defconfig freescale_imx6qsabreauto_defconfig qemu_arm_nuri_defconfig raspberrypi_defconfig at91sam9261ek_defconfig freescale_imx6qsabresd_defconfig qemu_arm_versatile_defconfig raspberrypi_dt_defconfig at91sam9263ek_defconfig freescale_imx6sololiteevk_defconfig qemu_arm_vexpress_defconfig riotboard_defconfig at91sam9g20dfc_defconfig freescale_mpc8315erdb_defconfig qemu_microblazebe_mmu_defconfig s6lx9_microboard_defconfig at91sam9g45m10ek_defconfig freescale_p1010rdb_pa_defconfig qemu_microblazeel_mmu_defconfig sheevaplug_defconfig atmel_xplained_defconfig freescale_p2020ds_defconfig qemu_mips64el_malta_defconfig telit_evk_pro3_defconfig beaglebone_defconfig gnublin_defconfig qemu_mips64_malta_defconfig ts5x00_defconfig calao_qil_a9260_defconfig integrator926_defconfig qemu_mipsel_malta_defconfig udoo_quad_defconfig calao_snowball_defconfig kb9202_defconfig qemu_mips_malta_defconfig wandboard_defconfig calao_tny_a9g20_lpw_defconfig lego_ev3_defconfig qemu_ppc64_pseries_defconfig zedboard_defconfig calao_usb_a9260_defconfig loongson1c_smartloong_defconfig qemu_ppc_g3beige_defconfig calao_usb_a9263_defconfig mini2440_defconfig qemu_ppc_mpc8544ds_defconfig pi@rpi /opt/github/buildroot $ 
  • 目錄2: output

另外一個是 output 目錄, 存放着你構建好以後的輸出, 在 output/images/ 目錄下放着構建好的內核和根文件系統, 咱們能夠在開始構建以前看看該目錄的結構:less

pi@rpi /opt/github/buildroot $ tree ./output ./output └── build └── buildroot-config ├── conf.o ├── lxdialog │ ├── checklist.o │ ├── inputbox.o │ ├── menubox.o │ ├── textbox.o │ ├── util.o │ └── yesno.o ├── mconf ├── mconf.o ├── zconf.hash.c ├── zconf.lex.c └── zconf.tab.o 3 directories, 12 files pi@rpi /opt/github/buildroot $ 
  • 文件: .config

一個文件就是 .config, 它就是構建時使用的配置文件, 舉個例子, 若是咱們打算使用工具自帶的配置文件來構建樹莓派2的內核和根文件系統, 那麼首先把它從 configs 目錄拷出來, 覆蓋掉當前目錄下的 .config 文件, 命令以下:工具

cp ./configs/ raspberrypi2_defconfig ./.config 

講解了簡單的2個目錄和1個文件, 接下來講一下基本命令ui

2. 熟悉該工具的基本命令

buildroot 基本的命令就是 make, 對於新手來講只須要執行2次:

  • 第1次帶參數執行用來定製系統: 定製系統的命令爲:
make menuconfig 

執行後會啓動一個配置菜單, 進去以後能夠根據你本身的須要增長或裁剪系統功能, 而後選擇保存, 全部的配置會被保存爲當前目錄下的 .config 文件.

執行界面就是這個樣子: 執行界面

也能夠經過 load 選項加載工具自帶的配置文件, 看看典型配置是什麼樣的.

  • 第2次不帶參數執行用來構建系統: 構建命令爲:
make 

會構建比較長的時間, 構建完成後能夠查看剛纔說過的 ./output/images/ 目錄, 剛好我剛剛完成一次對龍芯智龍開源開發板的根文件系統構建, 咱們能夠看看:

git@debian:/opt/github/pengphai-buildroot$ ls -al ./output 總用量 28 drwxr-xr-x 6 git git 4096 8月 6 06:51 . drwxr-xr-x 16 git git 4096 8月 6 06:51 .. drwxr-xr-x 54 git git 4096 8月 6 07:36 build drwxr-xr-x 5 git git 4096 8月 6 07:12 host drwxr-xr-x 2 git git 4096 8月 6 07:36 images lrwxrwxrwx 1 git git 81 8月 6 06:51 staging -> /opt/github/pengphai-buildroot/output/host/usr/mipsel-buildroot-linux-gnu/sysroot drwxr-xr-x 19 git git 4096 8月 6 07:36 target git@debian:/opt/github/pengphai-buildroot$ ls -al ./output/images 總用量 22956 drwxr-xr-x 2 git git 4096 8月 6 07:36 . drwxr-xr-x 6 git git 4096 8月 6 06:51 .. -rw------- 1 git git 23498112 8月 6 07:36 rootfs.yaffs2img git@debian:/opt/github/pengphai-buildroot$ 

3. 構建出一個內核和一個根文件系統

命令很簡單, 咱們以樹莓派2爲例, 直接使用工具自帶的配置文件, 命令以下:

pi@rpi /opt/github/buildroot $ sudo cp ./configs/raspberrypi2_defconfig ./config pi@rpi /opt/github/buildroot $ sudo make 

我是在樹莓派2上執行的構建, 因此應該會有一個漫長的構建過程

===補充說明, 剛發現樹莓派2的配置文件還有不少項沒配置, 須要用戶選擇, 後續我寫一個徹底配置好的, 這個例子只會讓新手疑惑

--結束

相關文章
相關標籤/搜索