-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.sh
executable file
·185 lines (163 loc) · 4.43 KB
/
build.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
if [ ! -d root-fs ]; then
echo
echo "###############################################"
echo "# Error : The script need a root-fs directory #"
echo "###############################################"
echo
exit 1
fi
rm -rf build
mkdir -p build
echo
echo "############################"
echo "# Creating u-boot-bananapi #"
echo "############################"
echo
if [ ! -d u-boot-bananapi ]; then
git clone https://github.com/LeMaker/u-boot-bananapi.git
elif [ -d u-boot-bananapi ]; then
( cd u-boot-bananapi && git pull )
fi
(cd u-boot-bananapi &&
make CROSS_COMPILE=arm-linux-gnueabihf- Bananapi_config &&
make CROSS_COMPILE=arm-linux-gnueabihf-
cp u-boot-sunxi-with-spl.bin ../build/u-boot-sunxi-with-spl.bin)
echo
echo "########################"
echo "# Creating sunxi-tools #"
echo "########################"
echo
if [ ! -d sunxi-tools ]; then
git clone https://github.com/LeMaker/sunxi-tools.git
elif [ -d sunxi-tools ]; then
( cd sunxi-tools && git pull )
fi
(cd sunxi-tools &&
make clean &&
make)
echo
echo "#######################"
echo "# Creating script.bin #"
echo "#######################"
echo
if [ ! -d sunxi-boards ]; then
git clone https://github.com/LeMaker/sunxi-boards.git
elif [ -d sunxi-boards ]; then
( cd sunxi-boards && git pull )
fi
cp sunxi-boards/sys_config/a20/Bananapi.fex Bananapi.fex
# TODO : patch Bananapi.fex here
sunxi-tools/fex2bin Bananapi.fex build/script.bin
echo
echo "###################"
echo "# Creating uImage #"
echo "###################"
echo
if [ ! -d linux-bananapi ]; then
git clone https://github.com/LeMaker/linux-bananapi.git
elif [ -d linux-bananapi ]; then
( cd linux-bananapi && git pull )
fi
( cd linux-bananapi &&
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun7i_defconfig &&
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig &&
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules &&
cp arch/arm/boot/uImage ../build/uImage &&
cp .config ../build/.config &&
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=../build/modules modules_install )
IMG_FILE="bananapi.img"
echo
echo "#####################"
echo "# Creating img file #"
echo "#####################"
echo
dd if=/dev/zero of=${IMG_FILE} bs=1M count=3500
LOOP_DEV=`sudo losetup -f --show ${IMG_FILE}`
LOOP_PART_BOOT="${LOOP_DEV}p1"
LOOP_PART_SYS="${LOOP_DEV}p2"
echo
echo "#########################"
echo " +>${LOOP_DEV} "
echo " +->${LOOP_PART_BOOT} "
echo " +->${LOOP_PART_SYS} "
echo "#########################"
echo
echo
echo "#############################"
echo "# Creating partitions table #"
echo "#############################"
echo
sudo parted -s "${LOOP_DEV}" mklabel msdos
sudo parted -s "${LOOP_DEV}" unit cyl mkpart primary fat32 -- 0 2cyl
sudo parted -s "${LOOP_DEV}" unit cyl mkpart primary ext2 -- 2cyl -0
sudo parted -s "${LOOP_DEV}" set 1 boot on
sudo parted -s "${LOOP_DEV}" print
sudo partprobe "${LOOP_DEV}"
echo
echo "########################"
echo "# Creating filesystems #"
echo "########################"
echo
sudo mkfs.vfat "${LOOP_PART_BOOT}" -I -n boot
sudo mkfs.ext4 -O ^has_journal -E stride=2,stripe-width=1024 -b 4096 "${LOOP_PART_SYS}" -L system
sync
echo
echo "##########################"
echo "# Burning the bootloader #"
echo "##########################"
echo
sudo dd if=/dev/zero of=${LOOP_DEV} bs=1k count=1023 seek=1
sudo dd if=build/u-boot-sunxi-with-spl.bin of=${LOOP_DEV} bs=1024 seek=8
sync
echo
echo "######################"
echo "# Copying boot files #"
echo "######################"
echo
sudo mount -t vfat "${LOOP_PART_BOOT}" /mnt
sudo cp build/uImage /mnt
sudo cp build/script.bin /mnt
sudo cp uEnv.txt /mnt
sudo cp build/.config /mnt
sync
ls -al /mnt
sudo umount /mnt
echo
echo "##################"
echo "# Copying rootfs #"
echo "##################"
echo
sudo mount -t ext4 "${LOOP_PART_SYS}" /mnt
sudo rm -rf /mnt/*
sudo cp -r root-fs/* /mnt
if [ -f /mnt/README.md ]; then
sudo rm -rf /mnt/README.md
fi
sync
echo
echo "###################"
echo "# Copying modules #"
echo "###################"
echo
sudo mkdir -p /mnt/lib/modules
sudo rm -rf /mnt/lib/modules/
sudo cp -r build/modules/lib /mnt/
sync
echo
echo "############################################"
echo "# Creating /proc, /sys, /mnt, /tmp & /boot #"
echo "############################################"
echo
sudo mkdir -p /mnt/proc
sudo mkdir -p /mnt/sys
sudo mkdir -p /mnt/mnt
sudo mkdir -p /mnt/tmp
sudo mkdir -p /mnt/boot
sync
ls -al /mnt
sudo umount /mnt
echo
echo Umount
echo
sudo losetup -d ${LOOP_DEV}