Skip to content

Commit c40a534

Browse files
The-goingigorpecovnik
authored andcommitted
dtoverlays: Provide a choice and record only the overlays that can be loaded.
1 parent 4915f6a commit c40a534

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

tools/modules/system/manage_dtoverlays.sh

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
module_options+=(
33
["manage_dtoverlays,author"]="@viraniac"
4-
["manage_dtoverlays,maintainer"]="@igorpecovnik,@The-Going"
4+
["manage_dtoverlays,maintainer"]="@igorpecovnik,@The-going"
55
["manage_dtoverlays,ref_link"]=""
66
["manage_dtoverlays,feature"]="manage_dtoverlays"
77
["manage_dtoverlays,desc"]="Enable/disable device tree overlays"
@@ -33,48 +33,73 @@ function manage_dtoverlays () {
3333

3434
[[ ! -f "${overlayconf}" || ! -d "${overlaydir}" ]] && echo -e "Incompatible OS configuration\nArmbian device tree configuration files not found" | show_message && return 1
3535

36-
# check /boot/boot.scr scenario ${overlay_prefix}-${overlay_name}.dtbo
37-
# or ${overlay_name}.dtbo only
36+
# check /boot/boot.scr scenario overlay(s)/${overlay_prefix}-${overlay_name}.dtbo
37+
# or overlay(s)/${overlay_name}.dtbo.
3838
# scenario:
3939
# 00 - The /boot/boot.scr script cannot load the overlays provided by Armbian.
4040
# 01 - It is possible to load only if the full name of the overlay is written.
4141
# 10 - Loading is possible only if the overlay name is written without a prefix.
4242
# 11 - Both spellings will be loaded.
4343
scenario=$(
4444
awk 'BEGIN{p=0;s=0}
45-
/load.*overlay\/\${overlay_prefix}-\${overlay_file}.dtbo/{p=1}
46-
/load.*overlay\/\${overlay_file}.dtbo/{s=1}
47-
END{print p s}
48-
' /boot/boot.scr
45+
/load.*overlays?\/\${overlay_prefix}-\${overlay_file}.dtbo/{p=1}
46+
/load.*overlays?\/\${overlay_file}.dtbo/{s=1}
47+
END{print p s}
48+
' /boot/boot.scr
4949
)
5050

5151
while true; do
5252
local options=()
5353
j=0
5454

55-
# read overlays
56-
available_overlays=$(
57-
# Find the files that match the overlay prefix pattern.
58-
# Remove the overlay prefix, file extension, and path
59-
# in one pass. Sort it out.
60-
find ${overlaydir}/ -name "$overlay_prefix"'*.dtbo' 2>/dev/null | \
61-
awk -F'/' -v p="${overlay_prefix}-" '{
62-
gsub(p, "", $0)
63-
gsub(".dtbo", "", $0)
64-
print $NF
65-
}' | sort
66-
)
55+
if [[ "${scenario}" == "10" ]] || [[ "${scenario}" == "11" ]]; then
56+
# read overlays
57+
available_overlays=$(
58+
# Find the files that match the overlay prefix pattern.
59+
# Remove the overlay prefix, file extension, and path
60+
# in one pass. Sort it out.
61+
find "${overlaydir}"/ -name "$overlay_prefix"'*.dtbo' 2>/dev/null | \
62+
awk -F'/' -v p="${overlay_prefix}-" '{
63+
gsub(p, "", $NF)
64+
gsub(".dtbo", "", $NF)
65+
print $NF
66+
}' | sort
67+
)
68+
fi
6769

6870
# Check the branch in case it is not available in /etc/armbian-release
6971
update_kernel_env
7072

7173
# Add support for rk3588 vendor kernel overlays which don't have overlay prefix mostly
7274
builtin_overlays=""
73-
if [[ $BOARDFAMILY == "rockchip-rk3588" ]] && [[ $BRANCH == "vendor" ]]; then
74-
builtin_overlays=$(ls -1 ${overlaydir}/*.dtbo | grep -v ${overlay_prefix} | sed 's#^'${overlaydir}'/##' | sed 's/.dtbo//g')
75+
if [[ "${scenario}" == "01" ]] || [[ "${scenario}" == "11" ]]; then
76+
77+
if [[ $BOARDFAMILY == "rockchip-rk3588" ]] && [[ $BRANCH == "vendor" ]]; then
78+
builtin_overlays=$(
79+
find "${overlaydir}"/ -name '*.dtbo' ! -name "$overlay_prefix"'*.dtbo' 2>/dev/null | \
80+
awk -F'/' -v p="${overlay_prefix}" '{
81+
if ($0 !~ p) {
82+
gsub(".dtbo", "", $NF)
83+
print $NF
84+
}
85+
}' | sort
86+
)
87+
fi
88+
fi
89+
90+
if [[ "${scenario}" == "00" ]]; then
91+
$DIALOG --title " Manage devicetree overlays " \
92+
--no-button "Cancel" \
93+
--yes-button "Exit" \
94+
--yesno " The overlays provided by Armbian cannot be loaded\n by /boot/boot.scr script.\n" 11 44
95+
exit_status=$?
96+
if [ $exit_status == 0 ]; then
97+
exit 0
98+
fi
99+
break
75100
fi
76101

77-
for overlay in ${available_overlays}; do
102+
for overlay in ${available_overlays} ${builtin_overlays}; do
78103
local status="OFF"
79104
grep '^overlays' ${overlayconf} | grep -qw ${overlay} && status=ON
80105
# Raspberry Pi

0 commit comments

Comments
 (0)