====== SDカードからのブート ====== MA-S1xx シリーズは MA-E3xx シリーズと同様、オンボードフラッシュメモリ(SPI Flash)からだけではなく、\\ SD カードからのブート(MMC boot)も可能です。 \\ ===== 準備 ===== ブート可能なSDカードには、条件があります。 * 1番目のパーティションが、FAT であること(FAT32 も可) * 1番目のパーティションに、ブートローダーの2つのファイルがあること デフォルト状態では、ブートローダーから起動したあと Linux も起動する場合、root filesystem として mount する 2番目のパーティションが\\ **ext4** と想定したスクリプトになっているため、パーティションを作成する必要があります。 そのため、Linux で作業を行います。 \\ ==== パーティションの作成 ==== * 1番目のパーティション : FAT32(LBA) * 2番目のパーティション : ext4 としてパーティションを作成します。 root@gemini:~# fdisk /dev/mmcblk1 Welcome to fdisk (util-linux 2.34). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): d Selected partition 1 Partition 1 has been deleted. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-3911679, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3911679, default 3911679): +64M Created a new partition 1 of type 'Linux' and of size 64 MiB. Command (m for help): t Selected partition 1 Hex code (type L to list all codes): c Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'. Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): 2 First sector (133120-3911679, default 133120): Last sector, +/-sectors or +/-size{K,M,G,T,P} (133120-3911679, default 3911679): Created a new partition 2 of type 'Linux' and of size 1.8 GiB. Command (m for help): a Partition number (1,2, default 2): 1 The bootable flag on partition 1 is enabled now. Command (m for help): p Disk /dev/mmcblk1: 1.89 GiB, 2002780160 bytes, 3911680 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x00000000 Device Boot Start End Sectors Size Id Type /dev/mmcblk1p1 * 2048 133119 131072 64M c W95 FAT32 (LBA) /dev/mmcblk1p2 133120 3911679 3778560 1.8G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. root@gemini:~# \\ ==== ファイルシステムの作成 ==== mkfs.vfat, mkfs.ext4 でそれぞれファイルシステムを作成します。 root@gemini:~# mkfs.vfat /dev/mmcblk1p1 mkfs.fat 4.1 (2017-01-24) root@gemini:~# mkfs.ext4 -m 0 /dev/mmcblk1p2 mke2fs 1.45.5 (07-Jan-2020) Discarding device blocks: done Creating filesystem with 472320 4k blocks and 118080 inodes Filesystem UUID: c559e2aa-5cc4-4393-87d8-eee08d0cb027 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done root@gemini:~# \\ ==== FAT 領域の mount ==== ブートローダーのファイルをコピーするので、FAT の領域を適当な場所に mount しておきます。 root@gemini:~# mount /dev/mmcblk1p1 /mnt/sd \\ ==== ブートローダーのファイルの入手 ==== [[https://wiki.centurysys.jp/doku.php?id=download_software:mas1xx:start#sdcard_boot_%E7%94%A8_bootloader|SDcard boot 用 bootloader]] からダウンロードし、ZIP を展開しておきます。 \\ ==== ブートローダーファイルの配置 ==== ダウンロードして展開したファイルを SD 1番目の FAT 領域にコピーします。 root@gemini:~# cd /mnt/sd root@gemini:/mnt/sd# cp /tmp/boot.bin . root@gemini:/mnt/sd# cp /tmp/barebox.bin . root@gemini:/mnt/sd# ls -l total 472 -rwxr-xr-x 1 root root 459267 Nov 9 09:34 barebox.bin -rwxr-xr-x 1 root root 20665 Nov 9 09:34 boot.bin \\ ===== SDcard からの起動 ===== ==== bootloader の起動 ==== DIPSW を [OFF - OFF - OFF - **ON**] に設定((参照: [[mas1xx_ope:select_bootdevice:start|]]))し、再起動します。 [ 4245.860956] reboot: Restarting system AT91Bootstrap 3.9.1-00020-g74e795d (Wed Mar 11 09:31:51 JST 2020) SD/MMC: Image: Read file barebox.bin to 0x26f00000 MMC: ADMA supported SD: Card Capacity: Standard SD: Specification Version 3.0X SD/MMC: Done to load image barebox 2020.02.0-00221-g0accd163f #134 Fri Oct 9 13:28:05 JST 2020 Board: Century Systems Gemini AT91: Detected soc type: sama5d2 AT91: Detected soc subtype: sama5d26cu mdio_bus: miibus0: probed macb f8008000.ethernet@f8008000.of: Cadence GEM at 0xf8008000 atmel-ehci 500000.ehci@500000.of: USB EHCI 1.00 atmel_spi f8000000.spi@f8000000.of: version: 0x311 m25p80 m25p80@00: sst26vf016b (2048 Kbytes) at91-twi f8028000.i2c@f8028000.of: AT91 i2c bus driver. at91-twi fc028000.i2c@fc028000.of: AT91 i2c bus driver. sama5d2-sdhci a0000000.sdio-host@a0000000.of: registered as emmc emmc: detected MMC card version 5.0 emmc: Capacity: 1840 MiB emmc: registered emmc sama5d2-sdhci: "enable_cd" pin found, set to High. sama5d2-sdhci b0000000.sdio-host@b0000000.of: registered as sd sd: detected SD card version 2.0 sd: Capacity: 1910 MiB sd: registered sd pstore: Registered ramoops as persistent store backend ramoops: attached 0x100000@0x3fecc000, ecc: 16/0 malloc space: 0x27cfe500 -> 0x3fcfe4ff (size 384 MiB) envfs: no envfs (magic mismatch) - envfs never written? running /env/bin/init... * mounting /dev/emmc.0 to /mnt/emmc.0 (filesystem type: fat) * mounting /dev/emmc.1 to /mnt/emmc.1 (filesystem type: ext4) ext4 ext40: EXT2 rev 1, inode_size 256, descriptor size 64 * mounting /dev/sd.0 to /mnt/sd.0 (filesystem type: fat) * mounting /dev/sd.1 to /mnt/sd.1 (filesystem type: ext4) ext4 ext41: EXT2 rev 1, inode_size 256, descriptor size 64 * Power OFF/ON RS9116...done. Hit m for menu or any other key to stop autoboot: 1 type exit to get to the menu barebox:/ AT91Bootstrap の起動時の出力が "SD: " になっており、SDcard から起動していることが確認できました。 \\ ==== Linux の起動 ==== ここまでで SDcard からブートローダーの起動まで確認できました。\\ SDcard の 2 番目のパーティションに root filesystem を配置して起動するためには、追加で - root filesystem の配置 - Kernel, devicetree blob の配置 が必要となります。 2. の Kernel, devicetree blob は実機で動作しているものをコピーして使用することもできます。\\ その場合、まずは本体 Flash Memory の root filesystem を使用して起動させます。 ext4 ext41: EXT2 rev 1, inode_size 256, descriptor size 64 * Power OFF/ON RS9116...done. Hit m for menu or any other key to stop autoboot: 1 type exit to get to the menu barebox:/ boot <---------------- boot と入力し、Enter Booting entry 'emmc' ... 中略 ... [ OK ] Started monitoring mobile device. [ OK ] Started dnsmasq - A lightw�.|t DHCP and caching DNS server. [ OK ] Reached target Host and Network Name Lookups. Starting WireGuard via wg-quick(8) for wg0... [ OK ] Started WireGuard VPN(wg) Key Generation. [ OK ] Finished WireGuard via wg-quick(8) for wg0. Ubuntu 20.04.1 LTS gemini ttyS0 gemini login: \\ === Kernel 関係イメージのコピー === == 最新ファームウェア領域の確認 == ログインし、最新のファームウェアがどちらの領域に入っているか確認します。 root@gemini:~# firminfo -g 2 === firmup history === - entry 0: timestamp: 1604645132 (2020/11/06 15:45:32) area: 0x10 - entry 1: timestamp: 1604055452 (2020/10/30 19:57:32) area: 0x11 root@gemini:~# "entry 0" の **area** が 0x10 になっているので、AREA 0 に入っていることを示しています。 (0x11 になっている場合は、AREA 1 を示します。) \\ == SDcard 1番目パーティションの mount == SDcard の 1番目のパーティションの FAT 領域を mount します。 root@gemini:~# mount /dev/mmcblk1p1 /mnt/sd root@gemini:~# ls -l /mnt/sd total 466 -rwxr-xr-x 1 root root 459267 Nov 9 10:26 barebox.bin -rwxr-xr-x 1 root root 15361 Nov 9 10:26 boot.bin root@gemini:~# \\ == Kernel 関係ファイルのコピー == SDcard 1番目のパーティションに、Kernel 関係のファイルをコピーします。 root@gemini:~# cd /ro/.host/area0/ root@gemini:/ro/.host/area0# ls -l total 83380 -rwxr-xr-x 1 root root 33485 Nov 6 15:45 at91-centurysys-gemini-00.dtb -rwxr-xr-x 1 root root 33735 Nov 6 15:45 at91-centurysys-gemini-01.dtb -rwxr-xr-x 1 root root 1770 Nov 6 15:45 at91-centurysys-gemini-01.dtbo -rwxr-xr-x 1 root root 1683 Nov 6 15:45 at91-centurysys-gemini-02.dtbo -rwxr-xr-x 1 root root 1705 Nov 6 15:45 at91-centurysys-gemini-03.dtbo -rwxr-xr-x 1 root root 2460716 Nov 6 15:45 initramfs.img -rwxr-xr-x 1 root root 4843728 Nov 6 15:45 kernel.img -rwxr-xr-x 1 root root 1343488 Nov 6 15:45 kmod.img -rwxr-xr-x 1 root root 76607488 Nov 6 15:45 rootfs.img root@gemini:/ro/.host/area0# cp at91-centurysys-gemini* kernel.img /mnt/sd/ root@gemini:/ro/.host/area0# ls -l /mnt/sd total 5306 -rwxr-xr-x 1 root root 33485 Nov 9 12:02 at91-centurysys-gemini-00.dtb <--- DeviceTree -rwxr-xr-x 1 root root 33735 Nov 9 12:02 at91-centurysys-gemini-01.dtb -rwxr-xr-x 1 root root 1770 Nov 9 12:02 at91-centurysys-gemini-01.dtbo <--- DeviceTree Overlay -rwxr-xr-x 1 root root 1683 Nov 9 12:02 at91-centurysys-gemini-02.dtbo -rwxr-xr-x 1 root root 1705 Nov 9 12:02 at91-centurysys-gemini-03.dtbo -rwxr-xr-x 1 root root 459267 Nov 9 10:26 barebox.bin -rwxr-xr-x 1 root root 15361 Nov 9 10:26 boot.bin -rwxr-xr-x 1 root root 4843728 Nov 9 12:02 kernel.img <--- Kernel 本体 \\ SDcard から起動する場合、Kernel は uImage というファイル名を見るようになっているため、rename しておきます。 root@gemini:/mnt/sd# mv kernel.img uImage root@gemini:/mnt/sd# ls -l total 5306 -rwxr-xr-x 1 root root 33485 Nov 9 12:02 at91-centurysys-gemini-00.dtb -rwxr-xr-x 1 root root 33735 Nov 9 12:02 at91-centurysys-gemini-01.dtb -rwxr-xr-x 1 root root 1770 Nov 9 12:02 at91-centurysys-gemini-01.dtbo -rwxr-xr-x 1 root root 1683 Nov 9 12:02 at91-centurysys-gemini-02.dtbo -rwxr-xr-x 1 root root 1705 Nov 9 12:02 at91-centurysys-gemini-03.dtbo -rwxr-xr-x 1 root root 459267 Nov 9 10:26 barebox.bin -rwxr-xr-x 1 root root 15361 Nov 9 10:26 boot.bin -rwxr-xr-x 1 root root 4843728 Nov 9 12:02 uImage \\ === root filesystem の作成 === root filesystem を SDcard 2番目のパーティションに作成します。\\ debootstrap や配布されている rootfs のイメージを展開する方法などがありますが、本体ファームウェアのファイルシステムをコピーする方法でやってみます。 \\ root@gemini:~# umount /mnt/sd ・・・・・ FAT 領域の umount root@gemini:~# mount /dev/mmcblk1p2 /mnt/sd root@gemini:~# cd /mnt/sd/ \\ 現在の root filesystem のベース部分(squashfs を mount した箇所) を SDcard にコピーします。 root@gemini:/mnt/sd# cp -af /ro/* . root@gemini:/mnt/sd# ls -la total 92 drwxr-xr-x 21 root root 4096 Nov 10 11:06 . drwxr-xr-x 7 root root 70 May 29 20:07 .. drwxr-xr-x 2 root root 4096 Nov 6 15:39 bin drwxr-xr-x 2 root root 4096 Nov 6 15:41 boot drwxr-xr-x 4 root root 4096 Sep 7 2017 dev drwxr-xr-x 79 root root 4096 Nov 6 15:40 etc drwxr-xr-x 3 root root 4096 Sep 7 2017 home drwxr-xr-x 16 root root 4096 Oct 9 11:57 lib drwx------ 2 root root 16384 Nov 9 10:25 lost+found drwxr-xr-x 2 root root 4096 Sep 7 2017 media drwxr-xr-x 7 root root 4096 May 29 20:07 mnt drwxr-xr-x 3 root root 4096 Jun 8 18:33 opt drwxr-xr-x 2 root root 4096 Apr 13 2016 proc drwx------ 3 root root 4096 Nov 6 15:41 root drwxr-xr-x 14 root root 4096 Jul 5 2019 run drwxr-xr-x 2 root root 4096 Nov 6 15:39 sbin drwxr-xr-x 2 root root 4096 Sep 7 2017 srv drwxr-xr-x 2 root root 4096 Feb 5 2016 sys drwxrwxrwt 2 root root 4096 Nov 6 15:41 tmp drwxr-xr-x 10 root root 4096 Sep 7 2017 usr drwxr-xr-x 12 root root 4096 Aug 27 2018 var \\ === 再起動 === これで SDcard に * bootloader (at91bootstrap, barebox) * Kernel (uImage, dtb) * root filesystem が準備できましたので、DIPSW の設定を SDcard rootfs([OFF - **ON** - OFF - **ON**]) に変更して再起動します。 root@gemini:~# reboot root@gemini:~# Session terminated, killing shell...logout ...killed. Terminated \\ コンソールでは次のように、SDcard(mmcblk1) から各種ファイルをロードして起動していることが確認できます。\\ ... 略 ... ext4 ext41: EXT2 rev 1, inode_size 256, descriptor size 64 * Power OFF/ON RS9116...done. Hit m for menu or any other key to stop autoboot: 1 Booting entry 'sd' <------------------------------- SDcard rootfs 選択 * found devicetree file for option_code 00: /mnt/sd.0/at91-centurysys-gemini-00.dtb * found devicetree overlay file for xio_id 1: /mnt/sd.0/at91-centurysys-gemini-01.dtbo Image Name: Linux-5.4.41-linux4sam-2020.04+ Created: 2020-10-23 0:21:03 UTC OS: Linux Architecture: ARM Type: Kernel Image Compression: uncompressed Data Size: 4843664 Bytes = 4.6 MiB Load Address: 20008000 Entry Point: 20008000 Loading U-Boot uImage '/mnt/sd.0/uImage' Loading devicetree from '/mnt/sd.0/at91-centurysys-gemini-00.dtb' ramoops: Adding reserved-memory node ramoops: Adding ramoops node commandline: console=ttyS0,115200 board_id=00 mobiledev=AML574A root=/dev/mmcblk1p2 rw rootfstype=ext4 rootwait xio_id=1 <---- rootfs が mmcblk1p2, ext4 指定 [ 0.000000] Booting Linux on physical CPU 0x0 [ 0.000000] Linux version 5.4.41-linux4sam-2020.04+ (root@ryzen7) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #46 PREEMPT Fri Oct 23 09:20:51 JST 2020 [ 0.000000] CPU: ARMv7 Processor [410fc051] revision 1 (ARMv7), cr=10c53c7d [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache [ 0.000000] OF: fdt: Machine model: Century Systems Gemini [ 0.000000] Memory policy: Data cache writeback [ 0.000000] CPU: All CPU(s) started in SVC mode. [ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 129920 [ 0.000000] Kernel command line: console=ttyS0,115200 board_id=00 mobiledev=AML574A root=/dev/mmcblk1p2 rw rootfstype=ext4 rootwait xio_id=1 ... 略 ... \\ ログインしてみると、root(/) が SDcard になっていることが確認できました。 Starting Update UTMP about System Runlevel Changes... [ OK ] Finished Update UTMP about System Runlevel Changes. gemini login: root Password: Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.41-linux4sam-2020.04+ armv7l) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. root@gemini:~# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/root 1826824 245936 1564504 14% / devtmpfs 254076 0 254076 0% /dev tmpfs 254588 0 254588 0% /dev/shm tmpfs 50920 772 50148 2% /run tmpfs 5120 0 5120 0% /run/lock tmpfs 254588 0 254588 0% /sys/fs/cgroup tmpfs 50916 0 50916 0% /run/user/0 root@gemini:~# \\