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
相关推荐
AndyHeee17 天前
【SVC、PendSV(系统异常) 与 外设 IRQ 、NVIC笔记】
arm开发
暮云星影17 天前
瑞芯微rk3588利用Rockchip NPU运行大语言模型(LLM)
arm开发·人工智能·语言模型·自然语言处理
techdashen17 天前
绕过系统 ICMP:用 rawsock、Npcap 和 WMI 找到默认网卡
开发语言·arm开发·rust
振南的单片机世界17 天前
ARM中断比51快在哪?硬件压栈+NVIC集中管理
arm开发·stm32·单片机·嵌入式硬件
墨绿色的摆渡人17 天前
论文笔记(一百三十七)Learning Dual-Arm Push and Grasp Synergy in Dense Clutter
arm开发·论文阅读
暮云星影17 天前
全志linux开发屏幕适配(一)屏幕参数设置说明
linux·arm开发
m0_5474866617 天前
《ARM Cortex-M4嵌入式应用技术——基于STM32F407、STM32CubeMX与Proteus》全套PPT课件
arm开发·stm32·proteus
Lanceli_van18 天前
SQLite 3.45.2(sqlite-autoconf-3450200)ARM 交叉编译完整步骤
arm开发·sqlite
暮云星影18 天前
全志linux开发屏幕适配(二)`HDMI`驱动适配说明
linux·arm开发·驱动开发
暮云星影18 天前
瑞芯微rk3566开发FIT Secure Boot
linux·arm开发·驱动开发·安全