Loading microloader/Makefile 0 → 100644 +36 −0 Original line number Diff line number Diff line CC := arm-none-eabi-gcc AS := arm-none-eabi-as LD := arm-none-eabi-gcc OBJCOPY := arm-none-eabi-objcopy CFLAGS := -std=gnu99 -Os -mthumb -mcpu=cortex-a9 -fno-builtin-printf -fno-strict-aliasing -fno-builtin-memcpy -mno-unaligned-access -DPRINTF_DISABLE_SUPPORT_FLOAT=1 LDFLAGS := -T linker.x -nodefaultlibs -nostdlib BUILD_DIR := ./build TARGET := payload C_SRC = main.c ASM_SRC = start.S OBJ = $(C_SRC:%.c=$(BUILD_DIR)/%.o) $(ASM_SRC:%.S=$(BUILD_DIR)/%.o) DEP = $(OBJ:%.o=%.d) $(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf $(OBJCOPY) -O binary $^ $@ $(BUILD_DIR)/$(TARGET).elf: $(OBJ) $(LD) -o $@ $^ $(LDFLAGS) -include $(DEP) $(BUILD_DIR)/%.o: %.c mkdir -p $(@D) $(CC) -MMD -c -o $@ $< $(CFLAGS) $(BUILD_DIR)/%.o: %.S mkdir -p $(@D) $(AS) -o $@ $< clean: -rm -rf $(BUILD_DIR) microloader/linker.x 0 → 100644 +15 −0 Original line number Diff line number Diff line OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(start) SECTIONS { . = 0x4BD5C100; .text : { *(.text.start) *(.text .text.* .gnu.linkonce.t.*) } .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } .data : { *(.data .data.* .gnu.linkonce.d.*) } .bss : { *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) } /DISCARD/ : { *(.interp) *(.dynsym) *(.dynstr) *(.hash) *(.dynamic) *(.comment) } } microloader/main.c 0 → 100644 +50 −0 Original line number Diff line number Diff line #include <inttypes.h> #include <stddef.h> #include "../lk-payload/common.h" void low_uart_put(int ch) { volatile uint32_t *uart_reg0 = (volatile uint32_t*)0x11002014; volatile uint32_t *uart_reg1 = (volatile uint32_t*)0x11002000; while ( !((*uart_reg0) & 0x20) ) {} *uart_reg1 = ch; } int putchar(int character) { if (character == '\n') low_uart_put('\r'); low_uart_put(character); return character; } int puts(const char *line) { for (const char *c = line; *c; ++c) { putchar(*c); } putchar('\n'); return 0; } int main() { puts("microloader by xyz. Copyright 2019."); struct device_t *dev = (void*)get_device(); uint32_t *dst = (void*)PAYLOAD_DST; size_t ret = dev->read(dev, PAYLOAD_SRC, dst, PAYLOAD_SIZE, BOOT0_PART); // boot0 partition, read 2 megabytes cache_clean(dst, PAYLOAD_SIZE); // Jump to the payload void (*jump)(void) = (void*)dst; puts("Jump to the payload"); jump(); puts("Something went horribly wrong!"); while (1) { } } microloader/start.S 0 → 100644 +9 −0 Original line number Diff line number Diff line .syntax unified .code 32 .global start .section .text.start start: mov sp, #0x42000000 blx main Loading
microloader/Makefile 0 → 100644 +36 −0 Original line number Diff line number Diff line CC := arm-none-eabi-gcc AS := arm-none-eabi-as LD := arm-none-eabi-gcc OBJCOPY := arm-none-eabi-objcopy CFLAGS := -std=gnu99 -Os -mthumb -mcpu=cortex-a9 -fno-builtin-printf -fno-strict-aliasing -fno-builtin-memcpy -mno-unaligned-access -DPRINTF_DISABLE_SUPPORT_FLOAT=1 LDFLAGS := -T linker.x -nodefaultlibs -nostdlib BUILD_DIR := ./build TARGET := payload C_SRC = main.c ASM_SRC = start.S OBJ = $(C_SRC:%.c=$(BUILD_DIR)/%.o) $(ASM_SRC:%.S=$(BUILD_DIR)/%.o) DEP = $(OBJ:%.o=%.d) $(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf $(OBJCOPY) -O binary $^ $@ $(BUILD_DIR)/$(TARGET).elf: $(OBJ) $(LD) -o $@ $^ $(LDFLAGS) -include $(DEP) $(BUILD_DIR)/%.o: %.c mkdir -p $(@D) $(CC) -MMD -c -o $@ $< $(CFLAGS) $(BUILD_DIR)/%.o: %.S mkdir -p $(@D) $(AS) -o $@ $< clean: -rm -rf $(BUILD_DIR)
microloader/linker.x 0 → 100644 +15 −0 Original line number Diff line number Diff line OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") OUTPUT_ARCH(arm) ENTRY(start) SECTIONS { . = 0x4BD5C100; .text : { *(.text.start) *(.text .text.* .gnu.linkonce.t.*) } .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } .data : { *(.data .data.* .gnu.linkonce.d.*) } .bss : { *(.bss .bss.* .gnu.linkonce.b.*) *(COMMON) } /DISCARD/ : { *(.interp) *(.dynsym) *(.dynstr) *(.hash) *(.dynamic) *(.comment) } }
microloader/main.c 0 → 100644 +50 −0 Original line number Diff line number Diff line #include <inttypes.h> #include <stddef.h> #include "../lk-payload/common.h" void low_uart_put(int ch) { volatile uint32_t *uart_reg0 = (volatile uint32_t*)0x11002014; volatile uint32_t *uart_reg1 = (volatile uint32_t*)0x11002000; while ( !((*uart_reg0) & 0x20) ) {} *uart_reg1 = ch; } int putchar(int character) { if (character == '\n') low_uart_put('\r'); low_uart_put(character); return character; } int puts(const char *line) { for (const char *c = line; *c; ++c) { putchar(*c); } putchar('\n'); return 0; } int main() { puts("microloader by xyz. Copyright 2019."); struct device_t *dev = (void*)get_device(); uint32_t *dst = (void*)PAYLOAD_DST; size_t ret = dev->read(dev, PAYLOAD_SRC, dst, PAYLOAD_SIZE, BOOT0_PART); // boot0 partition, read 2 megabytes cache_clean(dst, PAYLOAD_SIZE); // Jump to the payload void (*jump)(void) = (void*)dst; puts("Jump to the payload"); jump(); puts("Something went horribly wrong!"); while (1) { } }
microloader/start.S 0 → 100644 +9 −0 Original line number Diff line number Diff line .syntax unified .code 32 .global start .section .text.start start: mov sp, #0x42000000 blx main