From 3e93562761ecef77606d7dda57be4a014d2d0ea8 Mon Sep 17 00:00:00 2001 From: Takumi Sueda Date: Wed, 10 Mar 2021 03:24:31 +0900 Subject: [PATCH] Add U-Boot loader over MMU --- x1/.gitignore | 1 + x1/Makefile | 9 +++++++++ x1/c/common.h | 1 + x1/c/generate.py | 27 +++++++++++++++++++++++++++ x1/c/main_uboot.c | 34 ++++++++++++++++++++++++++++++++++ x1/c/uboot_bin.h.tpl | 5 +++++ 6 files changed, 77 insertions(+) create mode 100644 x1/.gitignore create mode 100755 x1/c/generate.py create mode 100644 x1/c/main_uboot.c create mode 100644 x1/c/uboot_bin.h.tpl diff --git a/x1/.gitignore b/x1/.gitignore new file mode 100644 index 0000000..da9a2d8 --- /dev/null +++ b/x1/.gitignore @@ -0,0 +1 @@ +c/uboot_bin.h diff --git a/x1/Makefile b/x1/Makefile index 2ab6403..6598292 100644 --- a/x1/Makefile +++ b/x1/Makefile @@ -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 diff --git a/x1/c/common.h b/x1/c/common.h index 5c136c2..f5e8b01 100644 --- a/x1/c/common.h +++ b/x1/c/common.h @@ -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; diff --git a/x1/c/generate.py b/x1/c/generate.py new file mode 100755 index 0000000..82156ad --- /dev/null +++ b/x1/c/generate.py @@ -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() diff --git a/x1/c/main_uboot.c b/x1/c/main_uboot.c new file mode 100644 index 0000000..4b9a0e2 --- /dev/null +++ b/x1/c/main_uboot.c @@ -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