在qemu中启动用buildroot构建的OrangePi-PC镜像

一、OrangePi PC简介

在这里插入图片描述

Orange Pi PC 采用了全志四核A7高性能处理器 Allwinner H3,集成了板载网络、板载存储、以太网、USB-Host、USB-OTG、DVP camera等,支持HDMI、CVBS视频输出,而且兼容树莓派 GPIO

二、用 buildroot 构建 OrangePi-PC 镜像。

1、安装必要的软件

sudo apt install sed make binutils build-essential diffutils gcc g++ bash patch gzip bzip2 perl tar cpio unzip rsync file bc findutils wget

2、下载 buildroot 压缩包

wget https://buildroot.org/downloads/buildroot-2023.02.8.tar.xz

3、解压缩

tar xvf buildroot-2023.02.8.tar.xz

4、配置 OrangePi PC

make orangepi_pc_defconfig

5、配置 menuconfig

make menuconfig

根据需要自己设置
在这里插入图片描述6、build 镜像

make

如果你使用 windows 的 wsl ubuntu 子系统出现如下问题:

Your PATH contains spaces, TABs, and/or newline (\n) characters.
This doesn’t work. Fix you PATH.
make: *** [support/dependencies/dependencies.mk:27: dependencies] Error 1

则使用以下命令:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin make 

如果出现如下错误:

mkfs.ext4: Could not allocate block in ext2 filesystem while populating file system
*** Maybe you need to increase the filesystem size (BR2_TARGET_ROOTFS_EXT2_SIZE)

则 打开 .config 搜索 BR2_TARGET_ROOTFS_EXT2_SIZE 设置一个比较大的数,如 256

BR2_TARGET_ROOTFS_EXT2_SIZE="256M"

7、经过漫长的等待,如果没有出现错误,会在 output 文件夹里有个 images 文件夹,里面的文件是:

.
├── genimage.cfg
├── rootfs.ext2
├── rootfs.ext4 -> rootfs.ext2
├── sdcard.img
├── sun8i-h3-orangepi-pc.dtb
├── u-boot.bin
├── u-boot-sunxi-with-spl.bin
└── zImage

三、挂载 sdcard.img 进行自定义操作

先用fdisk -l命令找到镜像中的 start 数值

fdisk -l sdcard.img
Disklabel type: gpt
Disk identifier: A6763104-6F5E-44FB-8CA7-8984F5CA85B0

Device      Start    End Sectors Size Type
sdcard.img1  2048 124927  122880  60M Linux filesystem

注意这个表格中的start项:

Devicestart
sdcard.img12048

我这里显示的是2048。
挂载的偏移量 = start*512, 即 offset = 2048*512 = 1048576 。
因此,本例子中,通过设置偏移量为 1048576 即可挂载 sdcard.img 到某个文件夹。

sudo mkdir -p /mnt/fs
sudo mount -o loop,offset=1048576 sdcard.img /mnt/fs

挂载后,可以向 /mnt/fs 中写文件从而实现定制化的 rootfs
比如,我用 deersay(一个山寨cowsay程序)拷贝到 /mnt/fs/bin/deersay

git clone https://github.com/deerpi/deersay
cd deersay
arm-linux-gnueabihf-gcc -o deersay main.c
cp deersay /mnt/fs/bin/

,然后,通过 profile.d 文件夹内建立.sh文件从而令其开机自启某些程序。

nano /mnt/fs/etc/profile.d/welcome.sh

welcome.sh

#!/bin/sh
deersay "Welcome to DeerPi for OrangePi PC"

挂载后的操作,会导致 sdcard.img 镜像改变。

四、在 QEMU 中启动镜像

编写脚本start.sh,内容如下:

#!/bin/sh
qemu-system-arm \
-M orangepi-pc \
-m 1G \
-nographic \
-sd sdcard.img

执行

bash start.sh

显示:

WARNING: Image format was not specified for 'sdcard.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.

U-Boot SPL 2020.10 (Dec 17 2023 - 22:06:17 +0800)
DRAM: 1024 MiB
Failed to set core voltage! Can't set CPU frequency
Trying to boot from MMC1


U-Boot 2020.10 (Dec 17 2023 - 22:06:17 +0800) Allwinner Technology

