LoginSignup
4
3

More than 5 years have passed since last update.

[メモ] Raspberry Pi カーネルビルド(Bash On Ubuntu On Windows10)

Posted at

概要

  • Win10上のbashで、ラズパイのカーネルビルドメモ
  • 参考: Kernel building の Cross-Build

環境

  • Windows 10 - 1703 (開発者モード)
  • Bash On Ubuntu On Windows = Windows Subsystem for Linux(WSL)

手順

  1. Bash On Ubuntu On Windows を導入

    • 開発者モードにする
    • Windowsの機能追加で、Windows Subsystem for Linux (WSL)をインストール
    • C:\Windows\System32\bash.exe を実行。=> 必要なファイルがダウンロードされるまで、待つ。
    • ユーザ作成 | (例) ユーザ名:pi パスワード:raspberry
  2. 初期設定

    コマンドラインで実行
    # パスワード入力なしで、sudo実行
    echo "$USER ALL=(ALL) NOPASSWD: ALL " | sudo tee /etc/sudoers.d/${USER}-nopasswd
    
    # パッケージ更新と、カーネルビルドに必要なパッケージのインストール
    # echo 'Acquire::http::Proxy "http://apt-cache-server:3142";' | sudo tee /etc/apt/apt.conf.d/02proxy
    sudo sh -c 'apt update && apt upgrade -y && apt install -y build-essential git libncurses5-dev bc htop byobu'
    
    # ssh server
    sudo dpkg-reconfigure openssh-server
    sudo sed  -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
    sudo systemctl restart sshd
    
    # TimeZone設定
    # sudo dpkg-reconfigure tzdata
    
    # ツール取得
    git clone --depth=1 --quiet https://github.com/raspberrypi/tools ${HOME}/tools
    
    # aliasとPATHの設定
    #  alias b1='KERNEL=kernel  ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make'
    #  alias b2='KERNEL=kernel7 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make'
    #  alias b1cnf='b1 bcmrpi_defconfig'
    #  alias b2cnf='b2 bcm2709_defconfig'
    #  PATH=${HOME}/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:$PATH
    echo -e "alias b1='KERNEL=kernel  ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make'\n""alias b2='KERNEL=kernel7 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- make'\n""alias b1cnf='b1 bcmrpi_defconfig'\n""alias b2cnf='b2 bcm2709_defconfig'\n"PATH=${HOME}/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:'$PATH' >> ${HOME}/.bashrc
    source ${HOME}/.bashrc
    
  3. カーネルソース取得
    linux-rpi-4.9.y とかそういうフォルダができる。

    コマンドラインで実行
    ##特定のCOMMIT_IDを指定するか
    # 例: 2017-07-05-raspbian-jessieのカーネル
    # COMMIT_ID=be2540e540f5442d7b372208787fb64100af0c54
    
    ## rpi-4.9.yの最新
    COMMIT_ID=rpi-4.9.y
    
    wget https://github.com/raspberrypi/linux/archive/${COMMIT_ID}.tar.gz -O -  | tar zxf - -C ${HOME}
    cd linux-${COMMIT_ID}
    
  4. Makefile 編集。4行目 EXTRAVERSION = -mybuild とかする

  5. カーネルビルド

    1. Raspberry Pi 1/Zero向け:

      RPi_0/1
      b1cnf && time b1 zImage modules dtbs -j9
      #
      b1 INSTALL_MOD_PATH=${HOME}/built/rootfs modules_install
      #
      KERNEL=kernel
      BOOTDIR=${HOME}/built/boot
      mkdir -p ${BOOTDIR}/overlays/
      cp arch/arm/boot/zImage ${BOOTDIR}/$KERNEL.img
      cp arch/arm/boot/dts/*.dtb ${BOOTDIR}
      cp arch/arm/boot/dts/overlays/*.dtb* ${BOOTDIR}/overlays/
      cp arch/arm/boot/dts/overlays/README ${BOOTDIR}/overlays/
      
    2. Raspberry Pi 2/3向け:

      RPi_2/3
      b2cnf && time b2 zImage modules dtbs -j9
      #
      b2 INSTALL_MOD_PATH=${HOME}/built/rootfs modules_install
      #
      KERNEL=kernel7
      BOOTDIR=${HOME}/built/boot
      mkdir -p ${BOOTDIR}/overlays/
      cp arch/arm/boot/zImage ${BOOTDIR}/$KERNEL.img
      cp arch/arm/boot/dts/*.dtb ${BOOTDIR}
      cp arch/arm/boot/dts/overlays/*.dtb* ${BOOTDIR}/overlays/
      cp arch/arm/boot/dts/overlays/README ${BOOTDIR}/overlays/
      
  6. ${HOME}/builtに生成物があるので、rootfsを、ext4のパーティションへ、bootをFATへ、うまくコピーして起動。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3