From 4a9286c427b8929a097d568738a06eca94d5add8 Mon Sep 17 00:00:00 2001 From: kbrezhnyev Date: Tue, 29 Sep 2020 14:01:59 +0200 Subject: [PATCH 1/2] one more example for blinker is added, some comments to the bootloader code added --- blinker01_alternative/Makefile | 32 +++++++++++ blinker01_alternative/README | 9 ++++ blinker01_alternative/kernel.img | Bin 0 -> 136 bytes blinker01_alternative/memmap | 11 ++++ blinker01_alternative/notmain.c | 77 ++++++++++++++++++++++++++ blinker01_alternative/notmain.elf | Bin 0 -> 33640 bytes blinker01_alternative/notmain.list | 84 +++++++++++++++++++++++++++++ blinker01_alternative/notmain.o | Bin 0 -> 1016 bytes blinker01_alternative/notmain.srec | 11 ++++ blinker01_alternative/vectors.o | Bin 0 -> 800 bytes blinker01_alternative/vectors.s | 39 ++++++++++++++ bootloader10/README | 10 ++++ bootloader10/notmain.c | 25 +++++---- 13 files changed, 287 insertions(+), 11 deletions(-) create mode 100644 blinker01_alternative/Makefile create mode 100644 blinker01_alternative/README create mode 100755 blinker01_alternative/kernel.img create mode 100644 blinker01_alternative/memmap create mode 100644 blinker01_alternative/notmain.c create mode 100755 blinker01_alternative/notmain.elf create mode 100644 blinker01_alternative/notmain.list create mode 100644 blinker01_alternative/notmain.o create mode 100755 blinker01_alternative/notmain.srec create mode 100644 blinker01_alternative/vectors.o create mode 100644 blinker01_alternative/vectors.s diff --git a/blinker01_alternative/Makefile b/blinker01_alternative/Makefile new file mode 100644 index 0000000..10bca36 --- /dev/null +++ b/blinker01_alternative/Makefile @@ -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 + diff --git a/blinker01_alternative/README b/blinker01_alternative/README new file mode 100644 index 0000000..0a98f73 --- /dev/null +++ b/blinker01_alternative/README @@ -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 diff --git a/blinker01_alternative/kernel.img b/blinker01_alternative/kernel.img new file mode 100755 index 0000000000000000000000000000000000000000..191ba99a79b2707cf8bddca8c28ad6ab07310dfb GIT binary patch literal 136 zcmZR&x!^G?1Hb{OkXJDUh57lH5xqIiR{% LEDQ ram + .bss : { *(.bss*) } > ram +} diff --git a/blinker01_alternative/notmain.c b/blinker01_alternative/notmain.c new file mode 100644 index 0000000..f8619e2 --- /dev/null +++ b/blinker01_alternative/notmain.c @@ -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. +// +//------------------------------------------------------------------------- diff --git a/blinker01_alternative/notmain.elf b/blinker01_alternative/notmain.elf new file mode 100755 index 0000000000000000000000000000000000000000..7051b6c305f6a7eb3498682d31d3cf09b084a004 GIT binary patch literal 33640 zcmeIwOHUI~6u|K_eeh6Y5Fr>uGbY4Tk=hp+(FFvNjV8p@wN9b2O>9frfyl~%Xu{HO zK)-`uzz^ZZCDty04aSu&9M5e#Fd7#wUHory=iKw?W%3(dFFkr_S(XGVA_?hao=8rM zD?9p#NIWOD))Ue%v2H*3fyQ00yW^eO>0O}_jtC%t00IagfB*srAbjOqkx$K5T;%Ad?;pyL*S_lC-WPe- ziRQdMKYfswz4mwCKk6U*(6Yw1TMsn_d2Day^3oR>um-K+*oZZ1jYTh6 z$)>V*r_+Uv^2@dK4ZG8@GpY2Q)NCfDxBX>#-C9(v z-A7^LD6zMeANDw>2N>D*EK&E%5Q0I zeqYi!to@wE;P0FHdzwyorYK@^*(|QQwR$62lSxNPPW6RUYi`9USCgwUxhBg?`D{j3 zo|~;69Irmnq7q4lIimV6qT~A~xNHhjtFWox_U;DkznOd;SoY@z2 x>wPC{bVp?FBs;y&%!dCHzIYD(z!}opM7Fp0*u*^MX{Q@Smn{faD literal 0 HcmV?d00001 diff --git a/blinker01_alternative/notmain.list b/blinker01_alternative/notmain.list new file mode 100644 index 0000000..4e58f2c --- /dev/null +++ b/blinker01_alternative/notmain.list @@ -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 + +00008008 : + 8008: eafffffe b 8008 + +0000800c : + 800c: e5801000 str r1, [r0] + 8010: e12fff1e bx lr + +00008014 : + 8014: e5900000 ldr r0, [r0] + 8018: e12fff1e bx lr + +0000801c : + 801c: e12fff1e bx lr + +00008020 : + 8020: e92d4070 push {r4, r5, r6, lr} + 8024: e59f0054 ldr r0, [pc, #84] ; 8080 + 8028: ebfffff9 bl 8014 + 802c: e3c01707 bic r1, r0, #1835008 ; 0x1c0000 + 8030: e3811701 orr r1, r1, #262144 ; 0x40000 + 8034: e59f0044 ldr r0, [pc, #68] ; 8080 + 8038: ebfffff3 bl 800c + 803c: e3a06801 mov r6, #65536 ; 0x10000 + 8040: e59f503c ldr r5, [pc, #60] ; 8084 + 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 + 8058: e3540601 cmp r4, #1048576 ; 0x100000 + 805c: 1afffffa bne 804c + 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 + 8074: e3540601 cmp r4, #1048576 ; 0x100000 + 8078: 1afffffa bne 8068 + 807c: eafffff0 b 8044 + 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 + 4: 35312820 ldrcc r2, [r1, #-2080]! ; 0xfffff7e0 + 8: 332e363a ; instruction: 0x332e363a + c: 732b312e ; 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 ; instruction: 0x37313032 + 2c: 30323630 eorscc r3, r2, r0, lsr r6 + ... diff --git a/blinker01_alternative/notmain.o b/blinker01_alternative/notmain.o new file mode 100644 index 0000000000000000000000000000000000000000..00d248d46303cfba1e9bae21eeb4c802e7bdc6a9 GIT binary patch literal 1016 zcma)4U2D@|6n@?{?LHKlL+Lh)=3+v}SWH^CvEfC>Hpjq0k$S&$4YaUyqe;bGiJ<>N zSbvJYK=v0j^g_MSTM^@V(!4VjL=T)i&-r}cbKbn%d-7N*1uY6?{I-DhL=wqAOrVSz zOyaDz`l*47;mH?>uJ5Iw423{e|IrK2}P1A`B$_WC1pRiP1mkK;wg z%72M{jpNS-OcT`oot-VS?5u6ATUEP%OEjg?qQrNGOu+fJx>ZYjlIvaU`_d;|H refnI!w?32plKhhgB&p~;;@Iyhj!W@z2UN~GoAPYGOUdJGT6Di(4t9MY literal 0 HcmV?d00001 diff --git a/blinker01_alternative/notmain.srec b/blinker01_alternative/notmain.srec new file mode 100755 index 0000000..c5b297f --- /dev/null +++ b/blinker01_alternative/notmain.srec @@ -0,0 +1,11 @@ +S00F00006E6F746D61696E2E737265631F +S3150000800002D9A0E3050000EBFEFFFFEA001080E5C1 +S315000080101EFF2FE1000090E51EFF2FE11EFF2FE15E +S3150000802070402DE954009FE5F9FFFFEB0717C0E309 +S31500008030011781E344009FE5F3FFFFEB0168A0E32E +S315000080403C509FE50040A0E31C6085E50400A0E1EC +S31500008050014084E2F0FFFFEB010654E3FAFFFF1A4A +S315000080600040A0E3286085E50400A0E1014084E229 +S31500008070E9FFFFEB010654E3FAFFFF1AF0FFFFEA00 +S30D0000808004002020000020206E +S705000080007A diff --git a/blinker01_alternative/vectors.o b/blinker01_alternative/vectors.o new file mode 100644 index 0000000000000000000000000000000000000000..5f61e80c3c6b2a746c2e1e055aceb0183cb7b9cd GIT binary patch literal 800 zcma)3%}N4M6h7mmDYY=D2oiH)AQe+o51D2Ydrph zeMs^Cy*%E16?sUQeq#k<6)3+e&H~(AChrvNre>JM?#xsX7e5=W%>7b0$cW^BM6&~2 z$zsdi`K!u95?yj z9)#ftHQcR)!|Aw zbP%({zpw!nZzh+j`Hq#;Cvi_=9me~r!-z{1RlxHw)|9+*m%w&Fu4|O^zjEj&cO8h E2E?aAfB*mh literal 0 HcmV?d00001 diff --git a/blinker01_alternative/vectors.s b/blinker01_alternative/vectors.s new file mode 100644 index 0000000..9cdad8b --- /dev/null +++ b/blinker01_alternative/vectors.s @@ -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. +;@ +;@------------------------------------------------------------------------- diff --git a/bootloader10/README b/bootloader10/README index 7564a62..6dfcd8f 100644 --- a/bootloader10/README +++ b/bootloader10/README @@ -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. @@ -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) diff --git a/bootloader10/notmain.c b/bootloader10/notmain.c index 6780bd3..58ad688 100644 --- a/bootloader10/notmain.c +++ b/bootloader10/notmain.c @@ -22,19 +22,27 @@ 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); } +// 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; @@ -110,7 +118,7 @@ int notmain ( void ) } break; } - + // Reading size ----------------------------- case 2: { count=ctonib(ra); @@ -131,6 +139,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: @@ -144,14 +154,6 @@ int notmain ( void ) case 5: case 7: case 9: - { - count--; - addr<<=4; - addr|=ctonib(ra); - sum+=addr&0xFF; - state++; - break; - } case 11: { count--; @@ -161,6 +163,7 @@ int notmain ( void ) state++; break; } + // Reading data ----------------------------- case 12: { data=ctonib(ra); From 79e2ad681c57f543f711942bd1b4f3ee2dddb16b Mon Sep 17 00:00:00 2001 From: kbrezhnyev Date: Tue, 27 Oct 2020 22:20:05 +0100 Subject: [PATCH 2/2] added extra messages into bootloader, README extended for bootstrap --- bootloader10/notmain.c | 16 ++++++++++++++++ bootstrap/README | 2 ++ 2 files changed, 18 insertions(+) diff --git a/bootloader10/notmain.c b/bootloader10/notmain.c index 58ad688..e292088 100644 --- a/bootloader10/notmain.c +++ b/bootloader10/notmain.c @@ -33,6 +33,14 @@ unsigned int ctonib ( unsigned int c ) 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. @@ -68,6 +76,8 @@ int notmain ( void ) addr=0; type=0; entry=0x00008000; + + int startedDwnld = 0; while(1) { ra=uart_recv(); @@ -79,6 +89,11 @@ int notmain ( void ) { sum=0; state++; + if (!startedDwnld) + { + print("Started downloading...\n", 23); + startedDwnld = 1; + } } if((ra=='g')||(ra=='G')) { @@ -181,6 +196,7 @@ int notmain ( void ) if(type==7) { entry=addr; + print("Download completed!\n", 20); } sum&=0xFF; if(sum!=0xFF) diff --git a/bootstrap/README b/bootstrap/README index 76ea35c..2ac8195 100644 --- a/bootstrap/README +++ b/bootstrap/README @@ -31,6 +31,8 @@ assemble then disassemble, we are relying here on the disassembler to disassemble data as well as instructions, so we place data but it disassembles them as instructions which was the goal. +Assemble: add the .word instruction to each line of the terminal output and run *arm-none-eabi-as bootstrap.s -o bootstrap.o* +Disassemble: run *arm-none-eabi-objdump -D ./bootstrap.o* 00000000 <.text>: 0: e3a00000 mov r0, #0