mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-10-31 14:01:20 +00:00 
			
		
		
		
	tools/buildroot: Add support for generating Linux target system images
Integrate buildroot into devlib in order to ease building kernel and root filesystem images via 'generate-kernel-initrd.sh' helper script. As its name suggests, the script builds kernel image which also includes an initial RAM disk per default config files located under configs/<arch>/. Provide config files for buildroot and Linux kernel as well as a post-build.sh script which tweaks (e.g., allowing root login on SSH) target's root filesystem. doc/tools.rst talks about details of kernel and rootfs configuration. Signed-off-by: Metin Kaya <metin.kaya@arm.com>
This commit is contained in:
		
							
								
								
									
										1
									
								
								tools/buildroot/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								tools/buildroot/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| buildroot-v2023.11.1-*/ | ||||
							
								
								
									
										17
									
								
								tools/buildroot/configs/aarch64/arm-power_aarch64_defconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								tools/buildroot/configs/aarch64/arm-power_aarch64_defconfig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| BR2_aarch64=y | ||||
| BR2_cortex_a73_a53=y | ||||
| BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y | ||||
| BR2_TARGET_GENERIC_ROOT_PASSWD="root" | ||||
| BR2_SYSTEM_DHCP="eth0" | ||||
| BR2_ROOTFS_POST_BUILD_SCRIPT="board/arm-power/post-build.sh" | ||||
| BR2_LINUX_KERNEL=y | ||||
| BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y | ||||
| BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/arm-power/aarch64/linux.config" | ||||
| BR2_LINUX_KERNEL_XZ=y | ||||
| BR2_PACKAGE_OPENSSH=y | ||||
| # BR2_PACKAGE_OPENSSH_SANDBOX is not set | ||||
| BR2_PACKAGE_UTIL_LINUX=y | ||||
| BR2_PACKAGE_UTIL_LINUX_BINARIES=y | ||||
| BR2_TARGET_ROOTFS_CPIO_XZ=y | ||||
| BR2_TARGET_ROOTFS_INITRAMFS=y | ||||
| # BR2_TARGET_ROOTFS_TAR is not set | ||||
							
								
								
									
										36
									
								
								tools/buildroot/configs/aarch64/linux.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								tools/buildroot/configs/aarch64/linux.config
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | ||||
| CONFIG_SCHED_MC=y | ||||
| CONFIG_UCLAMP_TASK=y | ||||
| CONFIG_SCHED_SMT=y | ||||
| CONFIG_KERNEL_XZ=y | ||||
| CONFIG_SYSVIPC=y | ||||
| CONFIG_IKCONFIG=y | ||||
| CONFIG_IKCONFIG_PROC=y | ||||
| CONFIG_CGROUPS=y | ||||
| CONFIG_BLK_DEV_INITRD=y | ||||
| CONFIG_INITRAMFS_SOURCE="${BR_BINARIES_DIR}/rootfs.cpio" | ||||
| # CONFIG_RD_GZIP is not set | ||||
| # CONFIG_RD_BZIP2 is not set | ||||
| # CONFIG_RD_LZMA is not set | ||||
| # CONFIG_RD_LZO is not set | ||||
| # CONFIG_RD_LZ4 is not set | ||||
| # CONFIG_RD_ZSTD is not set | ||||
| CONFIG_SMP=y | ||||
| # CONFIG_GCC_PLUGINS is not set | ||||
| CONFIG_MODULES=y | ||||
| CONFIG_MODULE_UNLOAD=y | ||||
| CONFIG_NET=y | ||||
| CONFIG_PACKET=y | ||||
| CONFIG_UNIX=y | ||||
| CONFIG_INET=y | ||||
| CONFIG_PCI=y | ||||
| CONFIG_PCI_HOST_GENERIC=y | ||||
| CONFIG_DEVTMPFS=y | ||||
| CONFIG_DEVTMPFS_MOUNT=y | ||||
| CONFIG_NETDEVICES=y | ||||
| CONFIG_VIRTIO_NET=y | ||||
| CONFIG_INPUT_EVDEV=y | ||||
| CONFIG_SERIAL_AMBA_PL011=y | ||||
| CONFIG_SERIAL_AMBA_PL011_CONSOLE=y | ||||
| CONFIG_VIRTIO_CONSOLE=y | ||||
| CONFIG_VIRTIO_PCI=y | ||||
| CONFIG_TMPFS=y | ||||
							
								
								
									
										15
									
								
								tools/buildroot/configs/post-build.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										15
									
								
								tools/buildroot/configs/post-build.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| #!/bin/sh | ||||
