forked from uli/allwinner-bare-metal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.sh
executable file
·145 lines (116 loc) · 5.56 KB
/
configure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# configurable parameters
test -n "$STACK_PROT" && STACK_PROT_FLAGS="-fstack-protector-strong"
test -n "$UBSAN" && UBSAN_FLAGS="-fsanitize=object-size -fsanitize=null -fsanitize=bounds -fsanitize=alignment -fsanitize-address-use-after-scope"
test -n "$UBSAN_FULL" && UBSAN_FLAGS="-fsanitize=undefined -fno-sanitize=float-cast-overflow -fno-sanitize=pointer-overflow -fno-sanitize=vptr -fsanitize=bounds-strict"
test "$GDBSTUB" == "on" && GDB=1 || GDB=0
test "$LIBH3_MMC" == "off" && LIBH3_MMC=0 || LIBH3_MMC=1
test -z "$OSDIR" && OSDIR=`pwd`
test -z "$LIBH3DIR" && LIBH3DIR=$OSDIR/lib-h3
test -z "$LWIPDIR" && LWIPDIR=$OSDIR/lwip/src
test -z "$SYSROOT" && SYSROOT=~/x-tools/arm-unknown-eabihf/arm-unknown-eabihf
test -z "$CROSS_COMPILE" && CROSS_COMPILE=~/x-tools/arm-unknown-eabihf/bin/arm-unknown-eabihf-
test -z "$OBJDIR" && OBJDIR=$OSDIR/build
test "$LIBH3_MMC" == 1 && LIBH3_MMC_FLAGS="-DLIBH3_MMC -DSD_WRITE_SUPPORT"
test "$GDB" == 1 && GDB_FLAGS="-DGDB"
OPT_FLAGS="$STACK_PROT_FLAGS $UBSAN_FLAGS $GDB_FLAGS $LIBH3_MMC_FLAGS"
test -z "$MAKE" && MAKE=make
test -z "$CC" && CC=${CROSS_COMPILE}gcc
test -z "$CXX" && CXX=${CROSS_COMPILE}g++
test -z "$OBJCOPY" && OBJCOPY=${CROSS_COMPILE}objcopy
test -z "$AR" && AR=${CROSS_COMPILE}ar
test -e build.ninja && ninja -t clean
if [[ "$CC" == *clang* ]]; then
CC="$CC -target arm-none-eabihf --sysroot $SYSROOT"
COMPILER_LDFLAGS="`find $SYSROOT/.. -name libgcc.a` -L $SYSROOT/lib"
COMPILER_CFLAGS="-fno-delete-null-pointer-checks"
else
COMPILER_LDFLAGS="-lgcc"
fi
[[ "$CXX" == *clang++* ]] && CXX="$CXX -target arm-none-eabihf --sysroot $SYSROOT"
cat <<EOT >build.ninja.common
aw_cc = $CC
aw_cxx = $CXX
aw_common_flags = -g -O2 -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 -ffreestanding \$
-DREENTRANT_SYSCALLS_PROVIDED -D__DYNAMIC_REENT__ -DALLWINNER_BARE_METAL \$
-I $LIBH3DIR/lib-h3/include -I $LIBH3DIR/lib-arm/include -I $LIBH3DIR/lib-hal/include -DORANGE_PI_ONE \$
-I $LWIPDIR/include $OPT_FLAGS
aw_cflags = \$aw_common_flags -Wall -Wextra -I $OSDIR -I $OSDIR/tinyusb/src
aw_cxxflags = \$aw_common_flags -nostdlib -Wall -Wextra -I $OSDIR -I $OSDIR/tinyusb/src
aw_ldflags = -T $OSDIR/linker.ld -nostdlib
aw_sysroot = $SYSROOT
rule cc
depfile = \$out.d
command = $CC -MD -MF \$out.d \$aw_cflags \$cflags -c \$in -o \$out
rule cxx
depfile = \$out.d
command = $CXX -MD -MF \$out.d \$aw_cxxflags \$cxxflags -c \$in -o \$out
rule link
command = $CC \$aw_cflags \$cflags \$aw_ldflags -o \$out \$in -Wl,--wrap,__stack_chk_fail -Wl,-wrap,__malloc_lock -Wl,-wrap,__malloc_unlock -lc \$
-L$OSDIR -L$LIBH3DIR/lib-h3/lib_h3 -L$LIBH3DIR/lib-arm/lib_h3 \$libs -los -lh3 -larm -lc -lm $COMPILER_LDFLAGS
rule bin
command = $OBJCOPY -O binary --remove-section .uncached \$in \$out
rule uimg
command = mkimage -A arm -O u-boot -T firmware -d \$in \$out -C none -a 0x40000000
rule sdimg
command = dd if=/dev/zero of=\$out.fs bs=1M count=60 ; \$
mkfs.vfat -F 32 \$out.fs ; \$
dd if=/dev/zero of="\$out" bs=1M count=4 ; \$
cat \$out.fs >>"\$out" ; \$
rm -f \$out.fs ; \$
parted -s "\$out" mklabel msdos ; \$
parted -s "\$out" mkpart primary fat32 4 67 ; \$
dd if=$OSDIR/sunxi-spl.bin of="\$out" conv=notrunc bs=1024 seek=8 ; \$
dd if="\$in" of="\$out" conv=notrunc bs=1024 seek=40 ; \$
test -e "\$initfs_dir" && mcopy -s -i \${out}@@4M \$initfs_dir/* ::
rule upload
command = for i in 1 2 3 4 5 ; do sudo sunxi-fel -v -p spl $OSDIR/sunxi-spl.bin write 0x40000000 \$
\$in exe 0x40000000 && break ; sleep .5 ; done
pool = console
EOT
# convert LWIP file list from make to shell format
tr '()\t' '{} ' <$LWIPDIR/Filelists.mk |grep -v '#'|grep -v '^$'|sed 's, ,\\ ,g' >lwip.files
. lwip.files
rm lwip.files
SOURCES="boot.S startup.c uart.c ports.c mmu.c system.c display.c interrupts.c \
usb.c fs.c audio_hdmi.c audio_i2s.c exceptions.c cache.S display_filter.c \
dma.c rtc.c smp.c spinlock.c ubsan.c tve.c \
tinyusb/src/host/ohci/ohci1.c tinyusb/src/host/ohci/ohci2.c tinyusb/src/host/ohci/ohci3.c\
tinyusb/src/host/usbh1.c tinyusb/src/host/usbh2.c tinyusb/src/host/usbh3.c \
tinyusb/src/host/hub1.c tinyusb/src/host/hub2.c tinyusb/src/host/hub3.c \
tinyusb/src/class/hid/hid_host1.c tinyusb/src/class/hid/hid_host2.c tinyusb/src/class/hid/hid_host3.c \
tinyusb/src/common/tusb_fifo.c \
tinyusb/src/tusb1.c tinyusb/src/tusb2.c tinyusb/src/tusb3.c \
tinyusb/src/class/msc/msc_host1.c tinyusb/src/class/msc/msc_host2.c tinyusb/src/class/msc/msc_host3.c \
tinyusb/lib/fatfs/diskio1.c tinyusb/lib/fatfs/diskio2.c tinyusb/lib/fatfs/diskio3.c \
libc_io.c \
fatfs/ff.c fatfs/ffunicode.c \
network.c ${COREFILES} ${CORE4FILES} ${NETIFFILES} ${HTTPFILES} ${TFTPFILES} $LWIPDIR/api/err.c"
test "$GDB" == 1 && SOURCES="$SOURCES gdb/tzvecs.c gdb/gdbstub.c gdb/string.c gdb/printk.c"
if test "$LIBH3_MMC" == 1; then
SOURCES="$SOURCES lib-h3/lib-hal/src/h3/sdcard/diskio.c"
else
SOURCES="$SOURCES fatfs/mmc_sunxi.c"
fi
cat <<EOT >build.ninja
cflags = $COMPILER_CFLAGS
include build.ninja.common
rule libh3
command = $MAKE -C $LIBH3DIR/lib-h3 -f Makefile.H3 PREFIX=$CROSS_COMPILE PLATFORM=ORANGE_PI_ONE
rule libarm
command = $MAKE -C $LIBH3DIR/lib-arm -f Makefile.H3 PREFIX=$CROSS_COMPILE PLATFORM=ORANGE_PI_ONE
build lib-h3/lib-h3/lib_h3/libh3.a: libh3
build lib-h3/lib-arm/lib_h3/libarm.a: libarm
rule link_lib
command = bash -c "rm -f \$out; $AR rc \$out \$in"
EOT
{
echo -n "build libos.a: link_lib "
for s in $SOURCES ; do
echo -n "$OBJDIR/${s%.*}.o "
done
echo
for s in $SOURCES ; do
echo "build $OBJDIR/${s%.*}.o: cc $s"
done
} >>build.ninja