adding bootloader05

This commit is contained in:
root
2012-09-13 23:29:06 -04:00
parent 467e3eb389
commit c316c42e0a
22 changed files with 130271 additions and 0 deletions

83
bootloader05/Makefile Normal file
View File

@@ -0,0 +1,83 @@
ARMGNU ?= arm-none-eabi
COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding
gcc : kernel.img blinker.bin
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
bootloader05.o : bootloader05.c
$(ARMGNU)-gcc $(COPS) -c bootloader05.c -o bootloader05.o
periph.o : periph.c
$(ARMGNU)-gcc $(COPS) -c periph.c -o periph.o
kernel.img : loader vectors.o periph.o bootloader05.o
$(ARMGNU)-ld vectors.o periph.o bootloader05.o -T loader -o bootloader05.elf
$(ARMGNU)-objdump -D bootloader05.elf > bootloader05.list
$(ARMGNU)-objcopy bootloader05.elf -O ihex bootloader05.hex
$(ARMGNU)-objcopy bootloader05.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.bin : 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
$(ARMGNU)-objcopy blinker.elf -O binary blinker.bin
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 : bootloader05.bin
bootloader05.bc : bootloader05.c
clang $(LOPS) -c bootloader05.c -o bootloader05.bc
periph.bc : periph.c
clang $(LOPS) -c periph.c -o periph.bc
bootloader05.clang.elf : loader vectors.o bootloader05.bc periph.bc
llvm-link periph.bc bootloader05.bc -o bootloader05.nopt.bc
opt $(OOPS) bootloader05.nopt.bc -o bootloader05.opt.bc
llc $(LLCOPS) bootloader05.opt.bc -o bootloader05.clang.s
$(ARMGNU)-as bootloader05.clang.s -o bootloader05.clang.o
$(ARMGNU)-ld -o bootloader05.clang.elf -T loader vectors.o bootloader05.clang.o
$(ARMGNU)-objdump -D bootloader05.clang.elf > bootloader05.clang.list
bootloader05.bin : bootloader05.clang.elf
$(ARMGNU)-objcopy bootloader05.clang.elf bootloader05.clang.bin -O binary

46
bootloader05/README Normal file
View File

@@ -0,0 +1,46 @@
See the top level README file for more information on documentation
and how to run these programs.
Derived from bootloader03, this is a very simple bootloader. Instead
of the sd dance (see toplevel 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 serial
solution to connect a dumb termial program with xmodem capabilities
to the uart on the raspberry pi. (see the toplevel README for more
information).
The difference between bootloader03 and bootloader05 is very subtle,
first I dont like the config.txt thing and didnt want bootloader04 to
be the biggest numbered bootloader. Second I use minicom and lrzsz
as a dumb terminal and for xmodem transfers, there is a delay as
lrzsz is ending and returning back to minicom so there is a delay.
Bootloader05 has a loop that prints some numbers before it branches
to the downloaded program.
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.
With uart connected to a terminal
1) power off raspberry pi
2) power on raspberry pi
3) use xmodem to transfer binary file
Repeat for each new program to test
This bootloader sits at 0x200000 so that you have 0x200000 bytes to
develop with. And that way if you like your program you can just
copy a .bin version to kernel.img on the sd card and use it. Fairly
easy to change this address. bootloader05.c and vectors.s each have
a copy of this value. bootloader04 uses a rasberry pi specific
config file to move much deeper in memory giving you much more room
if you want more room use that bootloader.
bootloader01 uses .hex files, bootloader02 through bootloader05 use .bin
files, .hex files wont work. Consider bootloader01 and 02 to be
obsolete.
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).

BIN
bootloader05/blinker.bin Executable file

Binary file not shown.

70
bootloader05/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
bootloader05/blinker.elf Executable file

Binary file not shown.

16
bootloader05/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

96
bootloader05/blinker.list Normal file
View File

@@ -0,0 +1,96 @@
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: 00002c41 andeq r2, r0, r1, asr #24
4: 61656100 cmnvs r5, r0, lsl #2
8: 01006962 tsteq r0, r2, ror #18
c: 00000022 andeq r0, r0, r2, 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: 2c011a01 stccs 10, cr1, [r1], {1}
2c: Address 0x000000000000002c 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: 312e372e teqcc lr, lr, lsr #14
...