CPU:   Allwinner H3 (SUN8I 0000)
Model: Xunlong Orange Pi PC
DRAM:  1 GiB
MMC:   mmc@1c0f000: 0
Loading Environment from FAT... Unable to use mmc 0:1... Warning: HDMI PHY init timeout!
Warning: HDMI PHY init timeout!
In:    serial
Out:   serial
Err:   serial
Net:   phy interface0
eth0: ethernet@1c30000
starting USB...
Bus usb@1c1a000: USB EHCI 1.00
Bus usb@1c1a400: USB OHCI 1.0
Bus usb@1c1b000: USB EHCI 1.00
Bus usb@1c1b400: USB OHCI 1.0
Bus usb@1c1c000: USB EHCI 1.00
Bus usb@1c1c400: USB OHCI 1.0
Bus usb@1c1d000: USB EHCI 1.00
Bus usb@1c1d400: USB OHCI 1.0
scanning bus usb@1c1a000 for devices... 1 USB Device(s) found
scanning bus usb@1c1a400 for devices... 1 USB Device(s) found
scanning bus usb@1c1b000 for devices... 1 USB Device(s) found
scanning bus usb@1c1b400 for devices... 1 USB Device(s) found
scanning bus usb@1c1c000 for devices... 1 USB Device(s) found
scanning bus usb@1c1c400 for devices... 1 USB Device(s) found
scanning bus usb@1c1d000 for devices... 1 USB Device(s) found
scanning bus usb@1c1d400 for devices... 1 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  0
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
158 bytes read in 2 ms (77.1 KiB/s)
1:      default
Retrieving file: /boot/zImage
4783368 bytes read in 886 ms (5.1 MiB/s)
append: root=PARTUUID=3bc177e0-0dba-4e9d-b0e3-880950bf3c12 rootwait rootfstype=ext4 quiet panic=10
Retrieving file: /boot/sun8i-h3-orangepi-pc.dtb
22487 bytes read in 5 ms (4.3 MiB/s)
## Flattened Device Tree blob at 43000000
   Booting using the fdt blob at 0x43000000
   Loading Device Tree to 49ff7000, end 49fff7d6 ... OK

Starting kernel ...

[    0.073663] /cpus/cpu@0 missing clock-frequency property
[    0.074987] /cpus/cpu@1 missing clock-frequency property
[    0.075106] /cpus/cpu@2 missing clock-frequency property
[    0.075205] /cpus/cpu@3 missing clock-frequency property
[    0.881292] sun4i-usb-phy 1c19400.phy: Couldn't request ID GPIO
[    1.669484] sun8i-dw-hdmi 1ee0000.hdmi: Unsupported HDMI controller (0000:00:00)
[    1.677396] sun4i-drm display-engine: failed to bind 1ee0000.hdmi (ops 0xc084d888): -19
[    1.680662] sun4i-drm display-engine: Couldn't bind all pipelines components
[    1.701262] lima 1c40000.gpu: mmu gpmmu dte write test fail
[    4.084638] i2c i2c-0: mv64xxx: I2C bus locked, block: 1, time_left: 0
[    4.227092] sun4i-codec 1c22c00.codec: Failed to register our card
[    4.790006] debugfs: Directory '1c22c00.codec' with parent 'H3 Audio Codec' already present!
Saving 2048 bits of non-creditable seed for next boot
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Starting network: udhcpc: started, v1.36.1
udhcpc: broadcasting discover
udhcpc: broadcasting select for 10.0.2.15, server 10.0.2.2
udhcpc: lease of 10.0.2.15 obtained from 10.0.2.2, lease time 86400
deleting routers
adding dns 10.0.2.3
OK

Welcome to DeerPi for OrangePi PC

    \   \_\_    _/_/
     \      \__/
      \     (oo)\_______
            (__)\       )\/\
                ||-----||
                ||     ||

#

五、其他资料及下载

1、本定制镜像可在 github 下载:
https://github.com/deerpi/rootfs/releases

2、deersay 仓库位于:
https://github.com/deerpi/deersay

3、PINOUT
在这里插入图片描述
4、真机启动视频

putty串口登录

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值