# cross build
ARCH = arm-elf
CROSS_CC = $(ARCH)-gcc
+CROSS_AS = $(ARCH)-as
+CROSS_LD = $(ARCH)-ld
CROSS_OBJCOPY = $(ARCH)-objcopy
-CROSS_CFLAGS = -Wall -Os -mcpu=arm7tdmi-s -nostartfiles -nostdlib
+CROSS_OPTS = -mcpu=arm7tdmi-s
+CROSS_CFLAGS = $(CROSS_OPTS) -Wall -Os
+CROSS_ASLAGS = $(CROSS_OPTS) --gstabs
+CROSS_RAM_LDFLAGS = -Tlpc2220_ram.ld -nostartfiles -nostdlib
+CROSS_ROM_LDFLAGS = -Tlpc2220_rom.ld -nostartfiles -nostdlib
# build objects
HOST_TARGET = lpcload fwdump
-CROSS_TARGET = fwbc.hex fwflash.hex
+CROSS_TARGET = fwbc.hex fwflash.hex fwflash.elf # debug: .elf for objdump
# all projects
all: $(HOST_TARGET) $(CROSS_TARGET)
# arm code
arm: arm_clean $(CROSS_TARGET)
-# fwbc
-fwbc:
- $(CROSS_CC) $(CROSS_CFLAGS) -c fwbc.c -o fwbc
+# .o out of .c
+%.o: %.c
+ $(CROSS_CC) -c $(CROSS_CFLAGS) -o $@ $<
-fwbc.hex: fwbc
- $(CROSS_OBJCOPY) -O ihex fwbc fwbc.hex
+# .o out of .s
+%.o: %.s
+ $(CROSS_AS) $(CROSS_ASLAGS) -o $@ $<
-# fwflash
-fwflash:
- $(CROSS_CC) $(CROSS_CFLAGS) -c fwflash.c -o fwflash
+# .elf out of .o
+%.elf: %.o startup.o
+ $(CROSS_LD) $(CROSS_RAM_LDFLAGS) startup.o -o $@ $<
-fwflash.hex: fwflash
- $(CROSS_OBJCOPY) -O ihex fwflash fwflash.hex
+# .hex out of .elf
+%.hex: %.elf
+ $(CROSS_OBJCOPY) -O ihex $< $@
+# host clean
clean:
rm -f lpcload fwdump
+# arm clean
arm_clean:
- rm -f $(CROSS_TARGET) fwbc fwflash
+ rm -vf *.o *.hex *.elf
+
--- /dev/null
+/*
+ * lpc2220_ram.ld - linker script for the lpc2220 device (->ram)
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+SECTIONS {
+ . = 0x40000200;
+ .text . : {
+ startup.o(.text) /* startup code */
+ *(.text) /* all remaining code */
+ *(.glue_7) /* glue code */
+ *(.glue_7t) /* glue code */
+ }
+
+ . = ALIGN(4);
+
+ .rodata : { *(.rodata) } /* read only data */
+
+ . = ALIGN(4);
+
+ .data : { *(.data) } /* initialized data */
+
+ . = ALIGN(4);
+
+ .bss : { *(.bss) } /* uninitialized data */
+}
+
--- /dev/null
+/*
+ * lpc2220_rom.ld - linker script for the lpc2220 device (->rom)
+ *
+ * author: hackbard@hackdaworld.org
+ *
+ */
+
+/* memory definitions */
+
+MEMORY {
+ FLASH_BANK0 (rx) : ORIGIN=0x80000000, LENGTH=0x00100000
+ FLASH_BANK2 (rx) : ORIGIN=0x82000000, LENGTH=0x00100000
+ RAM (rw) : ORIGIN=0x40000000, LENGTH=0x00010000
+}
+
+/* section definitions */
+
+SECTIONS {
+
+ /* startup and user code (.text) */
+ .text : {
+ startup.o(.text) // startup code
+ *(.text) // our code
+ *(.glue_7) // glue code
+ *(.glue_7t) // glue code
+ } > FLASH_BANK0
+
+ . = ALIGN(4)
+
+ /* read only data */
+ .rodata : { *(.rodata) } > FLASH_BANK0
+
+ . = ALIGN(4)
+
+ /* initialized data */
+ .data : { *(.data) } > RAM
+
+ . = ALIGN(4);
+
+ /* uninitialized data */
+ .bss : { *(.bss) } > RAM
+}
+
--- /dev/null
+#
+# startup.s - starup code for the lpc2220
+#
+# author: hackbard@hackdaworld.org
+#
+
+#
+# some definitions
+#
+
+# sram
+
+.equ sram_size, (64*1024)
+.equ sram_addr, 0x40000000
+.equ sram_top, (sram_addr+sram_size-4)
+
+# stack
+
+.equ stack_size, (2*1024)
+.equ stack_top, sram_top
+.equ stack_limit, (sram_top-stack_size)
+
+#
+# the startup code
+#
+
+.text
+.arm
+
+ # init stack pointer
+
+ ldr r0, =sram_top
+ mov sp, r0
+ ldr r0, =stack_limit
+ mov sl, r0
+
+ # jump to c code
+
+ adr lr, loop_forever
+ mov r0, #0
+ mov r1, #0
+ ldr r2, =main
+ bx r2
+
+loop_forever:
+ b loop_forever
+