|  | ||||
| set -eux | ||||
|  | ||||
| # Enable root login on SSH | ||||
| sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/' "${TARGET_DIR}/etc/ssh/sshd_config" | ||||
|  | ||||
| # Increase the number of available channels so that devlib async code can | ||||
| # exploit concurrency better. | ||||
| sed -i 's/#MaxSessions.*/MaxSessions 100/' "${TARGET_DIR}/etc/ssh/sshd_config" | ||||
| sed -i 's/#MaxStartups.*/MaxStartups 100/' "${TARGET_DIR}/etc/ssh/sshd_config" | ||||
|  | ||||
| # To test Android bindings of ChromeOsTarget | ||||
| mkdir -p "${TARGET_DIR}/opt/google/containers/android" | ||||
|  | ||||
							
								
								
									
										16
									
								
								tools/buildroot/configs/x86_64/arm-power_x86_64_defconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								tools/buildroot/configs/x86_64/arm-power_x86_64_defconfig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| BR2_x86_64=y | ||||
| BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y | ||||
| BR2_TARGET_GENERIC_ROOT_PASSWD="root" | ||||
| BR2_SYSTEM_DHCP="eth0" | ||||
| BR2_ROOTFS_POST_BUILD_SCRIPT="board/arm-power/post-build.sh" | ||||
| BR2_LINUX_KERNEL=y | ||||
| BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y | ||||
| BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/arm-power/x86_64/linux.config" | ||||
| BR2_LINUX_KERNEL_XZ=y | ||||
| BR2_PACKAGE_OPENSSH=y | ||||
| # BR2_PACKAGE_OPENSSH_SANDBOX is not set | ||||
| BR2_PACKAGE_UTIL_LINUX=y | ||||
| BR2_PACKAGE_UTIL_LINUX_BINARIES=y | ||||
| BR2_TARGET_ROOTFS_CPIO_XZ=y | ||||
| BR2_TARGET_ROOTFS_INITRAMFS=y | ||||
| # BR2_TARGET_ROOTFS_TAR is not set | ||||
							
								
								
									
										31
									
								
								tools/buildroot/configs/x86_64/linux.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								tools/buildroot/configs/x86_64/linux.config
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| CONFIG_KERNEL_XZ=y | ||||
| CONFIG_SYSVIPC=y | ||||
| CONFIG_IKCONFIG=y | ||||
| CONFIG_IKCONFIG_PROC=y | ||||
| CONFIG_CGROUPS=y | ||||
| CONFIG_BLK_DEV_INITRD=y | ||||
| CONFIG_INITRAMFS_SOURCE="${BR_BINARIES_DIR}/rootfs.cpio" | ||||
| # CONFIG_RD_GZIP is not set | ||||
| # CONFIG_RD_BZIP2 is not set | ||||
| # CONFIG_RD_LZMA is not set | ||||
| # CONFIG_RD_LZO is not set | ||||
| # CONFIG_RD_LZ4 is not set | ||||
| # CONFIG_RD_ZSTD is not set | ||||
| CONFIG_SMP=y | ||||
| # CONFIG_GCC_PLUGINS is not set | ||||
| CONFIG_MODULES=y | ||||
| CONFIG_MODULE_UNLOAD=y | ||||
| CONFIG_NET=y | ||||
| CONFIG_PACKET=y | ||||
| CONFIG_UNIX=y | ||||
| CONFIG_INET=y | ||||
| CONFIG_PCI=y | ||||
| CONFIG_DEVTMPFS=y | ||||
| CONFIG_DEVTMPFS_MOUNT=y | ||||
| CONFIG_NETDEVICES=y | ||||
| CONFIG_VIRTIO_NET=y | ||||
| CONFIG_INPUT_EVDEV=y | ||||
| CONFIG_SERIAL_8250=y | ||||
| CONFIG_SERIAL_8250_CONSOLE=y | ||||
| CONFIG_VIRTIO_PCI=y | ||||
| CONFIG_TMPFS=y | ||||
							
								
								
									
										120
									
								
								tools/buildroot/generate-kernel-initrd.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										120
									
								
								tools/buildroot/generate-kernel-initrd.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,120 @@ | ||||
