Felt like doing another intel hex based loader, a little different approach. And modified

the primary serial bootloader (bootloader06) to wait for a specific keypress before running
the downloaded program.
This commit is contained in:
dwelch67
2014-09-20 21:25:33 -04:00
parent 1aac223429
commit 3451556310
25 changed files with 130673 additions and 114 deletions

View File

@@ -3,11 +3,11 @@ See the top level README file for more information on documentation
and how to run these programs.
Derived from bootloader05, this is a very simple bootloader. Instead
of the sd dance (see toplevel README), this makes life a bit simpler
of the sd dance (see top level README), this makes life a bit simpler
and greatly reduces physical wear and tear on the sd card socket. Do
the sd card dance one more time with kernel.img. Get some sort of
the sd card dance one more time with this kernel.img. Get some sort of
serial solution to connect a dumb termial program with xmodem
capabilities to the uart on the raspberry pi. (see the toplevel
capabilities to the uart on the raspberry pi. (see the top level
README for more information).
The difference between bootloader05 and bootloader06 is that I made
@@ -16,11 +16,12 @@ know or think the NAK stuff was working anyway. The whole xmodem
receiver is in a loop so you should be able to try again without
power cycling the board.
I use minicom and it uses lrzsz to do the xmodem transfer and there
is a delay after the transfer before minicom gets control again so
I added a delay at the end before branching to the application so
that no uart output is lost, in theory...Your favorite tools may give
you a different experience.
A new feature is that it does not automatically run your program it
waits for you to send a 'g' character (press the g button while in
the dumb terminal program). I use minicom and there is a delay between
when the external xmodem program finishes sending and when minicom
gets control again and data can be lost, data as in stuff the
downloaded program is printing out. So ideally this helps solve that.
You take the .bin file of your test program, assumed to be built based
on address 0x8000 and less than 0x200000-0x8000 bytes in size.
@@ -44,4 +45,3 @@ I normally do not deliver binaries. In this case I have included all
of the build files so that you can at least get started without having
to build the bootloader. Backup whatever kernel.img file you are using
and replace with the kernel.img file in this repo (on your sd card).

Binary file not shown.

View File

@@ -91,5 +91,5 @@ Disassembly of section .comment:
0: 3a434347 bcc 10d0d24 <notmain+0x10c8d04>
4: 4e472820 cdpmi 8, 4, cr2, cr7, cr0, {1}
8: 34202955 strtcc r2, [r0], #-2389 ; 0x955
c: 322e382e eorcc r3, lr, #3014656 ; 0x2e0000
c: 332e382e teqcc lr, #3014656 ; 0x2e0000
...

View File

@@ -126,8 +126,20 @@ int notmain ( void )
uart_send(0x0A);
uart_send(0x0A);
hexstring(0xDADADADA);
uart_flush();
BRANCHTO(ARMBASE);
while(1)
{
rb=uart_recv();
if((rb=='g')||(rb=='G'))
{
uart_send(0x0D);
uart_send('-');
uart_send('-');
uart_send(0x0D);
uart_send(0x0A);
uart_send(0x0A);
BRANCHTO(ARMBASE);
}
}
break;
}
default:

Binary file not shown.

View File

@@ -129097,40 +129097,43 @@
:100270000400A0E10C109FE563FFFFEB1040BDE818
:100280001EFF2FE108B400200002F90008402DE90C
:1002900008009FE562FFFFEB0840BDE81EFF2FE16D
:1002A00020B40020F0472DE9A7FFFFEB08029FE5EF
:1002A00020B40020F0472DE9A7FFFFEB38029FE5BF
:1002B0009EFFFFEB5CFFFFEB9CFFFFEB0209A0E35F
:1002C0009AFFFFEBE4FFFFEBF0719FE5F0619FE524
:1002C0009AFFFFEBE4FFFFEB20A29FE520929FE562
:1002D0001500A0E371FFFFEBEBFFFFEB0040A0E197
:1002E000020000EA66FFFFEB000050E30A00001A7C
:1002F000E5FFFFEB000064E0070050E1F8FFFF9A24
:1002F000E5FFFFEB000064E00A0050E1F8FFFF9A21
:100300001500A0E365FFFFEB5DFFFFEB3D4884E2D6
:10031000000050E3094C84E2F4FFFF0A02A9A0E3C5
:100320000080A0E3C040A0E30190A0E348FFFFEB02
:10033000C00054E30050A0E13600000A2500009AF6
:10034000C10054E35100000AC20054E34900001AFE
:10035000FF3069E2000053E15400000A1800A0E3F6
:10031000000050E3094C84E2F4FFFF0A0289A0E3E5
:100320000060A0E3C040A0E30170A0E348FFFFEB42
:10033000C00054E30050A0E12600000A5E00009ACD
:10034000C10054E35700000AC20054E34F00001AF2
:10035000FF3067E2000053E14900000A1800A0E303
:100360004EFFFFEB1800A0E34CFFFFEB1800A0E3EB
:100370004AFFFFEB1800A0E348FFFFEB1800A0E3E3
:1003800046FFFFEBC0FFFFEB0040A0E1BEFFFFEB2D
:10039000000064E0060050E1FBFFFF9A0D00A0E3BF
:10039000000064E0090050E1FBFFFF9A0D00A0E3BC
:1003A0003EFFFFEB0A00A0E33CFFFFEB0A00A0E3E7
:1003B0003AFFFFEB0C019FE55CFFFFEB44FFFFEB17
:1003B0003AFFFFEB3C019FE55CFFFFEB44FFFFEBE7
:1003C000000000EA22FFFFEB2DFFFFEB000050E3EF
:1003D000FBFFFF1ABDFFFFEA800054E32500001A6F
:1003E000FF8008E2080050E1DBFFFF1A0600A0E3EF
:1003F0002AFFFFEB16FFFFEBC040A0E3019089E26C
:10040000C00054E30580A0E180A08AE2FF9009E2E9
:100410000050A0E1C8FFFF1A010050E32000000ACD
:10042000040050E3CCFFFF1A0600A0E31BFFFFEB24
:1004300095FFFFEB0050A0E193FFFFEB000065E0AC
:10044000060050E1FBFFFF9A0D00A0E313FFFFEB56
:100450000A00A0E311FFFFEB0A00A0E30FFFFFEB90
:1004600064009FE531FFFFEB19FFFFEB0209A0E3FA
:10047000EFFEFFEBACFFFFEA0450CAE7014084E265
:10048000FF0054E3058088E0A7FFFF1AB2FFFFEAF0
:10049000090050E1B0FFFF1A098088E0C240A0E3E4
:1004A000A1FFFFEA0080A0E1C140A0E39EFFFFEAB8
:1004B000038088E00040A0E39BFFFFEA78563412F7
:1004C000FF083D007F841E00ADDBBA00DADADADA1D
:1003D000FBFFFF1ABDFFFFEA010050E32500000A02
:1003E000040050E3DCFFFF1A0600A0E32BFFFFEB45
:1003F000A5FFFFEBF8409FE50050A0E1A2FFFFEB57
:10040000000065E0040050E1FBFFFF9A0D00A0E34F
:1004100022FFFFEB0A00A0E320FFFFEB0A00A0E3AE
:100420001EFFFFEBD0009FE540FFFFEB08FFFFEB57
:100430002000C0E3470050E3FBFFFF1A0D00A0E3DC
:1004400016FFFFEB2D00A0E314FFFFEB2D00A0E350
:1004500012FFFFEB0D00A0E310FFFFEB0A00A0E38B
:100460000EFFFFEB0A00A0E30CFFFFEB0209A0E385
:10047000EFFEFFEBECFFFFEAC140A0E30560A0E167
:10048000A9FFFFEA065080E00040A0E3FAFFFFEA80
:100490000450C8E7014084E2FF0054E3056086E0B1
:1004A000A1FFFF1AACFFFFEA070050E1AAFFFF1A05
:1004B000075086E0C240A0E3EFFFFFEA800054E36C
:1004C000F2FFFF1AFF6006E2060050E1A2FFFF1AEA
:1004D0000600A0E3017087E2F0FEFFEB808088E277
:1004E000FF7007E2C040A0E3E3FFFFEA7856341252
:1004F000FF083D007F841E00ADDBBA00DADADADAED
:040000030000800079
:00000001FF

View File

