sheroy
Posts: 33
Joined: Fri Jun 14, 2013 5:34 pm

Bare metal on raspberry pi 3 B+ not booting - finally working

Thu May 24, 2018 5:06 pm

I was trying bare metal to boot my kernel on the PI 3 B+. It was unable to boot. Disassembly of the elf file, assembly seemed right - nothing wrong. yet was unable to boot.

Copied the files to kernel7.img and made a copy to kernel.img. Yet it did not seem to work.

What worked was adding

Code: Select all

kernel=kernel7.img
kernel_address=0x8000
these 2 lines to the config.txt

It finally worked after days of trying to figure out!!! I was yet unable to figure out why this behaviour.

satadru
Posts: 6
Joined: Thu Apr 18, 2013 5:18 pm

Re: Bare metal on raspberry pi 3 B+ not booting - finally working

Fri Jun 01, 2018 6:29 pm

That's supposed to be the default kernel address for 32 bit kernels.

I'm able to boot a 64 bit kernel saved as kernel8.img and this in the config.txt:

kernel=kernel8.img

dwelch67
Posts: 939
Joined: Sat May 26, 2012 5:32 pm

Re: Bare metal on raspberry pi 3 B+ not booting - finally working

Fri Jun 01, 2018 7:27 pm

config.txt is not required to run bare metal on the pi, just need to have the right bootstrap and the right linker/entry address and possibly file name for the particular board. you should understand both how to override the defaults with config.txt but also use the defaults without.

sheroy
Posts: 33
Joined: Fri Jun 14, 2013 5:34 pm

Re: Bare metal on raspberry pi 3 B+ not booting - finally working

Fri Jun 08, 2018 2:32 pm

dwelch67 wrote:
Fri Jun 01, 2018 7:27 pm
config.txt is not required to run bare metal on the pi, just need to have the right bootstrap and the right linker/entry address and possibly file name for the particular board. you should understand both how to override the defaults with config.txt but also use the defaults without.
kernel8.img as the file name did not work. I am using the pi 3 B+ in 32 bit.
I tried all configurations before finding this solution. My linker entry point is 0x8000. and just using kernel7.img also did not work. For some apparent reason I was forced to specify the entry point in the config file for it to work.

dwelch67
Posts: 939
Joined: Sat May 26, 2012 5:32 pm

Re: Bare metal on raspberry pi 3 B+ not booting - finally working

Sat Jun 09, 2018 3:14 am

If you had tried all combinations you would have found the ones that work.

dwelch67
Posts: 939
Joined: Sat May 26, 2012 5:32 pm

Re: Bare metal on raspberry pi 3 B+ not booting - finally working

Sat Jun 09, 2018 3:38 am

vectors.s

Code: Select all

.globl _start
_start:
    mov sp,#0x08000000
    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

Code: Select all

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

#define GPFSEL2 0x3F200008
#define GPSET0  0x3F20001C
#define GPCLR0  0x3F200028

int notmain ( void )
{
    unsigned int ra;

    ra=GET32(GPFSEL2);
    ra&=~(7<<27);
    ra|=1<<27;
    PUT32(GPFSEL2,ra);

    while(1)
    {
        PUT32(GPSET0,1<<29);
        for(ra=0;ra<0x80000;ra++) dummy(ra);
        PUT32(GPCLR0,1<<29);
        for(ra=0;ra<0x80000;ra++) dummy(ra);
    }

    return(0);
}

memmap

Code: Select all

MEMORY
{
    ram : ORIGIN = 0x8000, LENGTH = 0x1000000
}
SECTIONS
{
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}
build

Code: Select all

arm-none-eabi-as --warn --fatal-warnings vectors.s -o vectors.o
arm-none-eabi-gcc -Wall -O2  -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 kernel7.img

The only files on the sd card are the current bootcode.bin, start.elf and kernel7.img, just downloaded bootcode.bin and start.elf before writing this post.

Raspberry Pi 3 B+, the above runs and blinks the led.

vectors.s

Code: Select all

.globl _start
_start:
    b skip
    b hang
    b hang
    b hang
    b hang
    b hang
    b hang
    b hang

skip:
    mov sp,#0x08000000
    bl notmain
hang: b hang

.globl PUT32
PUT32:
  str w1,[x0]
  ret

.globl GET32
GET32:
    ldr w0,[x0]
    ret

.globl dummy
dummy:
    ret
notmain.c (can use the same one this one has a different timeout to see that the program did change)

Code: Select all


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

#define GPFSEL2 0x3F200008
#define GPSET0  0x3F20001C
#define GPCLR0  0x3F200028

int notmain ( void )
{
    unsigned int ra;

    ra=GET32(GPFSEL2);
    ra&=~(7<<27);
    ra|=1<<27;
    PUT32(GPFSEL2,ra);

    while(1)
    {
        PUT32(GPSET0,1<<29);
        for(ra=0;ra<0x100000;ra++) dummy(ra);
        PUT32(GPCLR0,1<<29);
        for(ra=0;ra<0x100000;ra++) dummy(ra);
    }

    return(0);
}
memmap

Code: Select all

MEMORY
{
    ram : ORIGIN = 0x80000, LENGTH = 0x1000000
}
SECTIONS
{
    .text : { *(.text*) } > ram
    .bss : { *(.bss*) } > ram
}
build

Code: Select all

aarch64-none-elf-as --warn --fatal-warnings vectors.s -o vectors.o
aarch64-none-elf-gcc -Wall -O2  -c notmain.c -o notmain.o
aarch64-none-elf-ld vectors.o notmain.o -T memmap -o notmain.elf
aarch64-none-elf-objdump -D notmain.elf > notmain.list
aarch64-none-elf-objcopy notmain.elf -O binary kernel8.img
The only files on the sd card are the same bootcode.bin and start.elf, downloaded around 10-15 minutes ago, and kernel8.img (remember to delete kernel7.img)

Raspberry Pi 3 B+. runs and blinks the led.

no config.txt required. There are plenty of examples demonstrating this as well as a fair amount of posts and threads on this site about the file name/arch/entry point combinations.

Return to “Bare metal, Assembly language”

Who is online

Users browsing this forum: No registered users and 2 guests