ようやく Debian13/trixie がリリースされましたね。そこで古い arm64 機(OrangePi PC 2)があるので腕試しにamd64機を作業PCにして Debian13 for arm64を sd カードにインストールしてみました。なお対象機に加え、SDカードリーダとUSBシリアルコンバーターが必要です。
以下作業内容です。まず初めに必要なパッケージを作業用PCにインストールしておきます。
armhfと同じくメインラインカーネルでのCPUサポートとdtbさえあれば、ほかのarm64機でもDebian13をインストールできるかもしれませんね。今回は以上です。それでは。
以下作業内容です。まず初めに必要なパッケージを作業用PCにインストールしておきます。
sudo apt-get install git bison flex gcc-aarch64-linux-gnu python3-setuptools \
swig python3-dev libssl-dev build-essential device-tree-compiler \
gcc-or1k-elf u-boot-tools qemu-utils qemu-user-static
gcc-or1k-elfはOpen RISC 1000用のコンパイラで今回の OrangePi PC 2 にのみ必要なパッケージです。
つづいて OrangePi PC 2 用のu-bootをクロスコンパイルしますが、trusted-firmware-a と crust が必要になるので、こちらもクロスコンパイルしておきます。
# trusted-firmware-a のビルド
cd /usr/src
sudo mkdir TF-A
sudo chown YourUID:YourGID TF-A
cd /usr/src/TF-A
git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git
cd trusted-firmware-a
make CROSS_COMPILE=aarch64-linux-gnu- PLAT=sun50i_a64 DEBUG=0 bl31
# 成果物
/usr/src/TF-A/trusted-firmware-a/build/sun50i_a64/release/bl31.bin
# crust のビルド
cd /usr/src
sudo mkdir crust
sudo chown YourUID:YourGID crust
cd crust
git clone https://github.com/crust-firmware/crust
cd crust
export CROSS_COMPILE=or1k-elf-
make orangepi_pc2_defconfig
make scp
# 成果物
/usr/src/crust/crust/build/scp/scp.bin
# u-boot のビルド
cd /usr/src
sudo mkdir -p /usr/src/u-boot/cross-arm64
sudo chown YourUID:YourGID u-boot
cd u-boot/cross-arm64
git clone https://source.denx.de/u-boot/u-boot.git
cd u-boot
git checkout v2025.07
export BL31=/usr/src/TF-A/trusted-firmware-a/build/sun50i_a64/release/bl31.bin
export SCP=/usr/src/crust/crust/build/scp/scp.bin
mkdir ../u-boot-build
make CROSS_COMPILE=aarch64-linux-gnu- \
O=../u-boot-build/ \
orangepi_pc2_defconfig
cd ../u-boot-build
make CROSS_COMPILE=aarch64-linux-gnu- -j20
# 成果物
/usr/src/u-boot/cross-arm64/u-boot-build/u-boot-sunxi-with-spl.bin
つづいてDebootstrap させるSDカードを作成していきます。
# 作業用PCでSDカードのパーティションをテーブルを消去(カードリーダ要)
TARGET=sdb
sudo dd if=/dev/zero of=/dev/${TARGET} bs=1024k count=64
sync
# on 作業用PCにてMicroSD card に dos パーテションを作成
sudo fdisk /dev/${TARGET}
#以下コマンドで 先頭1Gに linux partition を作成
o
n
# enter
# enter
# enter
+1G
#残りをパーティション タイプ linux にしておく
n
# enter
# enter
# enter
# enter
# 書き込み
w
# パーティションをフォーマット
sudo mkfs -t ext4 /dev/${TARGET}1
sudo mkfs -t ext4 /dev/${TARGET}2
# ブートローダ(u-boot)をSDカードに書き込み
sudo dd if=/usr/src/u-boot/cross-arm64/u-boot-build/u-boot-sunxi-with-spl.bin of=/dev/${TARGET} bs=1024 seek=8
ここまでで u-bootでブート可能なsdカードはできていますので、debootstrapでDebian13をインストールしていきます。
# 作業対象カードをマウント
sudo mount /dev/${TARGET}2 /mnt
sudo mkdir /mnt/boot
sudo mount /dev/${TARGET}1 /mnt/boot
# debootstrap
cd /mnt
sudo debootstrap --arch arm64 --foreign trixie . https://ftp.riken.jp/Linux/debian/debian
sudo mount --bind /dev dev/
sudo mount --bind /proc proc/
sudo mount --bind /sys sys/
sudo chroot . debootstrap/debootstrap --second-stage
debootstrap で基本パッケージのインストールが済んだので、他に必要なモノをインストールし、そのほか設定を書き込んでいきます。
sudo chroot .
apt-get install locales sudo
dpkg-reconfigure locales
# add below:
# en_US.UTF-8 UTF-8
# ja_JP.UTF-8 UTF-8
apt-get install linux-image-arm64 flash-kernel dbus
# エラーが出ますがあとでinitrdを更新するので無視してください。
# インストール対象機種のdtbを探す
find /usr/lib/linux-image* | grep -i orangepi
# 見つかったらコピーして環境変数にセットしておく
cd ~
cp /usr/lib/linux-image-6.12.38+deb13-arm64/allwinner/sun50i-h5-orangepi-pc2.dtb .
dtname=sun50i-h5-orangepi-pc2
# dtb から dtsを取り出す
dtc -I dtb -O dts -o ${dtname}.dts ${dtname}.dtb
# dts から Machine 名を取得し環境変数にセットしておく
machine=`cat ${dtname}.dts | grep model | awk -F'"' '{print $2}'`
# flash-kernel db に対象機を追加
sudo su
tee /etc/flash-kernel/db <<EOF >/dev/null
Machine: ${machine}
Kernel-Flavors: arm64
Boot-Script-Path: /boot/boot.scr
DTB-Id: allwinner/${dtname}.dtb
U-Boot-Script-Name: bootscr.uboot-generic
Required-Packages: u-boot-tools
EOF
echo ${machine} >> /etc/flash-kernel/machine
flash-kernel
update-initramfs -u
ここで一旦 chroot から抜け fstabを作成し、ホスト名の設定などを行います。
export rootdev=`sudo blkid | grep ${TARGET}2 | awk -F'"' '{print $2}'`
export bootdev=`sudo blkid | grep ${TARGET}1 | awk -F'"' '{print $2}'`
sudo tee /mnt/etc/fstab <<EOF >/dev/null
UUID=${rootdev} / ext4 defaults 0 0
UUID=${bootdev} /boot ext4 defaults 0 0
EOF
# ホスト名を設定
sudo tee /mnt/etc/hostname <<EOF >/dev/null
opipc2
EOF
# /etc/hostsにエントリーを追加
sudo tee -a /mnt/etc/hosts <<EOF >/dev/null
127.0.1.1 opipc2
EOF
ホスト名の設定などがすんだら、再びchrootしてパスワードの設定や追加のパッケージのインストールなどを行います。
sudo chroot /mnt # chang root password passwd # create an user adduser --uid 1000 user1000 apt-get install dbus ntpsec-ntpdate dpkg-reconfigure tzdata cat > /etc/network/interfaces <<EOF # interfaces(5) file used by ifup(8) and ifdown(8) # Include files from /etc/network/interfaces.d: source /etc/network/interfaces.d/* auto lo iface lo inet loopback auto end0 iface end0 inet dhcp EOFこれで作業PCでの作業はすんだので、chrootを抜け umountします。
exit sync cd /mnt sudo umount dev/ sudo umount sys/ sudo umount proc/ cd sudo umount /mnt/boot sudo umount /mnt出来上がったカードを実機に挿して起動し以下の作業を行ってください。
# 初回のみ シリアルコンソールにて起動時になにかキーをおしてプロンプトに入り、 # 以下のコマンドで起動 setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 boot # 手動で時刻を合わせる場合(aptは時刻があっていないとupdate/install できないため) date -s "08/10 12:34 2025" # 自動で時刻を合わせる場合 ntpdate ntp.nict.jp # ルートデバイスを実機に合わせるため initrd を更新 update-initramfs -u作業はこれで完了です。次回以降は単に再起動させるだけでブートできるはずです。
armhfと同じくメインラインカーネルでのCPUサポートとdtbさえあれば、ほかのarm64機でもDebian13をインストールできるかもしれませんね。今回は以上です。それでは。
コメント
コメントを投稿