From d9abb0811e0ed038897518633a68f4e4f1b655ef Mon Sep 17 00:00:00 2001 From: ikari Date: Mon, 6 Sep 2010 23:53:07 +0200 Subject: [PATCH] begin ARM firmware --- src/flash.cfg | 4 ++ src/flash.script | 13 +++++ src/lpc1754.cfg | 75 ++++++++++++++++++++++++ src/lpc1754.ld | 131 ++++++++++++++++++++++++++++++++++++++++++ src/openocd-usb.cfg | 12 ++++ src/startup.S | 101 ++++++++++++++++++++++++++++++++ src/utils/Makefile | 12 ++++ src/utils/lpcchksum | Bin 0 -> 6440 bytes src/utils/lpcchksum.c | 67 +++++++++++++++++++++ src/utils/lpcchksum.o | Bin 0 -> 2164 bytes 10 files changed, 415 insertions(+) create mode 100644 src/flash.cfg create mode 100644 src/flash.script create mode 100644 src/lpc1754.cfg create mode 100644 src/lpc1754.ld create mode 100644 src/openocd-usb.cfg create mode 100644 src/startup.S create mode 100644 src/utils/Makefile create mode 100755 src/utils/lpcchksum create mode 100644 src/utils/lpcchksum.c create mode 100644 src/utils/lpcchksum.o diff --git a/src/flash.cfg b/src/flash.cfg new file mode 100644 index 0000000..2973ea1 --- /dev/null +++ b/src/flash.cfg @@ -0,0 +1,4 @@ +# script running on reset +init +script flash.script + diff --git a/src/flash.script b/src/flash.script new file mode 100644 index 0000000..fcf702d --- /dev/null +++ b/src/flash.script @@ -0,0 +1,13 @@ +# mthomas 4/2008, tested with OpenOCD SVN555 + +#flash probe 0 +#flash erase_check 0 +#flash protect_check 0 +#flash info 0 + +reset init +flash write_image erase unlock obj/sd2snes.bin 0 bin +sleep 200 +reset run +shutdown + diff --git a/src/lpc1754.cfg b/src/lpc1754.cfg new file mode 100644 index 0000000..706d25f --- /dev/null +++ b/src/lpc1754.cfg @@ -0,0 +1,75 @@ +# NXP LPC1754 Cortex-M3 with 128kB Flash and 16kB+16kB Local On-Chip SRAM, +# reset_config trst_and_srst + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME lpc1754 +} + +# After reset the chip is clocked by the ~4MHz internal RC oscillator. +# When board-specific code (reset-init handler or device firmware) +# configures another oscillator and/or PLL0, set CCLK to match; if +# you don't, then flash erase and write operations may misbehave. +# (The ROM code doing those updates cares about core clock speed...) +# +# CCLK is the core clock frequency in KHz +if { [info exists CCLK ] } { + set _CCLK $CCLK +} else { + set _CCLK 4000 +} +if { [info exists CPUTAPID ] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x4ba00477 +} + +#delays on reset lines +adapter_nsrst_delay 200 +jtag_ntrst_delay 200 + +# LPC2000 & LPC1700 -> SRST causes TRST +#reset_config srst_pulls_trst +reset_config trst_and_srst srst_push_pull trst_push_pull + +jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID +jtag newtap x3s tap -irlen 6 -ircapture 0x11 -irmask 0x11 -expected-id 0x0141c093 + +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m3 -chain-position $_TARGETNAME -event reset-init 0 + +# LPC1754 has 16kB of SRAM In the ARMv7-M "Code" area (at 0x10000000) +# and 16K more on AHB, in the ARMv7-M "SRAM" area, (at 0x2007c000). +$_TARGETNAME configure -work-area-phys 0x10000000 -work-area-size 0x4000 +$_TARGETNAME configure -work-area-phys 0x2007c000 -work-area-size 0x4000 + +# LPC1754 has 128kB of flash memory, managed by ROM code (including a +# boot loader which verifies the flash exception table's checksum). +# flash bank lpc2000 0 0 [calc checksum] +set _FLASHNAME $_CHIPNAME.flash +flash bank $_FLASHNAME lpc2000 0x0 0x20000 0 0 $_TARGETNAME \ + lpc1700 $_CCLK calc_checksum + +# Run with *real slow* clock by default since the +# boot rom could have been playing with the PLL, so +# we have no idea what clock the target is running at. +jtag_khz 1000 + +$_TARGETNAME configure -event reset-init { + # Do not remap 0x0000-0x0020 to anything but the flash (i.e. select + # "User Flash Mode" where interrupt vectors are _not_ remapped, + # and reside in flash instead). + # + # See Table 612. Memory Mapping Control register (MEMMAP - 0x400F C040) bit description + # Bit Symbol Value Description Reset + # value + # 0 MAP Memory map control. 0 + # 0 Boot mode. A portion of the Boot ROM is mapped to address 0. + # 1 User mode. The on-chip Flash memory is mapped to address 0. + # 31:1 - Reserved. The value read from a reserved bit is not defined. NA + # + # http://ics.nxp.com/support/documents/microcontrollers/?scope=LPC1768&type=user + + mww 0x400FC040 0x01 +} diff --git a/src/lpc1754.ld b/src/lpc1754.ld new file mode 100644 index 0000000..246fcee --- /dev/null +++ b/src/lpc1754.ld @@ -0,0 +1,131 @@ +/* Linker script for LPC1754 + * + * Written 2010 by Ingo Korb + * + * Partially based on the linker scripts of avr-libc + */ + +OUTPUT_FORMAT(elf32-littlearm) +ENTRY(_start) + +MEMORY +{ + flash (rx) : ORIGIN = 0x00000000, LENGTH = 128K + ram (rwx) : ORIGIN = 0x10000000, LENGTH = 16K + ahbram (rwx) : ORIGIN = 0x2007C000, LENGTH = 16K +} + +SECTIONS +{ + .text : + { + KEEP(*(.vectors)) + KEEP(*(.init)) + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + + /* C++ con-/destructors */ + __ctors_start = . ; + *(.ctors) + __ctors_end = . ; + __dtors_start = . ; + *(.dtors) + __dtors_end = . ; + KEEP(SORT(*)(.ctors)) + KEEP(SORT(*)(.dtors)) + + KEEP(*(.fini)) + + __text_end = .; + } > flash + + /* .ARM.exidx is sorted, so has to go in its own output section. */ + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } >flash + __exidx_end = .; + + /* I hope this does what I think it does */ + .rodata : AT (ALIGN(__exidx_end,4)) + { + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + __rodata_end = .; + } > flash + + /* Data section */ + .data : AT (ALIGN(__rodata_end,4)) + { + __data_start = .; + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + __data_end = .; + } > ram + + /* Addresses of in-rom data section */ + __data_load_start = LOADADDR(.data); + __data_load_end = __data_load_start + SIZEOF(.data); + + . = ALIGN(4); + + /* BSS */ + .bss : + { + __bss_start__ = .; + *(.bss) + *(.bss.*) + *(COMMON) + __bss_end__ = .; + } > ram + + /* second BSS in AHB ram */ + .ahbram (NOLOAD) : + { + __ahbram_start__ = .; + *(.ahbram) + *(.ahbram.*) + __ahbram_end__ = .; + } > ahbram + + __heap_start = ALIGN(__bss_end__, 4); + + /* Default stack starts at end of ram */ + PROVIDE(__stack = ORIGIN(ram) + LENGTH(ram)) ; + + + /* Everyone seems to copy the stuff below straight from somewhere else, so I'll do that too */ + + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } +} diff --git a/src/openocd-usb.cfg b/src/openocd-usb.cfg new file mode 100644 index 0000000..d552239 --- /dev/null +++ b/src/openocd-usb.cfg @@ -0,0 +1,12 @@ +# +# Hubert Hoegl's USB to JTAG +# +# http://www.hs-augsburg.de/~hhoegl/proj/usbjtag/usbjtag.html +# + +interface ft2232 +ft2232_vid_pid 0x0403 0x6010 +ft2232_device_desc "Dual RS232" +ft2232_layout "oocdlink" +ft2232_latency 2 +adapter_khz 10 diff --git a/src/startup.S b/src/startup.S new file mode 100644 index 0000000..8604e91 --- /dev/null +++ b/src/startup.S @@ -0,0 +1,101 @@ +/* startup code for LPC17xx + * + * Written 2010 by Ingo Korb + */ + .syntax unified + + .section .vectors + + .macro except label + .weak \label + .set \label, __unhandled_exception + .word \label + .endm + + /* Cortex M3 standard except vectors */ + .word __stack + .word _start + except NMI_Handler + except HardFault_Handler + except MemManage_Handler + except BusFault_Handler + except UsageFault_Handler + .word 0 + .word 0 + .word 0 + .word 0 + except SVC_Handler + except DebugMon_Handler + .word 0 + except PendSV_Handler + except SysTick_Handler + + /* External interrupt vectors */ + except WDT_IRQHandler + except TIMER0_IRQHandler + except TIMER1_IRQHandler + except TIMER2_IRQHandler + except TIMER3_IRQHandler + except UART0_IRQHandler + except UART1_IRQHandler + except UART2_IRQHandler + except UART3_IRQHandler + except PWM1_IRQHandler + except I2C0_IRQHandler + except I2C1_IRQHandler + except I2C2_IRQHandler + except SPI_IRQHandler + except SSP0_IRQHandler + except SSP1_IRQHandler + except PLL0_IRQHandler + except RTC_IRQHandler + except EINT0_IRQHandler + except EINT1_IRQHandler + except EINT2_IRQHandler + except EINT3_IRQHandler + except ADC_IRQHandler + except BOD_IRQHandler + except USB_IRQHandler + except CAN_IRQHandler + except DMA_IRQHandler + except I2S_IRQHandler + except ENET_IRQHandler + except RIT_IRQHandler + except MCPWM_IRQHandler + except QEI_IRQHandler + except PLL1_IRQHandler + + .section .text + + .global _start + .thumb_func +_start: + /* copy data section to ram */ + ldr r0, =__data_load_start + ldr r1, =__data_load_end + ldr r2, =__data_start +dataloop: + ldr.w r3, [r0], #4 + str.w r3, [r2], #4 + cmp r0, r1 + blo dataloop + + /* clear bss section */ + ldr r0, =__bss_start__ + ldr r1, =__bss_end__ + ldr r2, =0 +bssloop: + str.w r2, [r0], #4 + cmp r0, r1 + blo bssloop + + /* start main() */ + b main + + /* endless loop */ + .weak __unhandled_exception + .thumb_func +__unhandled_exception: + b __unhandled_exception + + .end diff --git a/src/utils/Makefile b/src/utils/Makefile new file mode 100644 index 0000000..9e4bd90 --- /dev/null +++ b/src/utils/Makefile @@ -0,0 +1,12 @@ + +CC = gcc +CFLAGS = -Wall -Wstrict-prototypes -Werror + +all: lpcchksum + +lpcchksum: lpcchksum.o + $(CC) $(CFLAGS) $^ --output $@ + +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + diff --git a/src/utils/lpcchksum b/src/utils/lpcchksum new file mode 100755 index 0000000000000000000000000000000000000000..b910053e5469c83c694fe5f1abe0d5d3e4e92c23 GIT binary patch literal 6440 zcmb7I4~$gB9iH7=WJSsy2kNO;vZZ_Nk;1wM2k{KrgWH2ck3YhJD9B@P_wBtW`>(ri zh4|R^ZA4heo-fgMh^vo?a)7&tt{;#BxZ_Mu|V7;u0j%R z?FYbtOdw8~0SQ3rAoEek{DXlYWgakvHkM710eJhVY*KXJ<^RgYx(+FYN^C9dz?N4T}t1m74^WAT~@m&6AKfQSGwxwHsK-*jhnl9!* z+@VEG1&#~LWLf0aLpUZgA*?$Hxf*f}i6*3UfTGQS+dkbfbfGVPf=|1{R|_u*#Z z+CZ)jAw<5R0W|w_vj>+wc$EjQ_25MwyuyR;_u!o#Y}bW8FriChe?IDw;`=%H_?h$eV>it{_s5 znNEv*$tj9d(KPpnR3e=#nj#ZVr*jE`Y~YF1-h%CzB2_Ts$e%CRSto`1ScO|(CT?eG zH^tiCb*sCKrIEJDSXB1Jk6Gof4nG}N+6T-9;;!bKf;%;g)0t6OfYi!&(VWW5sC)a4 z*T<{NZ$Zv#%S!w+Pql?DwirD(fo#&Fj6zqB2@;=%KM_&@!rzkJ@;@pf^+$O%?Z9`pT}le<)FN5L8H4%VL#^(V%L zw+73v`07tI)}MIu^n1aP`3*3Y$Nb8AdZNMiicF}}2~8sb|9#`Kh}lE59cGS^O}^po z*{3VP!+weI57gkII*FPNtBe?}@`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Cab#NVpyG1n!r4=*BoPtfi2p?$5u zx_v&JLY4!Mx!-j^UU%*UmNzPBpSVHX3(b2MXOh^04&hD*1;3kvw5h=Q`N`WkvYu&4asvxsP%@_&(DMto^4EFISsu`1B5WXoF@T zJ_!5Kn*5_4{xM+P-UhVyS&#jc2cHF|f2j7{Al~!X{{bAse09nC=ZJp+?|1!auD?m} z4MhjGuL+p9aHh@m&l4@cyvoxLI9|&={Iwo@j|ZoLwf{C?J_kMaM}Z%6+e7=~9{Z1g zA3^)MN3#B>J@yxXYs)_ce242#js7{}x4?XZxDlH9-+|WqLnC+SM8PRKrBo`Cz*ARO z-^R^G@4790cv&-y*fexUSB)u|GX~PR{&?Du=RzZ18pP!!lTVwDnT#y&XkRL5FznFZaykYHy;t~3a2gA-z{a6@v-y>^Nyw8?+T%2Y$ zc&c`rBHu1+t?C(bDy7YR%A87xs)x|2gf=l?I;CYx(avNsXISxUGL1J+K9Ek4qOi)@ z*E2CWGV;ctogjY^%9SL;z}>*@ih6mi%^;_WPqej(z-+60lC4cQOnKSBRIj*Y aMFc%E@(IJSO4&V;{y{wJ;+a-@f%q?L@D?Kg literal 0 HcmV?d00001 diff --git a/src/utils/lpcchksum.c b/src/utils/lpcchksum.c new file mode 100644 index 0000000..7f9a63a --- /dev/null +++ b/src/utils/lpcchksum.c @@ -0,0 +1,67 @@ +/* + * calculate+inject LPC1700 vector checksum + */ + +#include +#include +#include + + +uint32_t getu32(uint8_t *buffer) { + return buffer[0]+(buffer[1]<<8)+(buffer[2]<<16)+(buffer[3]<<24); +} + +void putu32(uint8_t *buffer, uint32_t data) { + buffer[0]=(uint8_t)(data&0xff); + buffer[1]=(uint8_t)((data>>8)&0xff); + buffer[2]=(uint8_t)((data>>16)&0xff); + buffer[3]=(uint8_t)((data>>24)&0xff); +} + +int main(int argc, char **argv) { + FILE *bin; + uint32_t data; + size_t len; + int count; + uint8_t *buffer; + + if(argc<2) { + fprintf(stderr, "Usage: %s \nThe original file will be modified!\n", argv[0]); + return 1; + } + + if((bin=fopen(argv[1], "rb"))==NULL) { + perror("could not open input file"); + return 1; + } + + fseek(bin, 0, SEEK_END); + len=ftell(bin); + fseek(bin, 0, SEEK_SET); + if((buffer=malloc(len))==NULL) { + perror("could not reserve memory"); + fclose(bin); + return 1; + } + fread(buffer, len, 1, bin); + fclose(bin); + + data=0; + for(count=0; count<7; count++) { + data+=getu32(buffer+4*count); + } + printf("data=%x chksum=%x\n", data, ~data+1); + putu32(buffer+28,~data+1); + + if((bin=fopen(argv[1], "wb"))==NULL) { + perror("could not open output file"); + return 1; + } + + fwrite(buffer, len, 1, bin); + fclose(bin); + printf("done\n"); + free(buffer); + + return 0; +} diff --git a/src/utils/lpcchksum.o b/src/utils/lpcchksum.o new file mode 100644 index 0000000000000000000000000000000000000000..9cd852122d96993da7555cfad6840d41b2b24d58 GIT binary patch literal 2164 zcma)7O>Y}j6uo1cVp4X_A~jVg0;*66l28^c6e(r}3x7N(L&hF6GbSx6 z1Yse?G6Auvkl4V2{sW>aD<@r4l~}O^Rk9FBMP)%(Y>>h^GxO+R1oT;N&O7&>d*{B7 zd0t;U{gPoAqMIRUxy?jI>Bw_Dgp%x+tW^3x4;HieEy-^U2bFAZ*T`>8<+r}u`7yhB zXcDg8Fco=sMw7;FXh>_r^kydY=9Mr-u20_vBR0<(gT>s=jqFA$WO#y2#w;DO>5V9` z_tS5^Uyt?P%NpxP;231LS=(29^iNya{*smHXRI54?CtGc=2U(e;ko@BMo{;LnSmrF z{ROMgyI>Whd-!U`nu974c?pqM7p!awW?%*&0|e;&$uSaH)Kc>=T1&@4JA;?bNcSNjygH9w4zMcvzP65)iG%@*KEfz zYszf74ZCTp#-kJB)uirrorc+V1JmuOwrRIJ-5}H_Jf8BE_YNXe%k|DnqZ(A7FP<~& zE31CDh0%np{Uedv4gSj1aNA1c)cpJjv$UXUcC~FDFXMM~_DD1kDf{PJLA3@9ya-qH z$Wu-^Q0D?E^TkrG`M#7rHzIYn)lzNvFauRS^-ATaA5`n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