在qemu virt平台运行xen, guest OS Dom0 Mini-OS

该篇博客详细介绍了如何在AARCH64架构下编译Mini-OS并使用QEMU进行模拟运行。首先从GitHub下载或使用预修改的Mini-OS源代码,通过指定参数执行`make`生成可执行文件。接着,配置QEMU参数启动Xen和Mini-OS,并展示QEMU的启动过程。在Mini-OS运行过程中,可以看到一系列内核信息输出,表明Mini-OS成功加载并运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1)编译mini-os

        到github上去下载合适的mini-os源文件,或者使用博主下载的mini-os

注:博主已修改过一些东西,不需要的则可自行下载。

编译生成可执行文件:

make MINIOS_COMPILE_ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-

编译生成文件mini-os.img,将其拷贝至跟xen同一目录下。

2)运行 Qemu Xen Dom0 Mini-OS

qemu-system-aarch64 -machine virt,gic_version=3 -machine virtualization=true -cpu cortex-a57 -machine type=virt -m 2048 -smp 4 -bios u-boot.bin -device loader,file=xen,force-raw=on,addr=0x49000000 -device loader,file=mini-os.img,addr=0x47000000 -device loader,file=virt-gicv3.dtb,addr=0x44000000 -nographic -no-reboot -chardev socket,id=qemu-monitor,host=localhost,port=7777,server,nowait,telnet -mon qemu-monitor,mode=readline

U-Boot 2019.01 (Aug 25 2021 - 02:57:47 -0700)

DRAM:  2 GiB
Flash: 128 MiB
*** Warning - bad CRC, using default environment

In:    pl011@9000000
Out:   pl011@9000000
Err:   pl011@9000000
Net:   No ethernet found.
Hit any key to stop autoboot:  0 
=> 

配置设备树:

setenv xen_bootargs 'dom0_mem=512M'
fdt addr 0x44000000
fdt resize
fdt set /chosen \#address-cells <1>
fdt set /chosen \#size-cells <1>
fdt mknod /chosen module@0
fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
fdt set /chosen/module@0 reg <0x47000000 0x29388>
booti 0x49000000 - 0x44000000

mini-os运行结果:

U-Boot 2019.01 (Aug 25 2021 - 02:57:47 -0700)

DRAM:  2 GiB
Flash: 128 MiB
*** Warning - bad CRC, using default environment

In:    pl011@9000000
Out:   pl011@9000000
Err:   pl011@9000000
Net:   No ethernet found.
Hit any key to stop autoboot:  0 
=> setenv xen_bootargs 'dom0_mem=512M'
=> fdt addr 0x44000000
=> fdt resize
=> fdt set /chosen \#address-cells <1>
=> fdt set /chosen \#size-cells <1>
=> fdt mknod /chosen module@0
=> fdt set /chosen/module@0 compatible "xen,linux-zimage" "xen,multiboot-module"
=> fdt set /chosen/module@0 reg <0x47000000 0x29388>
=> booti 0x49000000 - 0x44000000
## Flattened Device Tree blob at 44000000
   Booting using the fdt blob at 0x44000000
   reserving fdt memory region: addr=44000000 size=2000
   Loading Device Tree to 00000000bedf6000, end 00000000bedfafff ... OK

Starting kernel ...

 Xen 4.16-unstable
