This page lists the main source components of the bootloader and their roles. Paths are relative to the Neutron project root.

Assembly

boot/start.S

  • First code executed after load at 0x80000.
  • Parks secondary cores; detects EL; drops from EL2 to EL1; disables MMU/caches; sets stack to 0x80000; zeroes BSS; calls neutron_main.
  • Defines a minimal exception vector table (all slots branch to an unhandled-exception stub).
  • Must be assembled with access to include/aarch64.h for SPSR and related constants.

Bootloader Core (C)

neutron/main.c

  • Entry point neutron_main() called from start.S.
  • Initialises UART, prints banner and CPU/mailbox info, initialises SD card, mounts FAT32, reads ATOM.BIN into 0x100000, checks NKRN magic, calls bl_load_kernel(), then bl_boot_kernel() with the kernel entry address and pointer to boot_info_t.
  • On any fatal error (SD init, FAT32 mount, file not found, bad magic, load failure), prints a message and halts in a WFE loop.

neutron/bootloader.c

  • bl_load_kernel(uintptr_t src, boot_info_t *out_info): Validates the NKRN header at src, checks payload size and CRC32, copies payload to header.load_addr, fills boot_info_t at BOOT_INFO_ADDR (0x1000). Returns BL_OK or an error code.
  • bl_boot_kernel(uintptr_t entry_addr, boot_info_t *info): Executes DSB/ISB, then calls the kernel at entry_addr with x0 = info. Does not return.
  • Also provides crc32() (IEEE 802.3) and internal helpers bl_memcpy and bl_memset (no libc).

Drivers

driver/uart.c

  • PL011 UART at UART0_BASE (0x3F201000). Configures GPIO 14/15 as ALT0, sets baud (115200, 48 MHz clock), 8N1, FIFO enabled. Provides uart_init, uart_putc, uart_puts, uart_getc, uart_printf, and hex/decimal output helpers.

driver/gpio.c

  • BCM2837 GPIO at GPIO_BASE. Implements gpio_set_func, gpio_set_pull, gpio_set, gpio_clear, gpio_get. Used by the UART driver to mux the UART pins.

driver/mbox.c

  • VideoCore mailbox at MBOX_BASE. Implements mbox_call() and wrappers mbox_get_board_revision() and mbox_get_arm_mem_size(). Uses a 16-byte-aligned buffer for property tags.

driver/sdcard.c

  • SD/MMC card initialisation and block read. Uses the EMMC/SDHCI controller (see include/sdcard.h for register layout). Provides sdcard_init(), sdcard_read_block(), sdcard_read_blocks().

driver/fat32.c

  • Read-only FAT32. Reads MBR, finds first partition, parses BPB, walks FAT and directory to find a file by name. Provides fat32_mount() and fat32_read_file(). Used to read ATOM.BIN from the SD card.

Linker Script

linker/bootloader.ld

  • ENTRY(_start). Load address 0x80000. Sections: .text.boot, .vectors (0x800-aligned), .text, .rodata, .data, .bss. Exports __bss_start, __bss_end, and _stack_top (0x80000).

Headers

  • include/platform.h: MMIO base, UART/GPIO/SDHOST/MBOX addresses, kernel load/staging addresses, register offsets.
  • include/bootloader.h: NKRN magic and header layout, boot_info_t, BOOT_INFO_ADDR, bl_load_kernel, bl_boot_kernel, crc32.
  • include/uart.h, include/gpio.h, include/mbox.h, include/sdcard.h, include/fat32.h: Driver APIs.
  • include/aarch64.h: SPSR and related constants for EL2 to EL1.

Build Output

  • Object files go under build/ (e.g. build/boot/start.o, build/neutron/main.o).
  • The linker produces build/neutron.elf; objcopy -O binary produces bin/kernel8.img.

For driver details and register usage, see Drivers.