💬

Yocto Linux を Raspberry Pi3 で動かしてオレオレゲーム機を作りたい

2024/05/01に公開

Background

ここ最近 Windows や Linux をベースにした携帯ゲーム機が増えている。特に中国メーカーからは小さめのゲーム機も出ているので、それらに自分のビルドした Linux が動かせたりしないかと思ったりするので、まずは Raspberry Pi で練習してみたい。

用意したもの

やること

基本は以下の記載の通り進めていく

Yocto Linux のビルド

パッケージなどをインストールする

(※libegl1-mesa は現在存在しないようだ)

$ sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libsdl1.2-dev python3-subunit mesa-common-dev zstd liblz4-tool file locales libacl1
$ sudo locale-gen en_US.UTF-8

poky を clone

ここでは nanbield ブランチを利用

$ git clone git://git.yoctoproject.org/poky
$ cd poky
$ git checkout -t origin/nanbield -b my-nanbield

Raspberry Pi BSP および OpenEmbedded BSP をクローン

$ git clone -b nanbield git://git.yoctoproject.org/meta-raspberrypi
$ git clone -b nanbield git://git.openembedded.org/meta-openembedded

ビルド環境設定

$ source oe-init-build-env pi-build

bblayers.conf の BBLAYERS に先程クローンしたフォルダを追加

bblayers.conf
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  /home/tomoki/poky/meta \
  /home/tomoki/poky/meta-poky \
  /home/tomoki/poky/meta-yocto-bsp \
  /home/tomoki/poky/meta-raspberrypi \
  /home/tomoki/poky/meta-openembedded/meta-oe \
  "

local.conf のターゲットマシンを変更し、 UART も有効化する。

local.conf
MACHINE ?= "raspberrypi3-64"
ENABLE_UART = "1"
bitbake core-image-minimal

エミュレータでの確認

TBD, runqemu できるはずだけど以下のエラーで失敗している。

$ runqemu 
runqemu - INFO - Running bitbake -e  ...
ls: cannot access '/home/tomoki/poky/pi-build/tmp/deploy/images/raspberrypi3-64/*.qemuboot.conf': No such file or directory
runqemu - ERROR - Command 'ls -t /home/tomoki/poky/pi-build/tmp/deploy/images/raspberrypi3-64/*.qemuboot.conf' returned non-zero exit status 2.
runqemu - INFO - Cleaning up
runqemu - INFO - Host uptime: 13343.51

MicroSD カードへの書き込み

書き込みに必要な bmap-tools をインストールし、

$ sudo apt install bmap-tools

gparted などで microSD カードがどの sdX かを確認し、 umount

$ sudo umount /dev/sdc1
$ sudo umount /dev/sdc2
$ sudo bmaptool copy tmp/deploy/images/raspberrypi3-64/core-image-minimal-raspberrypi3-64.rootfs.wic.bz2 /dev/sdX

UART 接続

手元の Ubuntu 24.04 では UART は /dev/ttyUSB0 として認識されている。

$ ls -al /dev
crw-rw----   1 root   dialout 188,   0 May  1 18:34 ttyUSB0

minicom をインストールする。

$ sudo apt install minicom

