Qemu arm操作系统开发环境

使用qemu虚拟arm硬件比较合适。

步骤如下:

  1. 安装qemu
bash 复制代码
apt install qemu-system
  1. 安装aarch64-none-elf-gcc

需要手动下载,下载地址:https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-aarch64-none-elf.tar.xz?rev=a05df3001fa34105838e6fba79ee1b23&hash=DCB97F9E407955B162E4652F4E78B6CCDF75E4FF

下载后无需编译。下载完虎,执行如下命令设置编译环境:

bash 复制代码
vim ~/.bashrc

export PATH=$PATH:/home/ljg/aarch/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-elf/aarch64-none-elf/bin

source ~/.bashrc
  1. 编译uart.c源文件

代码:

c 复制代码
void outputstr(char * str){

        int * base = (int*)0x9000000;
        while(*str){
                *base = (int)*str;
               str++;
        }
}

int main(){
        outputstr("hello world!\r\n");

        return 0x12345678;
}
~  

命令:

bash 复制代码
aarch64-none-elf-gcc -I -include -c uart.c -o uart.o
  1. 编写start.s汇编源文件

代码:

bash 复制代码
.global _start

_start:
ldr x30,=stack_top
mov sp,x30
bl main
b .
~   

命令:

bash 复制代码
aarch64-none-elf-as -c start.s -o start.o
  1. 链接

链接脚本文件:

bash 复制代码
ENTRY(_start)
SECTIONS
{
        . = 0x40000000;
        .startup . : {start.o(.text)}
        .text :{*(.text)}
        .data : {*(.data)}
        .bss : {*(.bss COMMON)}
        . = ALIGN(8);
        . = .+0x1000;
        stack_top = .;
}

命令:

bash 复制代码
aarch64-none-elf-ld -Tlink.ld  uart.o start.o -o hello.elf
  1. 制作镜像文件。
bash 复制代码
aarch64-none-elf-objcopy -O binary hello.elf hello.bin
  1. 运行测试
bash 复制代码
qemu-system-aarch64 -M virt -cpu cortex-a710 -monitor none -kernel hello.bin

或者:

bash 复制代码
qemu-system-aarch64 -M virt -cpu cortex-a710 -monitor none -nographic -serial stdio -kernel hello.bin

参考链接:

  1. https://blog.csdn.net/jingyu_1/article/details/135631512
  2. https://zhuanlan.zhihu.com/p/16952747762
  3. https://stdrc.cc/post/2021/02/23/u-boot-qemu-virt/
  4. https://zhuanlan.zhihu.com/p/708166648
  5. https://www.qemu.org/docs/master/system/arm/virt.html
相关推荐
GilgameshJSS12 小时前
STM32H743-ARM例程13-SDIO
c语言·arm开发·stm32·嵌入式硬件·学习
GilgameshJSS12 小时前
STM32H743-ARM例程8-EXTI外部中断
c语言·arm开发·stm32·单片机·嵌入式硬件·学习
月盈缺12 小时前
学习嵌入式的第四十三天——ARM——I2C
arm开发·学习
三毛20041 天前
玳瑁的嵌入式日记---0929(ARM--ADC)
arm开发
上园村蜻蜓队长1 天前
ARM芯片架构之DAP:AXI-AP 技术详解
arm开发·fpga开发·架构·rtl
月盈缺1 天前
学习嵌入式的第四十四天——ARM——I2C
arm开发·学习
馨羽的玩具1 天前
Windows系统安装arm麒麟系统
arm开发·windows
三毛20041 天前
玳瑁的嵌入式日记---0928(ARM--UART)
网络·arm开发
上园村蜻蜓队长2 天前
ARM芯片架构之调试访问端口(DAP)
arm开发·单片机·fpga开发·架构
GilgameshJSS2 天前
STM32H743-ARM例程9-IWDG看门狗
c语言·arm开发·stm32·单片机·嵌入式硬件·学习