Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions blinker01_alternative/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

ARMGNU ?= arm-none-eabi
#ARMGNU ?= arm-linux-gnueabi

AOPS = --warn --fatal-warnings
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding

all : kernel.img

clean :
rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.srec
rm -f *.elf
rm -f *.list
rm -f *.img

vectors.o : vectors.s
$(ARMGNU)-as $(AOPS) vectors.s -o vectors.o

notmain.o : notmain.c
$(ARMGNU)-gcc $(COPS) -c notmain.c -o notmain.o

notmain.elf : memmap vectors.o notmain.o
$(ARMGNU)-ld vectors.o notmain.o -T memmap -o notmain.elf
$(ARMGNU)-objdump -D notmain.elf > notmain.list

kernel.img : notmain.elf
$(ARMGNU)-objcopy --srec-forceS3 notmain.elf -O srec notmain.srec
$(ARMGNU)-objcopy notmain.elf -O binary kernel.img

9 changes: 9 additions & 0 deletions blinker01_alternative/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

See the top level README for information on where to find documentation
for the raspberry pi and the ARM processor inside. Also find information
on how to load and run these programs.

This is an LED blinker example for the pi zero.

Blinking with LED connected to GPIO 16 as alternative to blinker01
with extended comments to code
Binary file added blinker01_alternative/kernel.img
Binary file not shown.
11 changes: 11 additions & 0 deletions blinker01_alternative/memmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

MEMORY
{
ram : ORIGIN = 0x8000, LENGTH = 0x10000
}

SECTIONS
{
.text : { *(.text*) } > ram
.bss : { *(.bss*) } > ram
}
77 changes: 77 additions & 0 deletions blinker01_alternative/notmain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

//-------------------------------------------------------------------------
//-------------------------------------------------------------------------

// In this example the GPIO 16 is used to blink (you will need extra LED to test it)

extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
extern void dummy ( unsigned int );

#define GPFSEL3 0x2020000C
#define GPFSEL4 0x20200004
#define GPSET1 0x2020001C // would be probably better to call this one CLR
#define GPCLR1 0x20200028 // and this one SET (see below comments)

// see VII. DIE SPEZIELLE HARDWARE
// https://uol.de/f/2/dept/informatik/ag/svs/download/reader/reader-seminar-ws2013.pdf

// Translation to english:

// To use these Pins you only need the proper addresses, that start at
// ”0x20200000“. Each address is made up from 4 Bytes, each pin occupies 3 bits. These
// Bits specify, what function the pin will have. Thereby the value ”000“ stands for Input and
// "001“ for output. The 30th and 31st bits are reserved. So the address ”0x20200000“ is for Pins 0-9 and
// "0x20200004“ is for Pins 10-19. Up to the address ”0x20200014“ for Pins 50-53. ...
//
// 30 and 31 are reserved, then follow tripples for each of the pins (ex. 0-9):
// |..|...|...|...|...|...|...|...|...|...|...| pins 0-9 starting at 0x20200000
// |..|...|...|...|...|...|...|...|...|...|...| pins 10-19 starting at 0x20200004
// |..|...|...|...|...|...|...|...|...|...|...| pins 20-29 starting at 0x20200008
// |..|...|...|...|...|...|...|...|...|...|...| pins 30-29 starting at 0x2020000C
// |..|...|...|...|...|...|...|...|...|...|...| pins 40-49 starting at 0x20200010
// |..|...|...|...|...|...|...|...|...|...|...| pins 50-59 starting at 0x20200014
//
// If the pin ist set as OUT, it does not send any signal jet.
// Sending signal happens first when the address ”0x20200028“ for Pins 0 - 31 bzw.
// othwewise ”0x2020002C“ fur Pins 32 - 53 for each bit is set to 1 ...
// To disable it the addresses ”0x2020001C“ otherwise. ”0x20200020“ are used...

