CS 452/652 Fall 2023 - Patching Your Code for Direct Booting

This document assumes that you've already written some code (like your A0 solution) that you have been booting and testing using u-boot. You need to make a few changes to your code so that you can direct-boot it, without using u-boot. This document will walk you through those steps.

Step 1: Add boot.S

Download the boot.S file and add it to your project. This is the first code that will run when your program boots. It assumes your program's main function is called kmain, and it will invoke kmain after some initial setup.

Step 2: Replace linker.ld

Your project should include a linker script, linker.ld. Replace your existing linker.ld with this new one.

Step 3: Modify your Makefile

Replace this line in your existing Makefile:
CFLAGS:=-g -pipe -static $(WARNINGS) -ffreestanding -nostartfiles -ffunction-sections\
  
with this line
CFLAGS:=-g -pipe -static $(WARNINGS) -ffreestanding -nostartfiles\
  
That is, remove the -ffunction-sections flag.

Step 4: Modify uart_init()

In the file rpi.c, replace this function
void uart_init() {
  setup_gpio(4, GPIO_ALTFN4, GPIO_NONE);
  setup_gpio(5, GPIO_ALTFN4, GPIO_NONE);
  setup_gpio(6, GPIO_ALTFN4, GPIO_NONE);
  setup_gpio(7, GPIO_ALTFN4, GPIO_NONE);
}
with this one
void uart_init() {
  setup_gpio(4, GPIO_ALTFN4, GPIO_NONE);
  setup_gpio(5, GPIO_ALTFN4, GPIO_NONE);
  setup_gpio(6, GPIO_ALTFN4, GPIO_NONE);
  setup_gpio(7, GPIO_ALTFN4, GPIO_NONE);
  setup_gpio(14, GPIO_ALTFN0, GPIO_NONE);
  setup_gpio(15, GPIO_ALTFN0, GPIO_NONE);
 } 
This just does some extra GPIO configuration that we can no longer rely on u-boot to handle (since we're not using u-boot any more).

That's it. You should now be able to make your program as usual to generate an image file. You can then follow the new deployment instructions to deploy and boot your image.