Death Star
Posts: 1
Joined: Thu Apr 15, 2021 9:22 pm

Rpi4 bare metal - RTOS

Thu Apr 15, 2021 10:15 pm

Hi,
I'm trying to do something with a Raspberry Pi 4
I'm quite a beginner in programming but I am aware of the difficulties I'm going to have to learn something.

The final goal is far, for now I just want to learn some basics.
My first step was to build u-boot because I tought it was useful for loading kernel images through serial TTL cable.
Then I discovered:
https://gitlab.com/bztsrc/imgrecv
and
https://gitlab.com/bztsrc/usbimager
that seems to be a better choice for me.

I think my first step into this world should be to follow this:
https://github.com/bztsrc/raspi3-tutorial
but this is for Rpi3 and here I already have some difficulties.

What I have tried for now is:
✔ Boot u-boot with output on screen and serial (TTL cable to windows PC with putty). I put the kernel8.img of u-boot directly on the SD card.
✘ Boot u-boot chainloading it via usbimager and the SD card with the image of imgrecv (I am stuck at rainbow screen)
✘ Boot the https://github.com/bztsrc/raspi3-tutori ... areminimum chainloading it (I am stuck at rainbow screen)

In all of the tests I had the SD card FAT formatted with those files inside:
- bcm2711-rpi-4-b.dtb
- config.txt
- fixup4x.dat
- kernel8.img
- start4x.elf

Inside config.txt:

Code: Select all

# Set sdtv mode to PAL (as used in Europe)
sdtv_mode=2
# Force the monitor to HDMI mode so that sound will be sent over HDMI cable
hdmi_drive=2
# Set monitor mode to DMT
hdmi_group=2
# Set monitor resolution
hdmi_mode=82
# Make display smaller to stop text spilling off the screen
disable_overscan=0
overscan_left=256
overscan_right=0
overscan_top=64
overscan_bottom=0
#U-Boot
enable_uart=1
arm_64bit=1
#CSI
start_x=1
Now I'm a little stuck as I don't know how to proceed the troubleshoting or what to try more



Future steps:
https://gitlab.com/rodos

finlout
Posts: 1
Joined: Fri Apr 16, 2021 6:08 pm

Re: Rpi4 bare metal - RTOS

Fri Apr 16, 2021 6:10 pm

You can try to follow along with https://github.com/isometimes/rpi4-osdev which is based around the Pi4 and fill in the blanks with the Pi3 sources you have.

bzt
Posts: 630
Joined: Sat Oct 14, 2017 9:57 pm

Re: Rpi4 bare metal - RTOS

Sat Apr 17, 2021 12:23 pm

Death Star wrote:
Thu Apr 15, 2021 10:15 pm
Then I discovered:
https://gitlab.com/bztsrc/imgrecv
and
https://gitlab.com/bztsrc/usbimager
that seems to be a better choice for me.
Good to hear! :-)
Death Star wrote:
Thu Apr 15, 2021 10:15 pm
I think my first step into this world should be to follow this:
https://github.com/bztsrc/raspi3-tutorial
but this is for Rpi3 and here I already have some difficulties.
Yes, RPi4 uses a different MMIO base than the RPi3. Some peripherals are mapped at different offsets too, and some devices are different too. I've tested imgrecv on RPi3, because I don't have an RPi4 board.
Death Star wrote:
Thu Apr 15, 2021 10:15 pm
✘ Boot u-boot chainloading it via usbimager and the SD card with the image of imgrecv (I am stuck at rainbow screen)
That might by correct.
Death Star wrote:
Thu Apr 15, 2021 10:15 pm
✘ Boot the https://github.com/bztsrc/raspi3-tutori ... areminimum chainloading it (I am stuck at rainbow screen)
This is perfectly fine, that's exactly how it should look like.
Death Star wrote:
Thu Apr 15, 2021 10:15 pm
Inside config.txt:
All my tutorials and my other software were written to work with the default configuration (eg. no config.txt at all).
Death Star wrote:
Thu Apr 15, 2021 10:15 pm
Now I'm a little stuck as I don't know how to proceed the troubleshoting or what to try more
Try different solutions, replacing one at a time. The original code is here. Compile and place raspbootin as kernel7.img on the card (note, this is 32 bit code, not 64 bit). Instead of 01_bareminimum, try the 03_uart example (however USBImager does not display the uart output, so use the original raspbootcom or maybe my ANSI C version of raspbootcom, those will display everything that the RPi sends to the uart, so you should be able to see "Hello World", but the screen should display the rainbow splash). Alternatively try the 09_framebuffer example, that's the first one which draws something on the screen.

But before anything, replace the MMIO address in my tutorials with the RPi4's MMIO address, it won't work otherwise. Or try to load a kernel written directly for the RPi4, like rpi4-osdev.

Cheers,
bzt

sean.lawless
Posts: 59
Joined: Thu Jun 06, 2019 6:07 pm

Re: Rpi4 bare metal - RTOS

Fri Apr 23, 2021 12:15 am

If creating a bootloader sounds fun, this project was recently updated for RPi4: https://github.com/sean-lawless/computersystems

Return to “Bare metal, Assembly language”