To get my kernel to load and be run by the Cortex-A53 processors at reset, the config.txt file contains this single line:
kernel_old=1
And my code is in the file kernel8.img.
The cmdline.txt file is read by the GPU firmware (start.elf) and, with some other tags, overwrites memory, including some of the contents of kernel8.img, from 0x100.
To avoid this problem, the initialisation routine starts like this:
void __attribute__((section(".init"))) _start() { asm volatile goto ( "\tB %l[initialise]\n" ".align 10" // Leave space for GPU to corrupt. : : : : initialise ); u64 core; initialise: core = core_number();
It synchronises the four cores, establishes a memory area for each core and establishes a stack at the top of that memory area before calling "enter", which should never return, with the address of the core's memory area and the core's number (0-3) as parameters.
An ld.script file ensures that the start routine is located at the beginning of the image.
/* Script for -z combreloc: combine and sort reloc sections */ /* Copyright (C) 2014-2017 Free Software Foundation, Inc. Copying and distribution of this script, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. */ OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", "elf64-littleaarch64") OUTPUT_ARCH(aarch64) ENTRY(_start) SEARCH_DIR("/media/sda3/home/rolf/nfs_for_bb/IsambardOS/cross-compiler64/aarch64-none-elf/lib"); SECTIONS { . = 0x0; .init : { *(.init) } .text : { *(.text) } .rodata : { *(.rodata) } first_free_page = (. + 4095) & ~ 4095; }
The compiler option -fno-zero-initialized-in-bss ensures that zero-initialised variables (usually the .bss section) is zeroed and present in the kernel image.
aarch64-none-elf-gcc -Wall -I includes start.c task.c -o kernel8.elf -fno-zero-initialized-in-bss -nostartfiles -nostdlib -Os -fno-toplevel-reorder -T ld.script &&
aarch64-none-elf-objcopy kernel8.elf kernel8.img -O binary &&
aarch64-none-elf-objdump --source --disassemble kernel8.elf > kernel8.dump