-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchroot_build_steps.sh
More file actions
executable file
·233 lines (190 loc) · 7.7 KB
/
chroot_build_steps.sh
File metadata and controls
executable file
·233 lines (190 loc) · 7.7 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
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
#!/bin/bash
# ==============================================================================
# Chroot Build Script Template for FydeOS Terra Build
# This script runs INSIDE the ChromeOS SDK chroot
# ==============================================================================
set -euo pipefail
# Configuration from outer script
BOARD_NAME="terra_fydeos"
KERNEL_PACKAGE_NAME="chromeos-kernel-5_10"
NUM_JOBS="8"
LOAD_AVERAGE="10"
CCACHE_MAXSIZE="50G"
# Ensure we are at the root of the source checkout inside chroot
cd /mnt/host/source
echo "[CHROOT] Starting build process for ${BOARD_NAME}"
echo "[CHROOT] Build parallelism: ${NUM_JOBS} jobs, load average limit: ${LOAD_AVERAGE}"
# Set up ccache properly inside chroot
if command -v ccache >/dev/null 2>&1; then
echo "[CHROOT] Configuring ccache..."
ccache --set-config max_size="${CCACHE_MAXSIZE}"
ccache --set-config hash_dir=true
ccache --set-config compression=true
ccache --zero-stats
export USE_CCACHE=1
export CCACHE_DIR="/home/$(whoami)/.ccache"
echo "[CHROOT] ccache configuration complete"
fi
# Fix /usr/local/bin/ccache wrapper if it exists and is broken
if [ -f "/usr/local/bin/ccache" ]; then
if grep -q "exec.*-F" /usr/local/bin/ccache 2>/dev/null; then
echo "[CHROOT] Fixing broken ccache wrapper..."
sudo rm -f /usr/local/bin/ccache
sudo ln -sf /usr/bin/ccache /usr/local/bin/ccache
fi
fi
# Set up environment for better error handling and logging
export PORTAGE_TMPDIR=/var/tmp/portage
export PORTAGE_LOGDIR=/var/tmp/portage-logs
export PORT_LOGDIR=/var/tmp/portage-logs
# Create necessary directories with proper permissions
sudo mkdir -p "${PORTAGE_LOGDIR}" /var/cache/vpython /var/cache/cipd || true
sudo chmod 1777 /var/cache/vpython /var/cache/cipd || true
sudo chgrp portage "${PORTAGE_LOGDIR}" || true
sudo chmod 2775 "${PORTAGE_LOGDIR}" || true
# Ensure emerge log is writable
sudo touch /var/log/emerge.log || true
sudo chgrp portage /var/log/emerge.log || true
sudo chmod 664 /var/log/emerge.log || true
# Fix Portage repos.conf to add missing masters
echo "[CHROOT] Fixing Portage repository configuration..."
REPOS_CONF="/etc/portage/repos.conf"
if [ -d "${REPOS_CONF}" ]; then
for conf_file in "${REPOS_CONF}"/*.conf; do
if [ -f "${conf_file}" ] && ! grep -q "^masters" "${conf_file}" 2>/dev/null; then
repo_name=$(basename "${conf_file}" .conf)
if [[ "${repo_name}" == "crossdev" || "${repo_name}" == *"overlay"* ]]; then
echo "[CHROOT] Adding masters to ${conf_file}"
echo "masters = portage-stable chromiumos" | sudo tee -a "${conf_file}" > /dev/null
fi
fi
done
fi
echo "[CHROOT] Creating board overlay for ${BOARD_NAME}..."
OVERLAY_DIR="/mnt/host/source/src/overlays/overlay-${BOARD_NAME}"
# Create comprehensive overlay structure
sudo mkdir -p "${OVERLAY_DIR}/profiles/base" "${OVERLAY_DIR}/metadata" || true
# Create repo_name file
echo "${BOARD_NAME}" | sudo tee "${OVERLAY_DIR}/profiles/repo_name" > /dev/null
# Create layout.conf with proper masters
sudo tee "${OVERLAY_DIR}/metadata/layout.conf" > /dev/null << EOF
masters = portage-stable chromiumos eclass-overlay
repo-name = ${BOARD_NAME}
profile-formats = portage-2
cache-formats = md5-dict
EOF
# Create parent profile - inherit from appropriate base
sudo tee "${OVERLAY_DIR}/profiles/base/parent" > /dev/null << EOF
chromiumos:default/linux/amd64/10.0/chromeos
chromiumos:features/selinux
fydeos:default
EOF
# Create comprehensive make.defaults with all features
sudo tee "${OVERLAY_DIR}/profiles/base/make.defaults" > /dev/null << 'EOF'
# Board-specific configuration for terra_fydeos (C202SA)
BOARD_COMPILER_FLAGS="-march=silvermont -mtune=silvermont"
BOARD_USE="${BOARD_USE} kernel-5_10"
# Enable core features
USE="${USE} arc arcpp"
USE="${USE} crosvm kvm_guest"
USE="${USE} containers crostini"
# Audio support
USE="${USE} alsa pulseaudio"
# Hardware support
USE="${USE} wifi bluetooth usb"
# Development and debugging
USE="${USE} debug-symbols"
# FydeOS specific
USE="${USE} fydeos_store"
EOF
# Create toolchain.conf
sudo tee "${OVERLAY_DIR}/toolchain.conf" > /dev/null << EOF
x86_64-cros-linux-gnu {"default": true}
EOF
# Create comprehensive audio configuration
echo "[CHROOT] Creating audio configuration packages..."
create_audio_packages() {
# UCM package
local ucm_pkg="${OVERLAY_DIR}/chromeos-base/chromeos-alsa-ucm-terra"
local ucm_files="${ucm_pkg}/files/chtrt5650"
sudo mkdir -p "${ucm_files}"
# Download UCM files
curl -fsSL -o /tmp/chtrt5650.conf "https://raw.githubusercontent.com/GalliumOS/galliumos-braswell/master/usr/share/alsa/ucm/chtrt5650/chtrt5650.conf"
curl -fsSL -o /tmp/HiFi.conf "https://raw.githubusercontent.com/GalliumOS/galliumos-braswell/master/usr/share/alsa/ucm/chtrt5650/HiFi.conf"
sudo mv /tmp/chtrt5650.conf /tmp/HiFi.conf "${ucm_files}/"
sudo tee "${ucm_pkg}/chromeos-alsa-ucm-terra-1.0.ebuild" > /dev/null << 'EOFUCM'
# Copyright 2024 The FydeOS Authors
EAPI="7"
inherit cros-workon
DESCRIPTION="ALSA UCM profiles for TERRA (chtrt5650)"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~*"
src_install() {
local ucm_dir="${D}/usr/share/alsa/ucm2/conf.d/chtrt5650"
insinto "${ucm_dir}"
doins "${FILESDIR}/chtrt5650/"*
}
EOFUCM
# ALSA state package
local state_pkg="${OVERLAY_DIR}/chromeos-base/chromeos-alsa-state-terra"
local state_files="${state_pkg}/files"
sudo mkdir -p "${state_files}"
curl -fsSL -o /tmp/asound.state "https://raw.githubusercontent.com/rgvxsthi/Braswell-EDGAR-Linux-Fixes/master/asound.state"
sudo mv /tmp/asound.state "${state_files}/"
sudo tee "${state_pkg}/chromeos-alsa-state-terra-1.0.ebuild" > /dev/null << 'EOFSTATE'
# Copyright 2024 The FydeOS Authors
EAPI="7"
inherit cros-workon
DESCRIPTION="Custom asound.state for TERRA (Braswell)"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~*"
src_install() {
insinto /var/lib/alsa
doins "${FILESDIR}/asound.state"
}
EOFSTATE
}
create_audio_packages
# Create BSP package to tie everything together
echo "[CHROOT] Creating Board Support Package..."
BSP_PKG_DIR="${OVERLAY_DIR}/virtual/chromeos-bsp-terra"
sudo mkdir -p "${BSP_PKG_DIR}"
sudo tee "${BSP_PKG_DIR}/chromeos-bsp-terra-1.ebuild" > /dev/null << 'EOFBSP'
# Copyright 2024 The FydeOS Authors
EAPI="7"
DESCRIPTION="Board-specific packages for TERRA (C202SA)"
RDEPEND="
chromeos-base/chromeos-alsa-ucm-terra
chromeos-base/chromeos-alsa-state-terra
sys-kernel/linux-firmware
"
EOFBSP
echo "[CHROOT] Board overlay creation complete"
# Set up board with comprehensive error checking
echo "[CHROOT] Setting up board: ${BOARD_NAME}"
if ! /mnt/host/source/chromite/bin/setup_board --board="${BOARD_NAME}" --force; then
echo "[CHROOT] setup_board failed, checking for common issues..."
ls -la /mnt/host/source/chromite/bin/setup_board || true
ls -la /build/ || true
exit 1
fi
# Build packages with optimized settings
echo "[CHROOT] Building packages for ${BOARD_NAME}"
export MAKEOPTS="-j${NUM_JOBS} -l${LOAD_AVERAGE}"
export EMERGE_DEFAULT_OPTS="--jobs=${NUM_JOBS} --load-average=${LOAD_AVERAGE} --with-bdeps=y"
if ! /mnt/host/source/chromite/bin/build_packages --board="${BOARD_NAME}" --withdebugsymbols; then
echo "[CHROOT] build_packages failed, checking logs..."
find /build/"${BOARD_NAME}"/tmp/portage -name "build.log" -newer /tmp -exec tail -n 50 {} \; 2>/dev/null | tail -n 100
exit 1
fi
# Build optimized image
echo "[CHROOT] Building disk image for ${BOARD_NAME}"
if ! /mnt/host/source/chromite/bin/build_image --board="${BOARD_NAME}" --noenable_rootfs_verification; then
echo "[CHROOT] build_image failed"
exit 1
fi
echo "[CHROOT] Build process completed successfully"
echo "[CHROOT] ccache statistics:"
ccache --show-stats || true