Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/runtime/base/lava.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ context:
{%- else -%}
{%- set test_timeout = 15 + coverage_timeout -%}
{%- endif -%}
{%- set full_timeout = 15 + test_timeout -%}
{%- set full_timeout = boot_deploy_timeout|default(15)|int + test_timeout -%}

timeouts:
action:
Expand Down
107 changes: 63 additions & 44 deletions config/runtime/boot/fastboot.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -7,79 +7,98 @@
- LAVA postprocessing gaining access to the NFS path before mkbootimg
Until one of these is confirmed to work, fastboot platforms must be
excluded from NFS jobs in the scheduler configuration. #}
{# The profile packages artifacts; the device dictionary controls fastboot.
Only profiles preserving a legacy initramfs fallback accept NFS-labelled jobs. #}
{% import 'fastboot/profiles/' + fastboot_image_profile|default('android') + '.jinja2' as profile with context %}
{% if boot_commands == 'nfs' and not profile.allow_nfs_fallback|default(false) %}
{{ kci_raise('fastboot requires an initramfs; NFS boot is not supported') }}
{% endif %}
{% if profile.host_boot_only|default(false) and fastboot_docker_image|default('') %}
{{ kci_raise('this fastboot profile requires host-side device pre_os_command execution') }}
{% endif %}
{% set needs_kselftest = test_method|default('') in ['kselftest', 'kselftest-platform-parameters'] %}
{% set ramdisk_url = node.artifacts.ramdisk|default('', true) %}
{% if not ramdisk_url %}
{% set ramdisk_url = ramdisk|default('', true) %}
{% endif %}
{% if not ramdisk_url %}
{% set configured_ramdiskroot = ramdiskroot|default('', true) %}
{% if configured_ramdiskroot %}
{% set ramdisk_url = configured_ramdiskroot + '/rootfs.cpio.gz' %}
{% endif %}
{% endif %}
{% if not ramdisk_url %}
{{ kci_raise('fastboot requires a ramdisk from node artifacts or a rootfs_ref') }}
{% endif %}
{% if not node.artifacts.kernel or not node.artifacts.dtb %}
{{ kci_raise('fastboot requires kernel and DTB artifact URLs') }}
{% endif %}
{% set kselftest_url = node.artifacts.kselftest_tar_xz|default(node.artifacts.kselftest_tar_gz, true) %}
{% if needs_kselftest and not kselftest_url %}
{{ kci_raise('kselftest requires a kselftest_tar_xz or kselftest_tar_gz artifact') }}
{% endif %}
- deploy:
to: downloads
{% if profile.download_timeout %}
timeout:
minutes: {{ profile.download_timeout }}
timeouts:
download-retry:
minutes: {{ profile.download_timeout }}
http-download:
minutes: {{ profile.download_timeout }}
{% endif %}
images:
image:
url: '{{ node.artifacts.kernel }}'
url: {{ node.artifacts.kernel|tojson }}
dtb:
url: '{{ node.artifacts.dtb }}'
url: {{ node.artifacts.dtb|tojson }}
ramdisk:
{% if boot_commands == "ramdisk" %}
url: '{{ ramdiskroot }}/rootfs.cpio.gz'
{% else %}
url: '{{ ramdisk }}'
{% endif %}
url: {{ ramdisk_url|tojson }}
compression: gz
format: cpio.newc
overlays:
lava: true
{% if node.artifacts.modules %}
modules:
url: '{{ node.artifacts.modules }}'
url: {{ node.artifacts.modules|tojson }}
compression: xz
format: tar
path: /
{% if boot_commands == "ramdisk" %}
{% endif %}
{% if needs_kselftest %}
kselftest:
compression: xz
compression: {{ 'xz' if node.artifacts.kselftest_tar_xz else 'gz' }}
format: tar
path: /opt/kselftests/mainline/
url: {{ node.artifacts.kselftest_tar_xz }}
{% endif %}
{% set dtb = device_dtb.split('/')[-1] %}
{% if boot_commands == "ramdisk" %}
{% set ramdisk_name = "rootfs.cpio.gz" %}
{% else %}
{% set ramdisk_name = "rootfs.cpio.gz" %}
url: {{ kselftest_url|tojson }}
{% endif %}
{% set append_dtb = fastboot_boot_image_format|default('android-header-dtb') == 'appended-dtb' %}
{% set kernel_image = 'Image.gz' if node.data.kernel_type.endswith('.gz') else 'Image' %}
{% set boot_kernel_image = kernel_image + '+dtb' if append_dtb else 'Image' %}
postprocess:
docker:
image: ghcr.io/mwasilew/docker-mkbootimage:master
image: {{ profile.postprocess_image|tojson }}
steps:
{%- if append_dtb %}
- cat {{ kernel_image }} {{ dtb }} > {{ boot_kernel_image }}
{%- elif node.data.kernel_type.endswith('.gz') %}
- gunzip Image.gz
{%- endif %}
{%- if append_dtb %}
- mkbootimg --kernel {{ boot_kernel_image }} --cmdline "console=ttyMSM0,115200n8 earlycon qcom_geni_serial.con_enabled=1 mem_sleep_default=s2idle mitigations=auto video=efifb:off" --ramdisk {{ ramdisk_name }} --pagesize {{ fastboot_mkbootimg_pagesize|default(4096) }} --base {{ fastboot_mkbootimg_base|default('0x80000000') }} --output boot.img
{%- else %}
- mkbootimg --header_version 2 --kernel Image --dtb {{ dtb }} --cmdline "console=ttyMSM0,115200n8 earlycon qcom_geni_serial.con_enabled=1 mem_sleep_default=s2idle mitigations=auto video=efifb:off" --ramdisk {{ ramdisk_name }} --output boot.img
{%- endif %}
to: downloads
{%- set kernel = node.artifacts.kernel.split('?')[0].split('/')[-1] %}
{%- set dtb = node.artifacts.dtb.split('?')[0].split('/')[-1] %}
{%- set ramdisk_name = ramdisk_url.split('?')[0].split('/')[-1] %}
{{ profile.prepare(kernel, dtb, ramdisk_name).strip()|indent(8, true) }}

- deploy:
to: {{ profile.deploy_to }}
images:
boot:
url: 'downloads://boot.img'
{% if fastboot_docker_image %}
{{ profile.image_label }}:
url: {{ ('downloads://' + profile.image_name)|tojson }}
{% if fastboot_docker_image|default('') %}
docker:
image: '{{ fastboot_docker_image }}'
image: {{ fastboot_docker_image|tojson }}
{% endif %}
timeout:
minutes: 2
{% if fastboot_docker_image %}
to: fastboot
{% else %}
to: download
{% endif %}
minutes: {{ profile.deploy_timeout }}

- boot:
prompts:
- '/ #'
- '~ #'
- 'root@[^:]+:~#'
failure_retry: 3
timeout:
minutes: 10
Expand All @@ -89,7 +108,7 @@
auto-login-action:
minutes: 2
method: fastboot
{% if fastboot_docker_image %}
{% if fastboot_docker_image|default('') %}
docker:
image: '{{ fastboot_docker_image }}'
image: {{ fastboot_docker_image|tojson }}
{% endif %}
12 changes: 12 additions & 0 deletions config/runtime/fastboot/images/ext4.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{# Package the caller's STAGE directory; no board layout or fastboot commands. #}
{% macro create(image_name, label, capacity_mb, features, block_size=4096, minimum_mb=128) -%}
- PAYLOAD=$(du -sb "$STAGE" | cut -f1)
- PAYLOAD_MB=$(( (PAYLOAD + 1048575) / 1048576 ))
{# Payload + 15% + 16 MiB of metadata, rounded up to 16 MiB. #}
- SIZE=$(( (( (PAYLOAD_MB * 115 + 99) / 100 + 16 + 15) / 16) * 16 ))
- if [ "$SIZE" -lt {{ minimum_mb }} ]; then SIZE={{ minimum_mb }}; fi
- if [ "$SIZE" -gt {{ capacity_mb }} ]; then echo "image needs ${SIZE} MiB (payload ${PAYLOAD_MB} MiB), partition capacity is {{ capacity_mb }} MiB" >&2; exit 1; fi
- rm -f -- {{ image_name | shellquote }}
- mkfs.ext4 -F -q -L {{ label | shellquote }} -m 0 -b {{ block_size }} -O {{ features | shellquote }} -d "$STAGE" {{ image_name | shellquote }} "${SIZE}M"
- e2fsck -fn {{ image_name | shellquote }}
{%- endmacro %}
26 changes: 26 additions & 0 deletions config/runtime/fastboot/profiles/android.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{# Preserve the Android image formats used by existing fastboot platforms. #}
{# This stable branch also uses initramfs boot for jobs labelled NFS.
The job must still supply node.artifacts.ramdisk. #}
{% set allow_nfs_fallback = true %}
{% set image_name = 'boot.img' %}
{% set image_label = 'boot' %}
{% set deploy_to = 'fastboot' if fastboot_docker_image|default('') else 'download' %}
{% set postprocess_image = 'ghcr.io/mwasilew/docker-mkbootimage:master' %}
{# Preserve job/device timeout inheritance for existing Android platforms. #}
{% set download_timeout = none %}
{% set deploy_timeout = 2 %}

{% macro prepare(kernel, dtb, ramdisk, firmware=none) -%}
{% set append_dtb = fastboot_boot_image_format|default('android-header-dtb') == 'appended-dtb' %}
{% set cmdline = fastboot_kernel_cmdline|default('console=ttyMSM0,115200n8 earlycon qcom_geni_serial.con_enabled=1 mem_sleep_default=s2idle mitigations=auto video=efifb:off') %}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @docularxu for fixing default cmdline! No behaviour change for existing android device now.

- {% set cmdline = fastboot_kernel_cmdline|default('console=ttyMSM0,115200n8 earlycon root=/dev/ram rw rootwait rdinit=/sbin/init ignore_loglevel clk_ignore_unused pd_ignore_unused fw_devlink=off no_console_suspend kernel.sched_pelt_multiplier=4 mem_sleep_default=s2idle mitigations=auto video=efifb:off') %}
+ {% set cmdline = fastboot_kernel_cmdline|default('console=ttyMSM0,115200n8 earlycon qcom_geni_serial.con_enabled=1 mem_sleep_default=s2idle mitigations=auto video=efifb:off') %}

{% if append_dtb %}
- cat {{ kernel|shellquote }} {{ dtb|shellquote }} > kernel-with-dtb
- mkbootimg --kernel kernel-with-dtb --cmdline {{ cmdline|shellquote }} --ramdisk {{ ramdisk|shellquote }} --pagesize {{ fastboot_mkbootimg_pagesize|default(4096) }} --base {{ fastboot_mkbootimg_base|default('0x80000000') }} --output boot.img
{% else %}
{% if kernel.endswith('.gz') %}
- gzip -dc {{ kernel|shellquote }} > kernel-uncompressed
{% set kernel = 'kernel-uncompressed' %}
{% endif %}
- mkbootimg --header_version 2 --kernel {{ kernel|shellquote }} --dtb {{ dtb|shellquote }} --cmdline {{ cmdline|shellquote }} --ramdisk {{ ramdisk|shellquote }} --output boot.img
{% endif %}
{%- endmacro %}
53 changes: 53 additions & 0 deletions config/runtime/fastboot/profiles/spacemit-k3.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{# SpacemiT K3 firmware/partition contract. All board assumptions live here. #}
{% import 'fastboot/images/ext4.jinja2' as ext4 %}
{% set image_name = 'bootfs.ext4' %}
{% set image_label = 'bootfs' %}
{% set deploy_to = 'fastboot' %}
{% set host_boot_only = true %}
{% set download_timeout = 30 %}
{% set deploy_timeout = 10 %}
{% set postprocess_image = 'artifacts.codelinaro.org/clo-420-qli-registry/kmake-image-ci:ver.1.0' %}
{% set partition_size_mb = fastboot_bootfs_size_mb|default(256) %}
{% set dtb_directory = 'spacemit' %}
{% set environment_file = 'env_k3.txt' %}
{% set ramdisk_address = '0x130000000' %}
{% set large_ramdisk_threshold = 134217728 %}
{% set relocated_dtb_address = '0x13ff00000' %}
{% set maximum_ramdisk_size = 267386880 %}
{# An explicit feature list works with older e2fsprogs, which reject even
^orphan_file when they do not recognize orphan_file. Keep features readable
by the board's U-Boot, without orphan_file or metadata_csum_seed. #}
{% set ext4_features = 'none,has_journal,ext_attr,resize_inode,dir_index,filetype,extent,64bit,flex_bg,sparse_super,large_file,huge_file,dir_nlink,extra_isize,metadata_csum' %}

{% macro prepare(kernel, dtb, ramdisk, firmware=none) -%}
- KERNEL={{ kernel | shellquote }}
- DTB={{ dtb | shellquote }}
- RAMDISK={{ ramdisk | shellquote }}
- DTB_DIRECTORY={{ dtb_directory | shellquote }}
- ENVIRONMENT_FILE={{ environment_file | shellquote }}
- if gzip -t "$KERNEL" 2>/dev/null; then KCAT="gzip -dc"; else KCAT=cat; fi
- gzip -t "$RAMDISK"
- LIST=$(mktemp)
- STAGE=$(mktemp -d)
- trap 'rm -rf "$STAGE"; rm -f "$LIST"' EXIT
- gzip -dc "$RAMDISK" | cpio -it --quiet | sed 's#^\./##' > "$LIST"
- grep -qx init "$LIST" || { echo "ramdisk does not contain /init" >&2; exit 1; }
{# Prefer the kernel's version banner; accept one module release as fallback. #}
- MODVERS=$(sed -n 's#^\(usr/\)\{0,1\}lib/modules/\([^/]*\)/modules\.dep$#\2#p' "$LIST" | sort -u)
- KVER=$($KCAT "$KERNEL" | grep -a -o -m1 'Linux version [0-9][0-9]*\.[0-9][^ ]*' | cut -d' ' -f3)
- if [ -z "$KVER" ]; then NMOD=$(echo "$MODVERS" | grep -c . || true); [ "$NMOD" -eq 1 ] || { echo "cannot determine kernel release ($NMOD module releases)" >&2; exit 1; }; KVER=$MODVERS; fi
- 'echo "Kernel release: $KVER"'
- 'awk -v p="lib/modules/$KVER/" ''{ sub(/^usr\//, "") } index($0, p) == 1 { f = 1 } END { exit !f }'' "$LIST" || echo "WARNING: no modules for $KVER in the ramdisk"'
- mkdir -p "$STAGE/$DTB_DIRECTORY/$KVER"
- install -m 0644 "$KERNEL" "$STAGE/vmlinuz-$KVER"
- install -m 0644 "$RAMDISK" "$STAGE/initrd.img-$KVER"
- install -m 0644 "$DTB" "$STAGE/$DTB_DIRECTORY/$KVER/$DTB"
- printf '%s\n' "knl_name=vmlinuz-$KVER" "ramdisk_name=initrd.img-$KVER" "dtb_dir=$DTB_DIRECTORY/$KVER" {{ ('ramdisk_addr_r=' + ramdisk_address) | shellquote }} 'loglevel=8' 'commonargs=setenv bootargs plymouth.prefer-fbcon plymouth.ignore-serial-consoles splash' > "$STAGE/$ENVIRONMENT_FILE"
{# Relocate the DTB before a large ramdisk would overwrite its default address. #}
- RDSIZE=$(stat -c %s "$RAMDISK")
- if [ "$RDSIZE" -gt {{ large_ramdisk_threshold }} ]; then echo {{ ('fdt_addr_r=' + relocated_dtb_address) | shellquote }} >> "$STAGE/$ENVIRONMENT_FILE"; fi
- '[ "$RDSIZE" -le {{ maximum_ramdisk_size }} ] || { echo "ramdisk ($RDSIZE bytes) exceeds board load-address limits" >&2; exit 1; }'
- chmod 0644 "$STAGE/$ENVIRONMENT_FILE"
{{ ext4.create(image_name, image_label, partition_size_mb, ext4_features) }}
- find "$STAGE" -type f -printf '%P %s bytes\n' | sort
{%- endmacro %}
5 changes: 5 additions & 0 deletions config/runtime/tests/kselftest-platform-parameters.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
{% endif %}
- repository: https://github.com/linaro/test-definitions.git
from: git
{% if kselftest_shallow_clone %}
branch: master
history: false
{% else %}
revision: master
{% endif %}
path: automated/linux/kselftest/kselftest.yaml
name: '{{ node.name }}'
parameters:
Expand Down
5 changes: 5 additions & 0 deletions config/runtime/tests/kselftest.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
{% endif %}
- repository: https://github.com/linaro/test-definitions.git
from: git
{% if kselftest_shallow_clone %}
branch: master
history: false
{% else %}
revision: master
{% endif %}
path: automated/linux/kselftest/kselftest.yaml
name: '{{ node.name }}'
parameters:
Expand Down
17 changes: 13 additions & 4 deletions kernelci/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import abc
import importlib
import os
import shlex

import requests
import yaml
Expand Down Expand Up @@ -123,13 +124,21 @@ def templates(self):
"""List of template directories used with this runtime"""
return self._templates

def _get_template(self, job_config):
loaders = [FileSystemLoader(path) for path in self.templates]
@classmethod
def _get_jinja2_environment(cls, templates=None):
template_dirs = templates if templates is not None else cls.TEMPLATES
loaders = [FileSystemLoader(path) for path in template_dirs]
jinja2_env = Environment(
loader=ChoiceLoader(loaders), extensions=["jinja2.ext.do"]
)
jinja2_env.globals.update(self._get_jinja2_functions())
return jinja2_env.get_template(job_config.template)
jinja2_env.globals.update(cls._get_jinja2_functions())
jinja2_env.filters["shellquote"] = shlex.quote
return jinja2_env

def _get_template(self, job_config):
return self._get_jinja2_environment(self.templates).get_template(
job_config.template
)

@classmethod
def _get_jinja2_functions(cls):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import pytest
import requests
import yaml
from jinja2 import Environment, FileSystemLoader
from jinja2 import Environment
from jinja2.exceptions import TemplateRuntimeError

import kernelci.config
Expand Down Expand Up @@ -47,9 +47,9 @@ def test_legacy_kci_raise_uses_jinja_runtime_error():
def test_fastboot_docker_image_is_optional(docker_image):
"""Fastboot actions use a container only when one is configured."""
template_dir = Path(__file__).parents[1] / "config" / "runtime"
template = Environment(loader=FileSystemLoader(template_dir)).get_template(
"boot/fastboot.jinja2"
)
template = kernelci.runtime.Runtime._get_jinja2_environment(
[template_dir]
).get_template("boot/fastboot.jinja2")
params = {
"boot_commands": "ramdisk",
"device_dtb": "dtbs/qcom/apq8096-db820c.dtb",
Expand Down