1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-05 18:30:50 +01: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:
Metin Kaya 2024-01-19 16:15:14 +00:00 committed by Marc Bonnici
parent dd84dc7e38
commit 1431bebd80
9 changed files with 279 additions and 0 deletions

View File

@ -25,6 +25,7 @@ Contents:
derived_measurements
platform
connection
tools
Indices and tables
==================

View File

@ -41,3 +41,45 @@ Android emulator:
# After ~30 seconds, the emulated device will be ready:
adb -s emulator-5554 shell "lsmod"
Building buildroot
------------------
``buildroot/generate-kernel-initrd.sh`` helper script downloads and builds
``buildroot`` per config files located under ``tools/buildroot/configs``
for the specified architecture.
The script roughly checks out ``2023.11.1`` tag of ``buildroot``, copies config
files for buildroot (e.g., ``configs/aarch64/arm-power_aarch64_defconfig``) and
kernel (e.g., ``configs/aarch64/linux.config``) to necessary places under
buildroot directory, and runs ``make arm-power_aarch64_defconfig && make``
commands.
As its name suggests, ``generate-kernel-initrd.sh`` builds kernel image with an
initial RAM disk per default config files.
There is also ``post-build.sh`` script in order to make following tunings on
root filesystem generated by ``buildroot``:
- allow root login on SSH.
- increase number of concurrent SSH connections/channels to let devlib
consumers hammering the target system.
In order to keep rootfs minimal, only OpenSSH and util-linux packages
are enabled in the default configuration files.
DHCP client and SSH server services are enabled on target system startup.
SCHED_MC, SCHED_SMT and UCLAMP_TASK scheduler features are enabled for aarch64
kernel.
If you need to make changes on ``buildroot``, rootfs or kernel of target
system, you may want to run commands similar to these:
.. code:: shell
$ cd tools/buildroot/buildroot-v2023.11.1-aarch64
$ make menuconfig # or 'make linux-menuconfig' if you want to configure kernel
$ make
See https://buildroot.org/downloads/manual/manual.html for details.

1
tools/buildroot/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
buildroot-v2023.11.1-*/

View 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

View 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

View 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"

View 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

View 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

View 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."