简体   繁体   English

如何将ARM源文件制作为Raspberry Pi 3 B将运行的内核?

[英]How do I make an ARM source file into a kernel that the Raspberry Pi 3 B will run?

I was inspired by this Starfox fan game to create a game using ARM assembly on the Raspberry Pi. 我受到这个Starfox粉丝游戏的启发,在Raspberry Pi上使用ARM组件创建了一个游戏。 I have also looked at this tutorial series to get a better understanding of the mailbox and frame buffer systems. 我还查看了本教程系列 ,以更好地了解邮箱和帧缓冲系统。 No matter which Make/CMake I use, I cannot get anything from either of those places to run on startup because they were expected to run on the original Raspberry Pi. 无论我使用哪个Make / CMake,我都无法从这两个地方获得任何东西来启动,因为它们应该在原始的Raspberry Pi上运行。 I have looked at Valver's bare metal programming tutorial, the raspberrypi.org bare metal forums, and countless output source files from my own C code just to understand how to print graphics on the screen and have gotten nowhere. 我看过Valver的裸机编程教程,raspberrypi.org裸机论坛以及我自己的C代码中无数的输出源文件,只是为了了解如何在屏幕上打印图形而一无所获。 I have used the X11 library in my C code only to find that the output ARM source file simply calls the C functions as is (eg bl XOpenDisplay ). 我仅在C代码中使用X11库,只是发现输出ARM源文件仅按原样调用C函数(例如bl XOpenDisplay )。 If I try to execute the code given at the second link (making sure to change the base peripheral address to 0x3F000000 and the video core access to 0xC0000000 ) while Raspbian is running, I get segmentation faults. 如果我在Raspbian运行时尝试执行第二个链接给出的代码(确保将基本外设地址更改为0x3F000000并将视频核心访问权限更改为0xC0000000 ),则会遇到分段错误。

I want to have an assembly source file (say, main.s ) and make it into a binary (say, kernel7.img or similar) that will run as soon as I turn on my Raspberry Pi 3 B. 我想要一个程序集源文件(例如main.s )并将其制作为二进制文件(例如kernel7.img或类似文件),该文件将在我打开Raspberry Pi 3 B时立即运行。

Yes, I know making GUIs in high level languages is easier, but I am determined to make the game operate in ARM assembly. 是的,我知道用高级语言制作GUI会更容易,但是我决心让游戏在ARM汇编中运行。 Here are some answers that would be most helpful in my personal project: 以下是一些对我的个人项目最有帮助的答案:

  1. Porting the code from the first two links to successfully run on my Pi 3 upon startup, bearing in mind that they produce the wrong binaries for my model. 从前两个链接移植代码以在启动时成功在我的Pi 3上运行,请记住它们会为我的模型生成错误的二进制文件。
  2. Tools for building a custom OS that can inject assembly code as needed, though I'm not sure how plausible that is. 用于构建自定义OS的工具可以根据需要注入汇编代码,尽管我不确定这样做是否合理。
  3. Resources to learn how to make GUIs in ARM assembly that can run on the latest Raspbian without creating segmentation faults or similar errors. 学习如何在ARM程序集中制作GUI且可以在最新的Raspbian上运行而不产生分段错误或类似错误的资源。

Thank you! 谢谢!

baremetal is probably the right way to go here. 裸机可能是正确的选择。 the baking pi series is fine lots of folks have started there, it has issues that will probably get in your way. 烘焙pi系列很好,很多人都从那里开始,它的问题可能会困扰您。 The baremetal forum at raspberrypi.org is very very good, there is a pinned thread with lots of baremetal information and examples. raspberrypi.org上的baremetal论坛非常好,有一个固定的线程,其中包含许多baremetal信息和示例。

vectors.s vectors.s

.globl _start
_start:
    mov sp,#0x8000
    bl notmain
hang: b hang

.globl PUT32
PUT32:
    str r1,[r0]
    bx lr

.globl GET32
GET32:
    ldr r0,[r0]
    bx lr

.globl dummy
dummy:
    bx lr

notmain.c notmain.c

extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void dummy ( unsigned int );

#define SYSTIMERCLO 0x20003004
#define GPFSEL3 0x2020000C
#define GPFSEL4 0x20200010
#define GPSET1  0x20200020
#define GPCLR1  0x2020002C

//0x01000000 17 seconds
//0x00400000 4 seconds
//#define TIMER_BIT 0x01000000
#define TIMER_BIT 0x00400000

int notmain ( void )
{
    unsigned int ra;

    ra=GET32(GPFSEL4);
    ra&=~(7<<21);
    ra|=1<<21;
    PUT32(GPFSEL4,ra);

    while(1)
    {
        PUT32(GPSET1,1<<(47-32));
        while(1)
        {
            ra=GET32(SYSTIMERCLO);
            if((ra&=TIMER_BIT)==TIMER_BIT) break;
        }
        PUT32(GPCLR1,1<<(47-32));
        while(1)
        {
            ra=GET32(SYSTIMERCLO);
            if((ra&=TIMER_BIT)==0) break;
        }
    }
    return(0);
}

memmap MEMMAP

MEMORY
{
    ram : ORIGIN = 0x8000, LENGTH = 0x1000
}

SECTIONS
{
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}

build 建立

arm-none-eabi-as --warn --fatal-warnings vectors.s -o vectors.o
arm-none-eabi-gcc -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding -c notmain.c -o notmain.o
arm-none-eabi-ld vectors.o notmain.o -T memmap -o notmain.elf
arm-none-eabi-objdump -D notmain.elf > notmain.list
arm-none-eabi-objcopy notmain.elf -O binary kernel.img

on pi-zero remove any config.txt, save or rename any kernel.img and copy this kernel.img and the leds will blink. 在pi-zero上,删除任何config.txt,保存或重命名任何kernel.img,然后复制此kernel.img,LED将会闪烁。

remove the c code and branch into your main add that to the project and there you go... 删除c代码并将其分支到您的主目录中,然后将其添加到项目中,然后就可以开始...

the framebuffer for video is super easy, one mailbox handshake and you have a base address to shove pixels into... 视频的帧缓冲区非常容易,一个邮箱握手,您就有一个基地址可以将像素推入...

start with a pi-zero...for a pi3 you will want to be in aarch32 mode which you may need a config.txt to do. 从pi-zero开始...对于pi3,您将需要处于aarch32模式,这可能需要config.txt来完成。 it for the most part works the same if you are not doing any interrupts, if you are then there are plenty of baremetal examples to show you the modifications... 如果您不执行任何中断,则大多数情况下它都是相同的,如果您这样做,那么有很多裸机示例可以向您展示这些修改...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM