qemu 可以支持 ARMv8 
且支持的 boot 包括
	1. 从 ATF启动
	2. 从 UEFI启动
	3. 从 u-boot启动
	4. 从 linux 启动
这里打算用以下平台 qemu-system-aarch64 -M virt -cpu 

qemu virt 平台 // https://qemu.readthedocs.io/en/latest/system/arm/virt.html
	1.硬件平台
		1. 可配置项
			1. cpu微架构,个数 // cortex-a53/57/72 // many CPUs (up to 512 if using a GICv3 and highmem)
			2. 内存大小  // large amounts of RAM (at least 255GB, and more if using highmem)
			3. flash镜像 // -bios xxx , xxx 被装在到 flash 0x0000 0000 开始的地方
			4. RAM 镜像  // -drive if=pflash,format=raw,index=1,file=flash.img // flash.img 装在到 0x4000 0000 的地方
		2. 不可配置项 
			1. Flash memory starts at address 0x0000_0000 , 支持 XIP ,可配置
			2. RAM starts at 0x4000_0000
			3. One PL011 UART
			4. 其他配置项
				All other information about device locations may change between QEMU versions, so guest code must look in the DTB.
				qemu-system-aarch64 -machine virt,dumpdtb=virt.dtb -cpu cortex-a57 -smp 1 -m 2G -nographic
	2.boot
		QEMU supports two types of guest image boot for virt, and the way for the guest code to locate the dtb binary differs:
			1.For guests using the Linux kernel boot protocol (this means any non-ELF file passed to the QEMU -kernel option) 
				the address of the DTB is passed in a register (r2 for 32-bit guests, or x0 for 64-bit guests)
			2.For guests booting as “bare-metal” (any other kind of boot)
				the DTB is at the start of RAM (0x4000_0000) // 类似 u-boot.bin 或者 UEFI.bin
  • qemu 的boot
qemu-system-aarch64 -M virt -cpu cortex-a57 -nographic -smp 4
qemu-system-aarch64 支持bios ,但是必须显式设置,否则不使用bios
但是qemu-system-aarch64 在 不显式设置 bios 的时候,会去看share/qemu/efi-virtio.rom 是否为存在,是否为空,如果存在且不空, 才可正常走下去.否则,会自动结束
但是qemu-system-aarch64 并不会 读 share/qemu/efi-virtio.rom 中的内容

share/qemu/efi-virtio.rom 的格式
	bin/../share/qemu/efi-virtio.rom: BIOS (ia32) ROM Ext. (135*512)
	// aarch64-linux-gnu-objdump  -D -b binary -m aarch64  efi-virtio.rom   > efi-virtio.asm
	// 但是好像 efi-virtio.asm 并不像代码


不显式设置-bios // 例如-kernel xxx.elf
	直接跑kernel
-bios none 
	不支持
-bios xxx.bin
	 会去找 xxx.bin 文件,并以其为 bios 运行
	-bios QEMU_EFI.fd // 从UEFI启动
	-bios u-boot.bin // 从U-boot 启动

qemu-system-aarch64/qemu-system-x86/qemu-system-riscv64 都有自己的 bios // 对应不显示 传入 "-bios xxx" 的情况
对应 arm64 virt板 来说是  不跑bios
对应 x86 来说是 UEFI.fd ? // TODO
对应 rv 来说 是 opensbi-riscv64-generic-fw_dynamic.bin
// -kernel选项 ,如果有则跑完(或不跑)bios,就跑kernel, 目前不知道 bios 和 kernel 是怎么衔接的
-kernel  xxx.elf // 跑完不跑bios只跑xxx.elf
  • qemu从UEFI启动
UEFI + ubuntu-16.04.3-server-arm64.iso
	http://doc.okbase.net/69908250/archive/258251.html
	https://blog.csdn.net/chenxiangneu/article/details/78955462

// ubuntu-16.04.3-server-arm64.iso 是ubuntu 官方发布的镜像文件
// 这种方式 是 一种 安装系统的方式,类似于 X86的系统安装
// ubuntu-16.04.3-server-arm64.iso 中有 u-boot ,kernel ,rootfs
// 这种启动方式, 第一个启动代码是 UEFI
// 启动流程 UEFI -> grub -> kernel -> rootfs

我之前搭好了一个从 UEFI 启动的平台 : https://blog.csdn.net/u011011827/article/details/120601147

qemu-system-aarch64 \
    -M virt \
    -cpu cortex-a57  -smp 1 \
    -m 1024M \
    -bios QEMU_EFI.fd \
    -drive if=none,file=xenial-server-cloudimg-arm64-uefi1.img,format=qcow2,id=hd0 -device virtio-blk-device,drive=hd0 \
    -netdev user,id=hostnet0,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=hostnet0 \
    -nographic
  • qemu从U-Boot启动
