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
相关推荐
待什么青丝2 天前
【TMS570LC4357】之相关驱动开发学习记录1
c语言·arm开发·驱动开发·学习
南玖yy2 天前
x86 汇编逻辑运算全解析:从【位操作】到实际应用(AND,OR,NOT,XOR,TEST)
开发语言·汇编·arm开发·后端·架构·策略模式
菜只因C4 天前
嵌入式系统:从技术原理到未来趋势(驱动程序篇)
arm开发
!chen5 天前
鲲鹏Arm+麒麟V10 K8s 离线部署教程
java·arm开发·kubernetes
ScilogyHunter6 天前
ARM P15协处理器指令详解:架构、编程与应用实践
arm开发·协处理器指令·cp15
apolloyhl7 天前
1-Wire 一线式总线:从原理到实战,玩转 DS18B20 温度采集
arm开发·stm32·单片机·嵌入式硬件
二进制coder7 天前
芯片:数字时代的算力引擎——鲲鹏、升腾、海光、Intel 全景解析
arm开发·架构·硬件架构
荆楚闲人7 天前
Keil MDK5.37或更高版本不再预装ARM Compiler Version5导致编译错误的解决方法
arm开发
MonKingWD7 天前
【Redis原理】四万字总结Redis网络模型的全部概念
网络·arm开发·redis