-
Notifications
You must be signed in to change notification settings - Fork 36
/
build.sh
executable file
·287 lines (247 loc) · 12.4 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
# BEGIN PARAMETER ZONE
## ODbeta params
ODBETA_DOWNLOAD_PLAN="A" # "A": Direct download; "B": Artifact from GHAction
ODBETA_VERSION=2022-02-13 # ODbeta version to install. It should correspond with direct download or GHArtifact
### For plan "A"
ODBETA_DIR_URL=http://od.abstraction.se/opendingux/26145a93f2e17d0df86ae20b7af455ea155e169c
### For plan "B"
ODBETA_ARTIFACT_ID=287825131 # ID of `update-gcw0` artifact in last workflow execution of `opendingux`
# branch in https://github.com/OpenDingux/buildroot repository
GITHUB_ACCOUNT=PUT_HERE_YOUR_GITHUB_ACCOUNT
GITHUB_TOKEN=PUT_HERE_A_GITHUB_TOKEN
## Other params
MAKE_PGv1=true # Build image for GCW-Zero and PocketGo2 v1
MAKE_RG=true # Build image for RG350 and derived
COMP=xz # gz or xz
P1_SIZE_SECTOR=819168 # Size of partition 1 in sectors (819168 sectors= ~400M)
SIZE_M=3200 # Final image size in MiB
# END PARAMETER ZONE
# Deprecated
INSTALL_ODBETA_MODS=false
# Constants of convenience
DIRECTORY=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
VERSION=$(cat ${DIRECTORY}/v)
ODBETA_DIST_FILE=gcw0-update-${ODBETA_VERSION}.opk
SECTOR_SIZE=512
P1_OFFSET_SECTOR=32
# Check if we're root and re-execute if we're not.
rootcheck () {
if [ $(id -u) != "0" ]
then
sudo "$0" "$@"
sudo chown -R $(id -u):$(id -g) "${DIRECTORY}/releases"
sudo chown -R $(id -u):$(id -g) "${DIRECTORY}/select_kernel"
sudo chown -R $(id -u):$(id -g) "${DIRECTORY}/retroarch/build_odb"
sudo chown -R $(id -u):$(id -g) "${DIRECTORY}/retroarch/releases"
exit $?
fi
}
rootcheck "${@}"
# Calculations
mega="$(echo '2^20' | bc)"
p1_start_sector=${P1_OFFSET_SECTOR}
p1_size_sector=${P1_SIZE_SECTOR}
p2_start_sector=$((${P1_OFFSET_SECTOR}+${P1_SIZE_SECTOR}))
img_size_sector=$((${SIZE_M}*${mega}/${SECTOR_SIZE}))
p2_size_sector=$((${img_size_sector}-${p2_start_sector}))
# ODBeta download
if [ ! -f "${DIRECTORY}/select_kernel/${ODBETA_DIST_FILE}" ] ; then
case ${ODBETA_DOWNLOAD_PLAN} in
A)
echo "## Downloading ODBeta distribution"
ODBETA_DIST_URL=${ODBETA_DIR_URL}/${ODBETA_DIST_FILE}
wget -q -P "${DIRECTORY}/select_kernel" ${ODBETA_DIST_URL}
status=$?
[ ! ${status} -eq 0 ] && echo "@@ ERROR: Problem downloading ODBeta distribution" && exit 1
;;
B)
[ ${GITHUB_ACCOUNT} == "PUT_HERE_YOUR_GITHUB_ACCOUNT" ] && echo "@@ ERROR: Problem downloading ODBeta distribution. You have to put your github id in GITHUB_ACCOUNT parameter" && exit 1
[ ${GITHUB_TOKEN} == "PUT_HERE_A_GITHUB_TOKEN" ] && echo "@@ ERROR: Problem downloading ODBeta distribution. You have to put a github token in GITHUB_TOKEN parameter" && exit 1
echo "## Downloading ODBeta distribution"
curl -L -H "Accept: application/vnd.github.v3+json" -u "${GITHUB_ACCOUNT}:${GITHUB_TOKEN}" -o "${DIRECTORY}/select_kernel/update-gcw0.zip" https://api.github.com/repos/OpenDingux/buildroot/actions/artifacts/${ODBETA_ARTIFACT_ID}/zip
status=$?
[ ! ${status} -eq 0 ] && echo "@@ ERROR: Problem downloading ODBeta distribution" && exit 1
sync
unzip -q -d "${DIRECTORY}/select_kernel" "${DIRECTORY}/select_kernel/update-gcw0.zip"
rm "${DIRECTORY}/select_kernel/update-gcw0.zip"
;;
*)
echo "@@ ERROR: Unknown plan for download ODBeta distribution" && exit 1
;;
esac
fi
if [ -d "${DIRECTORY}/select_kernel/squashfs-root" ] ; then
rm -rf "${DIRECTORY}/select_kernel/squashfs-root"
fi
echo "## File creation"
dd if=/dev/zero of="${DIRECTORY}/sd_int.img" bs=1M count=${SIZE_M} status=progress conv=fsync
sync
sleep 1
echo "## Partition creation"
printf "
type=b, start=${p1_start_sector}, size=${p1_size_sector}
type=83, start=${p2_start_sector}, size=${p2_size_sector}
" | sfdisk -q "${DIRECTORY}/sd_int.img"
sync
sleep 1
echo "## Setting up loop device"
DEVICE=$(losetup -f)
losetup -P ${DEVICE} "${DIRECTORY}/sd_int.img"
sleep 1
echo "## Creating filesystems"
mkfs.vfat -F 32 ${DEVICE}p1
mkfs.ext4 -F -O ^64bit -O ^metadata_csum -O uninit_bg -L '' -q ${DEVICE}p2
sync
sleep 1
echo "## Mounting P1"
mkdir "${DIRECTORY}/mnt_p1"
mount -t vfat ${DEVICE}p1 "${DIRECTORY}/mnt_p1"
sleep 1
cd "${DIRECTORY}/select_kernel"
unsquashfs "${DIRECTORY}/select_kernel/${ODBETA_DIST_FILE}" > /dev/null
if [ ${INSTALL_ODBETA_MODS} = true ] ; then
echo "## Installing script S99resize_p2.sh in rootfs.squashfs"
cd "${DIRECTORY}/select_kernel/squashfs-root/gcw0"
unsquashfs rootfs.squashfs > /dev/null
cp "${DIRECTORY}/assets/S99resize_p2.sh" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/squashfs-root/etc/init.d"
mksquashfs squashfs-root rootfs.squashfs -noappend -comp zstd > /dev/null
fi
cd "${DIRECTORY}"
cp "${DIRECTORY}/select_kernel/squashfs-root/gcw0/rootfs.squashfs" "${DIRECTORY}/mnt_p1"
sha1sum "${DIRECTORY}/select_kernel/squashfs-root/gcw0/rootfs.squashfs" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/rootfs.squashfs.sha1"
cp "${DIRECTORY}/select_kernel/squashfs-root/gcw0/mininit-syspart" "${DIRECTORY}/mnt_p1"
cp "${DIRECTORY}/select_kernel/squashfs-root/gcw0/mininit-syspart.sha1" "${DIRECTORY}/mnt_p1"
cp "${DIRECTORY}/select_kernel/squashfs-root/gcw0/modules.squashfs" "${DIRECTORY}/mnt_p1"
cp "${DIRECTORY}/select_kernel/squashfs-root/gcw0/modules.squashfs.sha1" "${DIRECTORY}/mnt_p1"
mkdir "${DIRECTORY}/mnt_p1/dev"
mkdir "${DIRECTORY}/mnt_p1/root"
echo "## Mounting P2"
mkdir "${DIRECTORY}/mnt_p2"
mount -t ext4 ${DEVICE}p2 "${DIRECTORY}/mnt_p2"
sleep 1
echo "## Installing RetroArch stuff in P2"
E_BUILD_STOCK=false E_BUILD_ODBETA=true E_CONF_CSV=all "${DIRECTORY}/retroarch/build.sh"
status=$?
[ ! ${status} -eq 0 ] && echo "@@ ERROR: Problem installing RetroArch stuff." && exit ${status}
mkdir -p "${DIRECTORY}/mnt_p2/apps"
cp -f "${DIRECTORY}/retroarch/files_odb/retroarch_rg350_odbeta.opk" "${DIRECTORY}/mnt_p2/apps"
mkdir -p "${DIRECTORY}/mnt_p2/local/bin"
cp -f "${DIRECTORY}/retroarch/files_odb/retroarch_rg350_odbeta" "${DIRECTORY}/mnt_p2/local/bin"
# Installing OPK wrappers for cores
tar -xzf "${DIRECTORY}/retroarch/files_odb/apps_ra.tgz" -C "${DIRECTORY}/mnt_p2/apps"
# Installing home files
mkdir -p "${DIRECTORY}/mnt_p2/local/home/.retroarch"
tar -xzf "${DIRECTORY}/retroarch/files_odb/retroarch.tgz" -C "${DIRECTORY}/mnt_p2/local/home/.retroarch"
# Installing GMenu2X links
mkdir -p "${DIRECTORY}/mnt_p2/local/home/.gmenu2x/sections/retroarch"
tar -xzf "${DIRECTORY}/retroarch/files_odb/links.tgz" -C "${DIRECTORY}/mnt_p2/local/home/.gmenu2x/sections/retroarch"
sync
echo "## Installing Adam stuff in P2"
rm -rf "${DIRECTORY}/mnt_p2/local/home/.retroarch/system"
cp -r "${DIRECTORY}/data"/* "${DIRECTORY}/mnt_p2"
find "${DIRECTORY}/mnt_p2" -name .gitignore -delete
cp "${DIRECTORY}/assets/dosbox_pure_libretro.so" "${DIRECTORY}/mnt_p2/local/home/.retroarch/cores/"
echo "## Putting up version file flag"
echo ${VERSION} > "${DIRECTORY}/mnt_p2/adam_version.txt"
echo "## Setting permissions in P2"
chown -R 1000:100 "${DIRECTORY}/mnt_p2/apps"
chown -R 1000:100 "${DIRECTORY}/mnt_p2/local"
chown -R 0:0 "${DIRECTORY}/mnt_p2/local/etc"
chown -R 0:0 "${DIRECTORY}/mnt_p2/local/var/lib"
echo "## Unmounting P2"
umount ${DEVICE}p2
sync
sleep 1
if [ ! -d "${DIRECTORY}/releases" ] ; then
mkdir "${DIRECTORY}/releases"
fi
if [ ${MAKE_PGv1} = true ] ; then
echo "## Building P1 for PlayGo/PG2 v1 and GCW-Zero image"
cp "${DIRECTORY}/select_kernel/select_kernel_gcw0.bat" "${DIRECTORY}/mnt_p1/select_kernel.bat"
cp "${DIRECTORY}/select_kernel/select_kernel_gcw0.sh" "${DIRECTORY}/mnt_p1/select_kernel.sh"
mkdir "${DIRECTORY}/mnt_p1/pocketgo2v1"
mkdir "${DIRECTORY}/mnt_p1/gcw0"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/pocketgo2.dtb" > "${DIRECTORY}/mnt_p1/pocketgo2v1/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/pocketgo2v1/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/pocketgo2v1/uzImage.bin.sha1"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/gcw0.dtb" > "${DIRECTORY}/mnt_p1/gcw0/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/gcw0/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/gcw0/uzImage.bin.sha1"
sync
sleep 1
echo "## Unmounting P1"
umount ${DEVICE}p1
sync
sleep 1
echo "## Flashing bootloader for PlayGo/PG2 v1 and GCW-Zero image"
dd if="${DIRECTORY}/select_kernel/squashfs-root/gcw0/ubiboot-v20_mddr_512mb.bin" of=${DEVICE} bs=512 seek=1 count=16 conv=notrunc 2>/dev/null
sync
sleep 1
echo "## Compressing dump for PlayGo/PG2 v1 and GCW-Zero image"
if [ ${COMP} = "gz" ] ; then
gzip -9 -k "${DIRECTORY}/sd_int.img"
mv "${DIRECTORY}/sd_int.img.gz" "${DIRECTORY}/releases/adam_v${VERSION}_PGv1.img.gz"
else
xz -z -f -k -9 "${DIRECTORY}/sd_int.img"
mv "${DIRECTORY}/sd_int.img.xz" "${DIRECTORY}/releases/adam_v${VERSION}_PGv1.img.xz"
fi
sync
echo "## Remounting P1"
mount -t vfat ${DEVICE}p1 "${DIRECTORY}/mnt_p1"
sleep 1
rm -rf "${DIRECTORY}/mnt_p1/pocketgo2v1" 2> /dev/null && sync
rm -rf "${DIRECTORY}/mnt_p1/gcw0" 2> /dev/null && sync
rm "${DIRECTORY}/mnt_p1/select_kernel.bat" 2> /dev/null && sync
rm "${DIRECTORY}/mnt_p1/select_kernel.sh" 2> /dev/null && sync
fi
if [ ${MAKE_RG} = true ] ; then
echo "## Building P1 for RG image"
cp "${DIRECTORY}/select_kernel/select_kernel.bat" "${DIRECTORY}/mnt_p1"
cp "${DIRECTORY}/select_kernel/select_kernel.sh" "${DIRECTORY}/mnt_p1"
mkdir "${DIRECTORY}/mnt_p1/rg280v"
mkdir "${DIRECTORY}/mnt_p1/rg280m"
mkdir "${DIRECTORY}/mnt_p1/rg350"
mkdir "${DIRECTORY}/mnt_p1/rg350m"
mkdir "${DIRECTORY}/mnt_p1/pocketgo2v2"
mkdir "${DIRECTORY}/mnt_p1/rg300x"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/rg280v.dtb" > "${DIRECTORY}/mnt_p1/rg280v/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/rg280v/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/rg280v/uzImage.bin.sha1"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/rg280m.dtb" > "${DIRECTORY}/mnt_p1/rg280m/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/rg280m/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/rg280m/uzImage.bin.sha1"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/rg350.dtb" > "${DIRECTORY}/mnt_p1/rg350/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/rg350/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/rg350/uzImage.bin.sha1"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/rg350m.dtb" > "${DIRECTORY}/mnt_p1/rg350m/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/rg350m/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/rg350m/uzImage.bin.sha1"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/pocketgo2v2.dtb" > "${DIRECTORY}/mnt_p1/pocketgo2v2/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/pocketgo2v2/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/pocketgo2v2/uzImage.bin.sha1"
cat "${DIRECTORY}/select_kernel/squashfs-root/gcw0/uzImage.bin" "${DIRECTORY}/select_kernel/squashfs-root/gcw0/rg300x.dtb" > "${DIRECTORY}/mnt_p1/rg300x/uzImage.bin"
sha1sum "${DIRECTORY}/mnt_p1/rg300x/uzImage.bin" | awk '{ print $1 }'>"${DIRECTORY}/mnt_p1/rg300x/uzImage.bin.sha1"
sync
sleep 1
echo "## Unmounting P1"
umount ${DEVICE}p1
sync
sleep 1
echo "## Flashing bootloader for RG image"
dd if="${DIRECTORY}/select_kernel/squashfs-root/gcw0/ubiboot-rg350.bin" of=${DEVICE} bs=512 seek=1 count=16 conv=notrunc 2>/dev/null
sync
sleep 1
echo "## Compressing dump for RG image"
if [ ${COMP} = "gz" ] ; then
gzip -9 -k "${DIRECTORY}/sd_int.img"
mv "${DIRECTORY}/sd_int.img.gz" "${DIRECTORY}/releases/adam_v${VERSION}.img.gz"
else
xz -z -f -k -9 "${DIRECTORY}/sd_int.img"
mv "${DIRECTORY}/sd_int.img.xz" "${DIRECTORY}/releases/adam_v${VERSION}.img.xz"
fi
sync
fi
echo "## Final cleaning"
losetup -d ${DEVICE}
sync
sleep 1
rm -rf "${DIRECTORY}/select_kernel/squashfs-root"
if [ -f "${DIRECTORY}/sd_int.img" ] ; then
rm "${DIRECTORY}/sd_int.img"
fi
rmdir "${DIRECTORY}/mnt_p1"
rmdir "${DIRECTORY}/mnt_p2"