BIN
bootloader05/blinker.o Normal file

Binary file not shown.

186
bootloader05/bootloader05.c Normal file
View File

@@ -0,0 +1,186 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// The raspberry pi firmware at the time this was written defaults
// loading at address 0x8000. Although this bootloader could easily
// load at 0x0000, it loads at 0x8000 so that the same binaries built
// for the SD card work with this bootloader. Change the ARMBASE
// below to use a different location.
#define ARMBASE 0x8000
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 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 );
//------------------------------------------------------------------------
unsigned char xstring[256];
//------------------------------------------------------------------------
int notmain ( void )
{
unsigned int ra;
//unsigned int rb;
unsigned int rx;
unsigned int addr;
unsigned int block;
unsigned int state;
unsigned int crc;
uart_init();
hexstring(0x12345678);
hexstring(GETPC());
hexstring(ARMBASE);
timer_init();
//SOH 0x01
//ACK 0x06
//NAK 0x15
//EOT 0x04
//block numbers start with 1
//132 byte packet
//starts with SOH
//block number byte
//255-block number
//128 bytes of data
//checksum byte (whole packet)
//a single EOT instead of SOH when done, send an ACK on it too
block=1;
addr=ARMBASE;
state=0;
crc=0;
rx=timer_tick();
while(1)
{
ra=timer_tick();
if((ra-rx)>=4000000)
{
uart_send(0x15);
rx+=4000000;
}
if((uart_lcr()&0x01)==0) continue;
xstring[state]=uart_recv();
rx=timer_tick();
if(state==0)
{
if(xstring[state]==0x04)
{
uart_send(0x06);
for(ra=0;ra<30;ra++) hexstring(ra);
hexstring(0x11111111);
hexstring(0x22222222);
hexstring(0x33333333);
uart_flush();
BRANCHTO(ARMBASE);
break;
}
}
switch(state)
{
case 0:
{
if(xstring[state]==0x01)
{
crc=xstring[state];
state++;
}
else
{
//state=0;
uart_send(0x15);
}
break;
}
case 1:
{
if(xstring[state]==block)
{
crc+=xstring[state];
state++;
}
else
{
state=0;
uart_send(0x15);
}
break;
}
case 2:
{
if(xstring[state]==(0xFF-xstring[state-1]))
{
crc+=xstring[state];
state++;
}
else
{
uart_send(0x15);
state=0;
}
break;
}
case 131:
{
crc&=0xFF;
if(xstring[state]==crc)
{
for(ra=0;ra<128;ra++)
{
PUT8(addr++,xstring[ra+3]);
}
uart_send(0x06);
block=(block+1)&0xFF;
}
else
{
uart_send(0x15);
}
state=0;
break;
}
default:
{
crc+=xstring[state];
state++;
break;
}
}
}
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
bootloader05/bootloader05.elf Executable file

Binary file not shown.

129132
bootloader05/bootloader05.hex Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,370 @@
bootloader05.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: eb00009f bl 200288 <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: e20000ff and r0, r0, #255 ; 0xff
200074: e8bd4008 pop {r3, lr}
200078: e12fff1e bx lr
20007c: 20215054 eorcs r5, r1, r4, asr r0
200080: 20215040 eorcs r5, r1, r0, asr #32
00200084 <uart_send>:
200084: e92d4010 push {r4, lr}
200088: e1a04000 mov r4, r0
20008c: e59f001c ldr r0, [pc, #28] ; 2000b0 <uart_send+0x2c>
200090: ebffffe3 bl 200024 <GET32>
200094: e3100020 tst r0, #32
200098: 0afffffb beq 20008c <uart_send+0x8>
20009c: e59f0010 ldr r0, [pc, #16] ; 2000b4 <uart_send+0x30>
2000a0: e1a01004 mov r1, r4
2000a4: ebffffd8 bl 20000c <PUT32>
2000a8: e8bd4010 pop {r4, lr}
2000ac: e12fff1e bx lr
2000b0: 20215054 eorcs r5, r1, r4, asr r0
2000b4: 20215040 eorcs r5, r1, r0, asr #32
002000b8 <uart_flush>:
2000b8: e92d4008 push {r3, lr}
2000bc: e59f0010 ldr r0, [pc, #16] ; 2000d4 <uart_flush+0x1c>
2000c0: ebffffd7 bl 200024 <GET32>
2000c4: e3100c01 tst r0, #256 ; 0x100
2000c8: 0afffffb beq 2000bc <uart_flush+0x4>
2000cc: e8bd4008 pop {r3, lr}
2000d0: e12fff1e bx lr
2000d4: 20215054 eorcs r5, r1, r4, asr r0
002000d8 <hexstrings>:
2000d8: e92d4038 push {r3, r4, r5, lr}
2000dc: e1a05000 mov r5, r0
2000e0: e3a04020 mov r4, #32
2000e4: e2444004 sub r4, r4, #4
2000e8: e1a03435 lsr r3, r5, r4
2000ec: e203300f and r3, r3, #15
2000f0: e3530009 cmp r3, #9
2000f4: 82830037 addhi r0, r3, #55 ; 0x37
2000f8: 92830030 addls r0, r3, #48 ; 0x30
2000fc: ebffffe0 bl 200084 <uart_send>
200100: e3540000 cmp r4, #0
200104: 1afffff6 bne 2000e4 <hexstrings+0xc>
200108: e3a00020 mov r0, #32
20010c: e8bd4038 pop {r3, r4, r5, lr}
200110: eaffffdb b 200084 <uart_send>
00200114 <hexstring>:
200114: e92d4008 push {r3, lr}
200118: ebffffee bl 2000d8 <hexstrings>
20011c: e3a0000d mov r0, #13
200120: ebffffd7 bl 200084 <uart_send>
200124: e3a0000a mov r0, #10
200128: e8bd4008 pop {r3, lr}
20012c: eaffffd4 b 200084 <uart_send>
00200130 <uart_init>:
200130: e92d4010 push {r4, lr}
200134: e59f00d8 ldr r0, [pc, #216] ; 200214 <uart_init+0xe4>
200138: e3a01001 mov r1, #1
20013c: ebffffb2 bl 20000c <PUT32>
200140: e59f00d0 ldr r0, [pc, #208] ; 200218 <uart_init+0xe8>
200144: e3a01000 mov r1, #0
200148: ebffffaf bl 20000c <PUT32>
20014c: e59f00c8 ldr r0, [pc, #200] ; 20021c <uart_init+0xec>
200150: e3a01000 mov r1, #0
200154: ebffffac bl 20000c <PUT32>
200158: e59f00c0 ldr r0, [pc, #192] ; 200220 <uart_init+0xf0>
20015c: e3a01003 mov r1, #3
200160: ebffffa9 bl 20000c <PUT32>
200164: e59f00b8 ldr r0, [pc, #184] ; 200224 <uart_init+0xf4>
200168: e3a01000 mov r1, #0
20016c: ebffffa6 bl 20000c <PUT32>
200170: e59f00a0 ldr r0, [pc, #160] ; 200218 <uart_init+0xe8>
200174: e3a01000 mov r1, #0
200178: ebffffa3 bl 20000c <PUT32>
20017c: e59f00a4 ldr r0, [pc, #164] ; 200228 <uart_init+0xf8>
200180: e3a010c6 mov r1, #198 ; 0xc6
200184: ebffffa0 bl 20000c <PUT32>
200188: e59f109c ldr r1, [pc, #156] ; 20022c <uart_init+0xfc>
20018c: e59f009c ldr r0, [pc, #156] ; 200230 <uart_init+0x100>
200190: ebffff9d bl 20000c <PUT32>
200194: e59f0098 ldr r0, [pc, #152] ; 200234 <uart_init+0x104>
200198: ebffffa1 bl 200024 <GET32>
20019c: e3c01a3f bic r1, r0, #258048 ; 0x3f000
2001a0: e3811a12 orr r1, r1, #73728 ; 0x12000
2001a4: e59f0088 ldr r0, [pc, #136] ; 200234 <uart_init+0x104>
2001a8: ebffff97 bl 20000c <PUT32>
2001ac: e59f0084 ldr r0, [pc, #132] ; 200238 <uart_init+0x108>
2001b0: e3a01000 mov r1, #0
2001b4: ebffff94 bl 20000c <PUT32>
2001b8: e3a04000 mov r4, #0
2001bc: e1a00004 mov r0, r4
2001c0: e2844001 add r4, r4, #1
2001c4: ebffff9b bl 200038 <dummy>
2001c8: e3540096 cmp r4, #150 ; 0x96
2001cc: 1afffffa bne 2001bc <uart_init+0x8c>
2001d0: e59f0064 ldr r0, [pc, #100] ; 20023c <uart_init+0x10c>
2001d4: e3a01903 mov r1, #49152 ; 0xc000
2001d8: ebffff8b bl 20000c <PUT32>
2001dc: e3a04000 mov r4, #0
2001e0: e1a00004 mov r0, r4
2001e4: e2844001 add r4, r4, #1
2001e8: ebffff92 bl 200038 <dummy>
2001ec: e3540096 cmp r4, #150 ; 0x96
2001f0: 1afffffa bne 2001e0 <uart_init+0xb0>
2001f4: e59f0040 ldr r0, [pc, #64] ; 20023c <uart_init+0x10c>
2001f8: e3a01000 mov r1, #0
2001fc: ebffff82 bl 20000c <PUT32>
200200: e59f0014 ldr r0, [pc, #20] ; 20021c <uart_init+0xec>
200204: e3a01003 mov r1, #3
200208: ebffff7f bl 20000c <PUT32>
20020c: e8bd4010 pop {r4, lr}
200210: e12fff1e bx lr
200214: 20215004 eorcs r5, r1, r4
200218: 20215044 eorcs r5, r1, r4, asr #32
20021c: 20215060 eorcs r5, r1, r0, rrx
200220: 2021504c eorcs r5, r1, ip, asr #32
200224: 20215050 eorcs r5, r1, r0, asr r0
200228: 20215048 eorcs r5, r1, r8, asr #32
20022c: 0000010e andeq r0, r0, lr, lsl #2
200230: 20215068 eorcs r5, r1, r8, rrx
200234: 20200004 eorcs r0, r0, r4
200238: 20200094 mlacs r0, r4, r0, r0
20023c: 20200098 mlacs r0, r8, r0, r0
00200240 <timer_init>:
200240: e92d4010 push {r4, lr}
200244: e59f401c ldr r4, [pc, #28] ; 200268 <timer_init+0x28>
200248: e3a018f9 mov r1, #16318464 ; 0xf90000
20024c: e1a00004 mov r0, r4
200250: ebffff6d bl 20000c <PUT32>
200254: e1a00004 mov r0, r4
200258: e59f100c ldr r1, [pc, #12] ; 20026c <timer_init+0x2c>
20025c: ebffff6a bl 20000c <PUT32>
200260: e8bd4010 pop {r4, lr}
200264: e12fff1e bx lr
200268: 2000b408 andcs fp, r0, r8, lsl #8
20026c: 00f90200 rscseq r0, r9, r0, lsl #4
00200270 <timer_tick>:
200270: e92d4008 push {r3, lr}
200274: e59f0008 ldr r0, [pc, #8] ; 200284 <timer_tick+0x14>
200278: ebffff69 bl 200024 <GET32>
20027c: e8bd4008 pop {r3, lr}
200280: e12fff1e bx lr
200284: 2000b420 andcs fp, r0, r0, lsr #8
00200288 <notmain>:
200288: e92d4ff0 push {r4, r5, r6, r7, r8, r9, sl, fp, lr}
20028c: e24dd00c sub sp, sp, #12
200290: ebffffa6 bl 200130 <uart_init>
200294: e59f01d8 ldr r0, [pc, #472] ; 200474 <notmain+0x1ec>
200298: ebffff9d bl 200114 <hexstring>
20029c: ebffff62 bl 20002c <GETPC>
2002a0: ebffff9b bl 200114 <hexstring>
2002a4: e3a00902 mov r0, #32768 ; 0x8000
2002a8: ebffff99 bl 200114 <hexstring>
2002ac: ebffffe3 bl 200240 <timer_init>
2002b0: ebffffee bl 200270 <timer_tick>
2002b4: e59f91bc ldr r9, [pc, #444] ; 200478 <notmain+0x1f0>
2002b8: e3a03902 mov r3, #32768 ; 0x8000
2002bc: e3a08000 mov r8, #0
2002c0: e58d3004 str r3, [sp, #4]
2002c4: e59f71b0 ldr r7, [pc, #432] ; 20047c <notmain+0x1f4>
2002c8: e1a06008 mov r6, r8
2002cc: e3a0b001 mov fp, #1
2002d0: e1a05000 mov r5, r0
2002d4: e1a0a009 mov sl, r9
2002d8: e2894082 add r4, r9, #130 ; 0x82
2002dc: ebffffe3 bl 200270 <timer_tick>
2002e0: e0650000 rsb r0, r5, r0
2002e4: e1500007 cmp r0, r7
2002e8: 8a000017 bhi 20034c <notmain+0xc4>
2002ec: ebffff52 bl 20003c <uart_lcr>
2002f0: e3100001 tst r0, #1
2002f4: 0afffff8 beq 2002dc <notmain+0x54>
2002f8: ebffff55 bl 200054 <uart_recv>
2002fc: e7c90006 strb r0, [r9, r6]
200300: ebffffda bl 200270 <timer_tick>
200304: e3560000 cmp r6, #0
200308: e1a05000 mov r5, r0
20030c: 1a000013 bne 200360 <notmain+0xd8>
200310: e5da3000 ldrb r3, [sl]
200314: e3530004 cmp r3, #4
200318: 0a000041 beq 200424 <notmain+0x19c>
20031c: e5d93000 ldrb r3, [r9]
200320: e3530001 cmp r3, #1
200324: 01a08003 moveq r8, r3
200328: 01a06008 moveq r6, r8
20032c: 0affffea beq 2002dc <notmain+0x54>
200330: e3a00015 mov r0, #21
200334: ebffff52 bl 200084 <uart_send>
200338: ebffffcc bl 200270 <timer_tick>
20033c: e0650000 rsb r0, r5, r0
200340: e1500007 cmp r0, r7
200344: e3a06000 mov r6, #0
200348: 9affffe7 bls 2002ec <notmain+0x64>
20034c: e3a00015 mov r0, #21
200350: e285583d add r5, r5, #3997696 ; 0x3d0000
200354: ebffff4a bl 200084 <uart_send>
200358: e2855c09 add r5, r5, #2304 ; 0x900
20035c: eaffffe2 b 2002ec <notmain+0x64>
200360: e3560001 cmp r6, #1
200364: 0a000008 beq 20038c <notmain+0x104>
200368: 3affffeb bcc 20031c <notmain+0x94>
20036c: e3560002 cmp r6, #2
200370: 0a000023 beq 200404 <notmain+0x17c>
200374: e3560083 cmp r6, #131 ; 0x83
200378: 0a000009 beq 2003a4 <notmain+0x11c>
20037c: e7da3006 ldrb r3, [sl, r6]
200380: e2866001 add r6, r6, #1
200384: e0888003 add r8, r8, r3
200388: eaffffd3 b 2002dc <notmain+0x54>
20038c: e5da3001 ldrb r3, [sl, #1]
200390: e153000b cmp r3, fp
200394: 0088800b addeq r8, r8, fp
200398: 03a06002 moveq r6, #2
20039c: 1affffe3 bne 200330 <notmain+0xa8>
2003a0: eaffffcd b 2002dc <notmain+0x54>
2003a4: e5da3083 ldrb r3, [sl, #131] ; 0x83
2003a8: e20880ff and r8, r8, #255 ; 0xff
2003ac: e1530008 cmp r3, r8
2003b0: e58d3000 str r3, [sp]
2003b4: 1affffdd bne 200330 <notmain+0xa8>
2003b8: e59f80c0 ldr r8, [pc, #192] ; 200480 <notmain+0x1f8>
2003bc: e59d3004 ldr r3, [sp, #4]
2003c0: e5f81001 ldrb r1, [r8, #1]!
2003c4: e1a00003 mov r0, r3
2003c8: e2836001 add r6, r3, #1
2003cc: ebffff12 bl 20001c <PUT8>
2003d0: e1580004 cmp r8, r4
2003d4: e1a03006 mov r3, r6
2003d8: 1afffff8 bne 2003c0 <notmain+0x138>
2003dc: e3a00006 mov r0, #6
2003e0: ebffff27 bl 200084 <uart_send>
2003e4: e59d3004 ldr r3, [sp, #4]
2003e8: e28bb001 add fp, fp, #1
2003ec: e2833080 add r3, r3, #128 ; 0x80
2003f0: e58d3004 str r3, [sp, #4]
2003f4: e20bb0ff and fp, fp, #255 ; 0xff
2003f8: e59d8000 ldr r8, [sp]
2003fc: e3a06000 mov r6, #0
200400: eaffffb5 b 2002dc <notmain+0x54>
200404: e5da2001 ldrb r2, [sl, #1]
200408: e5da3002 ldrb r3, [sl, #2]
20040c: e26220ff rsb r2, r2, #255 ; 0xff
200410: e1530002 cmp r3, r2
200414: 00888003 addeq r8, r8, r3
200418: 03a06003 moveq r6, #3
20041c: 1affffc3 bne 200330 <notmain+0xa8>
200420: eaffffad b 2002dc <notmain+0x54>
200424: e3a00006 mov r0, #6
200428: ebffff15 bl 200084 <uart_send>
20042c: e1a00006 mov r0, r6
200430: e2866001 add r6, r6, #1
200434: ebffff36 bl 200114 <hexstring>
200438: e356001e cmp r6, #30
20043c: 1afffffa bne 20042c <notmain+0x1a4>
200440: e59f003c ldr r0, [pc, #60] ; 200484 <notmain+0x1fc>
200444: ebffff32 bl 200114 <hexstring>
200448: e59f0038 ldr r0, [pc, #56] ; 200488 <notmain+0x200>
20044c: ebffff30 bl 200114 <hexstring>
200450: e59f0034 ldr r0, [pc, #52] ; 20048c <notmain+0x204>
200454: ebffff2e bl 200114 <hexstring>
200458: ebffff16 bl 2000b8 <uart_flush>
20045c: e3a00902 mov r0, #32768 ; 0x8000
200460: ebfffef3 bl 200034 <BRANCHTO>
200464: e3a00000 mov r0, #0
200468: e28dd00c add sp, sp, #12
20046c: e8bd4ff0 pop {r4, r5, r6, r7, r8, r9, sl, fp, lr}
200470: e12fff1e bx lr
200474: 12345678 eorsne r5, r4, #125829120 ; 0x7800000
200478: 00200490 mlaeq r0, r0, r4, r0
20047c: 003d08ff ldrshteq r0, [sp], -pc
200480: 00200492 mlaeq r0, r2, r4, r0
200484: 11111111 tstne r1, r1, lsl r1
200488: 22222222 eorcs r2, r2, #536870914 ; 0x20000002
20048c: 33333333 teqcc r3, #-872415232 ; 0xcc000000
Disassembly of section .bss:
00200490 <xstring>:
...
Disassembly of section .ARM.attributes:
00000000 <.ARM.attributes>:
0: 00002c41 andeq r2, r0, r1, asr #24
4: 61656100 cmnvs r5, r0, lsl #2
8: 01006962 tsteq r0, r2, ror #18
c: 00000022 andeq r0, r0, r2, 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: 2c011a01 stccs 10, cr1, [r1], {1}
2c: Address 0x000000000000002c is out of bounds.
Disassembly of section .comment:
00000000 <.comment>:
0: 3a434347 bcc 10d0d24 <xstring+0xed0894>
4: 4e472820 cdpmi 8, 4, cr2, cr7, cr0, {1}
8: 34202955 strtcc r2, [r0], #-2389 ; 0x955
c: 312e372e teqcc lr, lr, lsr #14
...

BIN
bootloader05/bootloader05.o Normal file

Binary file not shown.

BIN
bootloader05/kernel.img Executable file

Binary file not shown.

12
bootloader05/loader Normal file
View File

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

12
bootloader05/memmap Normal file
View File

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

145
bootloader05/periph.c Normal file
View File

@@ -0,0 +1,145 @@
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
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);
}
//------------------------------------------------------------------------
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) 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.
//
//-------------------------------------------------------------------------

BIN
bootloader05/periph.o Normal file

Binary file not shown.

BIN
bootloader05/start.o Normal file

Binary file not shown.

39
bootloader05/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.
;@
;@-------------------------------------------------------------------------

BIN
bootloader05/vectors.o Normal file

Binary file not shown.

64
bootloader05/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.
;@
;@-------------------------------------------------------------------------