SSブログ

Linuxのコンパイル [電子工作]

Raspberry Pi Zeroに乗せるLinuxカーネルのコンパイルをしてみました。ubuntu-16.04.2-serverをHyper-Vで動かします。SSHサーバの設定で戸惑いましたが、無事にtera-termからsshでつながるようになりました。
まず最初に必要なツールをインストールします。
root@kuro:~$ sudo su -
[sudo] password for kuro:
root@kuro:~#
root@kuro:~$ apt-get update
root@kuro:~$ apt-get install make gcc git libncurses-dev bc unzip g++ genromfs subversion texinfo python
つぎにworkディレクトリを作成し、buildrootをダウンロードして展開します。
root@kuro:~$ mkdir work
root@kuro:~$ cd work
root@kuro:~/work$ wget https://buildroot.uclibc.org/downloads/buildroot-2017.02.2.tar.gz
root@kuro:~/work$ tar xvf buildroot-2017.02.2.tar.gz
root@kuro:~/work$ cd buildroot-2017.02.2

カーネルのバージョンをbuildrootのデフォルトのバージョンとは異なるバージョンでコンパイルするため、buildrootの設定ファイルをコピーして使用します。(編集内容は変更のあるところを抜き出して書いています)
root@kuro:~/work/buildroot-2017.02.2$ cp  configs/raspberrypi0_defconfig configs/raspberrypi1_defconfig
root@kuro:~/work/buildroot-2017.02.2$ cp -r board/raspberrypi0 board/raspberrypi1
root@kuro:~/work/buildroot-2017.02.2$ vi configs/raspberrypi1_defconfig
-----
BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi1/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi1/post-image.sh"
-----
root@kuro:~/work/buildroot-2017.02.2# mv board/raspberrypi0/genimage-raspberrypi.cfg board/raspberrypi1/genimage-raspberrypi1.cfg
root@kuro:~/work/buildroot-2017.02.2$ vi board/raspberrypi0/genimage-raspberrypi1.cfg
-----
image boot.vfat {
  vfat {
    files = {
      "bcm2708-rpi-b-plus.dtb",
      "rpi-firmware/bootcode.bin",
      "rpi-firmware/cmdline.txt",
      "rpi-firmware/config.txt",
      "rpi-firmware/fixup.dat",
      "rpi-firmware/start.elf",
      "zImage"
    }
  }
  size = 256M
}
-----

コンパイルするための設定をおこないます。
root@kuro:~/work/buildroot-2017.02.2$ make raspberrypi1_defconfig
root@kuro:~/work/buildroot-2017.02.2$ make menuconfig
-----
Toolchain  --->
 custom toolchain vendor name
  kuro
 Custom kernel headers series (4.4.x)  --->
  (X) 4.9.x
 [*] Enable RPC support
 [*] Enable WCHAR support
System configuration  --->
 System hostname
  kuro
 System banner
  Welcome to Kuro
 Root password
  root123
 Run a getty (login prompt) after boot  --->
  (console) TTY port
   ttyAMA0
  Baudrate (keep kernel default)  --->
   115200
 ()  Root filesystem overlay directories
  rootfs-overlay
Kernel  --->
 Custom repository version
  rpi-4.9.y
 Linux Kernel Tools  --->
  [*] gpio
Target packages  --->
 Audio and video applications  --->
 [*] alsa-utils  --->
  [*]   alsactl (NEW)
  [*]   alsamixer (NEW)
  [*]   aplay/arecord
 [*] ffmpeg  --->
  [*]   Build ffmpeg (the command line application) (NEW)
  [*]   Enable input devices (NEW)
  [*]   Enable output devices (NEW)
  [*]   Build libavresample
 [*] flac
 [*] lame
 [*] mpd  --->
  [*]   libsamplerate
  [*]   libsoxr
  [*]   dsd
  [*]   ffmpeg
  [*]   flac
  [*]   lame
 [*] mpd-mpc
 [*] mplayer
 [*] Build and install mplayer (NEW)
Filesystem and flash utilities  --->
 [*] nfs-utils
  [*]   rpc.lockd
Interpreter languages and scripting  --->
 [*] python
Networking applications  --->
 [*] bluez-utils
  [*]   audio support
  [*]   USB support
  [*]   GATT support
 [*] dropbear
 [*] openssh
Filesystem images  --->
 [*] initial RAM filesystem linked into linux kernel
 [*] romfs root filesystem
-----

一部設定を書き換えてバックアップしておきます。こうすることでmake menuconfigの設定を省くことができます。
root@kuro:~/work/buildroot-2017.02.2$ vi .config
-----
BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS=y
-----
root@kuro:~/work/buildroot-2017.02.2$ cp .config configs/raspberrypi1_defconfig

次にLinuxカーネルのコンパイル設定を行います。
root@kuro:~/work/buildroot-2017.02.2$ make linux-menuconfig
-----
General setup  --->
 Default hostname
  kuro
 [ ] Support for paging of anonymous memory (swap)
 [*]   Support initial ramdisks compressed using gzip
 [ ]   Support initial ramdisks compressed using bzip2
 [ ]   Support initial ramdisks compressed using LZMA
 [ ]   Support initial ramdisks compressed using XZ
 [ ]   Support initial ramdisks compressed using LZO
 [ ]   Support initial ramdisks compressed using LZ4
