meishaoming / blog

MIT License
1 stars 2 forks source link

raspberry pi cm3 flashing under macos #39

Open meishaoming opened 6 years ago

meishaoming commented 6 years ago

CM3 自带 4GB eMMC。要把 Raspbian 系统 烧写进去还需要一个底板,通过 USB Device 的方式来烧录。

本文记录在 MacOS 上烧写系统到 CM3 的过程,并分析讨论涉及到的硬件原理。

准备工作

底板

我买的是一个国产底板 Compute Module IO Board Plus

image

系统文件

下载 RASPBIAN STRETCH LITE 刷机文件。LITE 版本解压后约 1.8GB,没有桌面系统。而 RASPBIAN STRETCH WITH DESKTOP 解压后 4.95GB,CM3 的 eMMC 只有 4GB,用不了。

usbboot

git clone --depth=1 https://github.com/raspberrypi/usbboot.git

cd usbboot
make

生成 rpiboot 工具。

刷机过程

打 MacOS 的「关于」-> 「系统报告」-> 「硬件」-> 「USB」

可以看到 BCM2710 Boot 这个设备:

image

执行 sudo ./rpiboot 命令:

image

看到 rpiboot 通过 USB 发送了 bootcode.bin 和 start.elf 到 CM3 上执行。

此时电脑弹出磁盘,说明发送过去的 start.elf 将 CM3 上的 eMMC 模拟成一个 USB mass storage ,挂载到电脑上。

image

用 diskutil 可以看到:

image

USB 总线上也出现了 Compute Module 设备:

image

把映像文件 dd 进 CM3 磁盘:

sudo dd if=./img/2018-06-27-raspbian-stretch-lite.img of=/dev/disk2 bs=32m

整个命令执行耗时 15min+ 。刷完后在电脑上可以看到 boot 分区:

image

硬件分析

image image

EMMC_DISABLE_N 如何控制 SoC 的启动?

image

SoC 启动时尝试各种启动方式,当所有方式失败后,最后尝试 USB Device 方式启动。详见 raspberry pi boot process

参考链接

meishaoming commented 5 years ago

备份 image

sudo dd bs=4m if=/dev/disk2 of=fmtech_rpi_cm3.img

导出来的有 3.6G,缩小尺寸:

sudo ./pishrink.sh fmtech_rpi_cm3_20190322.img

image