help:\r
@echo Multi-OS Makefile, you are running on $(DETECTED_OS)\r
@echo Possible targets:\r
- @echo + all - Make both:\r
- @echo + osimage.s19 - The OS image\r
- @echo + fpgaimage.s19 - The FPGA image\r
- @echo + clean - Clean $(OBJDIR)\r
+ @echo + all - Make both:\r
+ @echo + $(OBJDIR)/osimage.s19 - The OS image\r
+ @echo + $(OBJDIR)/fpgaimage.s19 - The FPGA image\r
+ @echo + clean - Clean $(OBJDIR)\r
\r
# Makefile for bootrom, see ../common/Makefile.common for common settings\r
\r
-OBJJTAG = $(OBJDIR)/bootrom.o $(OBJDIR)/ram-reset.o $(OBJDIR)/usb.o\r
-OBJFLASH = $(OBJDIR)/flash-reset.o $(OBJDIR)/fromflash.o\r
-\r
-THUMBSRC = usb.c fromflash.c bootrom.c\r
-ASMSRC = ram-reset.s flash-reset.s\r
+# DO NOT use thumb mode in the phase 1 bootloader since that generates a section with glue code\r
+ARMSRC = fromflash.c \r
+THUMBSRC = usb.c bootrom.c\r
+ASMSRC = ram-reset.s flash-reset.s\r
\r
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}{OBJ,SRC}\r
include ../common/Makefile.common\r
\r
-all: bootrom-merged.s19\r
-\r
-bootrom-merged.s19: $(OBJDIR)/bootrom.s19 $(OBJDIR)/bootrom-forjtag.s19\r
- perl ../tools/merge-srec.pl $(OBJDIR)/bootrom.s19 $(OBJDIR)/bootrom-forjtag.s19 > bootrom-merged.s19\r
+all: $(OBJDIR)/bootrom.s19\r
\r
-$(OBJDIR)/bootrom.elf: $(OBJFLASH)\r
+$(OBJDIR)/bootrom.elf: $(ASMOBJ) $(ARMOBJ) $(THUMBOBJ)\r
$(LD) -g -Tldscript-flash --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^\r
\r
-$(OBJDIR)/bootrom-forjtag.elf: $(OBJJTAG)\r
- $(LD) -g -Tldscript-ram-jtag --oformat elf32-littlearm -Map=$(patsubst %.elf,%.map,$@) -o $@ $^\r
-\r
clean:\r
$(DELETE) $(OBJDIR)$(PATHSEP)*.o\r
$(DELETE) $(OBJDIR)$(PATHSEP)*.elf\r
$(DELETE) $(OBJDIR)$(PATHSEP)*.s19\r
$(DELETE) $(OBJDIR)$(PATHSEP)*.map\r
$(DELETE) $(OBJDIR)$(PATHSEP)*.d\r
- $(DELETE) bootrom-merged.s19\r
\r
.PHONY: all clean help\r
help:\r
@echo Multi-OS Makefile, you are running on $(DETECTED_OS)\r
@echo Possible targets:\r
- @echo + all - Make bootrom-merged.s19, the main bootrom\r
+ @echo + all - Make $(OBJDIR)/bootrom.s19, the main bootrom\r
@echo + clean - Clean $(OBJDIR)\r
.extern CopyBootToRAM\r
\r
-.text\r
-.code 32\r
-.align 0\r
+.section .startup,"ax"\r
+ .code 32\r
+ .align 0\r
\r
-.global start\r
-start:\r
+.global flashstart\r
+flashstart:\r
b Reset\r
b UndefinedInstruction\r
b SoftwareInterrupt\r
#include <proxmark3.h>\r
\r
-void CopyBootToRAM(void)\r
+void __attribute__((section("bootphase1"))) CopyBootToRAM(void)\r
{\r
int i;\r
\r
+MEMORY \r
+{\r
+ /* AT91SAM7S256 has 256k Flash and 64k RAM */\r
+ /* Important note: the correct ORIGIN for bootphase1 is 0x00100000 and for bootphase2 is 0x00100200\r
+ However, this will confuse the currently deployed flash code which expects logical and and not\r
+ physical addresses and performs no sanity checks at all. If confronted with physical addresses, \r
+ it will happily erase everything and brick the device. So for the time being pretend these addresses\r
+ to start at 0x0 while updating all the flash code with proper sanity checks, then come back later and\r
+ fix the addresses. -- Henryk Plötz <henryk@ploetzli.ch> 2009-08-27 */\r
+ bootphase1 : ORIGIN = 0x00000000, LENGTH = 0x200 /* Phase 1 bootloader: Copies real bootloader to RAM */\r
+ bootphase2 : ORIGIN = 0x00000200, LENGTH = 0x2000 - 0x200 /* Main bootloader code, stored in Flash, executed from RAM */\r
+ ram : ORIGIN = 0x00200000, LENGTH = 32K\r
+}\r
+\r
+\r
SECTIONS\r
{\r
- . = 0x00000000;\r
- .text : { obj/flash-reset.o(.text) *(.text) }\r
- .rodata : { *(.rodata) }\r
- . = 0x00200000;\r
- .data : { *(.data) }\r
- __bss_start__ = .;\r
- .bss : { *(.bss) }\r
+ . = 0;\r
+ \r
+ bootphase1 : {\r
+ *(.startup) \r
+ *(.bootphase1)\r
+ } >bootphase1\r
+ \r
+ bootphase2 : {\r
+ __bootphase2_start__ = .;\r
+ *(.startphase2)\r
+ *(.text)\r
+ *(.glue_7)\r
+ *(.rodata)\r
+ *(.data)\r
+ . = ALIGN( 32 / 8 );\r
+ __bootphase2_end__ = .;\r
+ } >ram AT>bootphase2\r
+ \r
+ .bss : {\r
+ __bss_start__ = .; \r
+ *(.bss)\r
+ } >ram\r
+ \r
+ . = ALIGN( 32 / 8 );\r
__bss_end__ = .;\r
}\r
+++ /dev/null
-SECTIONS\r
-{\r
- . = 0x00200000;\r
- .text : { obj/ram-reset.o(.text) *(.text) }\r
- .rodata : { *(.rodata) }\r
- .data : { *(.data) }\r
- __bss_start__ = .;\r
- .bss : { *(.bss) }\r
- __bss_end__ = .;\r
-}\r
.extern BootROM\r
\r
-.text\r
-.code 32\r
-.align 0\r
+.section .startphase2,"ax"\r
+ .code 32\r
+ .align 0\r
\r
-.global start\r
-start:\r
+.global ramstart\r
+ramstart:\r
ldr sp, = 0x0020FFF8\r
bl BootROM\r
$(DEPENDENCY_FILES): Makefile ../common/Makefile.common
$(OBJDIR)/%.d: %.c
- $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@
+ @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@
$(OBJDIR)/%.d: %.s
- $(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@
+ @$(CC) -MM -MT "$(@) $(@:.d=.o)" $(CFLAGS) $< > $@
-include $(DEPENDENCY_FILES)
+++ /dev/null
-# merge the code that initially executes out of flash with the RAM image\r
-\r
-($flashFile, $ramFile) = @ARGV;\r
-\r
-open(FLASH, $flashFile) or die "$flashFile: $!\n";\r
-\r
-while(<FLASH>) {\r
- print if /^S3/;\r
- $EOF_record = $_ if /^S[789]/;\r
-}\r
-\r
-open(RAM, $ramFile) or die "$ramFile: $!\n";\r
-\r
-while(<RAM>) {\r
- if(/^S3(..)(........)(.*)([0-9a-fA-F]{2})/) {\r
- $addr = sprintf('%08X', hex($2) - 0x00200000 + 0x200);\r
- $line = "$1$addr$3";\r
- $checksum = 0;\r
- $checksum += $_ foreach map(hex, unpack("a2"x40, $line));\r
- print "S3$line", sprintf("%02X", ($checksum%256)^0xff ), "\n";\r
- }\r
-}\r
-print $EOF_record;\r