Boot options  --->
 (console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ex
  console=ttyAMA0,115200
[*] Networking support  --->
 Networking options  --->
  [ ] Network packet filtering framework (Netfilter)  ----
  < > Asynchronous Transfer Mode (ATM)
  < > Layer Two Tunneling Protocol (L2TP)  ----
  < > 802.1d Ethernet Bridging
  < > 802.1Q/802.1ad VLAN Support
  < > Appletalk protocol support
  < > Open vSwitch
  [ ] MultiProtocol Label Switching  ----
 [ ]   Amateur Radio support  ----
 < >   CAN bus subsystem support  ----
 < >   WiMAX Wireless Broadband support  ----
 < >   RF switch subsystem support  ----
 < >   Plan 9 Resource Sharing Support (9P2000)  ----
 < >   NFC subsystem support  ----
Device Drivers  --->
 [ ] Multiple devices driver support (RAID and LVM)  ----
 [*] Network device support  --->
  < >     Bonding driver support
  < >     Dummy net driver support
  < >     MAC-VLAN support
  < >     IP-VLAN support
  < >     Virtual eXtensible Local Area Network (VXLAN)
  < >     Universal TUN/TAP device driver support
  < >     Virtual ethernet pair device
  < >   PPP (point-to-point protocol) support
  < >   SLIP (serial line) support
  < >   IEEE 802.15.4 drivers  ----
  Multimedia support  --->
  [ ]   Analog TV support
  [ ]   Digital TV support
  [ ]   AM/FM radio receivers/transmitters support
 [*] USB support  --->
  < >     Synopsis DWC host support
  < >     USB Printer support
  < >       Realtek Card Reader support
  < >       Datafab Compact Flash Reader support
  < >       Freecom USB/ATAPI Bridge support
  < >       ISD-200 USB/ATA Bridge support
  < >       USBAT/USBAT02-based storage support
  < >       SanDisk SDDR-09 (and other SmartMedia, including DPCM) support
  < >       SanDisk SDDR-55 SmartMedia support
  < >       Lexar Jumpshot Compact Flash Reader
  < >       Olympus MAUSB-10/Fuji DPC-R1 support
  < >       Support OneTouch Button on Maxtor Hard Drives
  < >       Support for Rio Karma music player
  < >       SAT emulation on Cypress USB/ATA Bridge with ATACB
  < >       USB ENE card reader support
  < >     USB Mustek MDC800 Digital Camera support
  < >     Microtek X6USB scanner support
  < >   DesignWare USB2 DRD Core Support
  < >   ADU devices from Ontrak Control Systems
  < >   USB 7-Segment LED Display
  < >   USB Diamond Rio500 support
  < >   USB Lego Infrared Tower support
  < >   USB LCD driver support
  < >   USB LED driver support
  < >   Cypress CY7C63xxx USB driver support
  < >   Cypress USB thermometer driver support
  < >   Siemens ID USB Mouse Fingerprint sensor support
  < >   Elan PCMCIA CardBus Adapter USB Client
  < >   Apple Cinema Display support
  < >   USB LD driver
  < >   PlayStation 2 Trance Vibrator driver support
  < >   IO Warrior driver support
  < >   USB testing driver
  < >   iSight firmware loading support
  < >   USB YUREX driver support
  < >   USB Gadget Support  ----
 < > Industrial I/O support  ----
-----

buildrootと同様の設定をバックアップしておきます。
root@kuro:~/work/buildroot-2017.02.2$ cp output/build/linux-rpi-4.9.y/.config linux_config

必要なディレクトリを作成します。
root@kuro:~/work/buildroot-2017.02.2$ mkdir rootfs-overlay

コンパイルします。
root@kuro:~/work/buildroot-2017.02.2$ make -j40

ビルドが終わったら必要なファイルをコピーするディレクトリを作成します。
root@kuro:~/work/buildroot-2017.02.2$ make -j40
root@kuro:~/work/buildroot-2017.02.2$ cd ..
root@kuro:~/work$ mkdir image
root@kuro:~/work$ cd image/

コピーします。
cp ../buildroot-2017.02.2/output/images/zImage .
cp ../buildroot-2017.02.2/output/images/bcm2708-rpi-b-plus.dtb .
cp -r ../buildroot-2017.02.2/output/images/rpi-firmware/* .
cp ../buildroot-2017.02.2/output/images/rootfs.romfs .

設定ファイルを編集します。
root@kuro:~/work/image$ vi cmdline.txt
-----
console=ttyAMA0,115200
-----
root@kuro:~/work/image$ vi config.txt
-----
kernel=zImage

#initramfs rootfs.cpio.gz

disable_overscan=1

# gpu_mem_256=100
# gpu_mem_512=100
# gpu_mem_1024=100


ファイルをwindowsへもっていき(WinScpなど)FATでフォーマットしたSDカードにファイルをコピーしておしまいです。
nice!(0)  コメント(0)  トラックバック(0) 

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。