(XEN) Xen version 4.16-unstable (hdwei@) (aarch64-linux-gnu-gcc (Linaro GCC 7.2-2017.11) 7.2.1 20171011) debug=y Thu Aug 26 01:38:18 PDT 2021
(XEN) Latest ChangeSet: Fri Aug 20 16:18:12 2021 +0200 git:93713f4
(XEN) build-id: 8378c443d4d2f5c70e34b7b0a987e652a6270b9f
(XEN) Processor: 00000000411fd070: "ARM Limited", variant: 0x1, part 0xd07,rev 0x0
(XEN) 64-bit Execution:
(XEN)   Processor Features: 0000000001000222 0000000000000000
(XEN)     Exception Levels: EL3:No EL2:64+32 EL1:64+32 EL0:64+32
(XEN)     Extensions: FloatingPoint AdvancedSIMD GICv3-SysReg
(XEN)   Debug Features: 0000000010305106 0000000000000000
(XEN)   Auxiliary Features: 0000000000000000 0000000000000000
(XEN)   Memory Model Features: 0000000000001124 0000000000000000
(XEN)   ISA Features:  0000000000011120 0000000000000000
(XEN) 32-bit Execution:
(XEN)   Processor Features: 0000000000000131:0000000010011001
(XEN)     Instruction Sets: AArch32 A32 Thumb Thumb-2 Jazelle
(XEN)     Extensions: GenericTimer
(XEN)   Debug Features: 0000000003010066
(XEN)   Auxiliary Features: 0000000000000000
(XEN)   Memory Model Features: 0000000010101105 0000000040000000
(XEN)                          0000000001260000 0000000002102211
(XEN)   ISA Features: 0000000002101110 0000000013112111 0000000021232042
(XEN)                 0000000001112131 0000000000011142 0000000000011121
(XEN) Using SMC Calling Convention v1.0
(XEN) Using PSCI v0.2
(XEN) SMP: Allowing 4 CPUs
(XEN) enabled workaround for: ARM erratum 832075
(XEN) enabled workaround for: ARM erratum 834220
(XEN) enabled workaround for: ARM erratum 1319367
(XEN) Generic Timer IRQ: phys=30 hyp=26 virt=27 Freq: 62500 KHz
(XEN) GICv3 initialization:
(XEN)       gic_dist_addr=0x00000008000000
(XEN)       gic_maintenance_irq=25
(XEN)       gic_rdist_stride=0
(XEN)       gic_rdist_regions=1
(XEN)       redistributor regions:
(XEN)         - region 0: 0x000000080a0000 - 0x00000009000000
(XEN) GICv3: 256 lines, (IID 0000043b).
(XEN) GICv3: CPU0: Found redistributor in region 0 @000000004001c000
(XEN) XSM Framework v1.0.0 initialized
(XEN) Initialising XSM SILO mode
(XEN) Using scheduler: SMP Credit Scheduler rev2 (credit2)
(XEN) Initializing Credit2 scheduler
(XEN)  load_precision_shift: 18
(XEN)  load_window_shift: 30
(XEN)  underload_balance_tolerance: 0
(XEN)  overload_balance_tolerance: -3
(XEN)  runqueues arrangement: socket
(XEN)  cap enforcement granularity: 10ms
(XEN) load tracking window length 1073741824 ns
(XEN) Allocated console ring of 32 KiB.
(XEN) CPU0: Guest atomics will try 1 times before pausing the domain
(XEN) Bringing up CPU1
(XEN) GICv3: CPU1: Found redistributor in region 0 @000000004003c000
(XEN) CPU1: Guest atomics will try 1 times before pausing the domain
(XEN) CPU 1 booted.
(XEN) Bringing up CPU2
(XEN) GICv3: CPU2: Found redistributor in region 0 @000000004005c000
(XEN) CPU2: Guest atomics will try 1 times before pausing the domain
(XEN) CPU 2 booted.
(XEN) Bringing up CPU3
(XEN) GICv3: CPU3: Found redistributor in region 0 @000000004007c000
(XEN) CPU3: Guest atomics will try 2 times before pausing the domain
(XEN) CPU 3 booted.
(XEN) Brought up 4 CPUs
(XEN) I/O virtualisation disabled
(XEN) P2M: 44-bit IPA with 44-bit PA and 8-bit VMID
(XEN) P2M: 4 levels with order-0 root, VTCR 0x0000000080043594
(XEN) Scheduling granularity: cpu, 1 CPU per sched-resource
(XEN) Adding cpu 0 to runqueue 0
(XEN)  First cpu on runqueue, activating
(XEN) Adding cpu 1 to runqueue 0
(XEN) Adding cpu 2 to runqueue 0
(XEN) Adding cpu 3 to runqueue 0
(XEN) alternatives: Patching with alt table 00000000002dc408 -> 00000000002dcc18
(XEN) **** No support for ARM_SMCCC_ARCH_WORKAROUND_1. ****
(XEN) **** Please update your firmware.                ****
(XEN) **** No support for ARM_SMCCC_ARCH_WORKAROUND_1. ****
(XEN) **** Please update your firmware.                ****
(XEN) **** No support for ARM_SMCCC_ARCH_WORKAROUND_1. ****
(XEN) **** Please update your firmware.                ****
(XEN) **** This CPU is affected by the errata 832075.                      ****
(XEN) **** Guests without CPU erratum workarounds can deadlock the system! ****
(XEN) **** Only trusted guests should be used.                             ****
(XEN) *** LOADING DOMAIN 0 ***
(XEN) Loading d0 kernel from boot module @ 0000000047000000
(XEN) Allocating 1:1 mappings totalling 512MB for dom0:
(XEN) BANK[0] 0x00000060000000-0x00000080000000 (512MB)
(XEN) Grant table range: 0x00000049000000-0x00000049040000
(XEN) Allocating PPI 16 for event channel interrupt
(XEN) Loading zImage from 0000000047000000 to 0000000060000000-0000000060029388
(XEN) Loading d0 DTB to 0x0000000068000000-0x0000000068001c88
(XEN) Initial low memory virq threshold set at 0x4000 pages.
(XEN) Scrubbing Free RAM in background
(XEN) Std. Loglevel: All
(XEN) Guest Loglevel: All
(XEN) ***************************************************
(XEN) PLEASE SPECIFY dom0_mem PARAMETER - USING 512M FOR NOW
(XEN) ***************************************************
(XEN) 3... 2... 1... 
(XEN) *** Serial input to DOM0 (type 'CTRL-a' three times to switch input)
(XEN) Freed 336kB init memory.
- Mini-OS booting -
- Setup CPU -
- Setup booting pagetable -
- MMU on -
- Setup stack -
- Jumping to C entry -
Checking DTB at ffffffbfffe00000...
map_console, phys = 0x0
Console is on port 0
Console ring is at mfn ffffffbfffc00000
MM: Init
    _text: ffffffc000000000(VA)
    _etext: ffffffc0000182a0(VA)
    _erodata: ffffffc00001e000(VA)
    _edata: ffffffc000029388(VA)
    stack start: ffffffc000025000(VA)
    _end: ffffffc0000327d8(VA)
Found memory at 0x60000000 (len 0x20000000)
Using pages 393267 to 524288 as free space for heap.
MM: Initialise page allocator for ffffffc000033000(60033000)-ffffffc020000000(80000000)
MM: done
Initialising timer interface
Virtual Count register is d61fdcf, freq = 62500000 Hz
Initialising console ... done.
Initialising scheduler
Thread "Idle": pointer: 0xffffffc000043020, stack: 0xffffffc000050000
Thread "xenstore": pointer: 0xffffffc000043080, stack: 0xffffffc000060000
xenbus initialised on irq 0 mfn 0x0
Thread "shutdown": pointer: 0xffffffc0000430e0, stack: 0xffffffc000070000
start mini-os 
hello world!!! 
hello world!!! 
hello world!!! 
hello world!!! 

已编译好的可执行文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值