From 4820fae9cdc9a39e3c1d2f1dd0b14c1f7128ea58 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 9 Apr 2013 11:27:28 +1000 Subject: [PATCH 01/41] fel-gpio: Error out if the FEL device can't be contacted --- fel-gpio | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fel-gpio b/fel-gpio index dc10c2a..839d39b 100755 --- a/fel-gpio +++ b/fel-gpio @@ -3,6 +3,7 @@ pio_to_sram=0x2000 sram_to_pio=0x2004 +set -e if [ -f fel-pio.bin ]; then ./fel write 0x2000 fel-pio.bin else @@ -13,6 +14,8 @@ fi ./fel read 0x3000 0x228 pio.reg ./pio -i pio.reg print > pio.old cat pio.old | fgrep -v '<0><0><0><0>' + +set +e while read cmd; do ./pio -i pio.reg -o pio.reg $cmd ./fel write 0x3000 pio.reg From 9e79a0d995b12df0fe7880613b32003a5348b542 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Fri, 12 Apr 2013 12:38:31 +1000 Subject: [PATCH 02/41] pio.c: Fix broken file I/O --- pio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pio.c b/pio.c index ea2bf35..e48a660 100644 --- a/pio.c +++ b/pio.c @@ -392,7 +392,7 @@ int main(int argc, char **argv) } } if (in) { - if (fread(buf, sizeof(buf), 1, in) != 1) { + if (fread(buf, PIO_REG_SIZE, 1, in) != 1) { perror("read input"); exit(1); } @@ -414,7 +414,7 @@ int main(int argc, char **argv) exit(1); } } - if (fwrite(buf, sizeof(buf), 1, out) != 1) { + if (fwrite(buf, PIO_REG_SIZE, 1, out) != 1) { perror("write output"); exit(1); } From 6339a8fecaabe3566b0f0095dfff53ff0cd5cff4 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 2 May 2013 12:38:22 +0200 Subject: [PATCH 03/41] fel-gpio: Fail on errors after initialization as well --- fel-gpio | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fel-gpio b/fel-gpio index 839d39b..11bb194 100755 --- a/fel-gpio +++ b/fel-gpio @@ -1,9 +1,8 @@ -#!/bin/sh +#!/bin/sh -e pio_to_sram=0x2000 sram_to_pio=0x2004 -set -e if [ -f fel-pio.bin ]; then ./fel write 0x2000 fel-pio.bin else @@ -15,7 +14,6 @@ fi ./pio -i pio.reg print > pio.old cat pio.old | fgrep -v '<0><0><0><0>' -set +e while read cmd; do ./pio -i pio.reg -o pio.reg $cmd ./fel write 0x3000 pio.reg @@ -23,6 +21,6 @@ while read cmd; do ./fel exe 0x2000 ./fel read 0x3000 0x228 pio.reg ./pio -i pio.reg print > pio.new - diff -U0 pio.old pio.new + diff -U0 pio.old pio.new || true mv -f pio.new pio.old done From e76e9985d3c980d2142e27ca94af55ceab3d4a4f Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Wed, 15 May 2013 11:08:01 +0200 Subject: [PATCH 04/41] fel: Decode known SoC IDs --- fel.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fel.c b/fel.c index 2b1ef4d..c719bd8 100644 --- a/fel.c +++ b/fel.c @@ -138,7 +138,7 @@ void aw_fel_get_version(libusb_device_handle *usb) { struct aw_fel_version { char signature[8]; - uint32_t unknown_08; /* 0x00162300 */ + uint32_t soc_id; /* 0x00162300 */ uint32_t unknown_0a; /* 1 */ uint16_t protocol; /* 1 */ uint8_t unknown_12; /* 0x44 */ @@ -151,14 +151,21 @@ void aw_fel_get_version(libusb_device_handle *usb) aw_usb_read(usb, &buf, sizeof(buf)); aw_read_fel_status(usb); - buf.unknown_08 = le32toh(buf.unknown_08); + buf.soc_id = le32toh(buf.soc_id); buf.unknown_0a = le32toh(buf.unknown_0a); buf.protocol = le32toh(buf.protocol); buf.scratchpad = le16toh(buf.scratchpad); buf.pad[0] = le32toh(buf.pad[0]); buf.pad[1] = le32toh(buf.pad[1]); - printf("%.8s %08x %08x ver=%04x %02x %02x scratchpad=%08x %08x %08x\n", buf.signature, buf.unknown_08, buf.unknown_0a, buf.protocol, buf.unknown_12, buf.unknown_13, buf.scratchpad, buf.pad[0], buf.pad[1]); + const char *soc_name="unknown"; + switch ((buf.soc_id >> 8) & 0xFFFF) { + case 0x1623: soc_name="A10";break; + case 0x1625: soc_name="A13";break; + case 0x1633: soc_name="A31";break; + } + + printf("%.8s soc=%08x(%s) %08x ver=%04x %02x %02x scratchpad=%08x %08x %08x\n", buf.signature, buf.soc_id, soc_name, buf.unknown_0a, buf.protocol, buf.unknown_12, buf.unknown_13, buf.scratchpad, buf.pad[0], buf.pad[1]); } void aw_fel_read(libusb_device_handle *usb, uint32_t offset, void *buf, size_t len) From a95d7e189656ac729ec841d3b5e2dda407327e26 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Wed, 15 May 2013 11:08:27 +0200 Subject: [PATCH 05/41] nand_part: Reduce duplicated code a bit --- nand-part.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/nand-part.c b/nand-part.c index 334776d..5b046fe 100644 --- a/nand-part.c +++ b/nand-part.c @@ -130,6 +130,23 @@ __s32 _free_mbr(MBR *mbr) return 0; } +void printmbr(MBR *mbr) +{ + int part_cnt; + for(part_cnt = 0; part_cnt < mbr->PartCount && part_cnt < MAX_PART_COUNT; part_cnt++) + { + if(1 || (mbr->array[part_cnt].user_type == 2) || (mbr->array[part_cnt].user_type == 0)) + { + printf("partition %2d: class = %12s, name = %12s, partition start = %8d, partition size = %8d user_type=%d\n", + part_cnt, + mbr->array[part_cnt].classname, + mbr->array[part_cnt].name, + mbr->array[part_cnt].addrlo, + mbr->array[part_cnt].lenlo, + mbr->array[part_cnt].user_type); + } + } +} void checkmbrs(int fd) { int part_cnt = 0; @@ -152,17 +169,7 @@ void checkmbrs(int fd) return; } - for(part_cnt = 0; part_cnt < mbr->PartCount && part_cnt < MAX_PART_COUNT; part_cnt++) - { - if(1 || (mbr->array[part_cnt].user_type == 2) || (mbr->array[part_cnt].user_type == 0)) - { - printf("partition %2d: name = %12s, partition start = %8d, partition size = %8d\n", - part_cnt, - mbr->array[part_cnt].name, - mbr->array[part_cnt].addrlo, - mbr->array[part_cnt].lenlo); - } - } + printmbr(mbr); for (i = 0; i < MBR_COPY_NUM; i++) { if (mbrs[i]) _free_mbr(mbrs[i]); @@ -233,17 +240,7 @@ int writembrs(int fd, char names[][MAX_NAME], __u32 *lens, unsigned int *user_ty } printf("\nready to write new partition tables:\n"); - for(part_cnt = 0; part_cnt < mbr->PartCount && part_cnt < MAX_PART_COUNT; part_cnt++) - { - if(1 || (mbr->array[part_cnt].user_type == 2) || (mbr->array[part_cnt].user_type == 0)) - { - printf("partition %2d: name = %12s, partition start = %8d, partition size = %8d\n", - part_cnt, - mbr->array[part_cnt].name, - mbr->array[part_cnt].addrlo, - mbr->array[part_cnt].lenlo); - } - } + printmbr(mbr); for (i = 0; i < MBR_COPY_NUM; i++) { if (mbrs[i]) _free_mbr(mbrs[i]); From 6963d52030275962bd31f6b986faf0d2ccb689c0 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 16 May 2013 01:18:18 +0200 Subject: [PATCH 06/41] felboot: Small system initialization for FEL booting --- bin/fel-boot-a13_olinuxino.bin | Bin 0 -> 6884 bytes bin/fel-boot-cubieboard.bin | Bin 0 -> 7080 bytes bin/fel-boot-eoma68.bin | Bin 0 -> 7088 bytes felboot/Makefile | 30 +++++ felboot/README.txt | 36 ++++++ felboot/common.h | 27 +++++ felboot/cpu.h | 145 +++++++++++++++++++++++ felboot/early_print.c | 64 ++++++++++ felboot/early_print.h | 62 ++++++++++ felboot/fel-boot.ld | 59 ++++++++++ felboot/io.h | 20 ++++ felboot/main.c | 71 +++++++++++ felboot/u-boot.sh | 5 + felboot/usb-boot.sh | 8 ++ felboot/util_printf.c | 208 +++++++++++++++++++++++++++++++++ 15 files changed, 735 insertions(+) create mode 100755 bin/fel-boot-a13_olinuxino.bin create mode 100755 bin/fel-boot-cubieboard.bin create mode 100755 bin/fel-boot-eoma68.bin create mode 100644 felboot/Makefile create mode 100644 felboot/README.txt create mode 100644 felboot/common.h create mode 100644 felboot/cpu.h create mode 100644 felboot/early_print.c create mode 100644 felboot/early_print.h create mode 100644 felboot/fel-boot.ld create mode 100644 felboot/io.h create mode 100644 felboot/main.c create mode 100755 felboot/u-boot.sh create mode 100755 felboot/usb-boot.sh create mode 100644 felboot/util_printf.c diff --git a/bin/fel-boot-a13_olinuxino.bin b/bin/fel-boot-a13_olinuxino.bin new file mode 100755 index 0000000000000000000000000000000000000000..2d3ed4beef45a41ec35ebc7ceec729ab9a531361 GIT binary patch literal 6884 zcmbtY4RBP~bw2mKm3EOg=nAbWkKo~C2?BS zv8{gR?OR|xG}CD{dUNhQ_x#;+&OPVuO*qZh|60)0YLlj(0!%n(uKl4&lfONCpI`a< z=9r4eQJsP&{~T))JX=A(lg9OC@cd;JO%Y|3NmS!By8eT}OUT&>dI#eTpc#m0{$qBw zaXE17fa_(P_+ysq6S+zhf1w5C0-~Mj*RYFd zo1g4)-&{;|!Jv9&xvpuuZoRPU1IoJf^H?`zunkoN+1Y{MUuI{ggnTcQ{a-{svuuZ`x#ruK{lV;ZS8PE1jKh%6(6kT6l-W(Y00~c~my8c?We|R(y!)|>Ibt(cR z+M$*cVegM9vRzecU(#zpx5_%E=Q=~dnx6Kc270Tc>u*K8gpEC6K8Ly#AP+HzFKZZ&oU3UDG~`=VhEp&^#x;?T^)_%-%wzWjri0kXx2_nO ze#Lm?M~!W-5B6I(uFgSxK2P*bVf6)6bd?d({^OP8*+FlxSnxtRvSEKwhy8Z1cr1Ru3!oHQC?3n=IsoHF38U#fPvz zww3c%ocvbM1i!rtf2F)*I%y#{;4@w$`5pN6nIPqreHNFlxEHi^@>^aI(KB6*#qr_X zEz?tRNL#U?>&*91ME_5q=Y79%8=nLp=jikuaJS1^558DtNGBkdWv-57p1qBaZJ3JY zx9_0|`SGdYOPY$e_R@rWx&BdkA1A>hPP+apfG1It9HPm&)OE?KSQJU!9{^MrzSv%`zOC7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@P z(9tfEcu%?MxRq~~=ojEk;|w&%xOZ6j{9!9UY#U`cET4PnCd7sB0oa}}Q3u=?tDO^< zN67R{x!Pkry#Fx#7e&h>xn&K<=su3UeH7novTFqT`R_(?T6BAyEX2tw#|gg$!Z;bt zx8lS&juUDij2-8mWnnI{49X!+-Tq;$U&A^ry8U$P!&b8Z9_zzczlJr}baV5qIB{JP zW!IGL?ttx;wcCEK))j(s=KnW#EV~`?yCoCfS%f!<`ag!5DU2g(IE>@5JH*jIeEH13 zz&#l;4(%{eb9ZWg z?b)&2+WO3vUE9*MwrlkU97eM6@!49qZNr)b(W0lH+qrWwKA@nX45E zuK)QL)prX9|ESnw~-;{&>4FDl)zv^2sZ&>a0&m(!V>1wpW_Mt;NQqsM(knipK(LV%Fh3R oAfpr>miMJcAESIeSGTT_kMY(Ir!ki@Bi_JAN=rt0k?oxs{jB1 literal 0 HcmV?d00001 diff --git a/bin/fel-boot-eoma68.bin b/bin/fel-boot-eoma68.bin new file mode 100755 index 0000000000000000000000000000000000000000..c877ea510a0e7f78c87b9285c0cb4f0bbdf830a3 GIT binary patch literal 7088 zcmbVQ4Qy0bc0TvLu{}&C_!>`A<9L@h1~!o3=GhKeV4d)A*o0Og8vl?$O51@z7pXLH zfV8xmbjLH8ppCsU{)tc&>PM*BXjL_CNTmpg?toJiv7kCl+N$lQeeYdv2JEV^Y1+~( z8}~bJ-T+mB3KpEE;(A7@#4K+E4bmA1)<2XHdPeT-UT+w_e!w0cG9#1*{t~*oG>C?Cind@8{-bh5S5}{aipjQq2wS%WFL7$RLJA9M&FPV0DOGFDh<;QwnpX;+< z1o&$Dvfkfe4BHfJQoJtMFk@z2pYd$p)hAmni=ykx>5YNGK5!vt()Byo{^8L;47>FS z>Q)3uv_-8T!rGrvWV@=?zM$du#478kp6?6=Yx+8a1oT!(*B_{&Sz%*Mc%Mf-ig7h| zp%}}$zKu8td;P_=pdmLC{5bT*7F7e;cYwYcv^HcuXdl(DVU6=B=gH}z;Oh5IU9y2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$>z67y2i2R99sVc<7t4#*Z(u z|CUAbGvKMRcX*s<;6KMTjPGsOo<7)fmF=-z{{ZeZ((7FR*l9j{T=vsUQlP$xp;8j( zd=lSi=Zolxt$e_Duxtxu(2EJz&-J0M7YmxQuXwpkH6ZpNdg*kyA2FA~9OXR$xybdI zq#Q08b%j#i;=7k_KURE#^9fZDImc_j-C^^ownrx>)4gXr?r)9VL$%3D( zvY*iZhki1eZ~BRG>?g!M^c}~WWuX_b49dYzJ^nF_-^4gAdi-?jqgJy39^+#ezlkyD zadY!cKXEP+Wjo7ucfj__*lj;w>k2_R^Z)BRmfa5j-IR&D72!=G=TD$d3jK(@4gGlH zHhwhVU*6|AuEX$gXopE8Zu6k0__==eE5& ztvx&U?%ZeX+qKi${`|H*JJPhid)-ECK(cW0Y%Sffu`@xm?70_r?_Q2e6BL#d3c`Lo zKf>eS;QT{8amd?^XByA@IKT$Ma~02f*qlu`jB|J{;=vsVVaWslrtnV|h7dvD#uNUa zW8^nR>|xmZfg4g*X8tF{y&h%N-I8JPY>Vs#>|3>3ZUX#KszW{nxZ%f-$fp6{y|7Mh z2DHAvUTy&#JovbL2JqVUUzWcDxMS@`xfO8wo{aoez>aI(^49?0`goK4b->i0ZDxo* sc8>n!jDU%h!ozEM{K-u;x-T`mvFfcKOuYWv_y6&?zI`=&`Ti&W8{-31=l}o! literal 0 HcmV?d00001 diff --git a/felboot/Makefile b/felboot/Makefile new file mode 100644 index 0000000..b129432 --- /dev/null +++ b/felboot/Makefile @@ -0,0 +1,30 @@ + +CC=gcc +BOARD=eoma68 +CROSS_COMPILE=/home/henrik/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- +UBOOT=/home/henrik/SRC/u-boot/ +UBOOTOBJ=$(UBOOT)build/$(BOARD)/ +CFLAGS=-g -O2 -marm -mno-thumb-interwork -mabi=aapcs-linux -march=armv7-a -fno-common -ffixed-r8 -msoft-float -I$(UBOOTOBJ)include2 -I$(UBOOTOBJ)include -I$(UBOOT)include + +all: fel-boot-$(BOARD).bin + +UBOOT_OBJS= \ + $(addprefix spl/arch/arm/cpu/armv7/sunxi/,clock.o pinmux.o dram.o board.o timer.o) \ + spl/arch/arm/cpu/armv7/syslib.o \ + spl/arch/arm/lib/eabi_compat.o \ + spl/drivers/power/axp209.o \ + spl/drivers/i2c/libi2c.o \ + spl/common/memsize.o \ + spl/board/sunxi/dram_$(BOARD).o + +.c.o: + $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ + +fel-boot-$(BOARD).elf: main.o util_printf.o early_print.o $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) + $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -nostartfiles $(CFLAGS) -Wl,-Map=$@.map $^ -o $@ + +fel-boot-$(BOARD).bin: fel-boot-$(BOARD).elf + $(CROSS_COMPILE)objcopy -O binary $< $@ + +clean: + rm -f *.o *.map *.elf diff --git a/felboot/README.txt b/felboot/README.txt new file mode 100644 index 0000000..d55cc16 --- /dev/null +++ b/felboot/README.txt @@ -0,0 +1,36 @@ +fel-boot.bin is a FEL bootstrap program. + +fel write 0x2000 fel-boot.bin +fel exe 0x2000 +fel write 0x4a000000 u-boot.bin +fel exe 0x4a000000 + +optionally load kernel + initramfs before fel exe of u-boot + +fel write 0x2000 fel-boot.bin +fel exe 0x2000 +fel write 0x4a000000 u-boot.bin +fel write 0x43000000 ../script.bin +fel write 0x44000000 ../uImage +fel write 0x4c000000 ../initramfs.img +fel exe 0x4a000000 + +Build instructions: + +1. You need to build u-boot sunxi-current SPL first for the same CPU generation, i.e. cubieboard. + +Change the paths in Makefile to reflect where your copy of u-boot and toolchain is, or specify the paths when runnign make + +make + + +To adopt for another board: + +1a) If the board is supported by u-boot SPL then change UBOOT_OBJS to include the dram spefications for your board and remove dram.o from fel-boot.elf: line. + +1b) Else update dram.c with the right parameters for your board. + +2. Change early_printf.c to define the right UART number for your board. + +3. make + diff --git a/felboot/common.h b/felboot/common.h new file mode 100644 index 0000000..1717709 --- /dev/null +++ b/felboot/common.h @@ -0,0 +1,27 @@ +#ifndef _COMMON_H +#define _COMMON_H + +#include + +#define u32 uint32_t +#define u16 uint16_t +#define u8 uint8_t + +#define s32 int32_t +#define s16 int16_t +#define s8 int8_t + +#define __u8 u8 +#define __u16 u16 +#define __u32 u32 + +#define __s8 s8 +#define __s16 s16 +#define __s32 s32 + + +#include "io.h" +#include "cpu.h" + + +#endif diff --git a/felboot/cpu.h b/felboot/cpu.h new file mode 100644 index 0000000..b73e164 --- /dev/null +++ b/felboot/cpu.h @@ -0,0 +1,145 @@ +/* + * (C) Copyright 2007-2011 + * Allwinner Technology Co., Ltd. + * Tom Cubie + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef _SUNXI_CPU_H +#define _SUNXI_CPU_H + +#define SUNXI_SRAM_A1_BASE 0X00000000 +#define SUNXI_SRAM_A1_SIZE (16 * 1024) /* 16k */ + +#define SUNXI_SRAM_A2_BASE 0X00004000 /* 16k */ +#define SUNXI_SRAM_A3_BASE 0X00008000 /* 13k */ +#define SUNXI_SRAM_A4_BASE 0X0000B400 /* 3k */ +#if 0 +#define SUNXI_SRAM_NAND_BASE 0Xdeaddead /* 2k(address not available on spec) */ +#endif +#define SUNXI_SRAM_D_BASE 0X01C00000 +#define SUNXI_SRAM_B_BASE 0X01C00000 /* 64k(secure) */ + +#define SUNXI_SRAMC_BASE 0X01C00000 +#define SUNXI_DRAMC_BASE 0X01C01000 +#define SUNXI_DMA_BASE 0X01C02000 +#define SUNXI_NFC_BASE 0X01C03000 +#define SUNXI_TS_BASE 0X01C04000 +#define SUNXI_SPI0_BASE 0X01C05000 +#define SUNXI_SPI1_BASE 0X01C06000 +#define SUNXI_MS_BASE 0X01C07000 +#define SUNXI_TVD_BASE 0X01C08000 +#define SUNXI_CSI0_BASE 0X01C09000 +#define SUNXI_TVE0_BASE 0X01C0A000 +#define SUNXI_EMAC_BASE 0X01C0B000 +#define SUNXI_LCD0_BASE 0X01C0C000 +#define SUNXI_LCD1_BASE 0X01C0D000 +#define SUNXI_VE_BASE 0X01C0E000 +#define SUNXI_MMC0_BASE 0X01C0F000 +#define SUNXI_MMC1_BASE 0X01C10000 +#define SUNXI_MMC2_BASE 0X01C11000 +#define SUNXI_MMC3_BASE 0X01C12000 +#define SUNXI_USB0_BASE 0X01C13000 +#define SUNXI_USB1_BASE 0X01C14000 +#define SUNXI_SS_BASE 0X01C15000 +#define SUNXI_HDMI_BASE 0X01C16000 +#define SUNXI_SPI2_BASE 0X01C17000 +#define SUNXI_SATA_BASE 0X01C18000 +#define SUNXI_PATA_BASE 0X01C19000 +#define SUNXI_ACE_BASE 0X01C1A000 +#define SUNXI_TVE1_BASE 0X01C1B000 +#define SUNXI_USB2_BASE 0X01C1C000 +#define SUNXI_CSI1_BASE 0X01C1D000 +#define SUNXI_TZASC_BASE 0X01C1E000 +#define SUNXI_SPI3_BASE 0X01C1F000 + +#define SUNXI_CCM_BASE 0X01C20000 +#define SUNXI_INTC_BASE 0X01C20400 +#define SUNXI_PIO_BASE 0X01C20800 +#define SUNXI_TIMER_BASE 0X01C20C00 +#define SUNXI_SPDIF_BASE 0X01C21000 +#define SUNXI_AC97_BASE 0X01C21400 +#define SUNXI_IR0_BASE 0X01C21800 +#define SUNXI_IR1_BASE 0X01C21C00 + +#define SUNXI_IIS_BASE 0X01C22400 +#define SUNXI_LRADC_BASE 0X01C22800 +#define SUNXI_AD_DA_BASE 0X01C22C00 +#define SUNXI_KEYPAD_BASE 0X01C23000 +#define SUNXI_TZPC_BASE 0X01C23400 +#define SUNXI_SID_BASE 0X01C23800 +#define SUNXI_SJTAG_BASE 0X01C23C00 + +#define SUNXI_TP_BASE 0X01C25000 +#define SUNXI_PMU_BASE 0X01C25400 + +#define SUNXI_UART0_BASE 0X01C28000 +#define SUNXI_UART1_BASE 0X01C28400 +#define SUNXI_UART2_BASE 0X01C28800 +#define SUNXI_UART3_BASE 0X01C28C00 +#define SUNXI_UART4_BASE 0X01C29000 +#define SUNXI_UART5_BASE 0X01C29400 +#define SUNXI_UART6_BASE 0X01C29800 +#define SUNXI_UART7_BASE 0X01C29C00 +#define SUNXI_PS2_0_BASE 0X01C2A000 +#define SUNXI_PS2_1_BASE 0X01C2A400 + +#define SUNXI_TWI0_BASE 0X01C2AC00 +#define SUNXI_TWI1_BASE 0X01C2B000 +#define SUNXI_TWI2_BASE 0X01C2B400 + +#define SUNXI_CAN_BASE 0X01C2BC00 + +#define SUNXI_SCR_BASE 0X01C2C400 + +#define SUNXI_GPS_BASE 0X01C30000 +#define SUNXI_MALI400_BASE 0X01C40000 + +#define SUNXI_SRAM_C_BASE 0X01D00000 /* module sram */ + +#define SUNXI_DE_FE0_BASE 0X01E00000 +#define SUNXI_DE_FE1_BASE 0X01E20000 +#define SUNXI_DE_BE0_BASE 0X01E60000 +#define SUNXI_DE_BE1_BASE 0X01E40000 +#define SUNXI_MP_BASE 0X01E80000 +#define SUNXI_AVG_BASE 0X01EA0000 + +#define SUNXI_CSDM_BASE 0X3F500000 /* CoreSight Debug Module*/ + +#define SUNXI_DDRII_DDRIII_BASE 0X40000000 /* 2G */ + +#define SUNXI_BROM_BASE 0XFFFF0000 /* 32K */ + +#define SUNXI_CPU_CFG (SUNXI_TIMER_BASE + 0x13c) + +#ifndef __ASSEMBLY__ +/* boot type */ +typedef enum { + SUNXI_BOOT_TYPE_NULL, + SUNXI_BOOT_TYPE_MMC0, + SUNXI_BOOT_TYPE_NAND, + SUNXI_BOOT_TYPE_MMC2, + SUNXI_BOOT_TYPE_SPI +} sunxi_boot_type_t; + +sunxi_boot_type_t get_boot_type(void); +#endif /* __ASSEMBLY__ */ + +#endif /* _CPU_H */ diff --git a/felboot/early_print.c b/felboot/early_print.c new file mode 100644 index 0000000..7976b7f --- /dev/null +++ b/felboot/early_print.c @@ -0,0 +1,64 @@ +/* + * (C) Copyright 2007-2012 + * Allwinner Technology Co., Ltd. + * Tom Cubie + * + * Early uart print for debugging. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include "config.h" +#include "common.h" +#include "early_print.h" +#include +#include + +static int uart_initialized = 0; + +#define UART CONFIG_CONS_INDEX-1 +void uart_init(void) { + + /* select dll dlh */ + writel(0x80, UART_LCR(UART)); + /* set baudrate */ + writel(0, UART_DLH(UART)); + writel(BAUD_115200, UART_DLL(UART)); + /* set line control */ + writel(LC_8_N_1, UART_LCR(UART)); + + uart_initialized = 1; +} + +#define TX_READY (readl(UART_LSR(UART)) & (1 << 6)) + +void uart_putc(char c) { + + while(!TX_READY) + ; + writel(c, UART_THR(UART)); +} + +void uart_puts(const char *s) { + + while(*s) + uart_putc(*s++); +} + + diff --git a/felboot/early_print.h b/felboot/early_print.h new file mode 100644 index 0000000..cbcc6ea --- /dev/null +++ b/felboot/early_print.h @@ -0,0 +1,62 @@ +/* + * (C) Copyright 2007-2012 + * Allwinner Technology Co., Ltd. + * Tom Cubie + * + * Early uart print for debugging. + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef _SUNXI_EARLY_PRINT_H +#define _SUNXI_EARLY_PRINT_H + +#define SUNXI_UART_BASE SUNXI_UART0_BASE + +#define UART_RBR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* receive buffer register */ +#define UART_THR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* transmit holding register */ +#define UART_DLL(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* divisor latch low register */ + +#define UART_DLH(n) (SUNXI_UART_BASE + (n)*0x400 + 0x4) /* divisor latch high register */ +#define UART_IER(n) (SUNXI_UART_BASE + (n)*0x400 + 0x4) /* interrupt enable reigster */ + +#define UART_IIR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x8) /* interrupt identity register */ +#define UART_FCR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x8) /* fifo control register */ + +#define UART_LCR(n) (SUNXI_UART_BASE + (n)*0x400 + 0xc) /* line control register */ + +#define UART_LSR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x14) /* line status register */ +#define UART_RBR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* receive buffer register */ +#define UART_THR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* transmit holding register */ +#define UART_DLL(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* divisor latch low register */ + + +#define BAUD_115200 (0xD) /* 24 * 1000 * 1000 / 16 / 115200 = 13 */ +#define NO_PARITY (0) +#define ONE_STOP_BIT (0) +#define DAT_LEN_8_BITS (3) +#define LC_8_N_1 (NO_PARITY << 3 | ONE_STOP_BIT << 2 | DAT_LEN_8_BITS) + +#ifndef __ASSEMBLY__ +void uart_init(void); +void uart_putc(char c); +void uart_puts(const char *s); +#endif /* __ASSEMBLY__ */ + +#endif /* _SUNXI_EARLY_PRINT_H */ diff --git a/felboot/fel-boot.ld b/felboot/fel-boot.ld new file mode 100644 index 0000000..19bc549 --- /dev/null +++ b/felboot/fel-boot.ld @@ -0,0 +1,59 @@ +OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") +OUTPUT_ARCH(arm) +ENTRY(_start) +SECTIONS +{ + . = 0x00002000; + . = ALIGN(4); + .text : + { + main.o (.text*) + *(.text*) + } + . = ALIGN(4); + .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } + . = ALIGN(4); + .data : { + *(.data*) + } + . = ALIGN(4); + . = .; + . = ALIGN(4); + .rel.dyn : { + __rel_dyn_start = .; + *(.rel*) + __rel_dyn_end = .; + } + .dynsym : { + __dynsym_start = .; + *(.dynsym) + } + . = ALIGN(4); + .note.gnu.build-id : + { + *(.note.gnu.build-id) + } + _end = .; + . = ALIGN(4096); + .mmutable : { + *(.mmutable) + } + .bss_start __rel_dyn_start (OVERLAY) : { + KEEP(*(.__bss_start)); + __bss_base = .; + } + .bss __bss_base (OVERLAY) : { + *(.bss*) + . = ALIGN(4); + __bss_limit = .; + } + .bss_end __bss_limit (OVERLAY) : { + KEEP(*(.__bss_end)); + } + /DISCARD/ : { *(.dynstr*) } + /DISCARD/ : { *(.dynamic*) } + /DISCARD/ : { *(.plt*) } + /DISCARD/ : { *(.interp*) } + /DISCARD/ : { *(.gnu*) } + /DISCARD/ : { *(.note*) } +} diff --git a/felboot/io.h b/felboot/io.h new file mode 100644 index 0000000..bfa3e9e --- /dev/null +++ b/felboot/io.h @@ -0,0 +1,20 @@ +#define __arch_getb(a) (*(volatile unsigned char *)(a)) +#define __arch_getw(a) (*(volatile unsigned short *)(a)) +#define __arch_getl(a) (*(volatile unsigned int *)(a)) + +#define __arch_putb(v,a) (*(volatile unsigned char *)(a) = (v)) +#define __arch_putw(v,a) (*(volatile unsigned short *)(a) = (v)) +#define __arch_putl(v,a) (*(volatile unsigned int *)(a) = (v)) + + +#define dmb() __asm__ __volatile__ ("" : : : "memory") +#define __iormb() dmb() +#define __iowmb() dmb() + +#define writeb(v,c) ({ u8 __v = v; __iowmb(); __arch_putb(__v,c); __v; }) +#define writew(v,c) ({ u16 __v = v; __iowmb(); __arch_putw(__v,c); __v; }) +#define writel(v,c) ({ u32 __v = v; __iowmb(); __arch_putl(__v,c); __v; }) + +#define readb(c) ({ u8 __v = __arch_getb(c); __iormb(); __v; }) +#define readw(c) ({ u16 __v = __arch_getw(c); __iormb(); __v; }) +#define readl(c) ({ u32 __v = __arch_getl(c); __iormb(); __v; }) diff --git a/felboot/main.c b/felboot/main.c new file mode 100644 index 0000000..7841216 --- /dev/null +++ b/felboot/main.c @@ -0,0 +1,71 @@ +void _start(void) +{ + clock_init(); + gpio_init(); + uart_init(); + s_init(); +} + +void dcache_enable(void) +{ +} + +void sunxi_wemac_initialize(void) +{ +} + +void *gd; +int gdata; + +void preloader_console_init(void) +{ +} + +void hang(void) +{ + printf("Please reset the board!"); +} + +void udelay(unsigned long usec) +{ + __udelay(usec); +} + +void sunxi_board_init(void) +{ + int power_failed = 1; + int ramsize; + + timer_init(); + + printf("DRAM:"); + ramsize = sunxi_dram_init(); + if (!ramsize) { + printf(" ?"); + ramsize = sunxi_dram_init(); + } + if (!ramsize) { + printf(" ?"); + ramsize = sunxi_dram_init(); + } + printf(" %dMB\n", ramsize>>20); + if (!ramsize) + hang(); + +#ifdef CONFIG_AXP209_POWER + power_failed |= axp209_init(); + power_failed |= axp209_set_dcdc2(1400); + power_failed |= axp209_set_dcdc3(1250); + power_failed |= axp209_set_ldo2(3000); + power_failed |= axp209_set_ldo3(2800); + power_failed |= axp209_set_ldo4(2800); +#endif + + /* + * Only clock up the CPU to full speed if we are reasonably + * assured it's being powered with suitable core voltage + */ + if (!power_failed) + clock_set_pll1(1008000000); +} + diff --git a/felboot/u-boot.sh b/felboot/u-boot.sh new file mode 100755 index 0000000..1a7bd97 --- /dev/null +++ b/felboot/u-boot.sh @@ -0,0 +1,5 @@ +#!/bin/sh -ex +fel write 0x2000 fel-boot-${1}.bin +fel exe 0x2000 +fel write 0x4a000000 ../u-boot.bin +fel exe 0x4a000000 diff --git a/felboot/usb-boot.sh b/felboot/usb-boot.sh new file mode 100755 index 0000000..edd99a7 --- /dev/null +++ b/felboot/usb-boot.sh @@ -0,0 +1,8 @@ +#!/bin/sh -ex +fel write 0x2000 fel-boot-${1}.bin +fel exe 0x2000 +fel write 0x4a000000 ../u-boot.bin +fel write 0x43000000 ../script.bin +fel write 0x44000000 ../uImage +fel write 0x4c000000 ../initramfs.img +fel exe 0x4a000000 diff --git a/felboot/util_printf.c b/felboot/util_printf.c new file mode 100644 index 0000000..d16bd1a --- /dev/null +++ b/felboot/util_printf.c @@ -0,0 +1,208 @@ +/* + + */ + + +#include +#include "early_print.h" + + +/* Debug uart have been init by boot rom. */ +void put_char(char ch) +{ + uart_putc(ch); +} + + +static void printchar(char **str, int c) +{ + if (str) { + **str = c; + ++(*str); + } + else { + put_char(c); + } +} + +#define PAD_RIGHT 1 +#define PAD_ZERO 2 + +static int prints(char **out, const char *string, int width, int pad) +{ + register int pc = 0, padchar = ' '; + + if (width > 0) { + register int len = 0; + register const char *ptr; + for (ptr = string; *ptr; ++ptr) ++len; + if (len >= width) width = 0; + else width -= len; + if (pad & PAD_ZERO) padchar = '0'; + } + if (!(pad & PAD_RIGHT)) { + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + } + for ( ; *string ; ++string) { + printchar (out, *string); + ++pc; + } + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + + return pc; +} + +/* the following should be enough for 32 bit int */ +#define PRINT_BUF_LEN 12 + +static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) +{ + char print_buf[PRINT_BUF_LEN]; + register char *s; + register int t, neg = 0, pc = 0; + register unsigned int u = i; + + if (i == 0) { + print_buf[0] = '0'; + print_buf[1] = '\0'; + return prints (out, print_buf, width, pad); + } + + if (sg && b == 10 && i < 0) { + neg = 1; + u = -i; + } + + s = print_buf + PRINT_BUF_LEN-1; + *s = '\0'; + + while (u) { + t = u % b; + if( t >= 10 ) + t += letbase - '0' - 10; + *--s = t + '0'; + u /= b; + } + + if (neg) { + if( width && (pad & PAD_ZERO) ) { + printchar (out, '-'); + ++pc; + --width; + } + else { + *--s = '-'; + } + } + + return pc + prints (out, s, width, pad); +} + + +static int print(char **out, const char *format, va_list args ) +{ + register int width, pad; + register int pc = 0; + char scr[2]; + + for (; *format != 0; format++) { + if (*format == '%') { + ++format; + width = pad = 0; + if (*format == '\0') break; + if (*format == '%') goto out; + if (*format == '-') { + ++format; + pad = PAD_RIGHT; + } + while (*format == '0') { + ++format; + pad |= PAD_ZERO; + } + for ( ; *format >= '0' && *format <= '9'; ++format) { + width *= 10; + width += *format - '0'; + } + if( *format == 's' ) { + register char *s = (char *)va_arg( args, int ); + pc += prints (out, s?s:"(null)", width, pad); + continue; + } + if( *format == 'd' ) { + pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); + continue; + } + if( *format == 'x' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); + continue; + } + if( *format == 'X' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); + continue; + } + if( *format == 'u' ) { + pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); + continue; + } + if( *format == 'c' ) { + /* char are converted to int then pushed on the stack */ + scr[0] = (char)va_arg( args, int ); + scr[1] = '\0'; + pc += prints (out, scr, width, pad); + continue; + } + } + else { + out: + printchar (out, *format); + ++pc; + } + } + + if (out) **out = '\0'; + + va_end( args ); + return pc; +} + +int sprintf(char *out, const char *format, ...) +{ + va_list args; + va_start( args, format ); + return print( &out, format, args ); +} + +int printf(const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( 0, format, args ); +} + + +int printu(const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( 0, format, args ); +} + + +void puts ( char * str ) +{ + int i=0; + while(str[i] != 0) + { + put_char(str[i]); + i++; + } +} + From c5fcedecf11c55aaea538f506beb75b598f55c31 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 16 May 2013 01:36:49 +0200 Subject: [PATCH 07/41] usb-boot: Script for FEL USB booting --- README | 8 +++++++- usb-boot | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 usb-boot diff --git a/README b/README index 051215b..f310999 100644 --- a/README +++ b/README @@ -26,11 +26,17 @@ fel: th CPU. You activate FEL mode by pushing the usboot/recovery button at poweron. +usb-boot: + Simple wrapper around felboot and fel to automate USB booting in FEL mode + fel-gpio: Simple wrapper around fel-pio and fel to allos GPIO manipulations via FEL + +felboot: + ARM native board initialization for FEL mode -fel-pio.bin: +fel-pio: ARM native helper for fel-gpio pio: diff --git a/usb-boot b/usb-boot new file mode 100755 index 0000000..5a7abc1 --- /dev/null +++ b/usb-boot @@ -0,0 +1,37 @@ +#!/bin/sh -e +if [ $# -lt 2 ]; then + echo "Usage: $0 board u-boot.bin [kernel script.bin [initramfs]]" + exit 1 +fi +board=$1 +uboot=$2 +kernel=$3 +scriptbin=$4 +initramfs=$5 +fel() { + echo fel "$@" + ./fel $@ +} +felboot=felboot/fel-boot-${board}.bin +if [ ! -f $felboot ]; then + felboot=bin/fel-boot-${board}.bin +fi +if [ ! -f $felboot ]; then + echo "ERROR: Can't find fel-boot binary for ${board}" + exit 1 +fi +fel write 0x2000 $felboot +fel exe 0x2000 +if [ -n "$uboot" ]; then + fel write 0x4a000000 $uboot +fi +if [ -n "$kernel" ]; then + if [ -n "$sciptbin" ]; then + fel write 0x43000000 $scriptbin + fi + fel write 0x44000000 $kernel + if [ -n "$initramfs" ]; then + fel write 0x4c000000 $initramfs + fi +fi +fel exe 0x4a000000 From 1d8769b44b858d38f9e799fdbec487ad8502484c Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 16 May 2013 01:53:10 +0200 Subject: [PATCH 08/41] Rename fel-boot to fel-sdboot to avoid confusion with new fel-boot FEL bootloader --- Makefile | 12 ++++++------ README | 3 +++ bin/fel-sdboot.sunxi | Bin 0 -> 512 bytes fel-boot.c => fel-sdboot.c | 0 4 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 bin/fel-sdboot.sunxi rename fel-boot.c => fel-sdboot.c (100%) diff --git a/Makefile b/Makefile index 961f66e..5f8fb69 100644 --- a/Makefile +++ b/Makefile @@ -58,14 +58,14 @@ jtag-loop.bin: jtag-loop.elf jtag-loop.sunxi: jtag-loop.bin mksunxiboot jtag-loop.bin jtag-loop.sunxi -fel-boot.elf: fel-boot.c fel-boot.lds - $(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder fel-boot.c -nostdlib -o fel-boot.elf -T fel-boot.lds -Wl,-N +fel-sdboot.elf: fel-sdboot.c fel-sdboot.lds + $(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder fel-sdboot.c -nostdlib -o fel-sdboot.elf -T fel-sdboot.lds -Wl,-N -fel-boot.bin: fel-boot.elf - $(CROSS_COMPILE)objcopy -O binary fel-boot.elf fel-boot.bin +fel-sdboot.bin: fel-sdboot.elf + $(CROSS_COMPILE)objcopy -O binary fel-sdboot.elf fel-sdboot.bin -fel-boot.sunxi: fel-boot.bin - mksunxiboot fel-boot.bin fel-boot.sunxi +fel-sdboot.sunxi: fel-sdboot.bin + mksunxiboot fel-sdboot.bin fel-sdboot.sunxi boot_head_sun3i.elf: boot_head_sun3i.S boot_head_sun3i.lds $(CROSS_COMPILE)gcc -g -Os -fpic -fno-common -fno-builtin -ffreestanding -nostdinc -mno-thumb-interwork -Wall -Wstrict-prototypes -fno-stack-protector -Wno-format-nonliteral -Wno-format-security -fno-toplevel-reorder boot_head.S -nostdlib -o boot_head_sun3i.elf -T boot_head.lds -Wl,-N -DMACHID=0x1094 diff --git a/README b/README index f310999..68b997f 100644 --- a/README +++ b/README @@ -36,6 +36,9 @@ fel-gpio: felboot: ARM native board initialization for FEL mode +fel-sdboot: + ARM native sdcard bootloader forcing the device into FEL mode + fel-pio: ARM native helper for fel-gpio diff --git a/bin/fel-sdboot.sunxi b/bin/fel-sdboot.sunxi new file mode 100644 index 0000000000000000000000000000000000000000..6d3bbb27cd3a0373eaea66f8e660741f42019c8f GIT binary patch literal 512 zcmZQ$V0e}4?(e7P6k?!roZX3mi2((0IOx9QFqr?8|G|QX!vFOjay0CHp}_F}KZ>GJ I&X5fO0E&1JV*mgE literal 0 HcmV?d00001 diff --git a/fel-boot.c b/fel-sdboot.c similarity index 100% rename from fel-boot.c rename to fel-sdboot.c From 6b42b22bf381ea76e111ed099c60a098c493afd1 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 16 May 2013 11:17:04 +0200 Subject: [PATCH 09/41] usb-boot: Correct a spelling error that prevented script.bin from being loaded --- usb-boot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb-boot b/usb-boot index 5a7abc1..299edca 100755 --- a/usb-boot +++ b/usb-boot @@ -26,7 +26,7 @@ if [ -n "$uboot" ]; then fel write 0x4a000000 $uboot fi if [ -n "$kernel" ]; then - if [ -n "$sciptbin" ]; then + if [ -n "$scriptbin" ]; then fel write 0x43000000 $scriptbin fi fel write 0x44000000 $kernel From 35e99723b0381acc9433f1ad7769d6418367829d Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 16 May 2013 22:29:47 +0200 Subject: [PATCH 10/41] felboot: Silence printf warning in main.c --- felboot/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/felboot/main.c b/felboot/main.c index 7841216..608188c 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -1,3 +1,24 @@ +/* + * (C) Copyright 2013 Henrik Nordstrom + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include + void _start(void) { clock_init(); From afcf0eef81e9074056c3045a673bde1a727263fd Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 16 May 2013 22:41:42 +0200 Subject: [PATCH 11/41] felboot: Clarify build procedure a little tiny bit --- felboot/Makefile | 16 +++++++++++++--- felboot/README.txt | 26 +++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/felboot/Makefile b/felboot/Makefile index b129432..53b2a26 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -1,9 +1,19 @@ CC=gcc -BOARD=eoma68 -CROSS_COMPILE=/home/henrik/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -UBOOT=/home/henrik/SRC/u-boot/ + +# Target board name. This should match the dram_.c in +# u-boot/board/sunxi/ +BOARD=cubieboard + +# Path/prefix of your tool chain +CROSS_COMPILE=arm-linux-gnueabihf- + +# U-boot main source path +UBOOT=$(HOME)/SRC/u-boot/ + +# U-boot object path (O=... when building u-boot). UBOOTOBJ=$(UBOOT)build/$(BOARD)/ + CFLAGS=-g -O2 -marm -mno-thumb-interwork -mabi=aapcs-linux -march=armv7-a -fno-common -ffixed-r8 -msoft-float -I$(UBOOTOBJ)include2 -I$(UBOOTOBJ)include -I$(UBOOT)include all: fel-boot-$(BOARD).bin diff --git a/felboot/README.txt b/felboot/README.txt index d55cc16..85e663d 100644 --- a/felboot/README.txt +++ b/felboot/README.txt @@ -17,20 +17,28 @@ fel exe 0x4a000000 Build instructions: -1. You need to build u-boot sunxi-current SPL first for the same CPU generation, i.e. cubieboard. +0. You need to build u-boot sunxi-current SPL first for the your board. -Change the paths in Makefile to reflect where your copy of u-boot and toolchain is, or specify the paths when runnign make +1. Specify needed configuration when when running make -make + BOARD= boardname + CROSS_COMPILE= compiler prefix + UBOOT= u-boot sources + UBOOTOBJ= u-boot built tree +make BOARD=cubieboard CROSS_COMPILE=arm-linux-gnueabihf- UBOOT=~/SRC/u-boot/ UBOOTOBJ=~/SRC/u-boot/build/'$(BOARD)'/ -To adopt for another board: +Defaults: -1a) If the board is supported by u-boot SPL then change UBOOT_OBJS to include the dram spefications for your board and remove dram.o from fel-boot.elf: line. +# Target board name. This should match the dram_.c in +# u-boot/board/sunxi/ +BOARD=eoma68 -1b) Else update dram.c with the right parameters for your board. +# Path to your tool chain +CROSS_COMPILE=ikk/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- -2. Change early_printf.c to define the right UART number for your board. - -3. make +# U-boot main source path +UBOOT=/home/henrik/SRC/u-boot/ +# U-boot object path (O=... when building u-boot). +UBOOTOBJ=$(UBOOT)build/$(BOARD)/ From 8b0ecf719748cb5b1ba4bf3d14cf65538c869c55 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 12:41:37 +0200 Subject: [PATCH 12/41] felboot: Replace util_printf.c with pristine printf-stdarg.c from menie.org same code but the util_printf.c one was missing copyright attribution and slightly hacked up. --- felboot/Makefile | 2 +- felboot/main.c | 10 ++ felboot/printf-stdarg.c | 266 ++++++++++++++++++++++++++++++++++++++++ felboot/util_printf.c | 208 ------------------------------- 4 files changed, 277 insertions(+), 209 deletions(-) create mode 100644 felboot/printf-stdarg.c delete mode 100644 felboot/util_printf.c diff --git a/felboot/Makefile b/felboot/Makefile index 53b2a26..50d0918 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -30,7 +30,7 @@ UBOOT_OBJS= \ .c.o: $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ -fel-boot-$(BOARD).elf: main.o util_printf.o early_print.o $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) +fel-boot-$(BOARD).elf: main.o printf-stdarg.o early_print.o $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -nostartfiles $(CFLAGS) -Wl,-Map=$@.map $^ -o $@ fel-boot-$(BOARD).bin: fel-boot-$(BOARD).elf diff --git a/felboot/main.c b/felboot/main.c index 608188c..04b2731 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -90,3 +90,13 @@ void sunxi_board_init(void) clock_set_pll1(1008000000); } + +int putchar(int ch) +{ + return uart_putc(ch); +} + +int puts(const char *str) +{ + return uart_puts(str); +} diff --git a/felboot/printf-stdarg.c b/felboot/printf-stdarg.c new file mode 100644 index 0000000..72fd2b9 --- /dev/null +++ b/felboot/printf-stdarg.c @@ -0,0 +1,266 @@ +/* + Copyright 2001, 2002 Georges Menie (www.menie.org) + stdarg version contributed by Christian Ettinger + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + putchar is the only external dependency for this file, + if you have a working putchar, leave it commented out. + If not, uncomment the define below and + replace outbyte(c) by your own function call. + +#define putchar(c) outbyte(c) +*/ + +#include + +static void printchar(char **str, int c) +{ + extern int putchar(int c); + + if (str) { + **str = c; + ++(*str); + } + else (void)putchar(c); +} + +#define PAD_RIGHT 1 +#define PAD_ZERO 2 + +static int prints(char **out, const char *string, int width, int pad) +{ + register int pc = 0, padchar = ' '; + + if (width > 0) { + register int len = 0; + register const char *ptr; + for (ptr = string; *ptr; ++ptr) ++len; + if (len >= width) width = 0; + else width -= len; + if (pad & PAD_ZERO) padchar = '0'; + } + if (!(pad & PAD_RIGHT)) { + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + } + for ( ; *string ; ++string) { + printchar (out, *string); + ++pc; + } + for ( ; width > 0; --width) { + printchar (out, padchar); + ++pc; + } + + return pc; +} + +/* the following should be enough for 32 bit int */ +#define PRINT_BUF_LEN 12 + +static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) +{ + char print_buf[PRINT_BUF_LEN]; + register char *s; + register int t, neg = 0, pc = 0; + register unsigned int u = i; + + if (i == 0) { + print_buf[0] = '0'; + print_buf[1] = '\0'; + return prints (out, print_buf, width, pad); + } + + if (sg && b == 10 && i < 0) { + neg = 1; + u = -i; + } + + s = print_buf + PRINT_BUF_LEN-1; + *s = '\0'; + + while (u) { + t = u % b; + if( t >= 10 ) + t += letbase - '0' - 10; + *--s = t + '0'; + u /= b; + } + + if (neg) { + if( width && (pad & PAD_ZERO) ) { + printchar (out, '-'); + ++pc; + --width; + } + else { + *--s = '-'; + } + } + + return pc + prints (out, s, width, pad); +} + +static int print(char **out, const char *format, va_list args ) +{ + register int width, pad; + register int pc = 0; + char scr[2]; + + for (; *format != 0; ++format) { + if (*format == '%') { + ++format; + width = pad = 0; + if (*format == '\0') break; + if (*format == '%') goto out; + if (*format == '-') { + ++format; + pad = PAD_RIGHT; + } + while (*format == '0') { + ++format; + pad |= PAD_ZERO; + } + for ( ; *format >= '0' && *format <= '9'; ++format) { + width *= 10; + width += *format - '0'; + } + if( *format == 's' ) { + register char *s = (char *)va_arg( args, int ); + pc += prints (out, s?s:"(null)", width, pad); + continue; + } + if( *format == 'd' ) { + pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); + continue; + } + if( *format == 'x' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); + continue; + } + if( *format == 'X' ) { + pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); + continue; + } + if( *format == 'u' ) { + pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); + continue; + } + if( *format == 'c' ) { + /* char are converted to int then pushed on the stack */ + scr[0] = (char)va_arg( args, int ); + scr[1] = '\0'; + pc += prints (out, scr, width, pad); + continue; + } + } + else { + out: + printchar (out, *format); + ++pc; + } + } + if (out) **out = '\0'; + va_end( args ); + return pc; +} + +int printf(const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( 0, format, args ); +} + +int sprintf(char *out, const char *format, ...) +{ + va_list args; + + va_start( args, format ); + return print( &out, format, args ); +} + +#ifdef TEST_PRINTF +int main(void) +{ + char *ptr = "Hello world!"; + char *np = 0; + int i = 5; + unsigned int bs = sizeof(int)*8; + int mi; + char buf[80]; + + mi = (1 << (bs-1)) + 1; + printf("%s\n", ptr); + printf("printf test\n"); + printf("%s is null pointer\n", np); + printf("%d = 5\n", i); + printf("%d = - max int\n", mi); + printf("char %c = 'a'\n", 'a'); + printf("hex %x = ff\n", 0xff); + printf("hex %02x = 00\n", 0); + printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3); + printf("%d %s(s)%", 0, "message"); + printf("\n"); + printf("%d %s(s) with %%\n", 0, "message"); + sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf); + sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf); + sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf); + sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf); + sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf); + sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf); + sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf); + sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf); + + return 0; +} + +/* + * if you compile this file with + * gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c + * you will get a normal warning: + * printf.c:214: warning: spurious trailing `%' in format + * this line is testing an invalid % at the end of the format string. + * + * this should display (on 32bit int machine) : + * + * Hello world! + * printf test + * (null) is null pointer + * 5 = 5 + * -2147483647 = - max int + * char a = 'a' + * hex ff = ff + * hex 00 = 00 + * signed -3 = unsigned 4294967293 = hex fffffffd + * 0 message(s) + * 0 message(s) with % + * justif: "left " + * justif: " right" + * 3: 0003 zero padded + * 3: 3 left justif. + * 3: 3 right justif. + * -3: -003 zero padded + * -3: -3 left justif. + * -3: -3 right justif. + */ + +#endif diff --git a/felboot/util_printf.c b/felboot/util_printf.c deleted file mode 100644 index d16bd1a..0000000 --- a/felboot/util_printf.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - - */ - - -#include -#include "early_print.h" - - -/* Debug uart have been init by boot rom. */ -void put_char(char ch) -{ - uart_putc(ch); -} - - -static void printchar(char **str, int c) -{ - if (str) { - **str = c; - ++(*str); - } - else { - put_char(c); - } -} - -#define PAD_RIGHT 1 -#define PAD_ZERO 2 - -static int prints(char **out, const char *string, int width, int pad) -{ - register int pc = 0, padchar = ' '; - - if (width > 0) { - register int len = 0; - register const char *ptr; - for (ptr = string; *ptr; ++ptr) ++len; - if (len >= width) width = 0; - else width -= len; - if (pad & PAD_ZERO) padchar = '0'; - } - if (!(pad & PAD_RIGHT)) { - for ( ; width > 0; --width) { - printchar (out, padchar); - ++pc; - } - } - for ( ; *string ; ++string) { - printchar (out, *string); - ++pc; - } - for ( ; width > 0; --width) { - printchar (out, padchar); - ++pc; - } - - return pc; -} - -/* the following should be enough for 32 bit int */ -#define PRINT_BUF_LEN 12 - -static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) -{ - char print_buf[PRINT_BUF_LEN]; - register char *s; - register int t, neg = 0, pc = 0; - register unsigned int u = i; - - if (i == 0) { - print_buf[0] = '0'; - print_buf[1] = '\0'; - return prints (out, print_buf, width, pad); - } - - if (sg && b == 10 && i < 0) { - neg = 1; - u = -i; - } - - s = print_buf + PRINT_BUF_LEN-1; - *s = '\0'; - - while (u) { - t = u % b; - if( t >= 10 ) - t += letbase - '0' - 10; - *--s = t + '0'; - u /= b; - } - - if (neg) { - if( width && (pad & PAD_ZERO) ) { - printchar (out, '-'); - ++pc; - --width; - } - else { - *--s = '-'; - } - } - - return pc + prints (out, s, width, pad); -} - - -static int print(char **out, const char *format, va_list args ) -{ - register int width, pad; - register int pc = 0; - char scr[2]; - - for (; *format != 0; format++) { - if (*format == '%') { - ++format; - width = pad = 0; - if (*format == '\0') break; - if (*format == '%') goto out; - if (*format == '-') { - ++format; - pad = PAD_RIGHT; - } - while (*format == '0') { - ++format; - pad |= PAD_ZERO; - } - for ( ; *format >= '0' && *format <= '9'; ++format) { - width *= 10; - width += *format - '0'; - } - if( *format == 's' ) { - register char *s = (char *)va_arg( args, int ); - pc += prints (out, s?s:"(null)", width, pad); - continue; - } - if( *format == 'd' ) { - pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); - continue; - } - if( *format == 'x' ) { - pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); - continue; - } - if( *format == 'X' ) { - pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); - continue; - } - if( *format == 'u' ) { - pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); - continue; - } - if( *format == 'c' ) { - /* char are converted to int then pushed on the stack */ - scr[0] = (char)va_arg( args, int ); - scr[1] = '\0'; - pc += prints (out, scr, width, pad); - continue; - } - } - else { - out: - printchar (out, *format); - ++pc; - } - } - - if (out) **out = '\0'; - - va_end( args ); - return pc; -} - -int sprintf(char *out, const char *format, ...) -{ - va_list args; - va_start( args, format ); - return print( &out, format, args ); -} - -int printf(const char *format, ...) -{ - va_list args; - - va_start( args, format ); - return print( 0, format, args ); -} - - -int printu(const char *format, ...) -{ - va_list args; - - va_start( args, format ); - return print( 0, format, args ); -} - - -void puts ( char * str ) -{ - int i=0; - while(str[i] != 0) - { - put_char(str[i]); - i++; - } -} - From de093ee7eff417e188b3c60c1dc1d574c9a546ac Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 16:07:54 +0200 Subject: [PATCH 13/41] felboot: Reuse sunxi_board_init() directly from u-boot tree --- felboot/Makefile | 2 +- felboot/main.c | 52 ++++++++++++------------------------------------ 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/felboot/Makefile b/felboot/Makefile index 50d0918..49b2a9c 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -25,7 +25,7 @@ UBOOT_OBJS= \ spl/drivers/power/axp209.o \ spl/drivers/i2c/libi2c.o \ spl/common/memsize.o \ - spl/board/sunxi/dram_$(BOARD).o + $(addprefix spl/board/sunxi/,board.o dram_$(BOARD).o) .c.o: $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ diff --git a/felboot/main.c b/felboot/main.c index 04b2731..a535995 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -24,9 +24,12 @@ void _start(void) clock_init(); gpio_init(); uart_init(); + timer_init(); s_init(); } +int gdata; + void dcache_enable(void) { } @@ -52,45 +55,6 @@ void udelay(unsigned long usec) __udelay(usec); } -void sunxi_board_init(void) -{ - int power_failed = 1; - int ramsize; - - timer_init(); - - printf("DRAM:"); - ramsize = sunxi_dram_init(); - if (!ramsize) { - printf(" ?"); - ramsize = sunxi_dram_init(); - } - if (!ramsize) { - printf(" ?"); - ramsize = sunxi_dram_init(); - } - printf(" %dMB\n", ramsize>>20); - if (!ramsize) - hang(); - -#ifdef CONFIG_AXP209_POWER - power_failed |= axp209_init(); - power_failed |= axp209_set_dcdc2(1400); - power_failed |= axp209_set_dcdc3(1250); - power_failed |= axp209_set_ldo2(3000); - power_failed |= axp209_set_ldo3(2800); - power_failed |= axp209_set_ldo4(2800); -#endif - - /* - * Only clock up the CPU to full speed if we are reasonably - * assured it's being powered with suitable core voltage - */ - if (!power_failed) - clock_set_pll1(1008000000); -} - - int putchar(int ch) { return uart_putc(ch); @@ -100,3 +64,13 @@ int puts(const char *str) { return uart_puts(str); } + +int sunxi_mmc_init(void) +{ + return -1; +} + +int status_led_set(void) +{ + return -1; +} From ab5089a1fffbb9998c588d71dd55634e840d1f53 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 16:50:03 +0200 Subject: [PATCH 14/41] felboot: NO_PRINTF=1 make option to disable printf for smaller code size --- felboot/Makefile | 10 +++++++++- felboot/README.txt | 3 +++ felboot/main.c | 31 ++++++++++++++++++++++++++----- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/felboot/Makefile b/felboot/Makefile index 49b2a9c..00d1977 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -30,7 +30,15 @@ UBOOT_OBJS= \ .c.o: $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ -fel-boot-$(BOARD).elf: main.o printf-stdarg.o early_print.o $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) +OBJS += main.o + +ifeq ($(NO_PRINTF),1) +CFLAGS += -DNO_PRINTF +else +OBJS += printf-stdarg.o early_print.o +endif + +fel-boot-$(BOARD).elf: $(OBJS) $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -nostartfiles $(CFLAGS) -Wl,-Map=$@.map $^ -o $@ fel-boot-$(BOARD).bin: fel-boot-$(BOARD).elf diff --git a/felboot/README.txt b/felboot/README.txt index 85e663d..b9a73cd 100644 --- a/felboot/README.txt +++ b/felboot/README.txt @@ -28,6 +28,9 @@ Build instructions: make BOARD=cubieboard CROSS_COMPILE=arm-linux-gnueabihf- UBOOT=~/SRC/u-boot/ UBOOTOBJ=~/SRC/u-boot/build/'$(BOARD)'/ +Other options + NO_PRINTF=1 Disable printf, reducing the code size a bit + Defaults: # Target board name. This should match the dram_.c in diff --git a/felboot/main.c b/felboot/main.c index a535995..a26243b 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -38,9 +38,6 @@ void sunxi_wemac_initialize(void) { } -void *gd; -int gdata; - void preloader_console_init(void) { } @@ -55,6 +52,18 @@ void udelay(unsigned long usec) __udelay(usec); } +int sunxi_mmc_init(void) +{ + return -1; +} + +int status_led_set(void) +{ + return -1; +} + + +#ifndef NO_PRINTF int putchar(int ch) { return uart_putc(ch); @@ -65,12 +74,24 @@ int puts(const char *str) return uart_puts(str); } -int sunxi_mmc_init(void) +#else +int putchar(int ch) { return -1; } -int status_led_set(void) +int puts(const char *str) { return -1; } + +int printf(const char *fmt, ...) +{ + return -1; +} + +void uart_init(void) +{ +} + +#endif From 755ff89ddeaa7ecfac9287fa93ce9c20058ca9e3 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 17:07:44 +0200 Subject: [PATCH 15/41] felboot: Prevent GCC from reordering _start. Must be at a known address --- felboot/fel-boot.ld | 2 +- felboot/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/felboot/fel-boot.ld b/felboot/fel-boot.ld index 19bc549..cf1419f 100644 --- a/felboot/fel-boot.ld +++ b/felboot/fel-boot.ld @@ -7,7 +7,7 @@ SECTIONS . = ALIGN(4); .text : { - main.o (.text*) + main.o (.text.start) *(.text*) } . = ALIGN(4); diff --git a/felboot/main.c b/felboot/main.c index a26243b..a06ecdf 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -19,7 +19,7 @@ #include -void _start(void) +__attribute__ ((section (".text.start"))) void _start(void) { clock_init(); gpio_init(); From 4c5e0845e117a10b3b5d12ee779799491e7b6cfd Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 17:07:55 +0200 Subject: [PATCH 16/41] felboot: Correct line output --- felboot/main.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/felboot/main.c b/felboot/main.c index a06ecdf..d8ce7b7 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -66,12 +66,17 @@ int status_led_set(void) #ifndef NO_PRINTF int putchar(int ch) { - return uart_putc(ch); + if (ch == '\n') + uart_putc('\r'); + uart_putc(ch); + return 0; } int puts(const char *str) { - return uart_puts(str); + while(*str) + putchar(*str++); + return 0; } #else From 789512036bf10919efd55209d6e85e307d2923e0 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 22:06:03 +0200 Subject: [PATCH 17/41] felboot: Use u-boot common.h instead of system stdio.h --- felboot/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/felboot/main.c b/felboot/main.c index d8ce7b7..432eb5f 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -17,7 +17,8 @@ * MA 02111-1307 USA */ -#include +#include "config.h" +#include "common.h" __attribute__ ((section (".text.start"))) void _start(void) { From c4ae8f2e7382f3b8634cd8a9d0d835402c3d2cd6 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 23:02:04 +0200 Subject: [PATCH 18/41] felboot: Reduce _start to just a call to s_init. --- felboot/main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/felboot/main.c b/felboot/main.c index 432eb5f..44537b6 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -22,10 +22,6 @@ __attribute__ ((section (".text.start"))) void _start(void) { - clock_init(); - gpio_init(); - uart_init(); - timer_init(); s_init(); } @@ -41,6 +37,7 @@ void sunxi_wemac_initialize(void) void preloader_console_init(void) { + uart_init(); } void hang(void) From d34a13fccf2f0d08727033287a037f9629cbeff5 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 17 May 2013 23:59:34 +0200 Subject: [PATCH 19/41] felboot: Even closer to u-boot --- felboot/Makefile | 2 +- felboot/common.h | 27 --------------------------- felboot/early_print.c | 1 + felboot/main.c | 9 ++++----- 4 files changed, 6 insertions(+), 33 deletions(-) delete mode 100644 felboot/common.h diff --git a/felboot/Makefile b/felboot/Makefile index 00d1977..316c331 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -14,7 +14,7 @@ UBOOT=$(HOME)/SRC/u-boot/ # U-boot object path (O=... when building u-boot). UBOOTOBJ=$(UBOOT)build/$(BOARD)/ -CFLAGS=-g -O2 -marm -mno-thumb-interwork -mabi=aapcs-linux -march=armv7-a -fno-common -ffixed-r8 -msoft-float -I$(UBOOTOBJ)include2 -I$(UBOOTOBJ)include -I$(UBOOT)include +CFLAGS=-g -O2 -marm -mno-thumb-interwork -mabi=aapcs-linux -march=armv7-a -fno-common -fno-builtin -ffreestanding -ffixed-r8 -msoft-float -D__KERNEL__ -I$(UBOOTOBJ)include2 -I$(UBOOTOBJ)include -I$(UBOOT)include all: fel-boot-$(BOARD).bin diff --git a/felboot/common.h b/felboot/common.h deleted file mode 100644 index 1717709..0000000 --- a/felboot/common.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _COMMON_H -#define _COMMON_H - -#include - -#define u32 uint32_t -#define u16 uint16_t -#define u8 uint8_t - -#define s32 int32_t -#define s16 int16_t -#define s8 int8_t - -#define __u8 u8 -#define __u16 u16 -#define __u32 u32 - -#define __s8 s8 -#define __s16 s16 -#define __s32 s32 - - -#include "io.h" -#include "cpu.h" - - -#endif diff --git a/felboot/early_print.c b/felboot/early_print.c index 7976b7f..10b03c7 100644 --- a/felboot/early_print.c +++ b/felboot/early_print.c @@ -29,6 +29,7 @@ #include "early_print.h" #include #include +#include "io.h" static int uart_initialized = 0; diff --git a/felboot/main.c b/felboot/main.c index 44537b6..3b21348 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -17,15 +17,15 @@ * MA 02111-1307 USA */ -#include "config.h" -#include "common.h" +#include __attribute__ ((section (".text.start"))) void _start(void) { s_init(); } -int gdata; +DECLARE_GLOBAL_DATA_PTR; +gd_t gdata __attribute__ ((section(".data"))); void dcache_enable(void) { @@ -70,11 +70,10 @@ int putchar(int ch) return 0; } -int puts(const char *str) +void puts(const char *str) { while(*str) putchar(*str++); - return 0; } #else From 99c3501bed4d7ca84839a263ac44839127bc7fed Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Sat, 18 May 2013 00:02:40 +0200 Subject: [PATCH 20/41] Revert "felboot: Reuse sunxi_board_init() directly from u-boot tree" For some reason cubieboard no longer works with this. a13-olinuxino do work however. Needs further analysis. This reverts commit de093ee7eff417e188b3c60c1dc1d574c9a546ac. Conflicts: felboot/main.c --- felboot/Makefile | 2 +- felboot/main.c | 42 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/felboot/Makefile b/felboot/Makefile index 316c331..cb37e47 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -25,7 +25,7 @@ UBOOT_OBJS= \ spl/drivers/power/axp209.o \ spl/drivers/i2c/libi2c.o \ spl/common/memsize.o \ - $(addprefix spl/board/sunxi/,board.o dram_$(BOARD).o) + spl/board/sunxi/dram_$(BOARD).o .c.o: $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ diff --git a/felboot/main.c b/felboot/main.c index 3b21348..0132b1b 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -24,7 +24,6 @@ __attribute__ ((section (".text.start"))) void _start(void) s_init(); } -DECLARE_GLOBAL_DATA_PTR; gd_t gdata __attribute__ ((section(".data"))); void dcache_enable(void) @@ -60,6 +59,43 @@ int status_led_set(void) return -1; } +void sunxi_board_init(void) +{ + int power_failed = 1; + int ramsize; + + timer_init(); + + printf("DRAM:"); + ramsize = sunxi_dram_init(); + if (!ramsize) { + printf(" ?"); + ramsize = sunxi_dram_init(); + } + if (!ramsize) { + printf(" ?"); + ramsize = sunxi_dram_init(); + } + printf(" %dMB\n", ramsize>>20); + if (!ramsize) + hang(); + +#ifdef CONFIG_AXP209_POWER + power_failed |= axp209_init(); + power_failed |= axp209_set_dcdc2(1400); + power_failed |= axp209_set_dcdc3(1250); + power_failed |= axp209_set_ldo2(3000); + power_failed |= axp209_set_ldo3(2800); + power_failed |= axp209_set_ldo4(2800); +#endif + + /* + * Only clock up the CPU to full speed if we are reasonably + * assured it's being powered with suitable core voltage + */ + if (!power_failed) + clock_set_pll1(1008000000); +} #ifndef NO_PRINTF int putchar(int ch) @@ -79,12 +115,12 @@ void puts(const char *str) #else int putchar(int ch) { - return -1; + return uart_putc(ch); } int puts(const char *str) { - return -1; + return uart_puts(str); } int printf(const char *fmt, ...) From 6829404a4409a5fecac937c56013cfdb86e13628 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Sat, 18 May 2013 00:34:20 +0200 Subject: [PATCH 21/41] felboot: Correct merge conflict --- felboot/main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/felboot/main.c b/felboot/main.c index 0132b1b..9452c23 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -42,6 +42,7 @@ void preloader_console_init(void) void hang(void) { printf("Please reset the board!"); + while(1); } void udelay(unsigned long usec) @@ -98,12 +99,11 @@ void sunxi_board_init(void) } #ifndef NO_PRINTF -int putchar(int ch) +void putchar(int ch) { if (ch == '\n') uart_putc('\r'); uart_putc(ch); - return 0; } void puts(const char *str) @@ -113,14 +113,12 @@ void puts(const char *str) } #else -int putchar(int ch) +void putchar(int ch) { - return uart_putc(ch); } -int puts(const char *str) +void puts(const char *str) { - return uart_puts(str); } int printf(const char *fmt, ...) From 9d30ca8e86f22c16507fb834776c1b3058f48e38 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Sun, 19 May 2013 11:55:17 +0200 Subject: [PATCH 22/41] fel: Detach (and reattach on exit) the awusb kernel driver if loaded --- fel.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fel.c b/fel.c index c719bd8..6da47c5 100644 --- a/fel.c +++ b/fel.c @@ -278,6 +278,7 @@ int main(int argc, char **argv) { int rc; libusb_device_handle *handle = NULL; + int iface_detached = -1; rc = libusb_init(NULL); assert(rc == 0); @@ -301,6 +302,13 @@ int main(int argc, char **argv) exit(1); } rc = libusb_claim_interface(handle, 0); +#if defined(__linux__) + if (rc != LIBUSB_SUCCESS) { + libusb_detach_kernel_driver(handle, 0); + iface_detached = 0; + rc = libusb_claim_interface(handle, 0); + } +#endif assert(rc == 0); while (argc > 1 ) { @@ -345,5 +353,10 @@ int main(int argc, char **argv) argv+=skip; } +#if defined(__linux__) + if (iface_detached >= 0) + libusb_attach_kernel_driver(handle, iface_detached); +#endif + return 0; } From bacc658e59f0b3610d7eafd179c72420a992373f Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Sun, 19 May 2013 21:33:30 +0200 Subject: [PATCH 23/41] Rename eoma68 to eoma68-a10 --- ...{fel-boot-eoma68.bin => fel-boot-eoma68-a10.bin} | Bin 1 file changed, 0 insertions(+), 0 deletions(-) rename bin/{fel-boot-eoma68.bin => fel-boot-eoma68-a10.bin} (100%) diff --git a/bin/fel-boot-eoma68.bin b/bin/fel-boot-eoma68-a10.bin similarity index 100% rename from bin/fel-boot-eoma68.bin rename to bin/fel-boot-eoma68-a10.bin From 05cdc60eb14cd10cf5f53453516cf7e6f84a708e Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Tue, 21 May 2013 23:19:19 +0200 Subject: [PATCH 24/41] usb-boot: Rework ram boot to use a boot.scr @0x41000000 to indicate RAM boot --- bin/ramboot.scr | Bin 0 -> 246 bytes felboot/ramboot.cmd | 7 +++++++ usb-boot | 34 +++++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 bin/ramboot.scr create mode 100644 felboot/ramboot.cmd diff --git a/bin/ramboot.scr b/bin/ramboot.scr new file mode 100644 index 0000000000000000000000000000000000000000..944aa5837726e04cdc07001c545c1acfefe3047b GIT binary patch literal 246 zcmY#ql?*GWost|l`$;MT1H(2T27@2dS#Gm3vB9|b=yf1TWra}Pr2PC6g&;>?1u&yH zxhS)sgsUhqHzl(;+m Date: Thu, 23 May 2013 21:12:53 +0200 Subject: [PATCH 25/41] usb-boot: Handle variable arguments --- bin/fel-boot-mele_a1000.bin | Bin 0 -> 7268 bytes felboot/main.c | 6 +++--- usb-boot | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100755 bin/fel-boot-mele_a1000.bin diff --git a/bin/fel-boot-mele_a1000.bin b/bin/fel-boot-mele_a1000.bin new file mode 100755 index 0000000000000000000000000000000000000000..7c6a31f04ac1052dbaad3e0bd73e30eca79aa8e7 GIT binary patch literal 7268 zcmd5=eQZ=$c0c#Mu{{hEe2s_HalFeL1C61eJli1)tdl%GHjAnx8e@k*Lfe7BE|qBF z08vq!bjLHcgLdte@kfNBP(MOdtyXD6L$`{k*ba7zQWjLwq~DwNy?418u&c(|CN0g9 zxWDt}4bUxGRsE|YJ)Jw}p6_$+x#zt;lcv8scdyS+zo6;3v+8P$CiFK2&3rL8H@$lu z(GNgFM-j1=xBRPamEHY+)Oj-oW1&xjyT73O?RJuG$XX|Ac=P8lp>@?U%VT@sA)&&?n*l zpF%cpS9q_A#ahFfqX$^}F_6zd>*!cX?N?=B-cZ&1CmT-UT+w_e!w0cG9#g{&Jg*oG?T64`;^ z@7Yetc6KWG!ZK7f^wmHw()06f77Hin1V3T6MV8gVTb$!OO9kY+Ex+;o@^`%DxgJa-A&Pmtr zVEczh12OE@CuoZzK%(txB@yg?QjzVdTKl5r)UC0O=>^VEu&!rAkbvGQ>H5zg_riux z_&<-j6ys{_LNS(gecLVs!rpYbh3mu31Rsa7*sf|Idp_u^L2E+eMTmjVA3_$TChS~vyNQ76YT!FbeMVilkv->Wj5f*~@liF&NJ zfvaL3yDu;uJn&AoB}{77PAH{ephLx48mHbA!JdBBGNp9WkHC{R~y1KWHd%+*%Ku_pWF zMP#8atf@s-lplhBY%ABTIQgBR332;Z#4F_;(@6`pftc|g$=^j>zZ;~ya?EO^EA9p@ zo&1g$M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Buy}5j>;~*vvsOM1_~TTE+zPn);|Jvv zfPZ{(z1#+9eSeeO4mddQb@?RVwOzj~p90+d(4%q(;HA4W@>c*mu5FRO3i!SEAD6!d znEIn_3^6Cq(d&}}---z3KmZ6RW-9;-55h~ojVJt}(T#j##2&`xJ8no>+4*k}X`&P! imiP6?9;Z7VsLy};+z$^t(r|I)PyghfPOmudx&L1yb!njh literal 0 HcmV?d00001 diff --git a/felboot/main.c b/felboot/main.c index 9452c23..8dd397e 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -55,14 +55,14 @@ int sunxi_mmc_init(void) return -1; } -int status_led_set(void) +void status_led_set(int led, int state) { - return -1; + return; } void sunxi_board_init(void) { - int power_failed = 1; + int power_failed = 0; int ramsize; timer_init(); diff --git a/usb-boot b/usb-boot index c72dc49..0444896 100755 --- a/usb-boot +++ b/usb-boot @@ -4,8 +4,8 @@ if [ $# -lt 2 ]; then echo "Usage: $0 board u-boot.bin [boot.scr|-] [kernel script.bin [initramfs]]" exit 1 fi -board=$1; shift -uboot=$1; shift +board=$1; shift || (echo "ERROR: Board must be specified"; exit 1;) +uboot=$1; shift || (echo "ERROR: u-boot.bin must be specified"; exit 1;) bootscr=$tob/felboot/ramboot.scr if [ ! -f $bootscr ]; then bootscr=$top/bin/ramboot.scr @@ -14,9 +14,9 @@ case "$1" in *.scr) bootscr="$1"; shift ;; esac -kernel=$1; shift -scriptbin=$1; shift -initramfs=$1; shift +kernel=$1; shift || true +scriptbin=$1; shift || true +initramfs=$1; shift || true fel() { echo fel "$@" $top/fel $@ From e42ec9b7ad88a2f1743103c1735382858bd968b7 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 23 May 2013 21:12:58 +0200 Subject: [PATCH 26/41] usb-boot: Fix for failure just after DRAM initialization. just need to wait a little for the DRAM initialization to finish. Can't use fel until we know it's finished or things breaks down. --- usb-boot | 1 + 1 file changed, 1 insertion(+) diff --git a/usb-boot b/usb-boot index 0444896..990091f 100755 --- a/usb-boot +++ b/usb-boot @@ -35,6 +35,7 @@ if [ ! -f $bootscr ]; then fi fel write 0x2000 $felboot fel exe 0x2000 +sleep 1 # Wait for DRAM initialization to complete if [ -n "$uboot" ]; then fel write 0x4a000000 $uboot fi From 3ba3dde4eed509e18515e86d1b396235251cb2e6 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 23 May 2013 21:18:02 +0200 Subject: [PATCH 27/41] felboot: Show u-boot version banner --- felboot/main.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/felboot/main.c b/felboot/main.c index 8dd397e..4492026 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -18,6 +18,7 @@ */ #include +#include __attribute__ ((section (".text.start"))) void _start(void) { @@ -37,6 +38,8 @@ void sunxi_wemac_initialize(void) void preloader_console_init(void) { uart_init(); + puts("\nU-Boot FEL " PLAIN_VERSION " (" U_BOOT_DATE " - " \ + U_BOOT_TIME ")\n"); } void hang(void) From 98b3125dfc56340afbb3e4be72a61abac9b49a17 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 23 May 2013 21:19:17 +0200 Subject: [PATCH 28/41] felboot: Use sunxi_board_init directly from u-boot as expected there was no problem to use sunxi_board_init directly from u-boot. Failure on A13 was a timing issue in the host side script (need to wait for DRAM init to finish before trying next fel operation) --- felboot/Makefile | 2 +- felboot/main.c | 38 -------------------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) diff --git a/felboot/Makefile b/felboot/Makefile index cb37e47..b9a7bd2 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -25,7 +25,7 @@ UBOOT_OBJS= \ spl/drivers/power/axp209.o \ spl/drivers/i2c/libi2c.o \ spl/common/memsize.o \ - spl/board/sunxi/dram_$(BOARD).o + $(addprefix spl/board/sunxi/,dram_$(BOARD).o board.o) .c.o: $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ diff --git a/felboot/main.c b/felboot/main.c index 4492026..4aad36f 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -63,44 +63,6 @@ void status_led_set(int led, int state) return; } -void sunxi_board_init(void) -{ - int power_failed = 0; - int ramsize; - - timer_init(); - - printf("DRAM:"); - ramsize = sunxi_dram_init(); - if (!ramsize) { - printf(" ?"); - ramsize = sunxi_dram_init(); - } - if (!ramsize) { - printf(" ?"); - ramsize = sunxi_dram_init(); - } - printf(" %dMB\n", ramsize>>20); - if (!ramsize) - hang(); - -#ifdef CONFIG_AXP209_POWER - power_failed |= axp209_init(); - power_failed |= axp209_set_dcdc2(1400); - power_failed |= axp209_set_dcdc3(1250); - power_failed |= axp209_set_ldo2(3000); - power_failed |= axp209_set_ldo3(2800); - power_failed |= axp209_set_ldo4(2800); -#endif - - /* - * Only clock up the CPU to full speed if we are reasonably - * assured it's being powered with suitable core voltage - */ - if (!power_failed) - clock_set_pll1(1008000000); -} - #ifndef NO_PRINTF void putchar(int ch) { From 7c056093847801c75a1195e4a0cf2ab444ed14bd Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Thu, 23 May 2013 22:46:20 +0200 Subject: [PATCH 29/41] felboot: Simplify Makefile a bit to more closely match u-boot --- felboot/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/felboot/Makefile b/felboot/Makefile index b9a7bd2..150fac3 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -19,13 +19,13 @@ CFLAGS=-g -O2 -marm -mno-thumb-interwork -mabi=aapcs-linux -march=armv7-a -fno-c all: fel-boot-$(BOARD).bin UBOOT_OBJS= \ - $(addprefix spl/arch/arm/cpu/armv7/sunxi/,clock.o pinmux.o dram.o board.o timer.o) \ + spl/arch/arm/cpu/armv7/sunxi/libsunxi.o \ spl/arch/arm/cpu/armv7/syslib.o \ spl/arch/arm/lib/eabi_compat.o \ - spl/drivers/power/axp209.o \ + spl/drivers/power/libpower.o \ spl/drivers/i2c/libi2c.o \ spl/common/memsize.o \ - $(addprefix spl/board/sunxi/,dram_$(BOARD).o board.o) + spl/board/sunxi/libsunxi.o .c.o: $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ @@ -39,7 +39,7 @@ OBJS += printf-stdarg.o early_print.o endif fel-boot-$(BOARD).elf: $(OBJS) $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) - $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -nostartfiles $(CFLAGS) -Wl,-Map=$@.map $^ -o $@ + $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -nostartfiles $(CFLAGS) -Wl,-Map=$@.map -o $@ $(OBJS) -Wl,--start-group $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) -Wl,--end-group fel-boot-$(BOARD).bin: fel-boot-$(BOARD).elf $(CROSS_COMPILE)objcopy -O binary $< $@ From c8493720d971ece3849b840cde2c3dc694c04b1e Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 24 May 2013 00:08:24 +0200 Subject: [PATCH 30/41] felboot: Move closer to u-boot build structure, reducing source size even further --- felboot/Makefile | 11 ++++++---- felboot/main.c | 56 ++++++------------------------------------------ 2 files changed, 14 insertions(+), 53 deletions(-) diff --git a/felboot/Makefile b/felboot/Makefile index 150fac3..5644ad4 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -20,11 +20,14 @@ all: fel-boot-$(BOARD).bin UBOOT_OBJS= \ spl/arch/arm/cpu/armv7/sunxi/libsunxi.o \ - spl/arch/arm/cpu/armv7/syslib.o \ + spl/arch/arm/cpu/armv7/libarmv7.o \ + spl/arch/arm/lib/libarm.o \ spl/arch/arm/lib/eabi_compat.o \ spl/drivers/power/libpower.o \ spl/drivers/i2c/libi2c.o \ - spl/common/memsize.o \ + spl/common/libcommon.o \ + spl/common/spl/libspl.o \ + spl/lib/libgeneric.o \ spl/board/sunxi/libsunxi.o .c.o: @@ -35,11 +38,11 @@ OBJS += main.o ifeq ($(NO_PRINTF),1) CFLAGS += -DNO_PRINTF else -OBJS += printf-stdarg.o early_print.o +OBJS += early_print.o endif fel-boot-$(BOARD).elf: $(OBJS) $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) - $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -nostartfiles $(CFLAGS) -Wl,-Map=$@.map -o $@ $(OBJS) -Wl,--start-group $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) -Wl,--end-group + $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -Wl,--gc-sections -nostartfiles -nostdlib $(CFLAGS) -Wl,-Map=$@.map -o $@ $(OBJS) -Wl,--start-group $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) -lgcc -Wl,--end-group fel-boot-$(BOARD).bin: fel-boot-$(BOARD).elf $(CROSS_COMPILE)objcopy -O binary $< $@ diff --git a/felboot/main.c b/felboot/main.c index 4aad36f..a086d33 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -25,34 +25,6 @@ __attribute__ ((section (".text.start"))) void _start(void) s_init(); } -gd_t gdata __attribute__ ((section(".data"))); - -void dcache_enable(void) -{ -} - -void sunxi_wemac_initialize(void) -{ -} - -void preloader_console_init(void) -{ - uart_init(); - puts("\nU-Boot FEL " PLAIN_VERSION " (" U_BOOT_DATE " - " \ - U_BOOT_TIME ")\n"); -} - -void hang(void) -{ - printf("Please reset the board!"); - while(1); -} - -void udelay(unsigned long usec) -{ - __udelay(usec); -} - int sunxi_mmc_init(void) { return -1; @@ -63,7 +35,12 @@ void status_led_set(int led, int state) return; } -#ifndef NO_PRINTF +int serial_init(void) +{ + uart_init(); + return 0; +} + void putchar(int ch) { if (ch == '\n') @@ -71,28 +48,9 @@ void putchar(int ch) uart_putc(ch); } -void puts(const char *str) +void serial_puts(const char *str) { while(*str) putchar(*str++); } -#else -void putchar(int ch) -{ -} - -void puts(const char *str) -{ -} - -int printf(const char *fmt, ...) -{ - return -1; -} - -void uart_init(void) -{ -} - -#endif From 498ffab9d11b9255bc0385b37312cae3e1cc700d Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 24 May 2013 00:14:37 +0200 Subject: [PATCH 31/41] felboot: Use u-boot serial driver --- felboot/Makefile | 7 +- felboot/early_print.c | 65 ---------- felboot/early_print.h | 62 ---------- felboot/main.c | 20 --- felboot/printf-stdarg.c | 266 ---------------------------------------- 5 files changed, 1 insertion(+), 419 deletions(-) delete mode 100644 felboot/early_print.c delete mode 100644 felboot/early_print.h delete mode 100644 felboot/printf-stdarg.c diff --git a/felboot/Makefile b/felboot/Makefile index 5644ad4..91134b3 100644 --- a/felboot/Makefile +++ b/felboot/Makefile @@ -28,6 +28,7 @@ UBOOT_OBJS= \ spl/common/libcommon.o \ spl/common/spl/libspl.o \ spl/lib/libgeneric.o \ + spl/drivers/serial/libserial.o \ spl/board/sunxi/libsunxi.o .c.o: @@ -35,12 +36,6 @@ UBOOT_OBJS= \ OBJS += main.o -ifeq ($(NO_PRINTF),1) -CFLAGS += -DNO_PRINTF -else -OBJS += early_print.o -endif - fel-boot-$(BOARD).elf: $(OBJS) $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -Wl,--gc-sections -nostartfiles -nostdlib $(CFLAGS) -Wl,-Map=$@.map -o $@ $(OBJS) -Wl,--start-group $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) -lgcc -Wl,--end-group diff --git a/felboot/early_print.c b/felboot/early_print.c deleted file mode 100644 index 10b03c7..0000000 --- a/felboot/early_print.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * (C) Copyright 2007-2012 - * Allwinner Technology Co., Ltd. - * Tom Cubie - * - * Early uart print for debugging. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include "config.h" -#include "common.h" -#include "early_print.h" -#include -#include -#include "io.h" - -static int uart_initialized = 0; - -#define UART CONFIG_CONS_INDEX-1 -void uart_init(void) { - - /* select dll dlh */ - writel(0x80, UART_LCR(UART)); - /* set baudrate */ - writel(0, UART_DLH(UART)); - writel(BAUD_115200, UART_DLL(UART)); - /* set line control */ - writel(LC_8_N_1, UART_LCR(UART)); - - uart_initialized = 1; -} - -#define TX_READY (readl(UART_LSR(UART)) & (1 << 6)) - -void uart_putc(char c) { - - while(!TX_READY) - ; - writel(c, UART_THR(UART)); -} - -void uart_puts(const char *s) { - - while(*s) - uart_putc(*s++); -} - - diff --git a/felboot/early_print.h b/felboot/early_print.h deleted file mode 100644 index cbcc6ea..0000000 --- a/felboot/early_print.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * (C) Copyright 2007-2012 - * Allwinner Technology Co., Ltd. - * Tom Cubie - * - * Early uart print for debugging. - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#ifndef _SUNXI_EARLY_PRINT_H -#define _SUNXI_EARLY_PRINT_H - -#define SUNXI_UART_BASE SUNXI_UART0_BASE - -#define UART_RBR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* receive buffer register */ -#define UART_THR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* transmit holding register */ -#define UART_DLL(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* divisor latch low register */ - -#define UART_DLH(n) (SUNXI_UART_BASE + (n)*0x400 + 0x4) /* divisor latch high register */ -#define UART_IER(n) (SUNXI_UART_BASE + (n)*0x400 + 0x4) /* interrupt enable reigster */ - -#define UART_IIR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x8) /* interrupt identity register */ -#define UART_FCR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x8) /* fifo control register */ - -#define UART_LCR(n) (SUNXI_UART_BASE + (n)*0x400 + 0xc) /* line control register */ - -#define UART_LSR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x14) /* line status register */ -#define UART_RBR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* receive buffer register */ -#define UART_THR(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* transmit holding register */ -#define UART_DLL(n) (SUNXI_UART_BASE + (n)*0x400 + 0x0) /* divisor latch low register */ - - -#define BAUD_115200 (0xD) /* 24 * 1000 * 1000 / 16 / 115200 = 13 */ -#define NO_PARITY (0) -#define ONE_STOP_BIT (0) -#define DAT_LEN_8_BITS (3) -#define LC_8_N_1 (NO_PARITY << 3 | ONE_STOP_BIT << 2 | DAT_LEN_8_BITS) - -#ifndef __ASSEMBLY__ -void uart_init(void); -void uart_putc(char c); -void uart_puts(const char *s); -#endif /* __ASSEMBLY__ */ - -#endif /* _SUNXI_EARLY_PRINT_H */ diff --git a/felboot/main.c b/felboot/main.c index a086d33..43d2d4e 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -34,23 +34,3 @@ void status_led_set(int led, int state) { return; } - -int serial_init(void) -{ - uart_init(); - return 0; -} - -void putchar(int ch) -{ - if (ch == '\n') - uart_putc('\r'); - uart_putc(ch); -} - -void serial_puts(const char *str) -{ - while(*str) - putchar(*str++); -} - diff --git a/felboot/printf-stdarg.c b/felboot/printf-stdarg.c deleted file mode 100644 index 72fd2b9..0000000 --- a/felboot/printf-stdarg.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - Copyright 2001, 2002 Georges Menie (www.menie.org) - stdarg version contributed by Christian Ettinger - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -/* - putchar is the only external dependency for this file, - if you have a working putchar, leave it commented out. - If not, uncomment the define below and - replace outbyte(c) by your own function call. - -#define putchar(c) outbyte(c) -*/ - -#include - -static void printchar(char **str, int c) -{ - extern int putchar(int c); - - if (str) { - **str = c; - ++(*str); - } - else (void)putchar(c); -} - -#define PAD_RIGHT 1 -#define PAD_ZERO 2 - -static int prints(char **out, const char *string, int width, int pad) -{ - register int pc = 0, padchar = ' '; - - if (width > 0) { - register int len = 0; - register const char *ptr; - for (ptr = string; *ptr; ++ptr) ++len; - if (len >= width) width = 0; - else width -= len; - if (pad & PAD_ZERO) padchar = '0'; - } - if (!(pad & PAD_RIGHT)) { - for ( ; width > 0; --width) { - printchar (out, padchar); - ++pc; - } - } - for ( ; *string ; ++string) { - printchar (out, *string); - ++pc; - } - for ( ; width > 0; --width) { - printchar (out, padchar); - ++pc; - } - - return pc; -} - -/* the following should be enough for 32 bit int */ -#define PRINT_BUF_LEN 12 - -static int printi(char **out, int i, int b, int sg, int width, int pad, int letbase) -{ - char print_buf[PRINT_BUF_LEN]; - register char *s; - register int t, neg = 0, pc = 0; - register unsigned int u = i; - - if (i == 0) { - print_buf[0] = '0'; - print_buf[1] = '\0'; - return prints (out, print_buf, width, pad); - } - - if (sg && b == 10 && i < 0) { - neg = 1; - u = -i; - } - - s = print_buf + PRINT_BUF_LEN-1; - *s = '\0'; - - while (u) { - t = u % b; - if( t >= 10 ) - t += letbase - '0' - 10; - *--s = t + '0'; - u /= b; - } - - if (neg) { - if( width && (pad & PAD_ZERO) ) { - printchar (out, '-'); - ++pc; - --width; - } - else { - *--s = '-'; - } - } - - return pc + prints (out, s, width, pad); -} - -static int print(char **out, const char *format, va_list args ) -{ - register int width, pad; - register int pc = 0; - char scr[2]; - - for (; *format != 0; ++format) { - if (*format == '%') { - ++format; - width = pad = 0; - if (*format == '\0') break; - if (*format == '%') goto out; - if (*format == '-') { - ++format; - pad = PAD_RIGHT; - } - while (*format == '0') { - ++format; - pad |= PAD_ZERO; - } - for ( ; *format >= '0' && *format <= '9'; ++format) { - width *= 10; - width += *format - '0'; - } - if( *format == 's' ) { - register char *s = (char *)va_arg( args, int ); - pc += prints (out, s?s:"(null)", width, pad); - continue; - } - if( *format == 'd' ) { - pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a'); - continue; - } - if( *format == 'x' ) { - pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a'); - continue; - } - if( *format == 'X' ) { - pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A'); - continue; - } - if( *format == 'u' ) { - pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a'); - continue; - } - if( *format == 'c' ) { - /* char are converted to int then pushed on the stack */ - scr[0] = (char)va_arg( args, int ); - scr[1] = '\0'; - pc += prints (out, scr, width, pad); - continue; - } - } - else { - out: - printchar (out, *format); - ++pc; - } - } - if (out) **out = '\0'; - va_end( args ); - return pc; -} - -int printf(const char *format, ...) -{ - va_list args; - - va_start( args, format ); - return print( 0, format, args ); -} - -int sprintf(char *out, const char *format, ...) -{ - va_list args; - - va_start( args, format ); - return print( &out, format, args ); -} - -#ifdef TEST_PRINTF -int main(void) -{ - char *ptr = "Hello world!"; - char *np = 0; - int i = 5; - unsigned int bs = sizeof(int)*8; - int mi; - char buf[80]; - - mi = (1 << (bs-1)) + 1; - printf("%s\n", ptr); - printf("printf test\n"); - printf("%s is null pointer\n", np); - printf("%d = 5\n", i); - printf("%d = - max int\n", mi); - printf("char %c = 'a'\n", 'a'); - printf("hex %x = ff\n", 0xff); - printf("hex %02x = 00\n", 0); - printf("signed %d = unsigned %u = hex %x\n", -3, -3, -3); - printf("%d %s(s)%", 0, "message"); - printf("\n"); - printf("%d %s(s) with %%\n", 0, "message"); - sprintf(buf, "justif: \"%-10s\"\n", "left"); printf("%s", buf); - sprintf(buf, "justif: \"%10s\"\n", "right"); printf("%s", buf); - sprintf(buf, " 3: %04d zero padded\n", 3); printf("%s", buf); - sprintf(buf, " 3: %-4d left justif.\n", 3); printf("%s", buf); - sprintf(buf, " 3: %4d right justif.\n", 3); printf("%s", buf); - sprintf(buf, "-3: %04d zero padded\n", -3); printf("%s", buf); - sprintf(buf, "-3: %-4d left justif.\n", -3); printf("%s", buf); - sprintf(buf, "-3: %4d right justif.\n", -3); printf("%s", buf); - - return 0; -} - -/* - * if you compile this file with - * gcc -Wall $(YOUR_C_OPTIONS) -DTEST_PRINTF -c printf.c - * you will get a normal warning: - * printf.c:214: warning: spurious trailing `%' in format - * this line is testing an invalid % at the end of the format string. - * - * this should display (on 32bit int machine) : - * - * Hello world! - * printf test - * (null) is null pointer - * 5 = 5 - * -2147483647 = - max int - * char a = 'a' - * hex ff = ff - * hex 00 = 00 - * signed -3 = unsigned 4294967293 = hex fffffffd - * 0 message(s) - * 0 message(s) with % - * justif: "left " - * justif: " right" - * 3: 0003 zero padded - * 3: 3 left justif. - * 3: 3 right justif. - * -3: -003 zero padded - * -3: -3 left justif. - * -3: -3 right justif. - */ - -#endif From fa8e86bb2a8948efc66ab370fd0d3ca90144fca4 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 24 May 2013 00:25:11 +0200 Subject: [PATCH 32/41] felboot: Update documentation slightly --- felboot/README.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/felboot/README.txt b/felboot/README.txt index b9a73cd..00eaea0 100644 --- a/felboot/README.txt +++ b/felboot/README.txt @@ -5,11 +5,13 @@ fel exe 0x2000 fel write 0x4a000000 u-boot.bin fel exe 0x4a000000 -optionally load kernel + initramfs before fel exe of u-boot +optionally load kernel + initramfs before fel exe of u-boot. The default +environmen looks for a boot script @0x41000000 and sources this if found. fel write 0x2000 fel-boot.bin fel exe 0x2000 fel write 0x4a000000 u-boot.bin +fel write 0x41000000 ramboot.scr fel write 0x43000000 ../script.bin fel write 0x44000000 ../uImage fel write 0x4c000000 ../initramfs.img @@ -28,9 +30,6 @@ Build instructions: make BOARD=cubieboard CROSS_COMPILE=arm-linux-gnueabihf- UBOOT=~/SRC/u-boot/ UBOOTOBJ=~/SRC/u-boot/build/'$(BOARD)'/ -Other options - NO_PRINTF=1 Disable printf, reducing the code size a bit - Defaults: # Target board name. This should match the dram_.c in @@ -38,10 +37,10 @@ Defaults: BOARD=eoma68 # Path to your tool chain -CROSS_COMPILE=ikk/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- +CROSS_COMPILE=$(HOME)/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- # U-boot main source path -UBOOT=/home/henrik/SRC/u-boot/ +UBOOT=$(HOME)/SRC/u-boot/ # U-boot object path (O=... when building u-boot). UBOOTOBJ=$(UBOOT)build/$(BOARD)/ From c749f83060d06ec2e29d78c241b3bb2ffebac707 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 24 May 2013 00:30:24 +0200 Subject: [PATCH 33/41] felboot: Reduce to only a linkerscript + stubs to compensate for general SPL config The stubs is only needed because we are using objects from a full SPL build. Even these will go away when felboot is integrated in u-boot, reducing it to only a link script and config changes. --- felboot/fel-boot.ld | 4 ++-- felboot/main.c | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/felboot/fel-boot.ld b/felboot/fel-boot.ld index cf1419f..cf02300 100644 --- a/felboot/fel-boot.ld +++ b/felboot/fel-boot.ld @@ -1,13 +1,13 @@ OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm) -ENTRY(_start) +ENTRY(s_init) SECTIONS { . = 0x00002000; . = ALIGN(4); .text : { - main.o (.text.start) + *(.text.s_init) *(.text*) } . = ALIGN(4); diff --git a/felboot/main.c b/felboot/main.c index 43d2d4e..fb3256a 100644 --- a/felboot/main.c +++ b/felboot/main.c @@ -18,12 +18,6 @@ */ #include -#include - -__attribute__ ((section (".text.start"))) void _start(void) -{ - s_init(); -} int sunxi_mmc_init(void) { From 68a4f6f2312d52ca4a2a6cb378681f439c60d44d Mon Sep 17 00:00:00 2001 From: Bartosz J Date: Tue, 26 Mar 2013 13:02:38 +0100 Subject: [PATCH 34/41] fexc: accept negative values in .fex files closes #16 --- script_fex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script_fex.c b/script_fex.c index 50e8d2b..361e86b 100644 --- a/script_fex.c +++ b/script_fex.c @@ -326,7 +326,7 @@ int script_parse_fex(FILE *in, const char *filename, struct script *script) perror("malloc"); } } - } else if (isdigit(*p)) { + } else if (isdigit(*p) || (*p == '-' && isdigit(*(p+1)))) { long long v = 0; char *end; v = strtoll(p, &end, 0); From 3fb12ad20b15574ac2f2a38f63106950f55ccefc Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 27 May 2013 19:56:18 +0200 Subject: [PATCH 35/41] usb-boot: fix small typo Signed-off-by: Alejandro Mery --- usb-boot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usb-boot b/usb-boot index 990091f..ff1ca23 100755 --- a/usb-boot +++ b/usb-boot @@ -6,7 +6,7 @@ if [ $# -lt 2 ]; then fi board=$1; shift || (echo "ERROR: Board must be specified"; exit 1;) uboot=$1; shift || (echo "ERROR: u-boot.bin must be specified"; exit 1;) -bootscr=$tob/felboot/ramboot.scr +bootscr=$top/felboot/ramboot.scr if [ ! -f $bootscr ]; then bootscr=$top/bin/ramboot.scr fi From 0be7b52c530d3d849410c856dff3a3474c1e9013 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Fri, 31 May 2013 23:28:59 +0200 Subject: [PATCH 36/41] felboot have been fully merged into sunxi u-boot --- README | 6 +- felboot/Makefile | 46 -------------- felboot/README.txt | 46 -------------- felboot/cpu.h | 145 -------------------------------------------- felboot/fel-boot.ld | 59 ------------------ felboot/io.h | 20 ------ felboot/main.c | 30 --------- felboot/ramboot.cmd | 7 --- felboot/u-boot.sh | 5 -- felboot/usb-boot.sh | 8 --- 10 files changed, 2 insertions(+), 370 deletions(-) delete mode 100644 felboot/Makefile delete mode 100644 felboot/README.txt delete mode 100644 felboot/cpu.h delete mode 100644 felboot/fel-boot.ld delete mode 100644 felboot/io.h delete mode 100644 felboot/main.c delete mode 100644 felboot/ramboot.cmd delete mode 100755 felboot/u-boot.sh delete mode 100755 felboot/usb-boot.sh diff --git a/README b/README index 68b997f..506930f 100644 --- a/README +++ b/README @@ -27,15 +27,13 @@ fel: button at poweron. usb-boot: - Simple wrapper around felboot and fel to automate USB booting in FEL mode + Simple wrapper to automate USB booting in FEL mode + See http://linux-sunxi.org/FEL/USBBoot for details fel-gpio: Simple wrapper around fel-pio and fel to allos GPIO manipulations via FEL -felboot: - ARM native board initialization for FEL mode - fel-sdboot: ARM native sdcard bootloader forcing the device into FEL mode diff --git a/felboot/Makefile b/felboot/Makefile deleted file mode 100644 index 91134b3..0000000 --- a/felboot/Makefile +++ /dev/null @@ -1,46 +0,0 @@ - -CC=gcc - -# Target board name. This should match the dram_.c in -# u-boot/board/sunxi/ -BOARD=cubieboard - -# Path/prefix of your tool chain -CROSS_COMPILE=arm-linux-gnueabihf- - -# U-boot main source path -UBOOT=$(HOME)/SRC/u-boot/ - -# U-boot object path (O=... when building u-boot). -UBOOTOBJ=$(UBOOT)build/$(BOARD)/ - -CFLAGS=-g -O2 -marm -mno-thumb-interwork -mabi=aapcs-linux -march=armv7-a -fno-common -fno-builtin -ffreestanding -ffixed-r8 -msoft-float -D__KERNEL__ -I$(UBOOTOBJ)include2 -I$(UBOOTOBJ)include -I$(UBOOT)include - -all: fel-boot-$(BOARD).bin - -UBOOT_OBJS= \ - spl/arch/arm/cpu/armv7/sunxi/libsunxi.o \ - spl/arch/arm/cpu/armv7/libarmv7.o \ - spl/arch/arm/lib/libarm.o \ - spl/arch/arm/lib/eabi_compat.o \ - spl/drivers/power/libpower.o \ - spl/drivers/i2c/libi2c.o \ - spl/common/libcommon.o \ - spl/common/spl/libspl.o \ - spl/lib/libgeneric.o \ - spl/drivers/serial/libserial.o \ - spl/board/sunxi/libsunxi.o - -.c.o: - $(CROSS_COMPILE)$(CC) -c $(CFLAGS) $< -o $@ - -OBJS += main.o - -fel-boot-$(BOARD).elf: $(OBJS) $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) - $(CROSS_COMPILE)$(CC) -Tfel-boot.ld -static -Wl,--gc-sections -nostartfiles -nostdlib $(CFLAGS) -Wl,-Map=$@.map -o $@ $(OBJS) -Wl,--start-group $(addprefix $(UBOOTOBJ),$(UBOOT_OBJS)) -lgcc -Wl,--end-group - -fel-boot-$(BOARD).bin: fel-boot-$(BOARD).elf - $(CROSS_COMPILE)objcopy -O binary $< $@ - -clean: - rm -f *.o *.map *.elf diff --git a/felboot/README.txt b/felboot/README.txt deleted file mode 100644 index 00eaea0..0000000 --- a/felboot/README.txt +++ /dev/null @@ -1,46 +0,0 @@ -fel-boot.bin is a FEL bootstrap program. - -fel write 0x2000 fel-boot.bin -fel exe 0x2000 -fel write 0x4a000000 u-boot.bin -fel exe 0x4a000000 - -optionally load kernel + initramfs before fel exe of u-boot. The default -environmen looks for a boot script @0x41000000 and sources this if found. - -fel write 0x2000 fel-boot.bin -fel exe 0x2000 -fel write 0x4a000000 u-boot.bin -fel write 0x41000000 ramboot.scr -fel write 0x43000000 ../script.bin -fel write 0x44000000 ../uImage -fel write 0x4c000000 ../initramfs.img -fel exe 0x4a000000 - -Build instructions: - -0. You need to build u-boot sunxi-current SPL first for the your board. - -1. Specify needed configuration when when running make - - BOARD= boardname - CROSS_COMPILE= compiler prefix - UBOOT= u-boot sources - UBOOTOBJ= u-boot built tree - -make BOARD=cubieboard CROSS_COMPILE=arm-linux-gnueabihf- UBOOT=~/SRC/u-boot/ UBOOTOBJ=~/SRC/u-boot/build/'$(BOARD)'/ - -Defaults: - -# Target board name. This should match the dram_.c in -# u-boot/board/sunxi/ -BOARD=eoma68 - -# Path to your tool chain -CROSS_COMPILE=$(HOME)/toolchains/arm-linux-gnueabihf/bin/arm-linux-gnueabihf- - -# U-boot main source path -UBOOT=$(HOME)/SRC/u-boot/ - -# U-boot object path (O=... when building u-boot). -UBOOTOBJ=$(UBOOT)build/$(BOARD)/ diff --git a/felboot/cpu.h b/felboot/cpu.h deleted file mode 100644 index b73e164..0000000 --- a/felboot/cpu.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * (C) Copyright 2007-2011 - * Allwinner Technology Co., Ltd. - * Tom Cubie - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#ifndef _SUNXI_CPU_H -#define _SUNXI_CPU_H - -#define SUNXI_SRAM_A1_BASE 0X00000000 -#define SUNXI_SRAM_A1_SIZE (16 * 1024) /* 16k */ - -#define SUNXI_SRAM_A2_BASE 0X00004000 /* 16k */ -#define SUNXI_SRAM_A3_BASE 0X00008000 /* 13k */ -#define SUNXI_SRAM_A4_BASE 0X0000B400 /* 3k */ -#if 0 -#define SUNXI_SRAM_NAND_BASE 0Xdeaddead /* 2k(address not available on spec) */ -#endif -#define SUNXI_SRAM_D_BASE 0X01C00000 -#define SUNXI_SRAM_B_BASE 0X01C00000 /* 64k(secure) */ - -#define SUNXI_SRAMC_BASE 0X01C00000 -#define SUNXI_DRAMC_BASE 0X01C01000 -#define SUNXI_DMA_BASE 0X01C02000 -#define SUNXI_NFC_BASE 0X01C03000 -#define SUNXI_TS_BASE 0X01C04000 -#define SUNXI_SPI0_BASE 0X01C05000 -#define SUNXI_SPI1_BASE 0X01C06000 -#define SUNXI_MS_BASE 0X01C07000 -#define SUNXI_TVD_BASE 0X01C08000 -#define SUNXI_CSI0_BASE 0X01C09000 -#define SUNXI_TVE0_BASE 0X01C0A000 -#define SUNXI_EMAC_BASE 0X01C0B000 -#define SUNXI_LCD0_BASE 0X01C0C000 -#define SUNXI_LCD1_BASE 0X01C0D000 -#define SUNXI_VE_BASE 0X01C0E000 -#define SUNXI_MMC0_BASE 0X01C0F000 -#define SUNXI_MMC1_BASE 0X01C10000 -#define SUNXI_MMC2_BASE 0X01C11000 -#define SUNXI_MMC3_BASE 0X01C12000 -#define SUNXI_USB0_BASE 0X01C13000 -#define SUNXI_USB1_BASE 0X01C14000 -#define SUNXI_SS_BASE 0X01C15000 -#define SUNXI_HDMI_BASE 0X01C16000 -#define SUNXI_SPI2_BASE 0X01C17000 -#define SUNXI_SATA_BASE 0X01C18000 -#define SUNXI_PATA_BASE 0X01C19000 -#define SUNXI_ACE_BASE 0X01C1A000 -#define SUNXI_TVE1_BASE 0X01C1B000 -#define SUNXI_USB2_BASE 0X01C1C000 -#define SUNXI_CSI1_BASE 0X01C1D000 -#define SUNXI_TZASC_BASE 0X01C1E000 -#define SUNXI_SPI3_BASE 0X01C1F000 - -#define SUNXI_CCM_BASE 0X01C20000 -#define SUNXI_INTC_BASE 0X01C20400 -#define SUNXI_PIO_BASE 0X01C20800 -#define SUNXI_TIMER_BASE 0X01C20C00 -#define SUNXI_SPDIF_BASE 0X01C21000 -#define SUNXI_AC97_BASE 0X01C21400 -#define SUNXI_IR0_BASE 0X01C21800 -#define SUNXI_IR1_BASE 0X01C21C00 - -#define SUNXI_IIS_BASE 0X01C22400 -#define SUNXI_LRADC_BASE 0X01C22800 -#define SUNXI_AD_DA_BASE 0X01C22C00 -#define SUNXI_KEYPAD_BASE 0X01C23000 -#define SUNXI_TZPC_BASE 0X01C23400 -#define SUNXI_SID_BASE 0X01C23800 -#define SUNXI_SJTAG_BASE 0X01C23C00 - -#define SUNXI_TP_BASE 0X01C25000 -#define SUNXI_PMU_BASE 0X01C25400 - -#define SUNXI_UART0_BASE 0X01C28000 -#define SUNXI_UART1_BASE 0X01C28400 -#define SUNXI_UART2_BASE 0X01C28800 -#define SUNXI_UART3_BASE 0X01C28C00 -#define SUNXI_UART4_BASE 0X01C29000 -#define SUNXI_UART5_BASE 0X01C29400 -#define SUNXI_UART6_BASE 0X01C29800 -#define SUNXI_UART7_BASE 0X01C29C00 -#define SUNXI_PS2_0_BASE 0X01C2A000 -#define SUNXI_PS2_1_BASE 0X01C2A400 - -#define SUNXI_TWI0_BASE 0X01C2AC00 -#define SUNXI_TWI1_BASE 0X01C2B000 -#define SUNXI_TWI2_BASE 0X01C2B400 - -#define SUNXI_CAN_BASE 0X01C2BC00 - -#define SUNXI_SCR_BASE 0X01C2C400 - -#define SUNXI_GPS_BASE 0X01C30000 -#define SUNXI_MALI400_BASE 0X01C40000 - -#define SUNXI_SRAM_C_BASE 0X01D00000 /* module sram */ - -#define SUNXI_DE_FE0_BASE 0X01E00000 -#define SUNXI_DE_FE1_BASE 0X01E20000 -#define SUNXI_DE_BE0_BASE 0X01E60000 -#define SUNXI_DE_BE1_BASE 0X01E40000 -#define SUNXI_MP_BASE 0X01E80000 -#define SUNXI_AVG_BASE 0X01EA0000 - -#define SUNXI_CSDM_BASE 0X3F500000 /* CoreSight Debug Module*/ - -#define SUNXI_DDRII_DDRIII_BASE 0X40000000 /* 2G */ - -#define SUNXI_BROM_BASE 0XFFFF0000 /* 32K */ - -#define SUNXI_CPU_CFG (SUNXI_TIMER_BASE + 0x13c) - -#ifndef __ASSEMBLY__ -/* boot type */ -typedef enum { - SUNXI_BOOT_TYPE_NULL, - SUNXI_BOOT_TYPE_MMC0, - SUNXI_BOOT_TYPE_NAND, - SUNXI_BOOT_TYPE_MMC2, - SUNXI_BOOT_TYPE_SPI -} sunxi_boot_type_t; - -sunxi_boot_type_t get_boot_type(void); -#endif /* __ASSEMBLY__ */ - -#endif /* _CPU_H */ diff --git a/felboot/fel-boot.ld b/felboot/fel-boot.ld deleted file mode 100644 index cf02300..0000000 --- a/felboot/fel-boot.ld +++ /dev/null @@ -1,59 +0,0 @@ -OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") -OUTPUT_ARCH(arm) -ENTRY(s_init) -SECTIONS -{ - . = 0x00002000; - . = ALIGN(4); - .text : - { - *(.text.s_init) - *(.text*) - } - . = ALIGN(4); - .rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) } - . = ALIGN(4); - .data : { - *(.data*) - } - . = ALIGN(4); - . = .; - . = ALIGN(4); - .rel.dyn : { - __rel_dyn_start = .; - *(.rel*) - __rel_dyn_end = .; - } - .dynsym : { - __dynsym_start = .; - *(.dynsym) - } - . = ALIGN(4); - .note.gnu.build-id : - { - *(.note.gnu.build-id) - } - _end = .; - . = ALIGN(4096); - .mmutable : { - *(.mmutable) - } - .bss_start __rel_dyn_start (OVERLAY) : { - KEEP(*(.__bss_start)); - __bss_base = .; - } - .bss __bss_base (OVERLAY) : { - *(.bss*) - . = ALIGN(4); - __bss_limit = .; - } - .bss_end __bss_limit (OVERLAY) : { - KEEP(*(.__bss_end)); - } - /DISCARD/ : { *(.dynstr*) } - /DISCARD/ : { *(.dynamic*) } - /DISCARD/ : { *(.plt*) } - /DISCARD/ : { *(.interp*) } - /DISCARD/ : { *(.gnu*) } - /DISCARD/ : { *(.note*) } -} diff --git a/felboot/io.h b/felboot/io.h deleted file mode 100644 index bfa3e9e..0000000 --- a/felboot/io.h +++ /dev/null @@ -1,20 +0,0 @@ -#define __arch_getb(a) (*(volatile unsigned char *)(a)) -#define __arch_getw(a) (*(volatile unsigned short *)(a)) -#define __arch_getl(a) (*(volatile unsigned int *)(a)) - -#define __arch_putb(v,a) (*(volatile unsigned char *)(a) = (v)) -#define __arch_putw(v,a) (*(volatile unsigned short *)(a) = (v)) -#define __arch_putl(v,a) (*(volatile unsigned int *)(a) = (v)) - - -#define dmb() __asm__ __volatile__ ("" : : : "memory") -#define __iormb() dmb() -#define __iowmb() dmb() - -#define writeb(v,c) ({ u8 __v = v; __iowmb(); __arch_putb(__v,c); __v; }) -#define writew(v,c) ({ u16 __v = v; __iowmb(); __arch_putw(__v,c); __v; }) -#define writel(v,c) ({ u32 __v = v; __iowmb(); __arch_putl(__v,c); __v; }) - -#define readb(c) ({ u8 __v = __arch_getb(c); __iormb(); __v; }) -#define readw(c) ({ u16 __v = __arch_getw(c); __iormb(); __v; }) -#define readl(c) ({ u32 __v = __arch_getl(c); __iormb(); __v; }) diff --git a/felboot/main.c b/felboot/main.c deleted file mode 100644 index fb3256a..0000000 --- a/felboot/main.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * (C) Copyright 2013 Henrik Nordstrom - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA - */ - -#include - -int sunxi_mmc_init(void) -{ - return -1; -} - -void status_led_set(int led, int state) -{ - return; -} diff --git a/felboot/ramboot.cmd b/felboot/ramboot.cmd deleted file mode 100644 index 72e13aa..0000000 --- a/felboot/ramboot.cmd +++ /dev/null @@ -1,7 +0,0 @@ -# U-boot RAM boot script -ramdisk= -if iminfo 0x4c000000; then - ramdisk=0x4c000000 -fi -setenv bootargs console=ttyS0,115200 rdinit=/sbin/init panic=10 -bootm 0x44000000 $ramdisk diff --git a/felboot/u-boot.sh b/felboot/u-boot.sh deleted file mode 100755 index 1a7bd97..0000000 --- a/felboot/u-boot.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -ex -fel write 0x2000 fel-boot-${1}.bin -fel exe 0x2000 -fel write 0x4a000000 ../u-boot.bin -fel exe 0x4a000000 diff --git a/felboot/usb-boot.sh b/felboot/usb-boot.sh deleted file mode 100755 index edd99a7..0000000 --- a/felboot/usb-boot.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -ex -fel write 0x2000 fel-boot-${1}.bin -fel exe 0x2000 -fel write 0x4a000000 ../u-boot.bin -fel write 0x43000000 ../script.bin -fel write 0x44000000 ../uImage -fel write 0x4c000000 ../initramfs.img -fel exe 0x4a000000 From d31d4a4ec225a50c113b2bc2227b4436736e08a7 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Sat, 1 Jun 2013 18:07:09 +0200 Subject: [PATCH 37/41] fel: More verbose error output if USB device not found --- fel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fel.c b/fel.c index 6da47c5..a5212be 100644 --- a/fel.c +++ b/fel.c @@ -298,7 +298,7 @@ int main(int argc, char **argv) handle = libusb_open_device_with_vid_pid(NULL, 0x1f3a, 0xefe8); if (!handle) { - fprintf(stderr, "A10 USB FEL device not found!"); + fprintf(stderr, "ERROR: Allwinner USB FEL device not found!\n"); exit(1); } rc = libusb_claim_interface(handle, 0); From fff571988e8139ea695725dc9f84793af8fca68c Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Mon, 10 Jun 2013 01:35:05 +0200 Subject: [PATCH 38/41] usb-boot: Support speficying the fel boot image by full path --- usb-boot | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/usb-boot b/usb-boot index ff1ca23..a999236 100755 --- a/usb-boot +++ b/usb-boot @@ -21,10 +21,16 @@ fel() { echo fel "$@" $top/fel $@ } -felboot=$top/felboot/fel-boot-${board}.bin -if [ ! -f $felboot ]; then - felboot=$top/bin/fel-boot-${board}.bin -fi +case $board in +*/*) felboot=$board + ;; +*) + felboot=$top/felboot/fel-boot-${board}.bin + if [ ! -f $felboot ]; then + felboot=$top/bin/fel-boot-${board}.bin + fi + ;; +esac if [ ! -f $felboot ]; then echo "ERROR: Can't find fel-boot binary for ${board}" exit 1 From ee4e95e7b1299885bb4dbd67d40c906b2e68fc74 Mon Sep 17 00:00:00 2001 From: Henrik Nordstrom Date: Sun, 23 Jun 2013 15:04:56 +0200 Subject: [PATCH 39/41] Teach fel about A20 SoC ID (for fel ver) --- fel.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fel.c b/fel.c index a5212be..10720ce 100644 --- a/fel.c +++ b/fel.c @@ -163,6 +163,7 @@ void aw_fel_get_version(libusb_device_handle *usb) case 0x1623: soc_name="A10";break; case 0x1625: soc_name="A13";break; case 0x1633: soc_name="A31";break; + case 0x1651: soc_name="A20";break; } printf("%.8s soc=%08x(%s) %08x ver=%04x %02x %02x scratchpad=%08x %08x %08x\n", buf.signature, buf.soc_id, soc_name, buf.unknown_0a, buf.protocol, buf.unknown_12, buf.unknown_13, buf.scratchpad, buf.pad[0], buf.pad[1]); From f1eca9d438a6a54bf31fa60c09d968d02857f75f Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Mon, 24 Jun 2013 14:08:04 +0000 Subject: [PATCH 40/41] nand-part: Add mbr parsing diagnostics. Signed-off-by: Michal Suchanek Signed-off-by: Henrik Nordstrom --- nand-part.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nand-part.c b/nand-part.c index 5b046fe..dde5e01 100644 --- a/nand-part.c +++ b/nand-part.c @@ -55,6 +55,8 @@ #define MAX_NAME 16 +void printmbrheader(MBR *mbr); + typedef struct tag_CRC32_DATA { __u32 CRC; //int的大小是32位 @@ -109,6 +111,7 @@ MBR *_get_mbr(int fd, int mbr_num) { /*checksum*/ printf("check partition table copy %d: ", mbr_num); + printmbrheader(mbr); if(*(__u32 *)mbr == calc_crc32((__u32 *)mbr + 1,MBR_SIZE - 4)) { printf("OK\n"); @@ -130,9 +133,16 @@ __s32 _free_mbr(MBR *mbr) return 0; } +void printmbrheader(MBR *mbr) +{ + printf("mbr: version 0x%08x, magic %8.8s\n", mbr->version, mbr->magic); +} + void printmbr(MBR *mbr) { int part_cnt; + + printmbrheader(mbr); for(part_cnt = 0; part_cnt < mbr->PartCount && part_cnt < MAX_PART_COUNT; part_cnt++) { if(1 || (mbr->array[part_cnt].user_type == 2) || (mbr->array[part_cnt].user_type == 0)) From c66667ff5276101f9ec1d9e77093af3ae1f5015c Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Mon, 24 Jun 2013 14:20:51 +0000 Subject: [PATCH 41/41] nand-part: Reject wrong partition version. Signed-off-by: Michal Suchanek Signed-off-by: Henrik Nordstrom --- nand-part.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/nand-part.c b/nand-part.c index dde5e01..3bd5138 100644 --- a/nand-part.c +++ b/nand-part.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include /* BLKRRPART */ #include "nand-part.h" @@ -96,6 +97,8 @@ __u32 calc_crc32(void * buffer, __u32 length) MBR *_get_mbr(int fd, int mbr_num) { MBR *mbr; + const char * magic = "softw311"; + unsigned version = 0x100; /*request mbr space*/ mbr = malloc(sizeof(MBR)); @@ -112,6 +115,16 @@ MBR *_get_mbr(int fd, int mbr_num) /*checksum*/ printf("check partition table copy %d: ", mbr_num); printmbrheader(mbr); + if(strncmp((char *)mbr->magic, magic, 8)) + { + printf("magic %8.8s is not %8s\n", mbr->magic, magic); + return NULL; + } + if(mbr->version != version) + { + printf("version 0x%08x is not 0x%08x\n", mbr->version, version); + return NULL; + } if(*(__u32 *)mbr == calc_crc32((__u32 *)mbr + 1,MBR_SIZE - 4)) { printf("OK\n");