-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·207 lines (175 loc) · 6.49 KB
/
build.sh
File metadata and controls
executable file
·207 lines (175 loc) · 6.49 KB
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
#!/bin/bash
# build.sh — Multi-target build script for PageSpeak
#
# Usage:
# ./build.sh # Build for default machine (rpi3)
# ./build.sh rpi3 # Build for Raspberry Pi 3
# ./build.sh rpi4 # Build for Raspberry Pi 4 (32-bit)
# ./build.sh rpi4-64 # Build for Raspberry Pi 4 (64-bit)
# ./build.sh rpi5 # Build for Raspberry Pi 5
# ./build.sh all # Build for all supported targets
# ./build.sh <machine> <recipe> # Build specific recipe (e.g., ./build.sh rpi3 pagespeak-cam-driver)
#
# Environment variables:
# DOCKER=0 # Set to 0 to build natively (Linux only)
# BB_NUMBER_THREADS=8 # Override parallel BitBake tasks
# PARALLEL_MAKE="-j 8" # Override parallel make jobs
set -eo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Help message
usage() {
cat <<EOF
PageSpeak Multi-Target Build Script
Usage: ./build.sh [target] [recipe]
Targets:
rpi3 Raspberry Pi 3B/3B+ (32-bit ARM, kernel 5.15)
rpi4 Raspberry Pi 4B (32-bit ARM, kernel 5.15)
rpi4-64 Raspberry Pi 4B (64-bit ARM, kernel 5.15)
rpi5 Raspberry Pi 5 (64-bit ARM, kernel 6.1)
all Build for rpi3, rpi4, and rpi5
Recipes (optional, defaults to pagespeak-image):
pagespeak-image Full bootable image with all modules
pagespeak-cam-driver Camera capture kernel module only
pagespeak-btn GPIO button kernel module only
Examples:
./build.sh # Build image for rpi3 (default)
./build.sh rpi5 # Build image for Raspberry Pi 5
./build.sh rpi3 pagespeak-cam-driver # Build only the camera driver for rpi3
./build.sh all # Build images for all targets
Environment:
DOCKER=0 Build natively instead of in Docker (Linux x86_64 only)
BB_NUMBER_THREADS=N Number of parallel BitBake tasks (default: 8)
Output images are placed in:
build/tmp/deploy/images/<machine>/pagespeak-image-<machine>.rpi-sdimg
EOF
exit 0
}
# Check for help flag early (before any other processing)
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
fi
# Default settings
DOCKER="${DOCKER:-1}"
BB_NUMBER_THREADS="${BB_NUMBER_THREADS:-8}"
PARALLEL_MAKE="${PARALLEL_MAKE:--j 8}"
DEFAULT_RECIPE="pagespeak-image"
# Machine name mapping (function to avoid bash 4 associative array requirement)
get_machine() {
case "$1" in
rpi3) echo "raspberrypi3" ;;
rpi4) echo "raspberrypi4" ;;
rpi4-64) echo "raspberrypi4-64" ;;
rpi5) echo "raspberrypi5" ;;
*) echo "" ;;
esac
}
# All supported targets for 'all' build
ALL_TARGETS="rpi3 rpi4 rpi5"
# Parse arguments
TARGET="${1:-rpi3}"
RECIPE="${2:-$DEFAULT_RECIPE}"
# Validate target
if [[ "$TARGET" != "all" ]]; then
MACHINE=$(get_machine "$TARGET")
if [[ -z "$MACHINE" ]]; then
echo "Error: Unknown target '$TARGET'"
echo "Valid targets: rpi3 rpi4 rpi4-64 rpi5 all"
exit 1
fi
fi
# Build function for a single target
build_target() {
local target="$1"
local recipe="$2"
local machine
machine=$(get_machine "$target")
echo ""
echo "=============================================="
echo " Building $recipe for $target ($machine)"
echo "=============================================="
echo ""
if [[ "$DOCKER" == "1" ]]; then
# Docker build
docker run --rm \
-v "$SCRIPT_DIR":/workdir \
-v yocto-downloads:/yocto-cache/downloads \
-v yocto-sstate:/yocto-cache/sstate-cache \
-v yocto-tmp:/yocto-cache/tmp \
-e MACHINE="$machine" \
yocto-arm64:latest \
bash -c "
cd /workdir
set +u
source sources/poky/oe-init-build-env build >/dev/null 2>&1
set -u
# Copy base config
cp /workdir/conf/local.conf conf/local.conf
# Append Docker-specific settings
cat >> conf/local.conf << CONF
# Docker cache volumes
DL_DIR = \"/yocto-cache/downloads\"
SSTATE_DIR = \"/yocto-cache/sstate-cache\"
TMPDIR = \"/yocto-cache/tmp\"
# Parallel build settings
BB_NUMBER_THREADS = \"$BB_NUMBER_THREADS\"
PARALLEL_MAKE = \"$PARALLEL_MAKE\"
# Target machine (from build.sh)
MACHINE = \"$machine\"
CONF
# Generate bblayers.conf
sed \\
-e 's|##POKY_DIR##|/workdir/sources/poky|g' \\
-e 's|##OE_DIR##|/workdir/sources/meta-openembedded|g' \\
-e 's|##META_RPI_DIR##|/workdir/sources/meta-raspberrypi|g' \\
-e 's|##PROJECT_DIR##|/workdir|g' \\
/workdir/conf/bblayers.conf.sample > conf/bblayers.conf
echo \"Building $recipe for MACHINE=$machine\"
bitbake $recipe
"
else
# Native build (Linux only)
(
set +u
# shellcheck disable=SC1091
source sources/poky/oe-init-build-env build >/dev/null 2>&1
set -u
cp "$SCRIPT_DIR/conf/local.conf" conf/local.conf
# Append machine override
echo "" >> conf/local.conf
echo "MACHINE = \"$machine\"" >> conf/local.conf
# Generate bblayers.conf
sed \
-e "s|##POKY_DIR##|$SCRIPT_DIR/sources/poky|g" \
-e "s|##OE_DIR##|$SCRIPT_DIR/sources/meta-openembedded|g" \
-e "s|##META_RPI_DIR##|$SCRIPT_DIR/sources/meta-raspberrypi|g" \
-e "s|##PROJECT_DIR##|$SCRIPT_DIR|g" \
"$SCRIPT_DIR/conf/bblayers.conf.sample" > conf/bblayers.conf
MACHINE="$machine" bitbake "$recipe"
)
fi
echo ""
echo "Build complete: $target ($machine) - $recipe"
}
# Main execution
if [[ "$TARGET" == "all" ]]; then
echo "Building for all targets: $ALL_TARGETS"
for t in $ALL_TARGETS; do
build_target "$t" "$RECIPE"
done
echo ""
echo "=============================================="
echo " All builds complete!"
echo "=============================================="
echo ""
echo "Output images:"
for t in $ALL_TARGETS; do
m=$(get_machine "$t")
echo " $t: build/tmp/deploy/images/$m/pagespeak-image-$m.rpi-sdimg"
done
else
build_target "$TARGET" "$RECIPE"
MACHINE=$(get_machine "$TARGET")
echo ""
echo "Output: build/tmp/deploy/images/$MACHINE/$RECIPE-$MACHINE.rpi-sdimg"
fi