Add U-Boot loader over MMU

This commit is contained in:
Takumi Sueda 2021-03-10 03:24:31 +09:00
parent 1be480557e
commit 3e93562761
6 changed files with 77 additions and 0 deletions

1
x1/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
c/uboot_bin.h

View File

@ -21,6 +21,15 @@ c/main.elf:
c/main.bin: c/main.elf
@./extract.py c/main.elf $@
c/uboot_loader.bin:
@if [ "$(UBOOT)" = "" ]; then \
echo "Please specify UBOOT."; \
exit 1; \
fi
@c/generate.py $(UBOOT) c/uboot_bin.h.tpl c/uboot_bin.h
@$(CC) -nostdlib -static -fPIC -marm -O0 c/start.S c/main_uboot.c -o c/uboot_loader.elf
@./extract.py c/uboot_loader.elf $@
spray/main.bin:
@$(AS) spray/top.S
@./extract.py -p a.out spray/top.bin

View File

@ -2,6 +2,7 @@
#define readl(a) (*(volatile unsigned int *)(a))
#define writel(v, a) (*(volatile unsigned int *)(a) = (v))
#define writeb(v, a) (*(volatile unsigned char *)(a) = (v))
typedef unsigned int u32;
typedef unsigned short u16;

27
x1/c/generate.py Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env python3
import sys
import textwrap
def main():
if len(sys.argv) < 3:
print(f'Usage: {sys.argv[0]} u-boot.bin uboot_bin.h.tpl uboot_bin.h')
with open(sys.argv[2]) as f:
tpl = f.read()
with open(sys.argv[1], 'rb') as ui, open(sys.argv[3], 'w') as header:
uboot = ui.read()
out = ''
for i, b in enumerate(uboot):
out += f'{b:#04x}, '
if (i+1) % 16 == 0:
out = out.rstrip()
out += '\n'
formatted = tpl.format(uboot_size=len(uboot), uboot_bin=textwrap.indent(out, ' '))
header.write(formatted)
main()

34
x1/c/main_uboot.c Normal file
View File

@ -0,0 +1,34 @@
#include "common.h"
#include "uboot_bin.h"
#define VIRT_START (unsigned char *)0x8c000000
void main() {
int i;
u8* ptr = VIRT_START;
// Turn off interrupts
asm volatile (
"cpsid if \n"
);
for (i=0; i<UBOOT_SIZE; i++) {
writeb(uboot_bin[i], ptr);
ptr++;
}
asm volatile (
"mrc p15, 0, r8, c14, c2, 1 \n"
"bic r8, r8, #1 \n"
"mcr p15, 0, r8, c14, c2, 1 \n"
"mrc p15, 0, r8, c14, c3, 1 \n"
"bic r8, r8, #1 \n"
"mcr p15, 0, r8, c14, c3, 1 \n"
"mrc p15, 0, r10, c1, c0, 0 \n"
"bic r10, r10, #1 \n"
"mcr p15, 0, r10, c1, c0, 0 \n"
"ldr r0, =0x60200000 \n"
"mov pc, r0"
);
}

5
x1/c/uboot_bin.h.tpl Normal file
View File

@ -0,0 +1,5 @@
#define UBOOT_SIZE {uboot_size}
unsigned char uboot_bin[] = {{
{uboot_bin}
}};