HiFive Unleashedは、特に何もすることなくデフォルトで付属しているBuildroot Linuxを使ってLinuxを起動することができる。 しかし、これではあまり面白くないので、RISC-VのSDKを使って自分でLinuxをビルドし、カスタマイズするための環境を作ってみる。
RISC-V Linuxのカスタマイズを行うためには、SiFive社が提供しているFreedom-u-sdkを使用する。 このSDKはGitHub上で配布されており、HiFive Unleashedで動作セする64ビットLinuxをビルドする環境も入っている。
# リポジトリのすべてをダウンロードしてしまうととても重いので、最新のリリースのみダウンロードする。 git clone https://github.com/sifive/freedom-u-sdk --depth 1 -b hifiveu-2.0-alpha --recurse-submodules cd freedom-u-sdk unset LD_LIBRARY_PATH make -j$(nprocs)
必要に応じてMakeには並列数を挿入する。コンパイルにはしばらく時間がかかった。
ビルドが完了すると、マイクロSDカードにLinuxのイメージを書き込む。 マイクロSDカードを用意して、まずはフォーマットする。 マイクロSDカードをPCに差し込むと、まずは認識されているデバイスを確認する。
lsusb
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT ... sda 8:0 0 500G 0 disk └─sda1 8:1 0 500G 0 part / sdc 8:32 1 14.8G 0 disk ├─sdc1 8:33 1 31M 0 part /mnt/sdcard ├─sdc2 8:34 1 5.5G 0 part ├─sdc3 8:35 1 460.5K 0 part └─sdc4 8:36 1 38K 0 part
マイクロSDカードが/dev/sdc
に認識されていることが分かる。そこで、gdisk
を使ってSDカードの初期化を行う。
sudo gdisk /dev/sdc $ sudo gdisk /dev/sdc [sudo] password for msyksphinz: GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p # デフォルトのパーティション情報を表示。次にパーティションをすべて削除する。 Disk /dev/sdc: 30965760 sectors, 14.8 GiB Model: Mini SD Reader Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 81BDE1E5-C39D-4976-94A4-56C3AEA1E352 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 30965726 Partitions will be aligned on 4-sector boundaries Total free space is 19446682 sectors (9.3 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 65502 31.0 MiB 0700 Vfat Boot 2 264192 11718750 5.5 GiB 8300 root 3 1100 2020 460.5 KiB FFFF uboot 4 1024 1099 38.0 KiB FFFF uboot-env Command (? for help): d # パーティション2を削除 Partition number (1-4): 2 Command (? for help): d # パーティション3を削除 Partition number (1-4): 3 Command (? for help): d # パーティション4を削除 Partition number (1-4): 4 Command (? for help): o # すべてのパーティションの情報を削除 This option deletes all partitions and creates a new protective MBR. Proceed? (Y/N): Y # Yesを選択する Command (? for help): w # ディスクへパーティション情報を書き込む。 Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): Y OK; writing new GUID partition table (GPT) to /dev/sdc. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.
SDカードへのフォーマットが完了すると、次にLinuxの情報をSDカードに書き込む。
これはmake
コマンドで実行できる。
以下のようにして書き込んだ。。
sudo make DISK=/dev/sdc format-boot-loader
$ sudo make DISK=/dev/sdc format-boot-loader /sbin/sgdisk --clear \ --new=1:2048:65502 --change-name=1:"Vfat Boot" --typecode=1:EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 \ --new=2:264192:11718750 --change-name=2:root --typecode=2:0FC63DAF-8483-4772-8E79-3D69D8477DE4 \ --new=3:1100:2020 --change-name=3:uboot --typecode=3:5B193300-FC78-40CD-8002-E86C45580B47 \ --new=4:1024:1099 --change-name=4:uboot-env --typecode=4:a09354ac-cd63-11e8-9aff-70b3d592f0fa \ /dev/sdc Setting name! partNum is 0 Setting name! partNum is 1 Setting name! partNum is 2 Setting name! partNum is 3 Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. /sbin/partprobe dd if=/home/msyksphinz/work/riscv/freedom-u-sdk/work/HiFive_U-Boot/u-boot.bin of=/dev/sdc3 bs=4096 113+1 records in 113+1 records out 464973 bytes (465 kB, 454 KiB) copied, 0.310722 s, 1.5 MB/s dd if=/home/msyksphinz/work/riscv/freedom-u-sdk/work/hifive-unleashed-vfat.part of=/dev/sdc1 bs=4096 7931+1 records in 7931+1 records out 32488448 bytes (32 MB, 31 MiB) copied, 0.0255919 s, 1.3 GB/s
マイクロSDカードの構築が完了しました。 HiFive Unleashedのボードに差し込んで起動する。このとき、HiFive Unleashedのディップス一致を1011に設定する必要があった。
U-Boot 2018.09-gca05d26 (Apr 20 2019 - 01:40:29 +0900) DRAM: 2 GiB MMC: In: serial Out: serial Err: serial Net: gmac0 Hit any key to stop autoboot: 0 MMC_SPI: 0 at 0:1 hz 20000000 mode 0 Partition Map for MMC device 0 -- Partition Type: EFI Part Start LBA End LBA Name Attributes Type GUID ... ## Starting application at 0x80000000 ... bbl loader SIFIVE, INC. 5555555555555555555555555 5555 5555 5555 5555 5555 5555 5555 5555555555555555555555 5555 555555555555555555555555 5555 5555 5555 5555 5555 5555 5555555555555555555555555555 55555 55555 555555555 55555 55555 55555 55555 55555 5 55555 55555 55555 55555 55555 55555 55555 55555 55555 55555 55555 555555555 55555 5 SiFive RISC-V Core IP [ 0.000000] OF: fdt: Ignoring memory range 0x80000000 - 0x80200000 [ 0.000000] Linux version 4.19.0-sifive-1+ (msyksphinz@msyksphinz) (gcc version 8.3.0 (Buildroot 2019.02-07449-g4eddd28f99)) ... [ 2.080000] Run /init as init process [ 2.090000] mmc0: new SDHC card on SPI [ 2.100000] mmcblk0: mmc0:0000 SPCC 14.8 GiB [ 2.130000] mmcblk0: p1 p2 p3 p4 Starting syslogd: OK Starting klogd: OK Starting mdev... modprobe: can't change directory to '/lib/modules': No such file or directory Initializing random number generator... [ 3.020000] random: dd: uninitialized urandom read (512 bytes read) done. Starting network: [ 3.090000] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready udhcpc: started, v1.29.3 udhcpc: sending discover [ 6.240000] macb 10090000.ethernet eth0: link up (100/Full) [ 6.240000] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready udhcpc: sending discover udhcpc: sending select for 192.168.11.17 udhcpc: lease of 192.168.11.17 obtained, lease time 172800 deleting routers adding dns 192.168.11.1 OK Starting dropbear sshd: [ 6.540000] random: dropbear: uninitialized urandom read (32 bytes read) OK Welcome to Buildroot buildroot login: root Password: #
ログイン画面が現れた。ブート成功。