This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 434
/
BUILDME.sh
executable file
·199 lines (165 loc) · 6.77 KB
/
BUILDME.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
#!/bin/bash
# Bash script to rebuild recovery
set -e
# Final directory where NOOBS files will be copied to
NOOBS_OUTPUT_DIR="output"
function get_package_version {
PACKAGE=$1
CONFIG_FILE="package/$PACKAGE/$PACKAGE.mk"
if [ -f "$CONFIG_FILE" ]; then
CONFIG_VAR=$(echo "$PACKAGE-version" | tr '[:lower:]-' '[:upper:]_')
grep -E "^$CONFIG_VAR\s*=\s*.+$" "$CONFIG_FILE" | tr -d ' ' | cut -d= -f2
fi
}
function update_github_package_version {
PACKAGE=$1
GITHUB_REPO=$2
BRANCH=$3
CONFIG_FILE="package/$PACKAGE/$PACKAGE.mk"
if [ -f "$CONFIG_FILE" ]; then
OLDREV=$(get_package_version $PACKAGE)
if [ -z "$OLDREV" ]; then
echo "Error getting OLDREV for $PACKAGE";
else
REPO_API=https://api.github.com/repos/$GITHUB_REPO/git/refs/heads/$BRANCH
GITREV=$(curl -s ${REPO_API} | awk '{ if ($1 == "\"sha\":") { print substr($2, 2, 40) } }')
if [ -z "$GITREV" ]; then
echo "Error getting GITREV for $PACKAGE ($BRANCH)";
else
if [ "$OLDREV" == "$GITREV" ]; then
echo "Package $PACKAGE ($BRANCH) is already newest version"
else
CONFIG_VAR=$(echo "$PACKAGE-version" | tr '[:lower:]-' '[:upper:]_')
sed -ri "s/(^$CONFIG_VAR\s*=\s*)[0-9a-f]+$/\1$GITREV/" "$CONFIG_FILE"
echo "Package $PACKAGE ($BRANCH) updated to version $GITREV"
fi
fi
fi
else
echo "$CONFIG_FILE doesn't exist"
fi
}
function get_kernel_version {
CONFIG_FILE=.config
CONFIG_VAR=BR2_LINUX_KERNEL_VERSION
grep -E "^$CONFIG_VAR=\".+\"$" "$CONFIG_FILE" | tr -d '"' | cut -d= -f2
}
function update_github_kernel_version {
PACKAGE=kernel
GITHUB_REPO=$1
BRANCH=$2
CONFIG_FILE=.config
if [ -f "$CONFIG_FILE" ]; then
OLDREV=$(get_kernel_version)
if [ -z "$OLDREV" ]; then
echo "Error getting OLDREV for $PACKAGE";
else
REPO_API=https://api.github.com/repos/$GITHUB_REPO/git/refs/heads/$BRANCH
GITREV=$(curl -s ${REPO_API} | awk '{ if ($1 == "\"sha\":") { print substr($2, 2, 40) } }')
if [ -z "$GITREV" ]; then
echo "Error getting GITREV for $PACKAGE ($BRANCH)";
else
if [ "$OLDREV" == "$GITREV" ]; then
echo "$PACKAGE ($BRANCH) is already newest version"
else
CONFIG_VAR=BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION
sed -ri "s/(^$CONFIG_VAR=\")[0-9a-f]+(\")$/\1$GITREV\2/" "$CONFIG_FILE"
CONFIG_VAR=BR2_LINUX_KERNEL_VERSION
sed -ri "s/(^$CONFIG_VAR=\")[0-9a-f]+(\")$/\1$GITREV\2/" "$CONFIG_FILE"
echo "$PACKAGE ($BRANCH) updated to version $GITREV"
fi
fi
fi
else
echo "$CONFIG_FILE doesn't exist"
fi
}
function select_kernelconfig {
ARCH=$1
CONFIG_FILE=.config
CONFIG_VAR=BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE
VAR_PREFIX=kernelconfig-recovery
sed -ri "s/(^$CONFIG_VAR=\"$VAR_PREFIX\.).+(\")$/\1$ARCH\2/" "$CONFIG_FILE"
}
export QT_SELECT=4
cd buildroot
# WARNING: don't try changing these - you'll break buildroot
BUILD_DIR="output/build"
IMAGES_DIR="output/images"
# Delete buildroot build directory to force rebuild
if [ -e "$BUILD_DIR" ]; then
rm -rf "$BUILD_DIR/recovery-$(get_package_version recovery)" || true
fi
SKIP_KERNEL_REBUILD=0
for i in $*; do
# Update raspberrypi/firmware master HEAD version in package/rpi-firmware/rpi-firmware.mk to latest
if [ $i = "update-firmware" ]; then
update_github_package_version rpi-firmware raspberrypi/firmware stable
fi
# Update raspberrypi/userland master HEAD version in package/rpi-userland/rpi-userland.mk to latest
if [ $i = "update-userland" ]; then
update_github_package_version rpi-userland raspberrypi/userland master
fi
# Update raspberrypi/linux rpi-4.1.y HEAD version in buildroot/.config to latest
if [ $i = "update-kernel" ]; then
update_github_kernel_version raspberrypi/linux rpi-5.10.y
fi
# Option to build just recovery without completely rebuilding both kernels
if [ $i = "skip-kernel-rebuild" ]; then
SKIP_KERNEL_REBUILD=1
fi
# Early-exit (in case we want to just update config files without doing a build)
if [ $i = "nobuild" ]; then
exit
fi
done
# Let buildroot build everything
make
# Create output dir and copy files
FINAL_OUTPUT_DIR="../$NOOBS_OUTPUT_DIR"
mkdir -p "$FINAL_OUTPUT_DIR"
mkdir -p "$FINAL_OUTPUT_DIR/os"
cp -r ../sdcontent/* "$FINAL_OUTPUT_DIR"
if [ $SKIP_KERNEL_REBUILD -ne 1 ]; then
# Rebuild kernel for ARMv7l
select_kernelconfig armv7l
make linux-reconfigure
# copy ARMv7l kernel
cp "$IMAGES_DIR/zImage" "$FINAL_OUTPUT_DIR/recovery7l.img"
# Rebuild kernel for ARMv7
select_kernelconfig armv7
make linux-reconfigure
# copy ARMv7 kernel
cp "$IMAGES_DIR/zImage" "$FINAL_OUTPUT_DIR/recovery7.img"
# Rebuild kernel for ARMv6
select_kernelconfig armv6
make linux-reconfigure
# copy ARMv6 kernel
cp "$IMAGES_DIR/zImage" "$FINAL_OUTPUT_DIR/recovery.img"
else
echo "Warning: kernels in '$NOOBS_OUTPUT_DIR' directory haven't been updated"
fi
# copy rootfs
cp "$IMAGES_DIR/rootfs.squashfs" "$FINAL_OUTPUT_DIR/recovery.rfs"
#cp "$IMAGES_DIR/rootfs.cpio.lzo" "$FINAL_OUTPUT_DIR/recovery.rfs"
# Ensure that final output dir contains files necessary to boot
cp "$IMAGES_DIR/rpi-firmware/start.elf" "$FINAL_OUTPUT_DIR/recovery.elf"
cp "$IMAGES_DIR/rpi-firmware/start4.elf" "$FINAL_OUTPUT_DIR/recover4.elf"
cp "$IMAGES_DIR/rpi-firmware/fixup.dat" "$FINAL_OUTPUT_DIR/fixup_rc.dat"
cp "$IMAGES_DIR/rpi-firmware/fixup4.dat" "$FINAL_OUTPUT_DIR/fixup4rc.dat"
cp "$IMAGES_DIR/rpi-firmware/config.txt" "$FINAL_OUTPUT_DIR"
cp "$IMAGES_DIR/rpi-firmware/bootcode.bin" "$FINAL_OUTPUT_DIR"
cp -a $IMAGES_DIR/*.dtb "$IMAGES_DIR/overlays" "$FINAL_OUTPUT_DIR"
cp "$IMAGES_DIR/cmdline.txt" "$FINAL_OUTPUT_DIR/recovery.cmdline"
touch "$FINAL_OUTPUT_DIR/RECOVERY_FILES_DO_NOT_EDIT"
# Create build-date timestamp file containing Git HEAD info for build
BUILD_INFO="$FINAL_OUTPUT_DIR/BUILD-DATA"
echo "Build-date: $(date +"%Y-%m-%d")" > "$BUILD_INFO"
echo "NOOBS Version: $(sed -n 's|.*VERSION_NUMBER.*\"\(.*\)\"|v\1|p' ../recovery/config.h)" >> "$BUILD_INFO"
echo "NOOBS Git HEAD @ $(git rev-parse --verify HEAD)" >> "$BUILD_INFO"
echo "rpi-userland Git master @ $(get_package_version rpi-userland)" >> "$BUILD_INFO"
echo "rpi-firmware Git master @ $(get_package_version rpi-firmware)" >> "$BUILD_INFO"
echo "rpi-linux Git rpi-5.10.y @ $(get_kernel_version)" >> "$BUILD_INFO"
cd ..
clear
echo "Build complete. Copy files in '$NOOBS_OUTPUT_DIR' directory onto a clean FAT formatted SD card to use."