Skip to content

Commit

Permalink
src: deploy: Add support for Rasbian 64 bits
Browse files Browse the repository at this point in the history
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 <PATH>

In the 64 bits scenario we have to use:

 cp arch/arm64/boot/dts/broadcom/*.dtb <PATH>

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 <siqueirajordao@riseup.net>
  • Loading branch information
rodrigosiqueira committed Mar 19, 2022
1 parent 86b69f1 commit e93ea54
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
10 changes: 10 additions & 0 deletions etc/kworkflow_template.config
Expand Up @@ -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

Expand Down
47 changes: 46 additions & 1 deletion src/deploy.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/kw_config_loader.sh
Expand Up @@ -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=(
Expand Down
54 changes: 54 additions & 0 deletions tests/deploy_test.sh
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/kw_config_loader_test.sh
Expand Up @@ -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"
Expand Down

0 comments on commit e93ea54

Please sign in to comment.