aboutsummaryrefslogtreecommitdiffstats
path: root/loader
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 14:44:31 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 15:17:28 +0200
commit861a0b11aaf3d7a2c1ef8577c592bfc02e59dcbd (patch)
tree3f08bc97361bb988b7ddf60eb4c5e78a5c50cc16 /loader
parent7bc3aeb314bb892f1881595b6f96c80cbca67efb (diff)
misc: Add driver/ and loader/ source found on ArchLinux
http://aur.archlinux.org/packages.php?ID=31596&detail=1 links to http://txrxio.net/wp/basket/makingthings/sam7utils-0.2.1.tar.gz that contains the driver and the loader sourcecode. I am not sure how this relates to loader256_data.h and loader128_data.h
Diffstat (limited to 'loader')
-rw-r--r--loader/at91.h61
-rw-r--r--loader/bin2c.c30
-rw-r--r--loader/crt0.S28
-rw-r--r--loader/loader.c48
-rw-r--r--loader/loader.lds128
5 files changed, 295 insertions, 0 deletions
diff --git a/loader/at91.h b/loader/at91.h
new file mode 100644
index 0000000..5f38a53
--- /dev/null
+++ b/loader/at91.h
@@ -0,0 +1,61 @@
+/*
+ * loader/at91.h
+ *
+ * Copyright (C) 2006 Erik Gilling, all rights reserved
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#define AT91_FLASH_ADDR ((uint32_t *) 0x100000)
+
+typedef unsigned int uint32_t;
+typedef signed int int32_t;
+
+typedef unsigned short uint16_t;
+typedef signed short int16_t;
+
+typedef unsigned char uint8_t;
+typedef signed char int8_t;
+
+typedef volatile uint32_t arm_reg_t;
+
+typedef struct {
+ arm_reg_t rcr; /* 00 - Remap Control Register */
+ arm_reg_t asr; /* 04 - Abort Status Rebister */
+ arm_reg_t aasr; /* 08 - Abort Address Status Register */
+ arm_reg_t res[21]; /* 0C..5C - Reserved */
+ arm_reg_t fmr; /* 60 - Flash Mode Register */
+ arm_reg_t fcr; /* 64 - Flash Command Register */
+ arm_reg_t fsr; /* 68 - Flash Status Register */
+} at91_mc_t;
+
+extern volatile at91_mc_t mc;
+
+#define AT91_MC_FMR_FRDY (1<<0)
+#define AT91_MC_FMR_LOCKE (1<<2)
+#define AT91_MC_FMR_PROGE (1<<3)
+#define AT91_MC_FMR_NEBP (1<<7)
+#define AT91_MC_FMR_WAIT_STATE_1_2 (0<<8)
+#define AT91_MC_FMR_WAIT_STATE_2_3 (1<<8)
+#define AT91_MC_FMR_WAIT_STATE_3_4 (2<<8)
+#define AT91_MC_FMR_WAIT_STATE_4_4 (3<<8)
+#define AT91_MC_FMR_FMCN( x ) (((x)&0xff) << 16)
+
+
+#define AT91_MC_FCR_FCMD_NOP 0x0
+#define AT91_MC_FCR_FCMD_WP 0x1
+#define AT91_MC_FCR_FCMD_SLB 0x2
+#define AT91_MC_FCR_FCMD_WPL 0x3
+#define AT91_MC_FCR_FCMD_CLB 0x4
+#define AT91_MC_FCR_FCMD_EA 0x8
+#define AT91_MC_FCR_FCMD_SGPB 0xb
+#define AT91_MC_FCR_FCMD_CGPB 0xd
+#define AT91_MC_FCR_FCMD_SSB 0xf
+
+#define AT91_MC_FCR_PAGEN( x ) (((x)&0x3ff)<<8)
+
+#define AT91_MC_FCR_KEY (0x5A << 24)
+
diff --git a/loader/bin2c.c b/loader/bin2c.c
new file mode 100644
index 0000000..9e16991
--- /dev/null
+++ b/loader/bin2c.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+
+int main( int argc, char *argv[] )
+{
+ char *data_name = "data";
+ int c;
+ int i=0;
+
+ if( argc == 2 ) {
+ data_name = argv[1];
+ }
+
+ printf( "uint8_t %s[] = {\n", data_name );
+
+ while( (c = getchar()) >= 0 ) {
+ if( i== 0 ) {
+ printf( "\t" );
+ } else if( i%8 == 0 ) {
+ printf( ",\n\t" );
+ } else {
+ printf( ", " );
+ }
+ i++;
+ printf( "0x%02x", c );
+ }
+
+ printf( "\n};\n" );
+
+ return 0;
+}
diff --git a/loader/crt0.S b/loader/crt0.S
new file mode 100644
index 0000000..bb0a94f
--- /dev/null
+++ b/loader/crt0.S
@@ -0,0 +1,28 @@
+//
+// loader/crt0.S
+//
+// Copyright (C) 2006 Erik Gilling, all rights reserved
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation, version 2.
+//
+//
+ .EQU STACK, 0x201C00
+
+ .code 32
+ .align 2
+
+ .global _entry
+ .func _entry
+_entry:
+ // init stack
+ ldr sp, =STACK
+
+ // save lr
+ stmfd sp!, {lr}
+
+ bl main
+
+ ldmia sp!, {r0}
+ bx r0
diff --git a/loader/loader.c b/loader/loader.c
new file mode 100644
index 0000000..2dc67ff
--- /dev/null
+++ b/loader/loader.c
@@ -0,0 +1,48 @@
+/*
+ * loader/loader.c
+ *
+ * Copyright (C) 2006 Erik Gilling, all rights reserved
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#include "at91.h"
+
+// SAM-BA apears to write the following data to 0x201400
+//
+// 0x00: data0
+// 0x01: data1
+// ...
+// PAGE_SIZE-1: last data byte
+// PAGE_SIZE : page number to write
+
+
+#define SAMBA_PAGE_BUFF ((uint32_t *) 0x201400)
+
+int main( void )
+{
+ int i;
+ uint32_t *page_buff = SAMBA_PAGE_BUFF;
+ // keep this in units of 32 bit words
+ int page_num = *(page_buff+PAGE_SIZE/4);
+ int page_offset = page_num * PAGE_SIZE/4;
+
+ // wait for mc to be ready
+ while( !(mc.fsr & AT91_MC_FMR_FRDY) ) { }
+
+ // write samba page buffer to flash buffer
+ for( i=0 ; i < (PAGE_SIZE/4) ; i++ ) {
+ AT91_FLASH_ADDR[ page_offset + i ] = page_buff[i];
+ }
+
+ // write page
+ mc.fcr = AT91_MC_FCR_FCMD_WP | AT91_MC_FCR_PAGEN(page_num) |
+ AT91_MC_FCR_KEY;
+
+ // dont wait for mc to be ready here so that flash ops can stack
+
+ return 0;
+}
diff --git a/loader/loader.lds b/loader/loader.lds
new file mode 100644
index 0000000..32fcf50
--- /dev/null
+++ b/loader/loader.lds
@@ -0,0 +1,128 @@
+/***********************************************************************/
+/* */
+/* ROM.ld: Linker Script File */
+/* */
+/***********************************************************************/
+ENTRY(_entry)
+
+MEMORY
+{
+ LOADER(rwx) : ORIGIN = 0x00201600, LENGTH = 0xEA00
+}
+
+/* Section Definitions */
+SECTIONS
+{
+
+ /* first section is .text which is used for code */
+ .text :
+ {
+ _text = .;
+ PROVIDE (text = _text);
+ *crt0.o (.text) /* Startup code */
+ *(.text .text.*) /* remaining code */
+ *(.gnu.linkonce.t.*)
+ *(.glue_7)
+ *(.glue_7t)
+ *(.gcc_except_table)
+ *(.rodata) /* read-only data (constants) */
+ *(.rodata*)
+ *(.gnu.linkonce.r.*)
+ } > LOADER
+
+ . = ALIGN(4);
+
+ _etext = . ;
+ PROVIDE (etext = .);
+
+ /* .data section which is used for initialized data */
+ .data : AT (_etext)
+ {
+ _data = .;
+ *(.data)
+ *(.data.*)
+ *(.gnu.linkonce.d*)
+ SORT(CONSTRUCTORS) /* mt 4/2005 */
+ } > LOADER
+
+ . = ALIGN(4);
+ _edata = . ;
+ PROVIDE (edata = .);
+
+ /* .bss section which is used for uninitialized data */
+ .bss (NOLOAD) :
+ {
+ __bss_start = . ;
+ __bss_start__ = . ;
+ *(.bss)
+ *(.gnu.linkonce.b*)
+ *(COMMON)
+ . = ALIGN(4);
+ } > LOADER
+
+ . = ALIGN(4);
+ __bss_end__ = . ;
+ PROVIDE (__bss_end = .);
+
+
+
+ _end = . ;
+ PROVIDE (end = .);
+
+ /* 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) }
+ /* SGI/MIPS DWARF 2 extensions */
+ .debug_weaknames 0 : { *(.debug_weaknames) }
+ .debug_funcnames 0 : { *(.debug_funcnames) }
+ .debug_typenames 0 : { *(.debug_typenames) }
+ .debug_varnames 0 : { *(.debug_varnames) }
+}
+
+
+PROVIDE(tc = 0xFFFA0000);
+PROVIDE(udp = 0xFFFB0000);
+PROVIDE(twi = 0xFFFB8000);
+PROVIDE(usart0 = 0xFFFC0000);
+PROVIDE(usart1 = 0xFFFC4000);
+PROVIDE(pwmc = 0xFFFCC000);
+PROVIDE(ssc = 0xFFFD4000);
+PROVIDE(adc = 0xFFFD8000);
+PROVIDE(spi = 0xFFFE0000);
+PROVIDE(aic = 0xFFFFF000);
+PROVIDE(dbgu = 0xFFFFF200);
+PROVIDE(pioa = 0xFFFFF400);
+PROVIDE(pmc = 0xFFFFFC00);
+PROVIDE(rstc = 0xFFFFFD00);
+PROVIDE(rtt = 0xFFFFFD20);
+PROVIDE(pit = 0xFFFFFD30);
+PROVIDE(wdt = 0xFFFFFD40);
+PROVIDE(vreg = 0xFFFFFD60);
+PROVIDE(mc = 0xFFFFFF00);
+
+