commit 58c3a2e03394e9994de1111f7654c0a030fe24ed
parent c150467dc23a314d73f042ba1f559e74e2c7a96a
Author: oblique <psyberbits@gmail.com>
Date: Mon, 9 Jul 2012 20:41:34 +0300
fix Makefile, add usbbootImage, init vector table
Diffstat:
11 files changed, 153 insertions(+), 28 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -8,3 +8,6 @@
/kernel.elf
/kernel.syms
/uImage
+/usbbootImage.elf
+/usbbootImage
+/usbboot/kernel_image.ld
diff --git a/Makefile b/Makefile
@@ -1,24 +1,26 @@
CROSS_COMPILE ?= arm-none-eabi-
MAKEFLAGS += -rR --no-print-directory
INC = -Iinclude
-LDFLAGS = -T kernel/linker.ld
+LDFLAGS = -T kernel/linker.ld -nostdlib -nostdinc -nodefaultlibs -nostartfiles \
+ -fno-builtin
CFLAGS = -march=armv7-r -ggdb -Wall -Wextra -Wformat-security -Wshadow \
-Wunreachable-code -Wpointer-arith -O2 -std=gnu99 -nostdlib \
-nostdinc -nodefaultlibs -nostartfiles -fno-builtin $(INC)
ASFLAGS = -march=armv7-r -ggdb -nostdlib -nostdinc -nodefaultlibs \
-nostartfiles -fno-builtin $(INC)
+LIBGCC = -L $(shell dirname $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)) -lgcc
CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
NM = $(CROSS_COMPILE)nm
objs = kernel/start.o kernel/kmain.o kernel/rs232.o kernel/print.o \
- kernel/debug.o
+ kernel/debug.o kernel/interrupts.o
-all: kernel.elf kernel.bin kernel.syms uImage
+all: kernel.elf kernel.bin kernel.syms uImage usbbootImage
kernel.elf: $(objs) kernel/linker.ld
@echo -e ' LD\t'$@
- @$(CC) $(LDFLAGS) -o $@ $(objs)
+ @$(CC) $(LDFLAGS) -o $@ $(objs) $(LIBGCC)
kernel.bin: kernel.elf
@$(OBJCOPY) $< -O binary $@
@@ -27,7 +29,20 @@ kernel.syms: kernel.elf
@$(NM) $< > $@
uImage: kernel.bin
- @mkimage -A arm -T kernel -C none -a 0x82000000 -e 0x82000000 -n Voron -d $< $@
+ @mkimage -A arm -T kernel -C none -a 0x80008000 -e 0x80008000 -n Voron -d $< $@
+
+usbbootImage.elf: usbboot/usbboot.o usbboot/usbboot.ld usbboot/kernel_image.ld
+ @echo -e ' LD\t'$@
+ @$(CC) -T usbboot/usbboot.ld -nostdlib -nostdinc -nodefaultlibs -nostartfiles \
+ -fno-builtin -o $@ $<
+
+usbbootImage: usbbootImage.elf
+ @echo "Create usbbootImage"
+ @echo -e "Entry Point: 0x82000000"
+ @$(OBJCOPY) $< -O binary $@
+
+usbboot/kernel_image.ld: kernel.bin
+ @hexdump -v -e '"BYTE(0x" 1/1 "%02X" ")\n"' $< > $@
%.o: %.c
@echo -e ' CC\t'$<
@@ -38,4 +53,5 @@ uImage: kernel.bin
@$(CC) $(ASFLAGS) -c -o $@ $<
clean:
- @rm -f $(objs) kernel.elf kernel.bin kernel.syms uImage
+ @rm -f $(objs) kernel.elf kernel.bin kernel.syms uImage usbbootImage \
+ usbbootImage.elf usbboot/kernel_image.ld usbboot/usbboot.o
diff --git a/include/varg.h b/include/varg.h
@@ -3,8 +3,8 @@
#include <inttypes.h>
-#define _BND (sizeof(uintptr_t) - 1)
-#define _bnd(X) ((sizeof(X) + _BND) & (~_BND))
+#define __BND (sizeof(uintptr_t) - 1)
+#define __bnd(X) ((sizeof(X) + __BND) & (~__BND))
/* AAPCS p.28 */
struct __va_list {
@@ -13,9 +13,9 @@ struct __va_list {
typedef struct __va_list va_list;
-#define va_start(ap, last) ((void) ((ap).__ap = ((char*) &(last) + _bnd(last))))
+#define va_start(ap, last) ((void) ((ap).__ap = ((char*) &(last) + __bnd(last))))
#define va_end(ap) ((void) 0)
-#define va_arg(ap, type) (*(type*) (((ap).__ap += _bnd(type)) - _bnd(type)))
+#define va_arg(ap, type) (*(type*) (((ap).__ap += __bnd(type)) - __bnd(type)))
#define va_copy(dest, src) ((void) ((dest).__ap = (src).__ap))
#endif /* __VARG_H */
diff --git a/kernel/debug.c b/kernel/debug.c
@@ -1,4 +1,5 @@
#include <inttypes.h>
+#include <debug.h>
static volatile u32 *gpio_wk7 = (u32*)0x4A31E058;
static volatile u32 *gpio_wk8 = (u32*)0x4A31E05C;
diff --git a/kernel/interrupts.S b/kernel/interrupts.S
@@ -0,0 +1,44 @@
+.section .text
+.global init_vector_table
+init_vector_table:
+ mrc p15, 0, r0, c1, c0, 0 @ read CP15 SCTRL register
+ bic r0, r0, #(1 << 13) @ set V flag to 0
+ mcr p15, 0, r0, c1, c0, 0 @ write CP15 SCTRL register
+
+ ldr r0, =vector_table
+ mcr p15, 0, r0, c12, c0, 0 @ set vector base address
+
+ bx lr
+
+vector_table:
+ ldr pc, =reset
+ ldr pc, =undefined
+ ldr pc, =svc
+ ldr pc, =prefetch_abort
+ ldr pc, =data_abort
+ mov pc, lr
+ ldr pc, =irq
+ ldr pc, =fiq
+.ltorg
+
+
+reset:
+ b .
+
+undefined:
+ b .
+
+svc:
+ b .
+
+prefetch_abort:
+ b .
+
+data_abort:
+ b .
+
+irq:
+ b .
+
+fiq:
+ b .
diff --git a/kernel/linker.ld b/kernel/linker.ld
@@ -1,20 +1,28 @@
-OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
- . = 0x82000000;
- . = ALIGN(4);
- .text :
+ .text 0x80008000 :
{
kernel/start.o (.text)
*(.text)
}
- .data : { *(.data) }
+ .data : ALIGN(4096)
+ {
+ *(.data)
+ }
- .bss : { *(.bss) }
+ .rodata : ALIGN(4096)
+ {
+ *(.rodata)
+ }
+
+ .bss : ALIGN(4096)
+ {
+ *(.bss)
+ }
- . = . + 0x2000;
- _stack_top = .;
+ _stack_top = . + 0x2000;
}
diff --git a/kernel/start.S b/kernel/start.S
@@ -1,6 +1,23 @@
-.text
+.section .text
.globl _start
_start:
- ldr sp, =_stack_top
+ cpsid if @ disable interrupts
+ ldr sp, =_stack_top @ set stack
+
+ /* set leds off */
+ mov r0, #0
+ bl set_leds
+
+ /* print booting message */
+ ldr r0, =boot_msg
+ bl kputs
+
+ /* initialize vector table */
+ bl init_vector_table
+
bl kmain
b .
+
+.section .rodata
+boot_msg:
+ .asciz "\n\nVoron booting...\n\n"
diff --git a/scripts/panda_usbboot.sh b/scripts/panda_usbboot.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+if [ $# -eq 0 ]; then
+ BIN="usbbootImage"
+else
+ BIN=$1
+fi
+USBBOOT_PATH="${HOME}/embedded/panda/omap4boot/out/panda"
+sudo ${USBBOOT_PATH}/usbboot ${USBBOOT_PATH}/aboot.bin $BIN
diff --git a/scripts/pandaboot.sh b/scripts/pandaboot.sh
@@ -1,8 +0,0 @@
-#!/bin/sh
-if [ $# -eq 0 ]; then
- BIN="kernel.bin"
-else
- BIN=$1
-fi
-USBBOOT_PATH="${HOME}/embedded/panda/omap4boot/out/panda"
-sudo ${USBBOOT_PATH}/usbboot ${USBBOOT_PATH}/aboot.bin $BIN
diff --git a/usbboot/usbboot.S b/usbboot/usbboot.S
@@ -0,0 +1,19 @@
+.section .text
+.globl _start
+_start:
+ ldr sp, =_usbboot_stack_top
+ push { r0 - r12 }
+
+ /* copy kernel image at 0x80008000 */
+ ldr r0, =_image_start
+ ldr r1, =_image_end
+ ldr r2, =0x80008000
+
+.L1:
+ ldmia r0!, { r3 - r12 }
+ stmia r2!, { r3 - r12 }
+ cmp r0, r1
+ blo .L1
+
+ pop { r0 - r12 }
+ ldr pc, =0x80008000 @ jump to 0x80008000
diff --git a/usbboot/usbboot.ld b/usbboot/usbboot.ld
@@ -0,0 +1,17 @@
+OUTPUT_FORMAT("elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+SECTIONS
+{
+ .text 0x82000000 :
+ {
+ usbboot/usbboot.o (.text)
+
+ _image_start = .;
+ INCLUDE "usbboot/kernel_image.ld";
+ _image_end = .;
+ }
+
+ . = ALIGN(4);
+ _usbboot_stack_top = . + 0x1000;
+}