changing kernel load address on rpi4

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
SikkiLadho
Posts: 2
Joined: Sat Oct 30, 2021 3:38 am
Libera.chat IRC: sikkiladho

changing kernel load address on rpi4

Post by SikkiLadho »

I am trying to learn systems programming. I have create a simple kernel, which prints Hello World to the UART on a Raspberry pi 4 model B. Source code can be found here. It works perfectly when kernel load address is 0x80000(which is the default load address). I would like to change the load address of the kernel and it should still be functional.

Here's the source code.
https://github.com/SikkiLadho/Leo

I tried to change the kernel_address=[any_address_other_than_defaul](for example kernel_address=0x7F78E), and I cannot see the Hello World printed on the UART. I tried reflecting this change of load_address in the linker script, but it still would not print Hello World.

Code: Select all

SECTIONS
{
	. = 0x7F78E;
	.text.boot : { *(.text.boot) }
	.text : { *(.text) }
	.rodata : { *(.rodata) }
	.data : { *(.data) }
	. = ALIGN(0x8);
	bss_begin = .;
	.bss : { *(.bss*) } 
	bss_end = .;
}
My kernel only prints Hello World, when it is loaded to 0x80000. How can I successfully load it at the different address?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: changing kernel load address on rpi4

Post by Octocontrabass »

You can't change the default load address, it's always 0x80000 for 64-bit kernels. If you want your kernel to run at a different address, you need to write code that will move the kernel.
SikkiLadho
Posts: 2
Joined: Sat Oct 30, 2021 3:38 am
Libera.chat IRC: sikkiladho

Re: changing kernel load address on rpi4

Post by SikkiLadho »

Octocontrabass wrote:You can't change the default load address, it's always 0x80000 for 64-bit kernels. If you want your kernel to run at a different address, you need to write code that will move the kernel.
Thank you for your reply. Actually, I wanted to load a simple hello world executable fused with the standard kernel) at [default load address - size of hello world kernel]. After simple kernel has printed Hello World to UART, it would eret to 0x80000, from where standard kernel would run.

How can I move the kernel to a different address in c so that both my hello world kernel and the standard kernel are able to run successfully?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: changing kernel load address on rpi4

Post by Octocontrabass »

SikkiLadho wrote:How can I move the kernel to a different address in c so that both my hello world kernel and the standard kernel are able to run successfully?
Change the link script for the standard kernel so it can run at a different address.

You might be able to do it entirely in C with some linker trickery, but I don't know how to pull it off. You're trying to move the kernel into the memory that contains the currently running code, which means the code that does the copying has to first be copied elsewhere so that it doesn't overwrite itself. (This isn't too difficult if you allow yourself to use some assembly.)
Post Reply