// 这种启动方式,要手动制作 u-boot , kernel , rootfs
// 这种启动方式, 第一个启动代码是 u-boot
// 启动流程 u-boot -> kernel -> rootfs

qemu virt 的启动有没有参考资料???
// 为什么可以从
我们探索从 u-boot 启动 ,可参考 https://stdrc.cc/post/2021/02/23/u-boot-qemu-virt/

qemu-system-aarch64  \
    -M virt \
    -cpu cortex-a57 -smp 1 \
    -m 2G \
    -bios u-boot.bin \
    -drive if=pflash,format=raw,index=1,file=flash.img \
    -nographic
  • 默认
从 EL1 boot
  • 虚拟化
-machine virt,virtualization=on
  • 安全
使用QEMU(3.0版本以上)模拟一个arm64 virt平台,virt平台上有两个cfi flash。
	// -machine virt,secure=on

启动过程为 : BootRom(BL1) 从Flash1 FIP中加载BL2,BL2再加载BL3, BL33(u-boot)

Flash0当成Boot使用,用于烧录 ATF(arm trust firmware)的BL1; 
	// -bios bl1.bin
Flash1上 用于烧录 格式为ATF FIP的Image 
	// 包含了BL2,BL31,BL33(uboot)
	// 注意 : BL33 可以为 Image ,即 不需要 uboot 的参与
	// BL33 在 ATF 配置为 ARM_LINUX_KERNEL_AS_BL33 是 Image 
	// 注意 : BL33 也可以为 QEMU_EFI.fd
	// QEMU_EFI.fd 可以完全替代 u-boot ,即 QEMU_EFI.fd 直接加载 Image
qemu-system-aarch64
-machine virt,secure=xxx 和 -machine virt,virtualization=yyy 的关系
总结:
	virtualization 可单独存在
	secure 存在时, virtualization 必须存在

qemu内存分配多少就用了多少 qemu支持的cpu_ios

qemu内存分配多少就用了多少 qemu支持的cpu_Virtualization_02

$ qemu-system-aarch64  -machine virt,help  
virt-6.1-machine options:
  acpi=<OnOffAuto>       - Enable ACPI
  append=<string>        - Linux kernel command line
  confidential-guest-support=<link<confidential-guest-support>> - Set confidential guest scheme to support
  default_bus_bypass_iommu=<bool> - Set on/off to enable/disable bypass_iommu for default root bus
  dt-compatible=<string> - Overrides the "compatible" property of the dt root node
  dtb=<string>           - Linux kernel device tree file
  dump-guest-core=<bool> - Include guest memory in a core dump
  dumpdtb=<string>       - Dump current dtb to a file and quit
  firmware=<string>      - Firmware image
  gic-version=<string>   - Set GIC version. Valid values are 2, 3, host and max
  graphics=<bool>        - Set on/off to enable/disable graphics emulation
  highmem=<bool>         - Set on/off to enable/disable using physical address space above 32 bits
  initrd=<string>        - Linux initial ramdisk file
  iommu=<string>         - Set the IOMMU type. Valid values are none and smmuv3
  its=<bool>             - Set on/off to enable/disable ITS instantiation
  kernel=<string>        - Linux kernel image file
  mem-merge=<bool>       - Enable/disable memory merge support
  memory-backend=<string> - Set RAM backendValid value is ID of hostmem based backend
  memory-encryption=<string> - Set memory encryption object to use
  mte=<bool>             - Set on/off to enable/disable emulating a guest CPU which implements the ARM Memory Tagging Extension
  phandle-start=<int>    - The first phandle ID we may generate dynamically
  ras=<bool>             - Set on/off to enable/disable reporting host memory errors to a KVM guest using ACPI and guest external abort exceptions
  secure=<bool>          - Set on/off to enable/disable the ARM Security Extensions (TrustZone)
  smp=<SMPConfiguration> - CPU topology
  suppress-vmdesc=<bool> - Set on to disable self-describing migration
  usb=<bool>             - Set on/off to enable/disable usb
  virtualization=<bool>  - Set on/off to enable/disable emulating a guest CPU which implements the ARM Virtualization Extensions
  x-oem-id=<string>      - Override the default value of field OEMID in ACPI table header.The string may be up to 6 bytes in size
  x-oem-table-id=<string> - Override the default value of field OEM Table ID in ACPI table header.The string may be up to 8 bytes in size