| #!/usr/bin/env bash | ||||
| # | ||||
| # SPDX-License-Identifier: Apache-2.0 | ||||
| # | ||||
| # Copyright (C) 2024, ARM Limited and contributors. | ||||
| # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||||
| # not use this file except in compliance with the License. | ||||
| # You may obtain a copy of the License at | ||||
| # | ||||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| # Unless required by applicable law or agreed to in writing, software | ||||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| # See the License for the specific language governing permissions and | ||||
| # limitations under the License. | ||||
| # | ||||
| # Forked from LISA/tools/lisa-buildroot-create-rootfs. | ||||
| # | ||||
|  | ||||
| set -eu | ||||
|  | ||||
| ARCH="aarch64" | ||||
| BUILDROOT_URI="git://git.busybox.net/buildroot" | ||||
| KERNEL_IMAGE_NAME="Image" | ||||
|  | ||||
| function print_usage | ||||
| { | ||||
| 	echo "Usage: ${0} [options]" | ||||
| 	echo "	options:" | ||||
| 	echo "		-a: set arch (default is aarch64, x86_64 is also supported)" | ||||
| 	echo "		-p: purge buildroot to force a fresh build" | ||||
| 	echo "		-h: print this help message" | ||||
| } | ||||
|  | ||||
| function set_arch | ||||
| { | ||||
| 	if [[ "${1}" == "aarch64" ]]; then | ||||
| 		return 0 | ||||
| 	elif [[ "${1}" == "x86_64" ]]; then | ||||
| 		ARCH="x86_64" | ||||
| 		KERNEL_IMAGE_NAME="bzImage" | ||||
| 		return 0 | ||||
| 	fi | ||||
|  | ||||
| 	return 1 | ||||
| } | ||||
|  | ||||
| while getopts "ahp" opt; do | ||||
| 	case ${opt} in | ||||
| 	a) | ||||
| 		shift | ||||
| 		if ! set_arch "${1}"; then | ||||
| 			echo "Invalid arch \"${1}\"." | ||||
| 			exit 1 | ||||
| 		fi | ||||
| 		;; | ||||
| 	p) | ||||
| 		rm -rf "${BUILDROOT_DIR}" | ||||
| 		exit 0 | ||||
| 		;; | ||||
| 	h) | ||||
| 		print_usage | ||||
| 		exit 0 | ||||
| 		;; | ||||
| 	*) | ||||
| 		print_usage | ||||
| 		exit 1 | ||||
| 		;; | ||||
| 	esac | ||||
| done | ||||
|  | ||||
| # Execute function for once | ||||
| function do_once | ||||
| { | ||||
| 	FILE="${BUILDROOT_DIR}/.devlib_${1}" | ||||
| 	if [ ! -e "${FILE}" ]; then | ||||
| 		eval "${1}" | ||||
| 		touch "${FILE}" | ||||
| 	fi | ||||
| } | ||||
|  | ||||
| function br_clone | ||||
| { | ||||
| 	git clone -b ${BUILDROOT_VERSION} -v ${BUILDROOT_URI} "${BUILDROOT_DIR}" | ||||
| } | ||||
|  | ||||
| function br_apply_config | ||||
| { | ||||
| 	pushd "${BUILDROOT_DIR}" >/dev/null | ||||
|  | ||||
| 	mkdir -p "board/arm-power/${ARCH}/" | ||||
| 	cp -f "../configs/post-build.sh" "board/arm-power/" | ||||
| 	cp -f "../configs/${ARCH}/arm-power_${ARCH}_defconfig" "configs/" | ||||
| 	cp -f "../configs/${ARCH}/linux.config" "board/arm-power/${ARCH}/" | ||||
|  | ||||
| 	make "arm-power_${ARCH}_defconfig" | ||||
|  | ||||
| 	popd >/dev/null | ||||
| } | ||||
|  | ||||
| function br_build | ||||
| { | ||||
| 	pushd "${BUILDROOT_DIR}" >/dev/null | ||||
| 	make | ||||
| 	popd >/dev/null | ||||
| } | ||||
|  | ||||
|  | ||||
| BUILDROOT_VERSION=${BUILDROOT_VERSION:-"2023.11.1"} | ||||
| BUILDROOT_DIR="$(dirname "$0")/buildroot-v${BUILDROOT_VERSION}-${ARCH}" | ||||
|  | ||||
| do_once br_clone | ||||
|  | ||||
| do_once br_apply_config | ||||
|  | ||||
| br_build | ||||
|  | ||||
| echo "Kernel image \"${BUILDROOT_DIR}/output/images/${KERNEL_IMAGE_NAME}\" is ready." | ||||
		Reference in New Issue
	
	Block a user