From e93ea549d91c72569f28753a19269556bc090192 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 15 Mar 2022 07:22:16 -0400 Subject: [PATCH] src: deploy: Add support for Rasbian 64 bits For deploying a new kernel to a Raspberry Pi with 32 bits, we need to copy the dtb files by using: cp arch/arm/boot/dts/*.dtb In the 64 bits scenario we have to use: cp arch/arm64/boot/dts/broadcom/*.dtb This tiny difference raised the attention that we need to handle dtb files deploy a little bit more carefully since any vendor can specify any boot layout (at least, this is what I understood). For this reason, this commit introduces a new config option named dtb_copy_pattern, which gives the developers the flexibility to tell kw how it should copy these dtbs files. Signed-off-by: Rodrigo Siqueira --- etc/kworkflow_template.config | 10 +++++++ src/deploy.sh | 47 ++++++++++++++++++++++++++++- src/kw_config_loader.sh | 1 + tests/deploy_test.sh | 54 ++++++++++++++++++++++++++++++++++ tests/kw_config_loader_test.sh | 1 + 5 files changed, 112 insertions(+), 1 deletion(-) diff --git a/etc/kworkflow_template.config b/etc/kworkflow_template.config index b7700cf81..5f6968452 100644 --- a/etc/kworkflow_template.config +++ b/etc/kworkflow_template.config @@ -48,6 +48,16 @@ kernel_img_name=bzImage # Specify cross-compile name #cross_compile=aarch64-linux-gnu- +# Use this parameter to configure how kw will handle the dtb files. Follows +# some examples on how to use this parameter: +# Empty (dtb_copy_pattern=): It will use the battern *.dtb in the dts folder +# Pattern path (e.g., dtb_copy_pattern=broadcom/*): It will copy all dtb files +# inside broadcom folder. +# Copy folder (dtb_copy_pattern=broadcom): Points to a folder. +# Multiple folder copy (dtb_copy_pattern=broadcom,rockchip,arm): You can +# specify multiple folder to be deployed. +dtb_copy_pattern= + # Default kernel menu config option menu_config=nconfig diff --git a/src/deploy.sh b/src/deploy.sh index 8737eb47b..c5736d610 100644 --- a/src/deploy.sh +++ b/src/deploy.sh @@ -821,6 +821,48 @@ function modules_install_to() cmd_manager "$flag" "$cmd" } +# This function manages three different patterns from the config file: empty, +# single folder with a pattern, multiple folders. +# +# @arch_target: Target architecture +# +# Return: +# Return a string to be used in the source parameter of a cp command. +function compose_copy_source_parameter_for_dtb() +{ + local arch_target="$1" + local copy_pattern + local char_count + local dts_base_path + + copy_pattern="${configurations[dtb_copy_pattern]}" + dts_base_path="arch/$arch_target/boot/dts" + + # Pattern 1: No pattern. Let's copy all dtb files, e.g., copy_pattern='*.dtb' + if [[ -z "$copy_pattern" ]]; then + printf '%s/*.dtb' "$dts_base_path" + return + fi + + # Pattern 2: Mupliple dts folder, e.g., copy_pattern={broadcom,rockchip,arm} + char_count=$(str_count_char_repetition "$copy_pattern" ',') + if [[ "$char_count" -ge 1 ]]; then + printf ' -r %s/{%s}' "$dts_base_path" "$copy_pattern" + return + fi + + # Pattern 3: The '*' wildcard. E.g., copy_pattern='broadcom/*' + char_count=$(str_count_char_repetition "$copy_pattern" '*') + if [[ "$char_count" -ge 1 ]]; then + printf '%s/%s' "$dts_base_path" "$copy_pattern" + return + fi + + # Pattern 3: All other cases, e.g., dts_copy_pattern=broadcom + printf ' -r %s/%s' "$dts_base_path" "$copy_pattern" + return +} + # This function is responsible for putting all the required boot files in a # single place (~/.cache/kw/to_deploy) to be deployed to the /boot folder # later. This function checks if there are dtb/dtbo files; if so, it moves @@ -891,7 +933,10 @@ function pack_kernel_files_and_send() # 3. If we have dtb files, let's copy it if [[ -d "$dts_base_path" ]]; then - cmd_manager "$flag" "cp ${dts_base_path}/*.dtb ${cache_boot_files_path}/" + # Simple patter, e.g., copy_pattern='broadcom/*' + copy_pattern=$(compose_copy_source_parameter_for_dtb "$arch_target") + cmd_manager "$flag" "cp ${copy_pattern} ${cache_boot_files_path}/" + if [[ -d "${dts_base_path}/overlays" ]]; then cmd_manager "$flag" "mkdir -p ${cache_boot_files_path}/overlays" cmd_manager "$flag" "cp ${dts_base_path}/overlays/*.dtbo ${cache_boot_files_path}/overlays" diff --git a/src/kw_config_loader.sh b/src/kw_config_loader.sh index 9cbf15d3f..d1a5c74b7 100644 --- a/src/kw_config_loader.sh +++ b/src/kw_config_loader.sh @@ -74,6 +74,7 @@ function show_variables() [kw_files_remote_path]='kw files in the remote machine' [deploy_temporary_files_path]='Temporary files path used in the remote machine' [deploy_default_compression]='Default compression option used in the deploy' + [dtb_copy_pattern]='How kw should copy dtb files to the boot folder' ) local -Ar mail=( diff --git a/tests/deploy_test.sh b/tests/deploy_test.sh index 3ebac509a..d5fa12e81 100755 --- a/tests/deploy_test.sh +++ b/tests/deploy_test.sh @@ -333,6 +333,60 @@ function test_modules_install_to() } } +function test_compose_copy_source_parameter_for_dtb_no_pattern() +{ + local output + local expected_result + + configurations[dtb_copy_pattern]='' + expected_result='arch/arm64/boot/dts/*.dtb' + output=$(compose_copy_source_parameter_for_dtb 'arm64') + + assert_equals_helper 'Expected *.dtb pattern' "$LINENO" "$expected_result" "$output" +} + +function test_compose_copy_source_parameter_for_dtb_multiple_folder() +{ + local output + local expected_result + + configurations[dtb_copy_pattern]='broadcom,rockchip,arm' + expected_result=' -r arch/arm/boot/dts/{broadcom,rockchip,arm}' + output=$(compose_copy_source_parameter_for_dtb 'arm') + + assert_equals_helper 'Expected {} pattern' "$LINENO" "$expected_result" "$output" +} + +function test_compose_copy_source_parameter_for_dtb_wildcard() +{ + local output + local expected_result + + configurations[dtb_copy_pattern]='broadcom,rockchip/*,arm' + expected_result=' -r arch/arm/boot/dts/{broadcom,rockchip/*,arm}' + output=$(compose_copy_source_parameter_for_dtb 'arm') + + assert_equals_helper 'Expected * pattern' "$LINENO" "$expected_result" "$output" + + configurations[dtb_copy_pattern]='rockchip/*' + expected_result='arch/arm64/boot/dts/rockchip/*' + output=$(compose_copy_source_parameter_for_dtb 'arm64') + + assert_equals_helper 'Expected * pattern' "$LINENO" "$expected_result" "$output" +} + +function test_compose_copy_source_parameter_for_dtb_any_other_pattern() +{ + local output + local expected_result + + configurations[dtb_copy_pattern]='broadcom' + expected_result=' -r arch/arm/boot/dts/broadcom' + output=$(compose_copy_source_parameter_for_dtb 'arm') + + assert_equals_helper 'Expected folder name' "$LINENO" "$expected_result" "$output" +} + function test_kernel_install_to_remote_reboot() { local original="$PWD" diff --git a/tests/kw_config_loader_test.sh b/tests/kw_config_loader_test.sh index 959853a98..9513728cf 100755 --- a/tests/kw_config_loader_test.sh +++ b/tests/kw_config_loader_test.sh @@ -137,6 +137,7 @@ function test_parse_configuration_standard_config() [kw_files_remote_path]='/opt/kw' [deploy_temporary_files_path]='/tmp/kw' [deploy_default_compression]='lzop' + [dtb_copy_pattern]='' ) parse_configuration "$TMP_DIR/kworkflow.config"