Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Raspberry Pi Zeroをストレージ無しで活用

Raspberry Pi Zeroをストレージ無しで活用

Avatar for Kenichiro MATOHARA

Kenichiro MATOHARA

May 14, 2022
Tweet

More Decks by Kenichiro MATOHARA

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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