22
33set -e -o pipefail
44
5- # Common error handling
6- bail () {
7- if [[ $# -gt 0 ]]; then
8- >&2 echo " Error: $* "
9- fi
10- exit 1
11- }
5+ KERNEL_KIT_DIR=" /bottlerocket-kernel-kit"
6+ MICROCODE_DIR=" ${KERNEL_KIT_DIR} /packages/microcode"
127
13- # Function to display usage information
8+ # Usage information
149usage () {
1510 cat << EOF
16- Usage: $( basename " $0 " ) -r RPM_FILE
11+ Usage: $0
1712
18- Extract kernel configurations from an RPM, merge with Bottlerocket's, and write out to a file, per architecture (x86_64 and aarch64).
13+ This script generates and validates full kernel configurations for all available
14+ kernel versions in the Bottlerocket kernel kit.
1915
20- This script provides functions intended to be run inside the bottlerocket-sdk container.
21- For typical usage, run 'make full-config RPM_FILE=/path/to/kernel-source.rpm' from the top-level bottlerocket-kernel-kit directory.
16+ IMPORTANT: This script is designed to run inside the Bottlerocket SDK container
17+ and should typically be invoked via the Makefile target:
2218
23- Direct script usage (for development/debugging):
24- -r RPM_FILE Path to RPM file
25- -h Display this help message
19+ make full-config
2620
27- Dependencies (when running directly):
28- - docker
29- - rpm2cpio
30- - cpio
31- - tar
32- - tq
21+ Running this script directly outside the SDK container will fail because it
22+ requires the proper build environment and mounted paths.
3323
34- Note: The inner_full_config() function is designed to run within the bottlerocket-sdk container environment
35- and expects specific mount points and toolchain paths to be available.
36- EOF
37- }
24+ The script will:
25+ 1. Discover all kernel-* packages with available RPMs
26+ 2. Extract and patch kernel sources
27+ 3. Merge Bottlerocket-specific configurations
28+ 4. Generate full configuration files
29+ 5. Validate that all required configs are present
3830
39- usage_error () {
40- >&2 usage
41- bail " $1 "
31+ EOF
4232}
4333
44- check_dependencies () {
45- hash rpm2cpio || usage_error " DEPENDENCY ERROR: Please install rpm2cpio somewhere in your PATH "
46- hash cpio || usage_error " DEPENDENCY ERROR: Please install cpio somewhere in your PATH "
47- hash tar || usage_error " DEPENDENCY ERROR: Please install tar somewhere in your PATH "
48- hash docker || usage_error " DEPENDENCY ERROR: Please install docker somewhere in your PATH "
49- hash tq || usage_error " DEPENDENCY ERROR: Please cargo install tomlq somewhere in your PATH "
34+ # Common error handling
35+ bail () {
36+ if [[ $# -gt 0 ]] ; then
37+ >&2 echo " Error: $* "
38+ fi
39+ exit 1
5040}
5141
52- # Get the SDK version from workspace Twoliter.toml and Twoliter.override, if provided.
53- # Assumes running in the top level of the project and `tq` on $PATH.
54- resolve_bottlerocket_sdk () {
55- # Inspect Twoliter.lock file for [sdk] section source
56- source=" $( tq -r " .sdk.source" -f Twoliter.lock) "
57- version=" $( tq -r " .sdk.version" -f Twoliter.lock) "
58- _name=" $( tq -r " .sdk.name" -f Twoliter.lock) "
59- # Trim from last slash, e.g. public.ecr.aws/bottlerocket/bottlerocket-sdk:v0.61.0 -> public.ecr.aws/bottlerocket
60- _registry=" ${source%/* } "
61-
62- # Check Twoliter.override to get the registry. For simplicity, assume overrides are only against named project named bottlerocket-sdk
63- registry=" $( tq -r " .bottlerocket.bottlerocket-sdk.registry" -f Twoliter.override 2> /dev/null || echo " $_registry " ) "
64- name=" $( tq -r " .bottlerocket.bottlerocket-sdk.name" -f Twoliter.override 2> /dev/null || echo " $_name " ) "
65-
66- # Form the final SDK
67- echo " ${registry} /${name} :v${version} "
68- }
42+ # Function to merge kernel configurations for a specific kernel version
43+ merge_kernel_configs () {
44+ local version=" $1 "
45+ local majorminor=" $2 "
46+ local tmpdir=" $3 "
6947
70- # Function to perform the kernel configuration merging inside Docker container
71- inner_full_config () {
72- pushd /work || bail " Unable to enter /work (bind mount to tmp dir)"
48+ local kernel_package_dir=" ${KERNEL_KIT_DIR} /packages/kernel-${majorminor} "
7349
74- version=" $( rpm --query --nosignature --queryformat ' %{VERSION}' kernel-source.rpm) "
75- majorminor=${version% .* } # Trim after last '.', e.g. 6.1.132 -> 6.1
7650 if [ " ${majorminor} " == " 6.12" ]; then
7751 # kernel 6.12 has a patch file that is not applied to the kernel sources, so
7852 # only pick up the 1000-series kernel patches for our purposes here.
79- readarray -t br_patches < <( find /kernel-package -maxdepth 1 -name " 10*.patch" )
53+ readarray -t br_patches < <( find " ${kernel_package_dir} " -maxdepth 1 -name " 10*.patch" )
8054 spec_file=" kernel6.12.spec"
8155 microcode_file=" config-microcode-6-12"
8256 else
83- readarray -t br_patches < <( find /kernel-package -maxdepth 1 -name " *.patch" )
57+ readarray -t br_patches < <( find " ${kernel_package_dir} " -maxdepth 1 -name " *.patch" )
8458 spec_file=" kernel.spec"
8559 microcode_file=" config-microcode"
8660 fi
8761
88- kernel_path=/kernel-package
62+ local kernel_path=" ${kernel_package_dir} "
63+
64+ pushd " ${tmpdir} " || bail " Unable to enter temporary directory"
8965
9066 rpm2cpio kernel-source.rpm | cpio -iu {,./}linux-" ${version} " .tar{,.xz} {,./}config-x86_64 {,./}config-aarch64 {,./}" *.patch" {,./}" ${spec_file} "
9167
@@ -116,13 +92,9 @@ inner_full_config() {
11692 popd || bail " Could not move around - 'popd' back to /work failed. Lets stop before we break anything further."
11793
11894 for arch in " x86_64" " aarch64" ; do
119-
120- export CROSS_COMPILE=/usr/bin/${arch} -bottlerocket-linux-gnu-
121- export KCONFIG_CONFIG=bottlerocket_${arch} _defconfig
122-
12395 br_cfg=" ${kernel_path} /config-bottlerocket"
12496 br_cfg_arch=" ${kernel_path} /config-bottlerocket-${arch} "
125- microcode_cfg=" /microcode /${microcode_file} "
97+ microcode_cfg=" ${MICROCODE_DIR} /${microcode_file} "
12698
12799 pushd " linux-${version} " || bail " Could not move into linux-${version} "
128100
@@ -134,25 +106,24 @@ inner_full_config() {
134106 script_args=(" ../config-${arch} " " ${microcode_cfg} " " ${br_cfg} " " ${br_cfg_arch} " )
135107 fi
136108
137- ARCH=${karch} ./scripts/kconfig/merge_config.sh " ${script_args[@]} "
109+ ARCH=${karch} \
110+ CROSS_COMPILE=/usr/bin/${arch} -bottlerocket-linux-gnu- \
111+ KCONFIG_CONFIG=bottlerocket_${arch} _defconfig \
112+ ./scripts/kconfig/merge_config.sh " ${script_args[@]} "
113+
138114 mv -f " bottlerocket_${arch} _defconfig" " ${kernel_path} /config-full-bottlerocket-${arch} " || bail " Failed to create config-full-bottlerocket-${arch} "
139115 popd || bail " Could not move around - 'popd' failed in merge_config loop. Lets stop before we break anything further."
140116 done
141117
142- # Validate the generated configurations
143- echo " Validating generated kernel configurations..."
144- validate_kernel_configs
118+ popd || bail " Could not return from temporary directory"
145119}
146120
147121# Function to validate kernel configurations (similar to validate_config.sh)
148122validate_kernel_configs () {
123+ local version=" $1 "
124+ local majorminor=" $2 "
149125 local errors=0
150- local kernel_path=/kernel-package
151-
152- # Extract kernel version for validation
153- local version
154- version=" $( rpm --query --nosignature --queryformat ' %{VERSION}' kernel-source.rpm) "
155- local majorminor=${version% .* } # Trim after last '.', e.g. 6.1.132 -> 6.1
126+ local kernel_path=" ${KERNEL_KIT_DIR} /packages/kernel-${majorminor} "
156127
157128 for arch in x86_64 aarch64; do
158129 echo " === Validating kernel-${majorminor} ${arch} ==="
@@ -213,3 +184,74 @@ validate_kernel_configs() {
213184 bail " Kernel configuration validation failed"
214185 fi
215186}
187+
188+ # Parse command line arguments
189+ while [[ $# -gt 0 ]]; do
190+ case $1 in
191+ -h|--help)
192+ usage
193+ exit 0
194+ ;;
195+ * )
196+ echo " Unknown option: $1 "
197+ usage
198+ exit 1
199+ ;;
200+ esac
201+ shift
202+ done
203+
204+ # Ensure this script is run within the Bottlerocket SDK container
205+ if [[ ! -d " ${KERNEL_KIT_DIR} " ]]; then
206+ usage
207+ bail
208+ fi
209+
210+ # In kernel kit automation, CodePipeline updates each kernel separately.
211+ # This script processes only kernels that have available RPM files,
212+ # skipping any kernel packages without corresponding source RPMs.
213+ kernels_to_process=()
214+ for kernel_dir in " ${KERNEL_KIT_DIR} /packages" /kernel-* ; do
215+ if [[ -d " ${kernel_dir} " ]]; then
216+ kernel_pkg=$( basename " ${kernel_dir} " )
217+ # In CodePipeline, only one RPM exists per kernel package, but during development
218+ # multiple RPMs can coexist. Use version sorting to select the latest RPM.
219+ # Sorting rules: https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html
220+ rpm_file=$( find " ${kernel_dir} " -name " kernel*.src.rpm" | sort -V | tail -1)
221+ if [[ -n " ${rpm_file} " ]]; then
222+ kernels_to_process+=(" ${kernel_pkg} " )
223+ echo " Found RPM for ${kernel_pkg} : $( basename " ${rpm_file} " ) "
224+ else
225+ echo " No RPM found for ${kernel_pkg} , skipping"
226+ fi
227+ else
228+ bail " No Kernel directory found for ${kernel_dir} "
229+ fi
230+ done
231+
232+ if [[ ${# kernels_to_process[@]} -eq 0 ]]; then
233+ bail " No kernel RPMs found in any package directory"
234+ fi
235+
236+ # Process available kernels
237+ for kernel_pkg in " ${kernels_to_process[@]} " ; do
238+ echo " Processing ${kernel_pkg} ..."
239+
240+ tmpdir=$( mktemp -d)
241+
242+ pushd " ${tmpdir} " || bail " Unable to enter temporary directory"
243+
244+ rpm_file=$( find " ${KERNEL_KIT_DIR} /packages/${kernel_pkg} " -name " kernel*.src.rpm" | head -1)
245+
246+ cp " ${rpm_file} " kernel-source.rpm
247+
248+ version=" $( rpm --query --nosignature --queryformat ' %{VERSION}' kernel-source.rpm) "
249+ majorminor=${version% .* } # Trim after last '.', e.g. 6.1.132 -> 6.1
250+
251+ merge_kernel_configs " ${version} " " ${majorminor} " " ${tmpdir} "
252+
253+ echo " Validating ${kernel_pkg} configurations..."
254+ validate_kernel_configs " ${version} " " ${majorminor} " || bail " Validation failed for ${kernel_pkg} "
255+
256+ popd || bail " Could not return from temporary directory"
257+ done
0 commit comments