0%

Qcow2 qemu 打包日记

Qcow2 qemu 打包日记

1
2
3
4
5
6
7
8
9
10
11
12
13
modprobe nbd
qemu-img create -f qcow2 image.qcow2 1G
sudo qemu-nbd --connect=/dev/nbd0 image.qcow2
sudo sgdisk -g --clear -a 1 \
--new=1:34:2081         --change-name=1:spl --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
--new=2:2082:10273      --change-name=2:uboot  --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
--new=3:16384:282623    --change-name=3:boot --typecode=3:0x8300 \
  /dev/nbd0
sudo dd if=<u-boot_root_path/build/u-boot.itb> of=/dev/nbd0p2   "将u-boot.itb 拷贝到sd卡的第二个分区"
sudo mkfs.ext4 /dev/nbd0p3
sudo mount /dev/nbd0p3 <mnt_dir>
cp Image wave,boston-kingv.dtb <mnt_dir> "Image 为 kernel 编译出的 <build>/arch/riscv/boot/Image, dtb 为kernel 用的dtb"
sudo umount <mnt_dir> sudo qemu-nbd --disconnect /dev/nbd0

制作分区

1
2
3
4
5
6
sudo sgdisk -g --clear -a 1 \
--new=1:34:2081 --change-name=1:spl --typecode=1:5B193300-FC78-40CD-8002-E86C45580B47 \
--new=2:2082:10273 --change-name=2:uboot --typecode=2:2E54B353-1271-4842-806F-E436D6AF6985 \
--new=3:16384:282623 --change-name=3:boot --typecode=3:0x0700 \
--new=4:286720:2018207 --change-name=4:root --typecode=4:0x8300 \
test.img

挂载

1
2
3
sudo fdisk -l test.img
sudo losetup -f --show -P test.img
sudo mount /dev/loopXpX mnt

无卡启动

配置tftpd

1
2
3
4
5
6
7
8
9
10
sudo apt install tftpd-hpa
sudo vi /etc/default/tftpd-hpa #编辑 /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-s"

sudo chmod 777 -R /srv/tftp

配置完后, tftp 使用的目录为 /srv/tftp

将编出的 work/image.fit 拷贝到该文件夹中

本机测试

1
2
tftp localhost
> get image.fit

无错误代表没问题

开发板 u-boot tftp 下载

1
StarFive # setenv ipaddr 192.168.xx.xx;setenv serverip 192.168.xx.xx

serverip 为 tftpd 即刚才配置好 tftpd 的ip
ipaddr 为 开发版的 ip

开发板 u-boot 配置环境变量

  1. set enviroment parameter:

    1
    setenv bootfile vmlinuz; setenv fileaddr a0000000; setenv fdtcontroladdr 0xffffffffffffffff;
  2. upload image file to ddr:

    1
    tftpboot ${fileaddr} ${serverip}:image.fit;

    如果下载不了, 执行下 run bootcmd_dhcp 再执行下 tftpboot ${fileaddr} ${serverip}:image.fit

  3. load and excute:

    1
    bootm start ${fileaddr};bootm loados ${fileaddr};run chipa_set_linux;booti 0x40200000 0x46100000:${filesize} 0x46000000
  4. login

    1
    2
    buildroot login:root
    Password: starfive

更新spl uboot

更新SPL二进制文件

1
2
tftpboot 0xa0000000 ${serverip}:u-boot-spl.bin.normal.out
sf update 0xa0000000 0x0 $filesize

更新U-Boot二进制文件

1
2
tftpboot 0xa0000000 ${serverip}:visionfive2_fw_payload.img
sf update 0xa0000000 0x100000 $filesize