Share
Embed
Raspberry Pi Zeroをストレージ無しで活用
Kenichiro MATOHARA
May 14, 2022
Transcript
27 slides
-
Raspberry Pi Zeroを Raspberry Pi Zeroを ストレージ無しで ストレージ無しで 活用 活用
Kenichiro Matohara(matoken) <[email protected]> 1 / 27 -
USBホスト起動 USBホスト起動 OSを導入したUSBストレージから起動 Raspberry Pi 3 model B以降はUSB起動も可能 3B+以降は標準でUSB起動OK 対応機種
Raspberry Pi 3B, 3B+, 3A+, and 2B v1.2(4?) 3BはOTP(One Time Programmable)メモリの設定が必要 https://www.raspberrypi.com/documentation/computers/ pi.html#usb-host-boot-mode 8 / 27 -
USBデバイス起動※今回のネタ USBデバイス起動※今回のネタ ホストPCからUSBデバイス経由でブートコードを転送して起動 対応デバイス Raspberry Pi Compute Module, Compute Module
3, Raspb Zero, Zero W, A, A+, and 3A+(4?) https://www.raspberrypi.com/documentation/computers/ pi.html#usb-device-boot-mode 9 / 27 -
rpibootの用意 rpibootの用意 $ sudo apt install git libusb-1.0-0-dev $ git
clone https://github.com/raspberrypi/usbboot $ cd usbboot $ make $ sudo ./rpiboot raspberrypi/usbboot: Raspberry Pi USB booting code, moved from tools repository 11 / 27 -
PiZero1.2を接続した状態で実行 PiZero1.2を接続した状態で実行 dmesg $ sudo ./rpiboot RPIBOOT: build-date May 8
2022 version 20220504~214218 5e0ae34d Waiting for BCM2835/6/7/2711... Loading embedded: bootcode.bin Sending bootcode.bin Successful read 4 bytes Waiting for BCM2835/6/7/2711... Loading embedded: bootcode.bin Second stage boot server Loading embedded: start.elf File read: start.elf Second stage boot server done [ +0.000798] usb 2-2: New USB device found, idVendor=0a5c, idProduct=2764, bcdDevice= 0.00 [ +0.000014] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=1 [ +0.000007] usb 2-2: Product: BCM2710 Boot [ +0.000005] usb 2-2: Manufacturer: Broadcom [ +0.000005] usb 2-2: SerialNumber: Broadcom [May13 23:02] usb 2-2: USB disconnect, device number 124 12 / 27 -
microSD接続時 microSD接続時 [ +0.947679] usb 2-2: new high-speed USB device
number 122 using xhci_hcd [ +0.148916] usb 2-2: New USB device found, idVendor=0a5c, idProduct=0001, bcdDevice= 0.01 [ +0.000019] usb 2-2: New USB device strings: Mfr=2, Product=1, SerialNumber=3 [ +0.000001] usb 2-2: Product: Compute Module [ +0.000002] usb 2-2: Manufacturer: Raspberry Pi [ +0.000001] usb 2-2: SerialNumber: e96d0f1a [ +0.575814] usb-storage 2-2:1.0: USB Mass Storage device detected [ +0.000232] scsi host6: usb-storage 2-2:1.0 [ +0.000114] usbcore: registered new interface driver usb-storage [ +0.006272] usbcore: registered new interface driver uas [ +0.997140] scsi 6:0:0:0: Direct-Access RPi-MSD- 0001 PQ: 0 ANSI: 2 [ +0.000374] sd 6:0:0:0: Attached scsi generic sg2 type 0 [ +0.000206] sd 6:0:0:0: [sdb] 31422464 512-byte logical blocks: (16.1 GB/15.0 GiB) [ +0.000141] sd 6:0:0:0: [sdb] Write Protect is off [ +0.000003] sd 6:0:0:0: [sdb] Mode Sense: 0f 00 00 00 [ +0.000131] sd 6:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO [ +0.001797] sdb: sdb1 [ +0.001095] sd 6:0:0:0: [sdb] Attached SCSI removable disk 13 / 27 -
usbbootguiというものも usbbootguiというものも raspberrypi/usbbootgui: GUI for booting a Raspberry Pi device
like Pi Zero or compute module as a device 14 / 27 -
OSイメージをBuildrootで作成 OSイメージをBuildrootで作成 RAM 256MB〜なので標準のOSは大きすぎる Buildrootで作成することに The maximum size for
a ramdisk file is 96MB. Buildroot - Making Embedded Linux Easy https://www.raspberrypi.com/documentation/compute pi.html#configuration-properties-in-config-txt 15 / 27 -
Buildroot環境用意 Buildroot環境用意 3ヶ月毎のリリースなのでそろそろ2022-05が出る? $ wget2 https://buildroot.org/downloads/buildroot-2022.02.1.tar.xz \ > https://buildroot.org/downloads/buildroot-2022.02.1.tar.xz.sign
$ wget2 https://github.com/pweaver/buildroot/raw/master/buildroot_pubkey.gpg $ gpg --import ./buildroot_pubkey.gpg gpg: /home/ubuntu/.gnupg/trustdb.gpg: trustdb created gpg: key B025BA8B59C36319: public key "Peter Korsgaard <[email protected]>" imported gpg: Total number processed: 1 gpg: imported: 1 $ gpg --verify ./buildroot-2022.02.1.tar.xz.sign gpg: Signature made Mon 11 Apr 2022 09:51:18 PM UTC gpg: using DSA key AB07D806D2CE741FB886EE50B025BA8B59C36319 gpg: Good signature from "Peter Korsgaard <[email protected]>" [unknown] gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: AB07 D806 D2CE 741F B886 EE50 B025 BA8B 59C3 6319 gpg: WARNING: not a detached signature; file './buildroot-2022.02.1.tar.xz' was NOT verified! $ tar tvf ./buildroot-2022.02.1.tar.xz | lv $ tar xf ./buildroot-2022.02.1.tar.xz $ cd buildroot-2022.02.1 16 / 27 -
Raspberry Piのconfig Raspberry Piのconfig $ make list-defconfigs | lv $
make list-defconfigs | grep rasp raspberrypi0_defconfig - Build for raspberrypi0 raspberrypi0w_defconfig - Build for raspberrypi0w raspberrypi2_defconfig - Build for raspberrypi2 raspberrypi3_64_defconfig - Build for raspberrypi3_64 raspberrypi3_defconfig - Build for raspberrypi3 raspberrypi3_qt5we_defconfig - Build for raspberrypi3_qt5we raspberrypi4_64_defconfig - Build for raspberrypi4_64 raspberrypi4_defconfig - Build for raspberrypi4 raspberrypi_defconfig - Build for raspberrypi raspberrypicm4io_64_defconfig - Build for raspberrypicm4io_64 raspberrypicm4io_defconfig - Build for raspberrypicm4io raspberrypizero2w_defconfig - Build for raspberrypizero2w 17 / 27 -
build build とりあえずPi0の既定値 $ time make raspberrypi0_defconfig $ make menuconfig
$ time make -j$( nproc ) 18 / 27 -
初回ビルド時間 初回ビルド時間 手元の端末(Intel i5-3320M)での初回ビルド時間 real 439m1.278s Oracle無料VPS(aarch64 4core)での初回ビルド時間 real 53m12.657s
初回はsourceの取得&すべてのbuildで時間が掛かる 19 / 27 -
images images sdcard.img をSD cardに書き込むと起動するはず 今回の環境ではVPSでbuildして成果物だけ貰ってくるのが良さそう $ du -hs output/images/*
28K output/images/bcm2708-rpi-zero.dtb 8.8M output/images/boot.vfat 62M output/images/rootfs.ext2 0 output/images/rootfs.ext4 3.0M output/images/rpi-firmware 71M output/images/sdcard.img 5.8M output/images/zImage 20 / 27 -
RAMFS利用 RAMFS利用 make menuconfig等で以下のあたりを設定 Filesystem Images → initial RAM filesystem
linked into linux kernel (BR2_TARGET_ROOTFS_INITRAMFS) cpio the root filesystem (for use as an initial RAM filesystem) (BR2_TARGET_ROOTFS_CPIO) xz (BR2_TARGET_ROOTFS_CPIO_XZ) $ time make -j$( nproc ) 21 / 27 -
boot dirを作成してファイルをcp boot dirを作成してファイルをcp $ ls boot bcm2708-rpi-zero.dtb cmdline.txt rootfs.cpio.xz
boot.vfat config.txt start.elf bootcode.bin fixup.dat zImage 22 / 27 -
BuildrootのイメージでUSB起動 BuildrootのイメージでUSB起動 USBと通信用にUARTを繋いで 起動 HostPC -- USB --- Pi0 +------
UART ----+ $ sudo ./rpiboot -d boot 23 / 27 -
USB-GadgetでSerial/Ethernet利用 USB-GadgetでSerial/Ethernet利用 USB-GadgetでSerialやEthernetを使うとUSBケーブル1本だ けでOKになるはず 未解決 dummy_hcd では読み込めるので恐らくPi0のHostUSB設定がおか しい # modprobe
dwc2 # modprobe g_ether [ 58.491922] udc-core: couldn't find an available UDC - added [g_ether] to list of pending d 25 / 27 -
まとめ まとめ 本来はOSインストール向けだと思われるUSBデバイス起動 小さめのイメージを流し込んで遊ぶのにも使えそう HostPC(PiでもOK)に繋がる環境でストレージ無しでサイネージな どにも使えそう データの保存がネック(PiZeroWやmicroSDなら) USB Gadgetを使いたい SerialやEthernet等が使えるようになる
Buildrootとkernelをもう少し探索…… PiZero1.3+ではWebCamにすることもできそう 26 / 27 -
奥付 奥付 発表 発表者 利用ソフトウェア ライセンス 小江戸らぐ 5月のオフな集まり(第238回) Kenichiro Matohara(matoken)
Asciidoctor Reveal.js CC BY 4.0 27 / 27