Where does Raspberry Pi 4 load the kernel?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Where does Raspberry Pi 4 load the kernel?

Post by pvc »

I've recently bought RPI4 and it seems to be quite powerful board, but lack of any kind of technical documentation in just painful.
I've had problems running bare metal code on it because of memory corruption, or so I thought. I don't have any 3V compatible serial adapter and no one seems to be able to debug it over JTAG yet.
After I've got video controller to be able to display some text, I've found that my kernel8.img seems to be loaded at address 0 instead of 0x80000. kernel_base and old_kernel options seem to be ignored. Can anyone confirm that behaviour? BTW. I am booting it over network using built-in bootcode.bin (no SD card).
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: Where does Raspberry Pi 4 load the kernel?

Post by bzt »

Hi,

Yes, finding the latest documentation for Raspberry is not an easy job. It is quite nice for Pi3 and older models, but not for the Pi4. I'd suggest to start here raspi3-tutorial, although it's for the Pi3, there's a bunch of links on the readme to other tutorials, some of which already ported to Pi4. Maybe you can find a clue. If you're not afraid of Pascal, it definitely worth checking out https://ultibo.org as it has the most comprehensive bare metal support (Pi4 included).

I'm not surprised it does not recognize kernel_old options, the bootcode.bin was almost entirely rewritten for the RPi4. Unfortunately the stub does not help either. https://github.com/raspberrypi/linux/bl ... m/memory.h refers to VA only, and the code to set up paging https://github.com/raspberrypi/linux/bl ... nel/head.S is not something I would call clean and readable source (I'd not suggest to check the linker script because that's even worse). Maybe you should start by deleting config.txt, name your kernel kernel8.img, then the firmeware should load it at 0x80000 from SD. Offset 0 is suspicious, I don't think that should be, not with network boot either. Not sure config.txt is loaded correctly if not loaded from SD, it may depend on what server you use? (I mean maybe some config pushed in dhcp overrides perhaps? Just guessing here.)

About the serial, I'd suggest to get one. You'll get debug messages sooner with RS232 than with JTAG. Also try SD card first, and when it's working properly then you can compare it to the network boot, that way you can confirm if the problem is indeed with the configuration loaded over the network, or something else.

Cheers,
bzt
User avatar
pvc
Member
Member
Posts: 201
Joined: Mon Jan 15, 2018 2:27 pm

Re: Where does Raspberry Pi 4 load the kernel?

Post by pvc »

Oh yeah. I was using code from your tutorial to get video controller going. You did great job on that.
Post Reply