ユーザを dialout グループにいれる。 (参考: [小ネタ]Ubuntu でttyUSB0(USBシリアル変換)が権限関連で使えない場合の対処方法 #Ubuntu - Qiita)

$ sudo adduser $USER dialout
$ groups $USER
tomoki : tomoki adm tty dialout cdrom sudo dip plugdev users lpadmin
$ minicom -D /dev/ttyUSB0

Raspberry Pi の電源を抜き差しして以下のようなログが出たら成功。

[    0.000000] Booting Linux on physical CPU 0x0000000000 [0x410fd034]
[    0.000000] Linux version 6.1.61-v8 (oe-user@oe-host) (aarch64-poky-linux-gcc (GCC) 13.2.0, GNU ld (GNU Binutils) 2.41.0.20231213) #1 SMP PREEMPT Thu Nov  9 14:54:02 UTC 2023
[    0.000000] random: crng init done
[    0.000000] Machine model: Raspberry Pi 3 Model B Plus Rev 1.3
[    0.000000] efi: UEFI not found.
[    0.000000] Reserved memory: created CMA memory pool at 0x000000001ec00000, size 256 MiB
[    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x000000003b3fffff]
[    0.000000]   DMA32    empty
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000003b3fffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000003b3fffff]
[    0.000000] On node 0, zone DMA: 19456 pages in unavailable ranges
[    0.000000] percpu: Embedded 28 pages/cpu s75816 r8192 d30680 u114688
[    0.000000] Detected VIPT I-cache on CPU0
[    0.000000] CPU features: kernel page table isolation forced ON by KASLR
[    0.000000] CPU features: detected: Kernel page table isolation (KPTI)
[    0.000000] CPU features: detected: ARM erratum 843419
[    0.000000] CPU features: detected: ARM erratum 845719
[    0.000000] alternatives: applying boot alternatives
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 238896
[    0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=1 snd_bcm2835.enable_headphones=0 snd_bcm2835.enable_headphones=1 snd_bcm2835.enable_hdmi=1 clk_ignore_unused video=Composite-1:720x480@60i vc_mem.mt
[    0.000000] Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes, linear)
[    0.000000] Inode-cache hash table entries: 65536 (order: 7, 524288 bytes, linear)
[    0.000000] mem auto-init: stack:all(zero), heap alloc:off, heap free:off
[    0.000000] Memory: 664752K/970752K available (12096K kernel code, 2046K rwdata, 3992K rodata, 4032K init, 1015K bss, 43856K reserved, 262144K cma-reserved)
[    0.000000] SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] ftrace: allocating 39123 entries in 153 pages
[    0.000000] ftrace: allocated 153 pages with 4 groups
[    0.000000] trace event string verifier disabled
[    0.000000] rcu: Preemptible hierarchical RCU implementation.
[    0.000000] rcu:     RCU event tracing is enabled.
[    0.000000]  Trampoline variant of Tasks RCU enabled.
[    0.000000]  Rude variant of Tasks RCU enabled.
[    0.000000]  Tracing variant of Tasks RCU enabled.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 100 jiffies.
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] Root IRQ handler: bcm2836_arm_irqchip_handle_irq
[    0.000000] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[    0.000000] arch_timer: cp15 timer(s) running at 19.20MHz (phys).
[    0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns
[    0.000001] sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns
[    0.000374] Console: colour dummy device 80x25
[    0.000454] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=19200)
[    0.000489] pid_max: default: 32768 minimum: 301
[    0.000662] LSM: Security Framework initializing
[    0.000966] Mount-cache hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.001002] Mountpoint-cache hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.002705] cgroup: Disabling memory control group subsystem
[    0.005498] cblist_init_generic: Setting adjustable number of callback queues.
[    0.005517] cblist_init_generic: Setting shift to 2 and lim to 1.
[    0.005743] cblist_init_generic: Setting adjustable number of callback queues.
[    0.005760] cblist_init_generic: Setting shift to 2 and lim to 1.
[    0.006003] cblist_init_generic: Setting adjustable number of callback queues.
[    0.006019] cblist_init_generic: Setting shift to 2 and lim to 1.
[    0.006570] rcu: Hierarchical SRCU implementation.
[    0.006585] rcu:     Max phase no-delay instances is 400.
[    0.007801] EFI services will not be available.
[    0.008476] smp: Bringing up secondary CPUs ...
[    0.009835] Detected VIPT I-cache on CPU1
[    0.010001] CPU1: Booted secondary processor 0x0000000001 [0x410fd034]
[    0.012259] Detected VIPT I-cache on CPU2
[    0.012411] CPU2: Booted secondary processor 0x0000000002 [0x410fd034]
[    0.014472] Detected VIPT I-cache on CPU3
[    0.014614] CPU3: Booted secondary processor 0x0000000003 [0x410fd034]
[    0.015422] smp: Brought up 1 node, 4 CPUs
[    0.015442] SMP: Total of 4 processors activated.
[    0.015459] CPU features: detected: 32-bit EL0 Support
[    0.015474] CPU features: detected: CRC32 instructions
[    0.015640] CPU: All CPU(s) started at EL2
[    0.015655] alternatives: applying system-wide alternatives
[    0.017930] devtmpfs: initialized
[    0.036169] Enabled cp15_barrier support
[    0.036210] Enabled setend support
[    0.036663] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275000 ns
[    0.036704] futex hash table entries: 1024 (order: 4, 65536 bytes, linear)
[    0.048503] pinctrl core: initialized pinctrl subsystem
[    0.049668] DMI not present or invalid.
[    0.050302] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.059578] DMA: preallocated 1024 KiB GFP_KERNEL pool for atomic allocations
[    0.060300] DMA: preallocated 1024 KiB GFP_KERNEL|GFP_DMA pool for atomic allocations
[    0.061655] DMA: preallocated 1024 KiB GFP_KERNEL|GFP_DMA32 pool for atomic allocations
[    0.061788] audit: initializing netlink subsys (disabled)
[    0.062177] audit: type=2000 audit(0.060:1): state=initialized audit_enabled=0 res=1
[    0.062995] thermal_sys: Registered thermal governor 'step_wise'
[    0.063115] cpuidle: using governor menu
[    0.063446] hw-breakpoint: found 6 breakpoint and 4 watchpoint registers.
[    0.063709] ASID allocator initialised with 32768 entries
[    0.063943] Serial: AMBA PL011 UART driver
[    0.076543] bcm2835-mbox 3f00b880.mailbox: mailbox enabled
[    0.087055] raspberrypi-firmware soc:firmware: Attached to firmware from 2023-05-09T12:17:54, variant start
[    0.088051] raspberrypi-firmware soc:firmware: Firmware hash is 30aa0d70ab280427ba04ebc718c81d4350b9d394
[    0.095820] KASLR enabled
[    0.132065] bcm2835-dma 3f007000.dma: DMA legacy API manager, dmachans=0x1
[    0.137810] SCSI subsystem initialized
[    0.138112] usbcore: registered new interface driver usbfs
[    0.138187] usbcore: registered new interface driver hub
[    0.138290] usbcore: registered new device driver usb
[    0.138764] usb_phy_generic phy: supply vcc not found, using dummy regulator
[    0.139456] pps_core: LinuxPPS API ver. 1 registered
[    0.139472] pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti <giometti@linux.it>
[    0.139508] PTP clock support registered
[    0.139872] Advanced Linux Sound Architecture Driver Initialized.
[    0.141600] clocksource: Switched to clocksource arch_sys_counter
[    0.142245] VFS: Disk quotas dquot_6.6.0
[    0.142402] VFS: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[    0.142669] FS-Cache: Loaded
[    0.142956] CacheFiles: Loaded
[    0.156845] NET: Registered PF_INET protocol family
[    0.157253] IP idents hash table entries: 16384 (order: 5, 131072 bytes, linear)
[    0.159524] tcp_listen_portaddr_hash hash table entries: 512 (order: 1, 8192 bytes, linear)
[    0.159590] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.159717] TCP established hash table entries: 8192 (order: 4, 65536 bytes, linear)
[    0.159848] TCP bind hash table entries: 8192 (order: 6, 262144 bytes, linear)
[    0.160217] TCP: Hash tables configured (established 8192 bind 8192)
[    0.160644] MPTCP token hash table entries: 1024 (order: 2, 24576 bytes, linear)
[    0.160738] UDP hash table entries: 512 (order: 2, 16384 bytes, linear)
[    0.160798] UDP-Lite hash table entries: 512 (order: 2, 16384 bytes, linear)
[    0.161067] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.161966] RPC: Registered named UNIX socket transport module.
[    0.161984] RPC: Registered udp transport module.
[    0.161998] RPC: Registered tcp transport module.
[    0.162012] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.164206] hw perfevents: enabled with armv8_cortex_a53 PMU driver, 7 counters available
[    1.837980] Initialise system trusted keyrings
[    1.838623] workingset: timestamp_bits=46 max_order=18 bucket_order=0
[    1.848199] zbud: loaded
[    1.852019] NFS: Registering the id_resolver key type
[    1.852068] Key type id_resolver registered
[    1.852084] Key type id_legacy registered
[    1.852226] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    1.852247] nfs4flexfilelayout_init: NFSv4 Flexfile Layout Driver Registering...
[    1.853997] Key type asymmetric registered
[    1.854020] Asymmetric key parser 'x509' registered
[    1.854122] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 246)
[    1.854144] io scheduler mq-deadline registered
[    1.854162] io scheduler kyber registered
[    1.863193] simple-framebuffer 3eaa9000.framebuffer: framebuffer at 0x3eaa9000, 0x151800 bytes
[    1.863227] simple-framebuffer 3eaa9000.framebuffer: format=a8r8g8b8, mode=720x480x32, linelength=2880
[    1.866996] Console: switching to colour frame buffer device 90x30
[    1.870110] simple-framebuffer 3eaa9000.framebuffer: fb0: simplefb registered!
[    1.876003] Serial: 8250/16550 driver, 1 ports, IRQ sharing enabled
[    1.879185] bcm2835-rng 3f104000.rng: hwrng registered
[    1.880035] vc-mem: phys_addr:0x00000000 mem_base=0x3ec00000 mem_size:0x40000000(1024 MiB)
[    1.889746] Console: switching to colour dummy device 80x25
[    1.891240] vc4-drm soc:gpu: bound 3f600000.firmwarekms (ops vc4_fkms_ops)
[    1.891471] vc4-drm soc:gpu: bound 3fc00000.v3d (ops vc4_v3d_ops)
[    1.893000] [drm] Initialized vc4 0.0.0 20140616 for soc:gpu on minor 0
[    1.950414] Console: switching to colour frame buffer device 90x30
[    1.967238] vc4-drm soc:gpu: [drm] fb0: vc4drmfb frame buffer device
[    1.984747] brd: module loaded
[    1.994933] loop: module loaded
[    1.995884] Loading iSCSI transport class v2.0-870.
[    1.997972] usbcore: registered new interface driver lan78xx
[    1.998062] usbcore: registered new interface driver smsc95xx
[    1.998099] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    2.726731] Core Release: 2.80a
[    2.726765] Setting default values for core params
[    2.726795] Finished setting default values for core params
[    2.927250] Using Buffer DMA mode
[    2.927264] Periodic Transfer Interrupt Enhancement - disabled
[    2.927280] Multiprocessor Interrupt Enhancement - disabled
[    2.927294] OTG VER PARAM: 0, OTG VER FLAG: 0
[    2.927314] Dedicated Tx FIFOs mode
[    2.927882]
[    2.927896] WARN::dwc_otg_hcd_init:1072: FIQ DMA bounce buffers: virt = ffffffc008461000 dma = 0x00000000df0ac000 len=9024
[    2.927937] FIQ FSM acceleration enabled for :
[    2.927937] Non-periodic Split Transactions
[    2.927937] Periodic Split Transactions
[    2.927937] High-Speed Isochronous Endpoints
[    2.927937] Interrupt/Control Split Transaction hack enabled
[    2.928008]
[    2.928021] WARN::hcd_init_fiq:496: MPHI regs_base at ffffffc00806d000
[    2.928069] dwc_otg 3f980000.usb: DWC OTG Controller
[    2.928121] dwc_otg 3f980000.usb: new USB bus registered, assigned bus number 1
[    2.928184] dwc_otg 3f980000.usb: irq 74, io mem 0x00000000
[    2.928242] Init: Port Power? op_state=1
[    2.928256] Init: Power Port (0)
[    2.928768] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002, bcdDevice= 6.01
[    2.928794] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    2.928816] usb usb1: Product: DWC OTG Controller
[    2.928834] usb usb1: Manufacturer: Linux 6.1.61-v8 dwc_otg_hcd
[    2.928853] usb usb1: SerialNumber: 3f980000.usb
[    2.929905] hub 1-0:1.0: USB hub found
[    2.929991] hub 1-0:1.0: 1 port detected
[    2.932314] usbcore: registered new interface driver usb-storage
[    2.938691] sdhci: Secure Digital Host Controller Interface driver
[    2.938712] sdhci: Copyright(c) Pierre Ossman
[    2.939375] sdhci-pltfm: SDHCI platform and OF driver helper
[    2.942364] ledtrig-cpu: registered to indicate activity on CPUs
[    2.942665] hid: raw HID events driver (C) Jiri Kosina
[    2.942781] usbcore: registered new interface driver usbhid
[    2.942788] usbhid: USB HID core driver
[    2.947923] Initializing XFRM netlink socket
[    2.947972] NET: Registered PF_PACKET protocol family
[    2.948056] Key type dns_resolver registered
[    2.948833] registered taskstats version 1
[    2.948884] Loading compiled-in X.509 certificates
[    2.949475] Key type .fscrypt registered
[    2.949483] Key type fscrypt-provisioning registered
[    2.958841] uart-pl011 3f201000.serial: cts_event_workaround enabled
[    2.958969] 3f201000.serial: ttyAMA1 at MMIO 0x3f201000 (irq = 99, base_baud = 0) is a PL011 rev2
[    2.959138] serial serial0: tty port ttyAMA1 registered
[    2.961506] bcm2835-aux-uart 3f215040.serial: there is not valid maps for state default
[    2.961994] printk: console [ttyS0] disabled
[    2.962071] 3f215040.serial: ttyS0 at MMIO 0x3f215040 (irq = 71, base_baud = 50000000) is a 16550
[    3.033695] Indeed it is in host mode hprt0 = 00021501
[    3.035892] printk: console [ttyS0] enabled
[    3.215592] usb 1-1: new high-speed USB device number 2 using dwc_otg
[    3.217647] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer
[    3.235545] Indeed it is in host mode hprt0 = 00001101
[    3.242790] bcm2835-power bcm2835-power: Broadcom BCM2835 power domains driver
[    3.471034] usb 1-1: New USB device found, idVendor=0424, idProduct=2514, bcdDevice= b.b3
[    3.478517] mmc-bcm2835 3f300000.mmcnr: mmc_debug:0 mmc_debug2:0
[    3.484255] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    3.492199] mmc-bcm2835 3f300000.mmcnr: DMA channel allocated
[    3.518249] sdhost: log_buf @ 0000000004687b3c (c3125000)
[    3.530839] hub 1-1:1.0: USB hub found
[    3.602352] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[    3.626531] hub 1-1:1.0: 4 ports detected
[    3.635136] of_cfs_init
[    3.678522] mmc0: host does not support reading read-only switch, assuming write-enable
[    3.686465] of_cfs_init: OK
[    3.721626] mmc0: new high speed SDXC card at address 0001
[    3.762670] clk: Not disabling unused clocks
[    3.769478] mmcblk0: mmc0:0001 ED4QT 119 GiB
[    3.771372] ALSA device list:
[    3.780986]  mmcblk0: p1 p2
[    3.784808]   No soundcards found.
[    3.792021] mmcblk0: mmc0:0001 ED4QT 119 GiB
[    4.161623] usb 1-1.1: new high-speed USB device number 3 using dwc_otg
[    4.352513] EXT4-fs (mmcblk0p2): orphan cleanup on readonly fs
[    4.358528] EXT4-fs (mmcblk0p2): mounted filesystem with ordered data mode. Quota mode: none.
[    4.367319] VFS: Mounted root (ext4 filesystem) readonly on device 179:2.
[    4.375056] devtmpfs: mounted
[    4.384471] Freeing unused kernel memory: 4032K
[    4.389242] Run /sbin/init as init process
[    4.404790] mmc1: new high speed SDIO card at address 0001
[    4.431201] usb 1-1.1: New USB device found, idVendor=0424, idProduct=2514, bcdDevice= b.b3
[    4.439756] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    4.448249] hub 1-1.1:1.0: USB hub found
[    4.452500] hub 1-1.1:1.0: 3 ports detected
INIT: version 3.04 booting
Starting udev
[    4.810180] dwc_otg_handle_wakeup_detected_intr lxstate = 2
[    4.966345] udevd[134]: starting version 3.2.12
[    5.021180] udevd[136]: starting eudev-3.2.12
[    5.191603] usb 1-1.1.1: new high-speed USB device number 4 using dwc_otg
[    5.287143] usb 1-1.1.1: New USB device found, idVendor=0424, idProduct=7800, bcdDevice= 3.00
[    5.295869] usb 1-1.1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    5.370044] EXT4-fs (mmcblk0p2): re-mounted. Quota mode: none.
Fri Mar  9 12:34:56 UTC 2018
[    5.568791] lan78xx 1-1.1.1:1.0 (unnamed net_device) (uninitialized): No External EEPROM. Setting MAC Speed
[    5.599332] lan78xx 1-1.1.1:1.0 (unnamed net_device) (uninitialized): int urb period 64
INIT: Entering runlevel: 5
Configuring network interfaces... [    6.540409] lan78xx 1-1.1.1:1.0 eth0: Link is Down
udhcpc: started, v1.36.1
udhcpc: broadcasting discover
udhcpc: broadcasting discover
udhcpc: broadcasting discover
udhcpc: no lease, forking to background
done.
Starting syslogd/klogd: done

Poky (Yocto Project Reference Distro) 4.3.4 raspberrypi3-64 /dev/ttyS0

raspberrypi3-64 login:

ちなみに root でログインして色々できるっぽい。

Discussion