//-------------------------------------------------------------------------
int notmain ( void )
{
unsigned int ra;

// Set the 16th GPIO to OUT:
ra=GET32(GPFSEL4);
ra&=~(7<<18); // first cleaning the 3 bits
ra|=(1<<18); // then setting 1 to denote OUT
PUT32(GPFSEL4,ra);
int * p;

while(1)
{
// also here is another way tested to set the value without asm:
p = (int*)(GPSET1); *p = (1<<(16));
for(ra=0;ra<0x100000;ra++) dummy(ra);
p = (int*)(GPCLR1); *p = (1<<(16));
for(ra=0;ra<0x100000;ra++) dummy(ra);
}

return(0);
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------


//-------------------------------------------------------------------------
//
// Copyright (c) 2015 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.
//
//-------------------------------------------------------------------------
Binary file added blinker01_alternative/notmain.elf
Binary file not shown.
84 changes: 84 additions & 0 deletions blinker01_alternative/notmain.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

notmain.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: e59f0054 ldr r0, [pc, #84] ; 8080 <notmain+0x60>
8028: ebfffff9 bl 8014 <GET32>
802c: e3c01707 bic r1, r0, #1835008 ; 0x1c0000
8030: e3811701 orr r1, r1, #262144 ; 0x40000
8034: e59f0044 ldr r0, [pc, #68] ; 8080 <notmain+0x60>
8038: ebfffff3 bl 800c <PUT32>
803c: e3a06801 mov r6, #65536 ; 0x10000
8040: e59f503c ldr r5, [pc, #60] ; 8084 <notmain+0x64>
8044: e3a04000 mov r4, #0
8048: e585601c str r6, [r5, #28]
804c: e1a00004 mov r0, r4
8050: e2844001 add r4, r4, #1
8054: ebfffff0 bl 801c <dummy>
8058: e3540601 cmp r4, #1048576 ; 0x100000
805c: 1afffffa bne 804c <notmain+0x2c>
8060: e3a04000 mov r4, #0
8064: e5856028 str r6, [r5, #40] ; 0x28
8068: e1a00004 mov r0, r4
806c: e2844001 add r4, r4, #1
8070: ebffffe9 bl 801c <dummy>
8074: e3540601 cmp r4, #1048576 ; 0x100000
8078: 1afffffa bne 8068 <notmain+0x48>
807c: eafffff0 b 8044 <notmain+0x24>
8080: 20200004 eorcs r0, r0, r4
8084: 20200000 eorcs r0, r0, r0

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 ; 0xfffff9e0
18: 08020600 stmdaeq r2, {r9, sl}
1c: 12010901 andne r0, r1, #16384 ; 0x4000
20: 15011404 strne r1, [r1, #-1028] ; 0xfffffbfc
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: 35312820 ldrcc r2, [r1, #-2080]! ; 0xfffff7e0
8: 332e363a ; <UNDEFINED> instruction: 0x332e363a
c: 732b312e ; <UNDEFINED> instruction: 0x732b312e
10: 35326e76 ldrcc r6, [r2, #-3702]! ; 0xfffff18a
14: 39333033 ldmdbcc r3!, {r0, r1, r4, r5, ip, sp}
18: 7562312d strbvc r3, [r2, #-301]! ; 0xfffffed3
1c: 31646c69 cmncc r4, r9, ror #24
20: 2e362029 cdpcs 0, 3, cr2, cr6, cr9, {1}
24: 20312e33 eorscs r2, r1, r3, lsr lr
28: 37313032 ; <UNDEFINED> instruction: 0x37313032
2c: 30323630 eorscc r3, r2, r0, lsr r6
...
Binary file added blinker01_alternative/notmain.o
Binary file not shown.
11 changes: 11 additions & 0 deletions blinker01_alternative/notmain.srec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
S00F00006E6F746D61696E2E737265631F
S3150000800002D9A0E3050000EBFEFFFFEA001080E5C1
S315000080101EFF2FE1000090E51EFF2FE11EFF2FE15E
S3150000802070402DE954009FE5F9FFFFEB0717C0E309
S31500008030011781E344009FE5F3FFFFEB0168A0E32E
S315000080403C509FE50040A0E31C6085E50400A0E1EC
S31500008050014084E2F0FFFFEB010654E3FAFFFF1A4A
S315000080600040A0E3286085E50400A0E1014084E229
S31500008070E9FFFFEB010654E3FAFFFF1AF0FFFFEA00
S30D0000808004002020000020206E
S705000080007A
Binary file added blinker01_alternative/vectors.o
Binary file not shown.
39 changes: 39 additions & 0 deletions blinker01_alternative/vectors.s
Original file line number Diff line number Diff line change
@@ -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.
;@
;@-------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions bootloader10/README
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ so to deal with that once downloaded you press the letter g to go or
run the program. This way you or at least I dont lose any characters
from the downloaded program.

**Alternativelly you can use Cutecome GUI interface**

I normally do not deliver binaries. In this case I have left the
binary in the root directory as bootloader.img, copy this file to
your sd card and name it kernel.img.
Expand Down Expand Up @@ -145,3 +147,11 @@ if you run into this then just make it bigger as well.

ram : ORIGIN = 0x8000, LENGTH = 0x1000000

**Steps how to use the bootloader**

1. Copy the bootloader image to the SD Card as kernel.img
(now you will have three files there: bootcode.bin start.elf and kernel.img)
1. Set the SD card to PI and power up PI
1. Send the coresponding (ex.blinker) srec file over terminal as plain
1. Press 'g' key on the keyboard
(see the contents of the bootloader10/notmain.c)
41 changes: 30 additions & 11 deletions bootloader10/notmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,35 @@ extern void uart_flush ( void );

extern void leds_off ( void );

// We receive one character at a time: 0...1 or A...F each represeting half a byte (see srec files)
// ASCII code for '0' is 110000 and '9' is 111001
// then follow 7 symbols like ':' and ';'
// and then the 'A', 'B' ... 'F' (see ASCII table)
// so we offset the A,B,C symbols ... by 7 positions to have contigeous sequence: ..8,9,A,B,C..
unsigned int ctonib ( unsigned int c )
{
if(c>0x39) c-=7;
return(c&0xF);
}

void print(char * text, int len)
{
for (int i = 0; i < len; ++i)
{
uart_send(text[i]);
}
}

// http://srecord.sourceforge.net/man/man5/srec_motorola.html
// Checksum: The checksum is an 8-bit field that represents the least significant byte of the one’s complement
// of the sum of the values represented by the pairs of characters making up the record’s length, address, and data fields.
int notmain ( void )
{
unsigned int state;
unsigned int ra;
unsigned int type;
unsigned int count;
unsigned int sum;
unsigned int count; // number of bytes in the data (including size and CRC)
unsigned int sum; // checksum
unsigned int entry;
unsigned int addr;
unsigned int data;
Expand All @@ -60,6 +76,8 @@ int notmain ( void )
addr=0;
type=0;
entry=0x00008000;

int startedDwnld = 0;
while(1)
{
ra=uart_recv();
Expand All @@ -71,6 +89,11 @@ int notmain ( void )
{
sum=0;
state++;
if (!startedDwnld)
{
print("Started downloading...\n", 23);
startedDwnld = 1;
}
}
if((ra=='g')||(ra=='G'))
{
Expand Down Expand Up @@ -110,7 +133,7 @@ int notmain ( void )
}
break;
}

// Reading size -----------------------------
case 2:
{
count=ctonib(ra);
Expand All @@ -131,6 +154,8 @@ int notmain ( void )
state++;
break;
}
// Reading address -----------------------------
// read 8 positions each representing half a byte totalling to 32 bit address
case 4:
case 6:
case 8:
Expand All @@ -144,14 +169,6 @@ int notmain ( void )
case 5:
case 7:
case 9:
{
count--;
addr<<=4;
addr|=ctonib(ra);
sum+=addr&0xFF;
state++;
break;
}
case 11:
{
count--;
Expand All @@ -161,6 +178,7 @@ int notmain ( void )
state++;
break;
}
// Reading data -----------------------------
case 12:
{
data=ctonib(ra);
Expand All @@ -178,6 +196,7 @@ int notmain ( void )
if(type==7)
{
entry=addr;
print("Download completed!\n", 20);
}
sum&=0xFF;
if(sum!=0xFF)
Expand Down
Loading