@@ -218,15 +218,15 @@ Disassembly of section .text:
002002a4 <notmain>:
2002a4: e92d47f0 push {r4, r5, r6, r7, r8, r9, sl, lr}
2002a8: ebffffa7 bl 20014c <uart_init>
2002ac: e59f0208 ldr r0, [pc, #520] ; 2004bc <notmain+0x218>
2002ac: e59f0238 ldr r0, [pc, #568] ; 2004ec <notmain+0x248>
2002b0: ebffff9e bl 200130 <hexstring>
2002b4: ebffff5c bl 20002c <GETPC>
2002b8: ebffff9c bl 200130 <hexstring>
2002bc: e3a00902 mov r0, #32768 ; 0x8000
2002c0: ebffff9a bl 200130 <hexstring>
2002c4: ebffffe4 bl 20025c <timer_init>
2002c8: e59f71f0 ldr r7, [pc, #496] ; 2004c0 <notmain+0x21c>
2002cc: e59f61f0 ldr r6, [pc, #496] ; 2004c4 <notmain+0x220>
2002c8: e59fa220 ldr sl, [pc, #544] ; 2004f0 <notmain+0x24c>
2002cc: e59f9220 ldr r9, [pc, #544] ; 2004f4 <notmain+0x250>
2002d0: e3a00015 mov r0, #21
2002d4: ebffff71 bl 2000a0 <uart_send>
2002d8: ebffffeb bl 20028c <timer_tick>
@@ -237,7 +237,7 @@ Disassembly of section .text:
2002ec: 1a00000a bne 20031c <notmain+0x78>
2002f0: ebffffe5 bl 20028c <timer_tick>
2002f4: e0640000 rsb r0, r4, r0
2002f8: e1500007 cmp r0, r7
2002f8: e150000a cmp r0, sl
2002fc: 9afffff8 bls 2002e4 <notmain+0x40>
200300: e3a00015 mov r0, #21
200304: ebffff65 bl 2000a0 <uart_send>
@@ -246,22 +246,22 @@ Disassembly of section .text:
200310: e3500000 cmp r0, #0
200314: e2844c09 add r4, r4, #2304 ; 0x900
200318: 0afffff4 beq 2002f0 <notmain+0x4c>
20031c: e3a0a902 mov sl, #32768 ; 0x8000
200320: e3a08000 mov r8, #0
20031c: e3a08902 mov r8, #32768 ; 0x8000
200320: e3a06000 mov r6, #0
200324: e3a040c0 mov r4, #192 ; 0xc0
200328: e3a09001 mov r9, #1
200328: e3a07001 mov r7, #1
20032c: ebffff48 bl 200054 <uart_recv>
200330: e35400c0 cmp r4, #192 ; 0xc0
200334: e1a05000 mov r5, r0
200338: 0a000036 beq 200418 <notmain+0x174>
20033c: 9a000025 bls 2003d8 <notmain+0x134>
200338: 0a000026 beq 2003d8 <notmain+0x134>
20033c: 9a00005e bls 2004bc <notmain+0x218>
200340: e35400c1 cmp r4, #193 ; 0xc1
200344: 0a000051 beq 200490 <notmain+0x1ec>
200344: 0a000057 beq 2004a8 <notmain+0x204>
200348: e35400c2 cmp r4, #194 ; 0xc2
20034c: 1a000049 bne 200478 <notmain+0x1d4>
200350: e26930ff rsb r3, r9, #255 ; 0xff
20034c: 1a00004f bne 200490 <notmain+0x1ec>
200350: e26730ff rsb r3, r7, #255 ; 0xff
200354: e1530000 cmp r3, r0
200358: 0a000054 beq 2004b0 <notmain+0x20c>
200358: 0a000049 beq 200484 <notmain+0x1e0>
20035c: e3a00018 mov r0, #24
200360: ebffff4e bl 2000a0 <uart_send>
200364: e3a00018 mov r0, #24
@@ -276,7 +276,7 @@ Disassembly of section .text:
200388: e1a04000 mov r4, r0
20038c: ebffffbe bl 20028c <timer_tick>
200390: e0640000 rsb r0, r4, r0
200394: e1500006 cmp r0, r6
200394: e1500009 cmp r0, r9
200398: 9afffffb bls 20038c <notmain+0xe8>
20039c: e3a0000d mov r0, #13
2003a0: ebffff3e bl 2000a0 <uart_send>
@@ -284,7 +284,7 @@ Disassembly of section .text:
2003a8: ebffff3c bl 2000a0 <uart_send>
2003ac: e3a0000a mov r0, #10
2003b0: ebffff3a bl 2000a0 <uart_send>
2003b4: e59f010c ldr r0, [pc, #268] ; 2004c8 <notmain+0x224>
2003b4: e59f013c ldr r0, [pc, #316] ; 2004f8 <notmain+0x254>
2003b8: ebffff5c bl 200130 <hexstring>
2003bc: ebffff44 bl 2000d4 <uart_flush>
2003c0: ea000000 b 2003c8 <notmain+0x124>
@@ -293,68 +293,80 @@ Disassembly of section .text:
2003cc: e3500000 cmp r0, #0
2003d0: 1afffffb bne 2003c4 <notmain+0x120>
2003d4: eaffffbd b 2002d0 <notmain+0x2c>
2003d8: e3540080 cmp r4, #128 ; 0x80
2003dc: 1a000025 bne 200478 <notmain+0x1d4>
2003e0: e20880ff and r8, r8, #255 ; 0xff
2003e4: e1500008 cmp r0, r8
2003e8: 1affffdb bne 20035c <notmain+0xb8>
2003ec: e3a00006 mov r0, #6
2003f0: ebffff2a bl 2000a0 <uart_send>
2003f4: ebffff16 bl 200054 <uart_recv>
2003f8: e3a040c0 mov r4, #192 ; 0xc0
2003fc: e2899001 add r9, r9, #1
200400: e35400c0 cmp r4, #192 ; 0xc0
200404: e1a08005 mov r8, r5
200408: e28aa080 add sl, sl, #128 ; 0x80
20040c: e20990ff and r9, r9, #255 ; 0xff
200410: e1a05000 mov r5, r0
200414: 1affffc8 bne 20033c <notmain+0x98>
200418: e3500001 cmp r0, #1
20041c: 0a000020 beq 2004a4 <notmain+0x200>
200420: e3500004 cmp r0, #4
200424: 1affffcc bne 20035c <notmain+0xb8>
200428: e3a00006 mov r0, #6
20042c: ebffff1b bl 2000a0 <uart_send>
200430: ebffff95 bl 20028c <timer_tick>
200434: e1a05000 mov r5, r0
200438: ebffff93 bl 20028c <timer_tick>
20043c: e0650000 rsb r0, r5, r0
200440: e1500006 cmp r0, r6
200444: 9afffffb bls 200438 <notmain+0x194>
200448: e3a0000d mov r0, #13
20044c: ebffff13 bl 2000a0 <uart_send>
200450: e3a0000a mov r0, #10
200454: ebffff11 bl 2000a0 <uart_send>
200458: e3a0000a mov r0, #10
20045c: ebffff0f bl 2000a0 <uart_send>
200460: e59f0064 ldr r0, [pc, #100] ; 2004cc <notmain+0x228>
200464: ebffff31 bl 200130 <hexstring>
200468: ebffff19 bl 2000d4 <uart_flush>
2003d8: e3500001 cmp r0, #1
2003dc: 0a000025 beq 200478 <notmain+0x1d4>
2003e0: e3500004 cmp r0, #4
2003e4: 1affffdc bne 20035c <notmain+0xb8>
2003e8: e3a00006 mov r0, #6
2003ec: ebffff2b bl 2000a0 <uart_send>
2003f0: ebffffa5 bl 20028c <timer_tick>
2003f4: e59f40f8 ldr r4, [pc, #248] ; 2004f4 <notmain+0x250>
2003f8: e1a05000 mov r5, r0
2003fc: ebffffa2 bl 20028c <timer_tick>
200400: e0650000 rsb r0, r5, r0
200404: e1500004 cmp r0, r4
200408: 9afffffb bls 2003fc <notmain+0x158>
20040c: e3a0000d mov r0, #13
200410: ebffff22 bl 2000a0 <uart_send>
200414: e3a0000a mov r0, #10
200418: ebffff20 bl 2000a0 <uart_send>
20041c: e3a0000a mov r0, #10
200420: ebffff1e bl 2000a0 <uart_send>
200424: e59f00d0 ldr r0, [pc, #208] ; 2004fc <notmain+0x258>
200428: ebffff40 bl 200130 <hexstring>
20042c: ebffff08 bl 200054 <uart_recv>
200430: e3c00020 bic r0, r0, #32
200434: e3500047 cmp r0, #71 ; 0x47
200438: 1afffffb bne 20042c <notmain+0x188>
20043c: e3a0000d mov r0, #13
200440: ebffff16 bl 2000a0 <uart_send>
200444: e3a0002d mov r0, #45 ; 0x2d
200448: ebffff14 bl 2000a0 <uart_send>
20044c: e3a0002d mov r0, #45 ; 0x2d
200450: ebffff12 bl 2000a0 <uart_send>
200454: e3a0000d mov r0, #13
200458: ebffff10 bl 2000a0 <uart_send>
20045c: e3a0000a mov r0, #10
200460: ebffff0e bl 2000a0 <uart_send>
200464: e3a0000a mov r0, #10
200468: ebffff0c bl 2000a0 <uart_send>
20046c: e3a00902 mov r0, #32768 ; 0x8000
200470: ebfffeef bl 200034 <BRANCHTO>
200474: eaffffac b 20032c <notmain+0x88>
200478: e7ca5004 strb r5, [sl, r4]
20047c: e2844001 add r4, r4, #1
200480: e35400ff cmp r4, #255 ; 0xff
200484: e0888005 add r8, r8, r5
200488: 1affffa7 bne 20032c <notmain+0x88>
20048c: eaffffb2 b 20035c <notmain+0xb8>
200490: e1500009 cmp r0, r9
200494: 1affffb0 bne 20035c <notmain+0xb8>
200498: e0888009 add r8, r8, r9
20049c: e3a040c2 mov r4, #194 ; 0xc2
2004a0: eaffffa1 b 20032c <notmain+0x88>
2004a4: e1a08000 mov r8, r0
2004a8: e3a040c1 mov r4, #193 ; 0xc1
2004ac: eaffff9e b 20032c <notmain+0x88>
2004b0: e0888003 add r8, r8, r3
2004b4: e3a04000 mov r4, #0
2004b8: eaffff9b b 20032c <notmain+0x88>
2004bc: 12345678 eorsne r5, r4, #120, 12 ; 0x7800000
2004c0: 003d08ff ldrshteq r0, [sp], -pc
2004c4: 001e847f andseq r8, lr, pc, ror r4
2004c8: 00badbad adcseq sp, sl, sp, lsr #23
2004cc: dadadada ble ff8b703c <notmain+0xff6b6d98>
200474: eaffffec b 20042c <notmain+0x188>
200478: e3a040c1 mov r4, #193 ; 0xc1
20047c: e1a06005 mov r6, r5
200480: eaffffa9 b 20032c <notmain+0x88>
200484: e0805006 add r5, r0, r6
200488: e3a04000 mov r4, #0
20048c: eafffffa b 20047c <notmain+0x1d8>
200490: e7c85004 strb r5, [r8, r4]
200494: e2844001 add r4, r4, #1
200498: e35400ff cmp r4, #255 ; 0xff
20049c: e0866005 add r6, r6, r5
2004a0: 1affffa1 bne 20032c <notmain+0x88>
2004a4: eaffffac b 20035c <notmain+0xb8>
2004a8: e1500007 cmp r0, r7
2004ac: 1affffaa bne 20035c <notmain+0xb8>
2004b0: e0865007 add r5, r6, r7
2004b4: e3a040c2 mov r4, #194 ; 0xc2
2004b8: eaffffef b 20047c <notmain+0x1d8>
2004bc: e3540080 cmp r4, #128 ; 0x80
2004c0: 1afffff2 bne 200490 <notmain+0x1ec>
2004c4: e20660ff and r6, r6, #255 ; 0xff
2004c8: e1500006 cmp r0, r6
2004cc: 1affffa2 bne 20035c <notmain+0xb8>
2004d0: e3a00006 mov r0, #6
2004d4: e2877001 add r7, r7, #1
2004d8: ebfffef0 bl 2000a0 <uart_send>
2004dc: e2888080 add r8, r8, #128 ; 0x80
2004e0: e20770ff and r7, r7, #255 ; 0xff
2004e4: e3a040c0 mov r4, #192 ; 0xc0
2004e8: eaffffe3 b 20047c <notmain+0x1d8>
2004ec: 12345678 eorsne r5, r4, #120, 12 ; 0x7800000
2004f0: 003d08ff ldrshteq r0, [sp], -pc
2004f4: 001e847f andseq r8, lr, pc, ror r4
2004f8: 00badbad adcseq sp, sl, sp, lsr #23
2004fc: dadadada ble ff8b706c <notmain+0xff6b6dc8>
Disassembly of section .ARM.attributes:
@@ -378,5 +390,5 @@ Disassembly of section .comment:
0: 3a434347 bcc 10d0d24 <notmain+0xed0a80>
4: 4e472820 cdpmi 8, 4, cr2, cr7, cr0, {1}
8: 34202955 strtcc r2, [r0], #-2389 ; 0x955
c: 322e382e eorcc r3, lr, #3014656 ; 0x2e0000
c: 332e382e teqcc lr, #3014656 ; 0x2e0000
...

Binary file not shown.

82
bootloader07/Makefile Normal file
View File

@@ -0,0 +1,82 @@
ARMGNU ?= arm-none-eabi
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
gcc : kernel.img blinker.hex
all : gcc clang
clean :
rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.elf
rm -f *.list
rm -f *.img
rm -f *.bc
rm -f *.clang.s
vectors.o : vectors.s
$(ARMGNU)-as vectors.s -o vectors.o
bootloader07.o : bootloader07.c
$(ARMGNU)-gcc $(COPS) -c bootloader07.c -o bootloader07.o
periph.o : periph.c
$(ARMGNU)-gcc $(COPS) -c periph.c -o periph.o
kernel.img : loader vectors.o periph.o bootloader07.o
$(ARMGNU)-ld vectors.o periph.o bootloader07.o -T loader -o bootloader07.elf
$(ARMGNU)-objdump -D bootloader07.elf > bootloader07.list
$(ARMGNU)-objcopy bootloader07.elf -O ihex bootloader07.hex
$(ARMGNU)-objcopy bootloader07.elf -O binary kernel.img
start.o : start.s
$(ARMGNU)-as start.s -o start.o
blinker.o : blinker.c
$(ARMGNU)-gcc $(COPS) -c blinker.c -o blinker.o
blinker.hex : memmap start.o blinker.o
$(ARMGNU)-ld start.o blinker.o -T memmap -o blinker.elf
$(ARMGNU)-objdump -D blinker.elf > blinker.list
$(ARMGNU)-objcopy blinker.elf -O ihex blinker.hex
LOPS = -Wall -m32 -emit-llvm
LLCOPS0 = -march=arm
LLCOPS1 = -march=arm -mcpu=arm1176jzf-s
LLCOPS = $(LLCOPS1)
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
OOPS = -std-compile-opts
clang : bootloader07.bin
bootloader07.bc : bootloader07.c
clang $(LOPS) -c bootloader07.c -o bootloader07.bc
periph.bc : periph.c
clang $(LOPS) -c periph.c -o periph.bc
bootloader07.clang.elf : loader vectors.o bootloader07.bc periph.bc
llvm-link periph.bc bootloader07.bc -o bootloader07.nopt.bc
opt $(OOPS) bootloader07.nopt.bc -o bootloader07.opt.bc
llc $(LLCOPS) bootloader07.opt.bc -o bootloader07.clang.s
$(ARMGNU)-as bootloader07.clang.s -o bootloader07.clang.o
$(ARMGNU)-ld -o bootloader07.clang.elf -T loader vectors.o bootloader07.clang.o
$(ARMGNU)-objdump -D bootloader07.clang.elf > bootloader07.clang.list
bootloader07.bin : bootloader07.clang.elf
$(ARMGNU)-objcopy bootloader07.clang.elf bootloader07.clang.bin -O binary

37
bootloader07/README Normal file
View File

@@ -0,0 +1,37 @@
See the top level README file for more information on documentation
and how to run these programs.
This is a very simple bootloader. Instead of the sd dance (see
top level README), this makes life a bit simpler and greatly reduces
physical wear and tear on the sd card socket. Do the sd card dance one
more time with this kernel.img. Get some sort of serial solution to
connect a dumb termial program with the ability to download raw/ascii
files.
bootloader01 was .hex based, this one is also .hex based but a
different way to parse it. bootloader02 through bootloader06
expect binary files, a binary image of the memory starting at
address 0x8000. I intend to release bootloader08 at the same time
and it will be .bin based but have the go feature.
This bootloader07 parses intel hex formatted files. Look that up at
wikipedia, it is very simple and historically widely used for bare
metal embedded work. (S record is another format like intel hex but
of course motorola had to have their own. Intel hex and Motorola S-
record). I felt like doing another state machine and honestly had
forgotten I did one before in bootloader01. This bootloader does
not make any of the others obsolete, it was just a fun exercise.
The thing that annoyed me the most about my bootloader is that
I use minicom and minicom spawns a separate program to do the file
transfers, xmodem, ascii, kermit, etc, and there is a delay and
a loss of data when the spawned program exits and minicom returns.
The solution is that you hit the g key when you want the program
to start so you are basically back in the terminal at that point.
I normally do not deliver binaries. In this case I have included all
of the build files so that you can at least get started without having
to build the bootloader. Backup whatever kernel.img file you are using
and replace with the kernel.img file in this repo (on your sd card) to
use this program.

70
bootloader07/blinker.c Normal file
View File

@@ -0,0 +1,70 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void dummy ( unsigned int );
#define ARM_TIMER_LOD 0x2000B400
#define ARM_TIMER_VAL 0x2000B404
#define ARM_TIMER_CTL 0x2000B408
#define ARM_TIMER_DIV 0x2000B41C
#define ARM_TIMER_CNT 0x2000B420
#define SYSTIMERCLO 0x20003004
#define GPFSEL1 0x20200004
#define GPSET0 0x2020001C
#define GPCLR0 0x20200028
#define TIMEOUT 1000000
//-------------------------------------------------------------------------
int notmain ( void )
{
unsigned int ra;
unsigned int rb;
ra=GET32(GPFSEL1);
ra&=~(7<<18);
ra|=1<<18;
PUT32(GPFSEL1,ra);
PUT32(ARM_TIMER_CTL,0x00F90000);
PUT32(ARM_TIMER_CTL,0x00F90200);
rb=GET32(ARM_TIMER_CNT);
while(1)
{
PUT32(GPSET0,1<<16);
while(1)
{
ra=GET32(ARM_TIMER_CNT);
if((ra-rb)>=TIMEOUT) break;
}
rb+=TIMEOUT;
PUT32(GPCLR0,1<<16);
while(1)
{
ra=GET32(ARM_TIMER_CNT);
if((ra-rb)>=TIMEOUT) break;
}
rb+=TIMEOUT;
}
return(0);
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//
// Copyright (c) 2012 David Welch dwelch@dwelch.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-------------------------------------------------------------------------

BIN
bootloader07/blinker.elf Executable file

Binary file not shown.

16
bootloader07/blinker.hex Normal file
View File

@@ -0,0 +1,16 @@
:1080000002D9A0E3050000EBFEFFFFEA001080E5C7
:108010001EFF2FE1000090E51EFF2FE11EFF2FE164
:1080200070402DE98C009FE5F9FFFFEB0717C0E3D7
:10803000011781E37C009FE5F3FFFFEB78009FE5EC
:10804000F918A0E3F0FFFFEB6C009FE56C109FE5D3
:10805000EDFFFFEB68009FE5EDFFFFEB64409FE560
:108060000050A0E160009FE50118A0E3E6FFFFEBF0
:108070004C009FE5E6FFFFEB000065E0040050E1E7
:10808000FAFFFF9A3D6985E240009FE50118A0E3F1
:10809000096D86E2DCFFFFEB24009FE5DCFFFFEBD0
:1080A000000066E0040050E1FAFFFF9A7A5985E289
:1080B000125D85E2EAFFFFEA0400202008B40020F8
:1080C0000002F90020B400203F420F001C002020D5
:0480D0002800202044
:040000030000800079
:00000001FF

95
bootloader07/blinker.list Normal file
View File

@@ -0,0 +1,95 @@
blinker.elf: file format elf32-littlearm
Disassembly of section .text:
00008000 <_start>:
8000: e3a0d902 mov sp, #32768 ; 0x8000
8004: eb000005 bl 8020 <notmain>
00008008 <hang>:
8008: eafffffe b 8008 <hang>
0000800c <PUT32>:
800c: e5801000 str r1, [r0]
8010: e12fff1e bx lr
00008014 <GET32>:
8014: e5900000 ldr r0, [r0]
8018: e12fff1e bx lr
0000801c <dummy>:
801c: e12fff1e bx lr
00008020 <notmain>:
8020: e92d4070 push {r4, r5, r6, lr}
8024: e59f008c ldr r0, [pc, #140] ; 80b8 <notmain+0x98>
8028: ebfffff9 bl 8014 <GET32>
802c: e3c01707 bic r1, r0, #1835008 ; 0x1c0000
8030: e3811701 orr r1, r1, #262144 ; 0x40000
8034: e59f007c ldr r0, [pc, #124] ; 80b8 <notmain+0x98>
8038: ebfffff3 bl 800c <PUT32>
803c: e59f0078 ldr r0, [pc, #120] ; 80bc <notmain+0x9c>
8040: e3a018f9 mov r1, #16318464 ; 0xf90000
8044: ebfffff0 bl 800c <PUT32>
8048: e59f006c ldr r0, [pc, #108] ; 80bc <notmain+0x9c>
804c: e59f106c ldr r1, [pc, #108] ; 80c0 <notmain+0xa0>
8050: ebffffed bl 800c <PUT32>
8054: e59f0068 ldr r0, [pc, #104] ; 80c4 <notmain+0xa4>
8058: ebffffed bl 8014 <GET32>
805c: e59f4064 ldr r4, [pc, #100] ; 80c8 <notmain+0xa8>
8060: e1a05000 mov r5, r0
8064: e59f0060 ldr r0, [pc, #96] ; 80cc <notmain+0xac>
8068: e3a01801 mov r1, #65536 ; 0x10000
806c: ebffffe6 bl 800c <PUT32>
8070: e59f004c ldr r0, [pc, #76] ; 80c4 <notmain+0xa4>
8074: ebffffe6 bl 8014 <GET32>
8078: e0650000 rsb r0, r5, r0
807c: e1500004 cmp r0, r4
8080: 9afffffa bls 8070 <notmain+0x50>
8084: e285693d add r6, r5, #999424 ; 0xf4000
8088: e59f0040 ldr r0, [pc, #64] ; 80d0 <notmain+0xb0>
808c: e3a01801 mov r1, #65536 ; 0x10000
8090: e2866d09 add r6, r6, #576 ; 0x240
8094: ebffffdc bl 800c <PUT32>
8098: e59f0024 ldr r0, [pc, #36] ; 80c4 <notmain+0xa4>
809c: ebffffdc bl 8014 <GET32>
80a0: e0660000 rsb r0, r6, r0
80a4: e1500004 cmp r0, r4
80a8: 9afffffa bls 8098 <notmain+0x78>
80ac: e285597a add r5, r5, #1998848 ; 0x1e8000
80b0: e2855d12 add r5, r5, #1152 ; 0x480
80b4: eaffffea b 8064 <notmain+0x44>
80b8: 20200004 eorcs r0, r0, r4
80bc: 2000b408 andcs fp, r0, r8, lsl #8
80c0: 00f90200 rscseq r0, r9, r0, lsl #4
80c4: 2000b420 andcs fp, r0, r0, lsr #8
80c8: 000f423f andeq r4, pc, pc, lsr r2 ; <UNPREDICTABLE>
80cc: 2020001c eorcs r0, r0, ip, lsl r0
80d0: 20200028 eorcs r0, r0, r8, lsr #32
Disassembly of section .ARM.attributes:
00000000 <.ARM.attributes>:
0: 00002a41 andeq r2, r0, r1, asr #20
4: 61656100 cmnvs r5, r0, lsl #2
8: 01006962 tsteq r0, r2, ror #18
c: 00000020 andeq r0, r0, r0, lsr #32
10: 4d524105 ldfmie f4, [r2, #-20] ; 0xffffffec
14: 54347620 ldrtpl r7, [r4], #-1568 ; 0x620
18: 08020600 stmdaeq r2, {r9, sl}
1c: 12010901 andne r0, r1, #16384 ; 0x4000
20: 15011404 strne r1, [r1, #-1028] ; 0x404
24: 18031701 stmdane r3, {r0, r8, r9, sl, ip}
28: Address 0x0000000000000028 is out of bounds.
Disassembly of section .comment:
00000000 <.comment>:
0: 3a434347 bcc 10d0d24 <notmain+0x10c8d04>
4: 4e472820 cdpmi 8, 4, cr2, cr7, cr0, {1}
8: 34202955 strtcc r2, [r0], #-2389 ; 0x955
c: 332e382e teqcc lr, #3014656 ; 0x2e0000
...

228
bootloader07/bootloader07.c Normal file
View File

@@ -0,0 +1,228 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// 2 outer corner
// 4
// 6
// 8 TX out
// 10 RX in
extern void PUT32 ( unsigned int, unsigned int );
extern void PUT16 ( unsigned int, unsigned int );
extern void PUT8 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern unsigned int GETPC ( void );
extern void BRANCHTO ( unsigned int );
extern void dummy ( unsigned int );
extern void uart_init ( void );
extern unsigned int uart_lcr ( void );
extern void uart_flush ( void );
extern void uart_send ( unsigned int );
extern unsigned int uart_recv ( void );
extern unsigned int uart_check ( void );
extern void hexstring ( unsigned int );
extern void hexstrings ( unsigned int );
extern void timer_init ( void );
extern unsigned int timer_tick ( void );
extern void timer_init ( void );
extern unsigned int timer_tick ( void );
//------------------------------------------------------------------------
int notmain ( void )
{
unsigned int state;
unsigned int byte_count;
unsigned int address;
unsigned int record_type;
unsigned int segment;
unsigned int data;
unsigned int sum;
unsigned int ra;
uart_init();
hexstring(0x12345678);
hexstring(GETPC());
uart_send('I');
uart_send('H');
uart_send('E');
uart_send('X');
uart_send(0x0D);
uart_send(0x0A);
state=0;
segment=0;
sum=0;
data=0;
record_type=0;
address=0;
while(1)
{
ra=uart_recv();
if(ra==':')
{
state=1;
continue;
}
if(ra==0x0D)
{
state=0;
continue;
}
if(ra==0x0A)
{
state=0;
continue;
}
if((ra=='g')||(ra=='G'))
{
uart_send(0x0D);
uart_send('-');
uart_send('-');
uart_send(0x0D);
uart_send(0x0A);
uart_send(0x0A);
BRANCHTO(0x8000);
state=0;
break;
}
switch(state)
{
case 0:
{
break;
}
case 1:
case 2:
{
byte_count<<=4;
if(ra>0x39) ra-=7;
byte_count|=(ra&0xF);
byte_count&=0xFF;
state++;
break;
}
case 3:
case 4:
case 5:
case 6:
{
address<<=4;
if(ra>0x39) ra-=7;
address|=(ra&0xF);
address&=0xFFFF;
address|=segment;
state++;
break;
}
case 7:
{
record_type<<=4;
if(ra>0x39) ra-=7;
record_type|=(ra&0xF);
record_type&=0xFF;
state++;
break;
}
case 8:
{
record_type<<=4;
if(ra>0x39) ra-=7;
record_type|=(ra&0xF);
record_type&=0xFF;
switch(record_type)
{
case 0x00:
{
state=14;
break;
}
case 0x01:
{
hexstring(sum);
state=0;
break;
}
case 0x02:
{
state=9;
break;
}
default:
{
state=0;
break;
}
}
break;
}
case 9:
case 10:
case 11:
case 12:
{
segment<<=4;
if(ra>0x39) ra-=7;
segment|=(ra&0xF);
segment&=0xFFFF;
state++;
break;
}
case 13:
{
segment<<=4;
state=0;
break;
}
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
{
data<<=4;
if(ra>0x39) ra-=7;
data|=(ra&0xF);
if(state==21)
{
ra=(data>>24)|(data<<24);
ra|=(data>>8)&0x0000FF00;
ra|=(data<<8)&0x00FF0000;
data=ra;
PUT32(address,data);
sum+=address;
sum+=data;
address+=4;
state=14;
}
else
{
state++;
}
break;
}
}
}
return(0);
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//
// Copyright (c) 2014 David Welch dwelch@dwelch.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-------------------------------------------------------------------------

BIN
bootloader07/bootloader07.elf Executable file

Binary file not shown.

129139
bootloader07/bootloader07.hex Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,393 @@
bootloader07.elf: file format elf32-littlearm
Disassembly of section .text:
00008000 <_start>:
8000: ea07dffe b 200000 <skip>
...
00200000 <skip>:
200000: e3a0d302 mov sp, #134217728 ; 0x8000000
200004: eb0000a6 bl 2002a4 <notmain>
00200008 <hang>:
200008: eafffffe b 200008 <hang>
0020000c <PUT32>:
20000c: e5801000 str r1, [r0]
200010: e12fff1e bx lr
00200014 <PUT16>:
200014: e1c010b0 strh r1, [r0]
200018: e12fff1e bx lr
0020001c <PUT8>:
20001c: e5c01000 strb r1, [r0]
200020: e12fff1e bx lr
00200024 <GET32>:
200024: e5900000 ldr r0, [r0]
200028: e12fff1e bx lr
0020002c <GETPC>:
20002c: e1a0000e mov r0, lr
200030: e12fff1e bx lr
00200034 <BRANCHTO>:
200034: e12fff10 bx r0
00200038 <dummy>:
200038: e12fff1e bx lr
0020003c <uart_lcr>:
20003c: e92d4008 push {r3, lr}
200040: e59f0008 ldr r0, [pc, #8] ; 200050 <uart_lcr+0x14>
200044: ebfffff6 bl 200024 <GET32>
200048: e8bd4008 pop {r3, lr}
20004c: e12fff1e bx lr
200050: 20215054 eorcs r5, r1, r4, asr r0
00200054 <uart_recv>:
200054: e92d4008 push {r3, lr}
200058: e59f001c ldr r0, [pc, #28] ; 20007c <uart_recv+0x28>
20005c: ebfffff0 bl 200024 <GET32>
200060: e3100001 tst r0, #1
200064: 0afffffb beq 200058 <uart_recv+0x4>
200068: e59f0010 ldr r0, [pc, #16] ; 200080 <uart_recv+0x2c>
20006c: ebffffec bl 200024 <GET32>
200070: e8bd4008 pop {r3, lr}
200074: e20000ff and r0, r0, #255 ; 0xff
200078: e12fff1e bx lr
20007c: 20215054 eorcs r5, r1, r4, asr r0
200080: 20215040 eorcs r5, r1, r0, asr #32
00200084 <uart_check>:
200084: e92d4008 push {r3, lr}
200088: e59f000c ldr r0, [pc, #12] ; 20009c <uart_check+0x18>
20008c: ebffffe4 bl 200024 <GET32>
200090: e8bd4008 pop {r3, lr}
200094: e2000001 and r0, r0, #1
200098: e12fff1e bx lr
20009c: 20215054 eorcs r5, r1, r4, asr r0
002000a0 <uart_send>:
2000a0: e92d4010 push {r4, lr}
2000a4: e1a04000 mov r4, r0
2000a8: e59f001c ldr r0, [pc, #28] ; 2000cc <uart_send+0x2c>
2000ac: ebffffdc bl 200024 <GET32>
2000b0: e3100020 tst r0, #32
2000b4: 0afffffb beq 2000a8 <uart_send+0x8>
2000b8: e1a01004 mov r1, r4
2000bc: e59f000c ldr r0, [pc, #12] ; 2000d0 <uart_send+0x30>
2000c0: ebffffd1 bl 20000c <PUT32>
2000c4: e8bd4010 pop {r4, lr}
2000c8: e12fff1e bx lr
2000cc: 20215054 eorcs r5, r1, r4, asr r0
2000d0: 20215040 eorcs r5, r1, r0, asr #32
002000d4 <uart_flush>:
2000d4: e92d4008 push {r3, lr}
2000d8: e59f0010 ldr r0, [pc, #16] ; 2000f0 <uart_flush+0x1c>
2000dc: ebffffd0 bl 200024 <GET32>
2000e0: e3100c01 tst r0, #256 ; 0x100
2000e4: 1afffffb bne 2000d8 <uart_flush+0x4>
2000e8: e8bd4008 pop {r3, lr}
2000ec: e12fff1e bx lr
2000f0: 20215054 eorcs r5, r1, r4, asr r0
002000f4 <hexstrings>:
2000f4: e92d4038 push {r3, r4, r5, lr}
2000f8: e1a05000 mov r5, r0
2000fc: e3a04020 mov r4, #32
200100: e2444004 sub r4, r4, #4
200104: e1a03435 lsr r3, r5, r4
200108: e203300f and r3, r3, #15
20010c: e3530009 cmp r3, #9
200110: 82830037 addhi r0, r3, #55 ; 0x37
200114: 92830030 addls r0, r3, #48 ; 0x30
200118: ebffffe0 bl 2000a0 <uart_send>
20011c: e3540000 cmp r4, #0
200120: 1afffff6 bne 200100 <hexstrings+0xc>
200124: e3a00020 mov r0, #32
200128: e8bd4038 pop {r3, r4, r5, lr}
20012c: eaffffdb b 2000a0 <uart_send>
00200130 <hexstring>:
200130: e92d4008 push {r3, lr}
200134: ebffffee bl 2000f4 <hexstrings>
200138: e3a0000d mov r0, #13
20013c: ebffffd7 bl 2000a0 <uart_send>
200140: e3a0000a mov r0, #10
200144: e8bd4008 pop {r3, lr}
200148: eaffffd4 b 2000a0 <uart_send>
0020014c <uart_init>:
20014c: e92d4010 push {r4, lr}
200150: e59f00d8 ldr r0, [pc, #216] ; 200230 <uart_init+0xe4>
200154: e3a01001 mov r1, #1
200158: ebffffab bl 20000c <PUT32>
20015c: e59f00d0 ldr r0, [pc, #208] ; 200234 <uart_init+0xe8>
200160: e3a01000 mov r1, #0
200164: ebffffa8 bl 20000c <PUT32>
200168: e59f00c8 ldr r0, [pc, #200] ; 200238 <uart_init+0xec>
20016c: e3a01000 mov r1, #0
200170: ebffffa5 bl 20000c <PUT32>
200174: e59f00c0 ldr r0, [pc, #192] ; 20023c <uart_init+0xf0>
200178: e3a01003 mov r1, #3
20017c: ebffffa2 bl 20000c <PUT32>
200180: e59f00b8 ldr r0, [pc, #184] ; 200240 <uart_init+0xf4>
200184: e3a01000 mov r1, #0
200188: ebffff9f bl 20000c <PUT32>
20018c: e59f00a0 ldr r0, [pc, #160] ; 200234 <uart_init+0xe8>
200190: e3a01000 mov r1, #0
200194: ebffff9c bl 20000c <PUT32>
200198: e59f00a4 ldr r0, [pc, #164] ; 200244 <uart_init+0xf8>
20019c: e3a010c6 mov r1, #198 ; 0xc6
2001a0: ebffff99 bl 20000c <PUT32>
2001a4: e59f109c ldr r1, [pc, #156] ; 200248 <uart_init+0xfc>
2001a8: e59f009c ldr r0, [pc, #156] ; 20024c <uart_init+0x100>
2001ac: ebffff96 bl 20000c <PUT32>
2001b0: e59f0098 ldr r0, [pc, #152] ; 200250 <uart_init+0x104>
2001b4: ebffff9a bl 200024 <GET32>
2001b8: e3c01a3f bic r1, r0, #258048 ; 0x3f000
2001bc: e3811a12 orr r1, r1, #73728 ; 0x12000
2001c0: e59f0088 ldr r0, [pc, #136] ; 200250 <uart_init+0x104>
2001c4: ebffff90 bl 20000c <PUT32>
2001c8: e59f0084 ldr r0, [pc, #132] ; 200254 <uart_init+0x108>
2001cc: e3a01000 mov r1, #0
2001d0: ebffff8d bl 20000c <PUT32>
2001d4: e3a04000 mov r4, #0
2001d8: e1a00004 mov r0, r4
2001dc: e2844001 add r4, r4, #1
2001e0: ebffff94 bl 200038 <dummy>
2001e4: e3540096 cmp r4, #150 ; 0x96
2001e8: 1afffffa bne 2001d8 <uart_init+0x8c>
2001ec: e59f0064 ldr r0, [pc, #100] ; 200258 <uart_init+0x10c>
2001f0: e3a01903 mov r1, #49152 ; 0xc000
2001f4: ebffff84 bl 20000c <PUT32>
2001f8: e3a04000 mov r4, #0
2001fc: e1a00004 mov r0, r4
200200: e2844001 add r4, r4, #1
200204: ebffff8b bl 200038 <dummy>
200208: e3540096 cmp r4, #150 ; 0x96
20020c: 1afffffa bne 2001fc <uart_init+0xb0>
200210: e59f0040 ldr r0, [pc, #64] ; 200258 <uart_init+0x10c>
200214: e3a01000 mov r1, #0
200218: ebffff7b bl 20000c <PUT32>
20021c: e59f0014 ldr r0, [pc, #20] ; 200238 <uart_init+0xec>
200220: e3a01003 mov r1, #3
200224: ebffff78 bl 20000c <PUT32>
200228: e8bd4010 pop {r4, lr}
20022c: e12fff1e bx lr
200230: 20215004 eorcs r5, r1, r4
200234: 20215044 eorcs r5, r1, r4, asr #32
200238: 20215060 eorcs r5, r1, r0, rrx
20023c: 2021504c eorcs r5, r1, ip, asr #32
200240: 20215050 eorcs r5, r1, r0, asr r0
200244: 20215048 eorcs r5, r1, r8, asr #32
200248: 0000010e andeq r0, r0, lr, lsl #2
20024c: 20215068 eorcs r5, r1, r8, rrx
200250: 20200004 eorcs r0, r0, r4
200254: 20200094 mlacs r0, r4, r0, r0
200258: 20200098 mlacs r0, r8, r0, r0
0020025c <timer_init>:
20025c: e92d4010 push {r4, lr}
200260: e59f401c ldr r4, [pc, #28] ; 200284 <timer_init+0x28>
200264: e3a018f9 mov r1, #16318464 ; 0xf90000
200268: e1a00004 mov r0, r4
20026c: ebffff66 bl 20000c <PUT32>
200270: e1a00004 mov r0, r4
200274: e59f100c ldr r1, [pc, #12] ; 200288 <timer_init+0x2c>
200278: ebffff63 bl 20000c <PUT32>
20027c: e8bd4010 pop {r4, lr}
200280: e12fff1e bx lr
200284: 2000b408 andcs fp, r0, r8, lsl #8
200288: 00f90200 rscseq r0, r9, r0, lsl #4
0020028c <timer_tick>:
20028c: e92d4008 push {r3, lr}
200290: e59f0008 ldr r0, [pc, #8] ; 2002a0 <timer_tick+0x14>
200294: ebffff62 bl 200024 <GET32>
200298: e8bd4008 pop {r3, lr}
20029c: e12fff1e bx lr
2002a0: 2000b420 andcs fp, r0, r0, lsr #8
002002a4 <notmain>:
2002a4: e92d43f8 push {r3, r4, r5, r6, r7, r8, r9, lr}
2002a8: ebffffa7 bl 20014c <uart_init>
2002ac: e59f0244 ldr r0, [pc, #580] ; 2004f8 <notmain+0x254>
2002b0: ebffff9e bl 200130 <hexstring>
2002b4: ebffff5c bl 20002c <GETPC>
2002b8: ebffff9c bl 200130 <hexstring>
2002bc: e3a00049 mov r0, #73 ; 0x49
2002c0: ebffff76 bl 2000a0 <uart_send>
2002c4: e3a00048 mov r0, #72 ; 0x48
2002c8: ebffff74 bl 2000a0 <uart_send>
2002cc: e3a00045 mov r0, #69 ; 0x45
2002d0: ebffff72 bl 2000a0 <uart_send>
2002d4: e3a00058 mov r0, #88 ; 0x58
2002d8: ebffff70 bl 2000a0 <uart_send>
2002dc: e3a0000d mov r0, #13
2002e0: ebffff6e bl 2000a0 <uart_send>
2002e4: e3a0000a mov r0, #10
2002e8: ebffff6c bl 2000a0 <uart_send>
2002ec: e3a07000 mov r7, #0
2002f0: e1a08007 mov r8, r7
2002f4: e1a06007 mov r6, r7
2002f8: e1a05007 mov r5, r7
2002fc: e1a09007 mov r9, r7
200300: e1a04007 mov r4, r7
200304: ebffff52 bl 200054 <uart_recv>
200308: e350003a cmp r0, #58 ; 0x3a
20030c: 0a00002a beq 2003bc <notmain+0x118>
200310: e350000d cmp r0, #13
200314: 0a000054 beq 20046c <notmain+0x1c8>
200318: e350000a cmp r0, #10
20031c: 0a000052 beq 20046c <notmain+0x1c8>
200320: e3c03020 bic r3, r0, #32
200324: e3530047 cmp r3, #71 ; 0x47
200328: 0a000051 beq 200474 <notmain+0x1d0>
20032c: e2443001 sub r3, r4, #1
200330: e3530014 cmp r3, #20
200334: 979ff103 ldrls pc, [pc, r3, lsl #2]
200338: eafffff1 b 200304 <notmain+0x60>
20033c: 002003ac eoreq r0, r0, ip, lsr #7
200340: 002003ac eoreq r0, r0, ip, lsr #7
200344: 00200448 eoreq r0, r0, r8, asr #8
200348: 00200448 eoreq r0, r0, r8, asr #8
20034c: 00200448 eoreq r0, r0, r8, asr #8
200350: 00200448 eoreq r0, r0, r8, asr #8
200354: 00200428 eoreq r0, r0, r8, lsr #8
200358: 002003f4 strdeq r0, [r0], -r4 ; <UNPREDICTABLE>
20035c: 002003d0 ldrdeq r0, [r0], -r0 ; <UNPREDICTABLE>
200360: 002003d0 ldrdeq r0, [r0], -r0 ; <UNPREDICTABLE>
200364: 002003d0 ldrdeq r0, [r0], -r0 ; <UNPREDICTABLE>
200368: 002003d0 ldrdeq r0, [r0], -r0 ; <UNPREDICTABLE>
20036c: 002003c4 eoreq r0, r0, r4, asr #7
200370: 00200390 mlaeq r0, r0, r3, r0
200374: 00200390 mlaeq r0, r0, r3, r0
200378: 00200390 mlaeq r0, r0, r3, r0
20037c: 00200390 mlaeq r0, r0, r3, r0
200380: 00200390 mlaeq r0, r0, r3, r0
200384: 00200390 mlaeq r0, r0, r3, r0
200388: 00200390 mlaeq r0, r0, r3, r0
20038c: 00200390 mlaeq r0, r0, r3, r0
200390: e3500039 cmp r0, #57 ; 0x39
200394: 82400007 subhi r0, r0, #7
200398: e1a08208 lsl r8, r8, #4
20039c: e200000f and r0, r0, #15
2003a0: e3540015 cmp r4, #21
2003a4: e1808008 orr r8, r0, r8
2003a8: 0a000042 beq 2004b8 <notmain+0x214>
2003ac: ebffff28 bl 200054 <uart_recv>
2003b0: e350003a cmp r0, #58 ; 0x3a
2003b4: e2844001 add r4, r4, #1
2003b8: 1affffd4 bne 200310 <notmain+0x6c>
2003bc: e3a04001 mov r4, #1
2003c0: eaffffcf b 200304 <notmain+0x60>
2003c4: e1a06206 lsl r6, r6, #4
2003c8: e3a04000 mov r4, #0
2003cc: eaffffcc b 200304 <notmain+0x60>
2003d0: e3500039 cmp r0, #57 ; 0x39
2003d4: 82400007 subhi r0, r0, #7
2003d8: e1a06206 lsl r6, r6, #4
2003dc: e200000f and r0, r0, #15
2003e0: e1806006 orr r6, r0, r6
2003e4: e1a06806 lsl r6, r6, #16
2003e8: e1a06826 lsr r6, r6, #16
2003ec: e2844001 add r4, r4, #1
2003f0: eaffffc3 b 200304 <notmain+0x60>
2003f4: e3500039 cmp r0, #57 ; 0x39
2003f8: 82400007 subhi r0, r0, #7
2003fc: e1a05205 lsl r5, r5, #4
200400: e200000f and r0, r0, #15
200404: e1805005 orr r5, r0, r5
200408: e20550ff and r5, r5, #255 ; 0xff
20040c: e3550001 cmp r5, #1
200410: 0a000034 beq 2004e8 <notmain+0x244>
200414: 3a000031 bcc 2004e0 <notmain+0x23c>
200418: e3550002 cmp r5, #2
20041c: 03a04009 moveq r4, #9
200420: 13a04000 movne r4, #0
200424: eaffffb6 b 200304 <notmain+0x60>
200428: e3500039 cmp r0, #57 ; 0x39
20042c: 82400007 subhi r0, r0, #7
200430: e1a05205 lsl r5, r5, #4
200434: e200000f and r0, r0, #15
200438: e1805005 orr r5, r0, r5
20043c: e20550ff and r5, r5, #255 ; 0xff
200440: e3a04008 mov r4, #8
200444: eaffffae b 200304 <notmain+0x60>
200448: e3500039 cmp r0, #57 ; 0x39
20044c: 82400007 subhi r0, r0, #7
200450: e1a09209 lsl r9, r9, #4
200454: e200000f and r0, r0, #15
200458: e1809009 orr r9, r0, r9
20045c: e1a09809 lsl r9, r9, #16
200460: e1869829 orr r9, r6, r9, lsr #16
200464: e2844001 add r4, r4, #1
200468: eaffffa5 b 200304 <notmain+0x60>
20046c: e3a04000 mov r4, #0
200470: eaffffa3 b 200304 <notmain+0x60>
200474: e3a0000d mov r0, #13
200478: ebffff08 bl 2000a0 <uart_send>
20047c: e3a0002d mov r0, #45 ; 0x2d
200480: ebffff06 bl 2000a0 <uart_send>
200484: e3a0002d mov r0, #45 ; 0x2d
200488: ebffff04 bl 2000a0 <uart_send>
20048c: e3a0000d mov r0, #13
200490: ebffff02 bl 2000a0 <uart_send>
200494: e3a0000a mov r0, #10
200498: ebffff00 bl 2000a0 <uart_send>
20049c: e3a0000a mov r0, #10
2004a0: ebfffefe bl 2000a0 <uart_send>
2004a4: e3a00902 mov r0, #32768 ; 0x8000
2004a8: ebfffee1 bl 200034 <BRANCHTO>
2004ac: e3a00000 mov r0, #0
2004b0: e8bd43f8 pop {r3, r4, r5, r6, r7, r8, r9, lr}
2004b4: e12fff1e bx lr
2004b8: e0283868 eor r3, r8, r8, ror #16
2004bc: e1a03423 lsr r3, r3, #8
2004c0: e3c33cff bic r3, r3, #65280 ; 0xff00
2004c4: e0238468 eor r8, r3, r8, ror #8
2004c8: e1a00009 mov r0, r9
2004cc: e1a01008 mov r1, r8
2004d0: ebfffecd bl 20000c <PUT32>
2004d4: e0877009 add r7, r7, r9
2004d8: e0877008 add r7, r7, r8
2004dc: e2899004 add r9, r9, #4
2004e0: e3a0400e mov r4, #14
2004e4: eaffff86 b 200304 <notmain+0x60>
2004e8: e1a00007 mov r0, r7
2004ec: ebffff0f bl 200130 <hexstring>
2004f0: e3a04000 mov r4, #0
2004f4: eaffff82 b 200304 <notmain+0x60>
2004f8: 12345678 eorsne r5, r4, #120, 12 ; 0x7800000
Disassembly of section .ARM.attributes:
00000000 <.ARM.attributes>:
0: 00002a41 andeq r2, r0, r1, asr #20
4: 61656100 cmnvs r5, r0, lsl #2
8: 01006962 tsteq r0, r2, ror #18
c: 00000020 andeq r0, r0, r0, lsr #32
10: 4d524105 ldfmie f4, [r2, #-20] ; 0xffffffec
14: 54347620 ldrtpl r7, [r4], #-1568 ; 0x620
18: 08020600 stmdaeq r2, {r9, sl}
1c: 12010901 andne r0, r1, #16384 ; 0x4000
20: 15011404 strne r1, [r1, #-1028] ; 0x404
24: 18031701 stmdane r3, {r0, r8, r9, sl, ip}
28: Address 0x0000000000000028 is out of bounds.
Disassembly of section .comment:
00000000 <.comment>:
0: 3a434347 bcc 10d0d24 <notmain+0xed0a80>
4: 4e472820 cdpmi 8, 4, cr2, cr7, cr0, {1}
8: 34202955 strtcc r2, [r0], #-2389 ; 0x955
c: 332e382e teqcc lr, #3014656 ; 0x2e0000
...

194
bootloader07/ihex.c Normal file
View File

@@ -0,0 +1,194 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *fp;
unsigned char get_one ( void )
{
unsigned int ra;
unsigned char data[8];
ra=fread(data,1,1,fp);
if(ra==0) exit(0);
return(data[0]);
}
void PUT32 ( unsigned int a, unsigned int d )
{
printf("%08X:%08X\n",a,d);
}
int main ( void )
{
unsigned int state;
unsigned int byte_count;
unsigned int address;
unsigned int record_type;
unsigned int segment;
unsigned int start;
unsigned int data;
unsigned int sum;
unsigned int ra;
fp=fopen("blinker01.hex","rb");
if(fp==NULL) return(1);
state=0;
segment=0;
while(1)
{
ra=get_one();
if(ra==':')
{
state=1;
continue;
}
if(ra==0x0D)
{
state=0;
continue;
}
if(ra==0x0A)
{
state=0;
continue;
}
if((ra=='g')||(ra=='G'))
{
uart_putc(0x0D);
uart_putc('-');
uart_putc('-');
uart_putc(0x0D);
uart_putc(0x0A);
uart_putc(0x0A);
}
switch(state)
{
case 0:
{
break;
}
case 1:
case 2:
{
byte_count<<=4;
if(ra>0x39) ra-=7;
byte_count|=(ra&0xF);
byte_count&=0xFF;
state++;
break;
}
case 3:
case 4:
case 5:
case 6:
{
address<<=4;
if(ra>0x39) ra-=7;
address|=(ra&0xF);
address&=0xFFFF;
address|=segment;
state++;
break;
}
case 7:
{
record_type<<=4;
if(ra>0x39) ra-=7;
record_type|=(ra&0xF);
record_type&=0xFF;
state++;
break;
}
case 8:
{
record_type<<=4;
if(ra>0x39) ra-=7;
record_type|=(ra&0xF);
record_type&=0xFF;
switch(record_type)
{
case 0x00:
{
state=14;
break;
}
case 0x01:
{
printf("sum 0x%08X\n",sum);
state=0;
break;
}
case 0x02:
{
state=9;
break;
}
default:
{
state=0;
break;
}
}
break;
}
case 9:
case 10:
case 11:
case 12:
{
segment<<=4;
if(ra>0x39) ra-=7;
segment|=(ra&0xF);
segment&=0xFFFF;
state++;
break;
}
case 13:
{
segment<<=4;
state=0;
break;
}
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
{
data<<=4;
if(ra>0x39) ra-=7;
data|=(ra&0xF);
if(state==21)
{
ra=(data>>24)|(data<<24);
ra|=(data>>8)&0x0000FF00;
ra|=(data<<8)&0x00FF0000;
data=ra;
PUT32(address,data);
sum+=address;
sum+=data;
address+=4;
state=14;
}
else
{
state++;
}
break;
}
}
}
return(0);
}

BIN
bootloader07/kernel.img Executable file

Binary file not shown.

12
bootloader07/loader Normal file
View File

@@ -0,0 +1,12 @@
MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x1000000
}
SECTIONS
{
.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
}

12
bootloader07/memmap Normal file
View File

@@ -0,0 +1,12 @@
MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x1000
}
SECTIONS
{
.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
}

151
bootloader07/periph.c Normal file
View File

@@ -0,0 +1,151 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
extern void PUT32 ( unsigned int, unsigned int );
extern void PUT16 ( unsigned int, unsigned int );
extern void PUT8 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void BRANCHTO ( unsigned int );
extern void dummy ( unsigned int );
#define ARM_TIMER_CTL 0x2000B408
#define ARM_TIMER_CNT 0x2000B420
#define GPFSEL1 0x20200004
#define GPSET0 0x2020001C
#define GPCLR0 0x20200028
#define GPPUD 0x20200094
#define GPPUDCLK0 0x20200098
#define AUX_ENABLES 0x20215004
#define AUX_MU_IO_REG 0x20215040
#define AUX_MU_IER_REG 0x20215044
#define AUX_MU_IIR_REG 0x20215048
#define AUX_MU_LCR_REG 0x2021504C
#define AUX_MU_MCR_REG 0x20215050
#define AUX_MU_LSR_REG 0x20215054
#define AUX_MU_MSR_REG 0x20215058
#define AUX_MU_SCRATCH 0x2021505C
#define AUX_MU_CNTL_REG 0x20215060
#define AUX_MU_STAT_REG 0x20215064
#define AUX_MU_BAUD_REG 0x20215068
//GPIO14 TXD0 and TXD1
//GPIO15 RXD0 and RXD1
//------------------------------------------------------------------------
unsigned int uart_lcr ( void )
{
return(GET32(AUX_MU_LSR_REG));
}
//------------------------------------------------------------------------
unsigned int uart_recv ( void )
{
while(1)
{
if(GET32(AUX_MU_LSR_REG)&0x01) break;
}
return(GET32(AUX_MU_IO_REG)&0xFF);
}
//------------------------------------------------------------------------
unsigned int uart_check ( void )
{
if(GET32(AUX_MU_LSR_REG)&0x01) return(1);
return(0);
}
//------------------------------------------------------------------------
void uart_send ( unsigned int c )
{
while(1)
{
if(GET32(AUX_MU_LSR_REG)&0x20) break;
}
PUT32(AUX_MU_IO_REG,c);
}
//------------------------------------------------------------------------
void uart_flush ( void )
{
while(1)
{
if((GET32(AUX_MU_LSR_REG)&0x100)==0) break;
}
}
//------------------------------------------------------------------------
void hexstrings ( unsigned int d )
{
//unsigned int ra;
unsigned int rb;
unsigned int rc;
rb=32;
while(1)
{
rb-=4;
rc=(d>>rb)&0xF;
if(rc>9) rc+=0x37; else rc+=0x30;
uart_send(rc);
if(rb==0) break;
}
uart_send(0x20);
}
//------------------------------------------------------------------------
void hexstring ( unsigned int d )
{
hexstrings(d);
uart_send(0x0D);
uart_send(0x0A);
}
//------------------------------------------------------------------------
void uart_init ( void )
{
unsigned int ra;
PUT32(AUX_ENABLES,1);
PUT32(AUX_MU_IER_REG,0);
PUT32(AUX_MU_CNTL_REG,0);
PUT32(AUX_MU_LCR_REG,3);
PUT32(AUX_MU_MCR_REG,0);
PUT32(AUX_MU_IER_REG,0);
PUT32(AUX_MU_IIR_REG,0xC6);
PUT32(AUX_MU_BAUD_REG,270);
ra=GET32(GPFSEL1);
ra&=~(7<<12); //gpio14
ra|=2<<12; //alt5
ra&=~(7<<15); //gpio15
ra|=2<<15; //alt5
PUT32(GPFSEL1,ra);
PUT32(GPPUD,0);
for(ra=0;ra<150;ra++) dummy(ra);
PUT32(GPPUDCLK0,(1<<14)|(1<<15));
for(ra=0;ra<150;ra++) dummy(ra);
PUT32(GPPUDCLK0,0);
PUT32(AUX_MU_CNTL_REG,3);
}
//------------------------------------------------------------------------
void timer_init ( void )
{
//0xF9+1 = 250
//250MHz/250 = 1MHz
PUT32(ARM_TIMER_CTL,0x00F90000);
PUT32(ARM_TIMER_CTL,0x00F90200);
}
//-------------------------------------------------------------------------
unsigned int timer_tick ( void )
{
return(GET32(ARM_TIMER_CNT));
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//
// Copyright (c) 2012 David Welch dwelch@dwelch.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-------------------------------------------------------------------------

39
bootloader07/start.s Normal file
View File

@@ -0,0 +1,39 @@
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
.globl _start
_start:
mov sp,#0x8000
bl notmain
hang: b hang
.globl PUT32
PUT32:
str r1,[r0]
bx lr
.globl GET32
GET32:
ldr r0,[r0]
bx lr
.globl dummy
dummy:
bx lr
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@
;@ Copyright (c) 2012 David Welch dwelch@dwelch.com
;@
;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
;@
;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
;@
;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;@
;@-------------------------------------------------------------------------

64
bootloader07/vectors.s Normal file
View File

@@ -0,0 +1,64 @@
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
.globl _start
_start:
b skip
.space 0x200000-0x8004,0
skip:
mov sp,#0x08000000
bl notmain
hang: b hang
.globl PUT32
PUT32:
str r1,[r0]
bx lr
.globl PUT16
PUT16:
strh r1,[r0]
bx lr
.globl PUT8
PUT8:
strb r1,[r0]
bx lr
.globl GET32
GET32:
ldr r0,[r0]
bx lr
.globl GETPC
GETPC:
mov r0,lr
bx lr
.globl BRANCHTO
BRANCHTO:
bx r0
.globl dummy
dummy:
bx lr
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@-------------------------------------------------------------------------
;@
;@ Copyright (c) 2012 David Welch dwelch@dwelch.com
;@
;@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
;@
;@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
;@
;@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;@
;@-------------------------------------------------------------------------