iop: genconfig: Get subtarget using data from OpenWrt

Determine the subtarget for a given device using data generated from the
OpenWrt build system instead of parsing the image makefiles directly.
This provides correct results even when fancy tricks like includes
inside the Makefiles are used, which is the case for an upcoming feature
where additional devices can be defined in external feeds.

Signed-off-by: Andreas Gnau <andreas.gnau@iopsys.eu>
This commit is contained in:
Andreas Gnau 2023-03-29 14:42:39 +02:00
parent 39dbb175b9
commit a22898c92b
2 changed files with 41 additions and 7 deletions

View file

@ -298,6 +298,24 @@ function genconfig {
fi
}
get_subtarget_for_device() {
readonly target="$1"
readonly device="$2"
readonly targetinfo_file="tmp/info/.targetinfo-feeds_$target"
readonly target_profile_line="Target-Profile: DEVICE_$device"
# We want to know after which Target: $target/$subtarget line
# our $target_profile_line appears
# This is a crude way to "parse" the file using shell 🤯
# 1. grep for both lines with line number output
# 2. grep again to determine the device profile line that we looked for
# but output one context line before as well to determine corresponding subtarget line
# 4. Use head and sed to extract the subtarget
grep "^Target: $target/\|^$target_profile_line" "$targetinfo_file" \
| grep -E -B1 "^$target_profile_line" \
| head -n1 \
| sed -E "s|^Target: $target/||"
}
create_and_copy_files()
{
local BOARDTYPE=$1
@ -345,12 +363,11 @@ function genconfig {
airoha | iopsys_mediatek | brcmbca | ipq95xx)
# This assumes the device name to be unique within one target,
# which is a fair assumption to make.
local mk_file="$(grep -Fx --files-with-matches "define Device/${BOARDTYPE}" "$target_config_path/../image/"*.mk)"
if [ -z "$mk_file" ]; then
local subtarget="$(get_subtarget_for_device "$target" "$BOARDTYPE")"
if [ -z "$subtarget" ]; then
echo "Error determining subtarget for $target / ${BOARDTYPE}"
return 1
fi
local subtarget="$(basename "${mk_file%.mk}")"
echo "CONFIG_TARGET_${target}=y" >> .config
echo "CONFIG_TARGET_${target}_${subtarget}=y" >> .config
echo "CONFIG_TARGET_DEVICE_${target}_${subtarget}_DEVICE_${BOARDTYPE}=y" >> .config

View file

@ -272,6 +272,24 @@ function genconfig_min {
fi
}
get_subtarget_for_device() {
readonly target="$1"
readonly device="$2"
readonly targetinfo_file="tmp/info/.targetinfo-feeds_$target"
readonly target_profile_line="Target-Profile: DEVICE_$device"
# We want to know after which Target: $target/$subtarget line
# our $target_profile_line appears
# This is a crude way to "parse" the file using shell 🤯
# 1. grep for both lines with line number output
# 2. grep again to determine the device profile line that we looked for
# but output one context line before as well to determine corresponding subtarget line
# 4. Use head and sed to extract the subtarget
grep "^Target: $target/\|^$target_profile_line" "$targetinfo_file" \
| grep -E -B1 "^$target_profile_line" \
| head -n1 \
| sed -E "s|^Target: $target/||"
}
create_and_copy_files()
{
local BOARDTYPE=$1
@ -319,12 +337,11 @@ function genconfig_min {
airoha | iopsys_mediatek | brcmbca | ipq95xx)
# This assumes the device name to be unique within one target,
# which is a fair assumption to make.
local mk_file="$(grep -Fx --files-with-matches "define Device/${BOARDTYPE}" "$target_config_path/../image/"*.mk)"
if [ -z "$mk_file" ]; then
local subtarget="$(get_subtarget_for_device "$target" "$BOARDTYPE")"
if [ -z "$subtarget" ]; then
echo "Error determining subtarget for $target / ${BOARDTYPE}"
return 1
fi
local subtarget="$(basename "${mk_file%.mk}")"
echo "CONFIG_TARGET_${target}=y" >> .config
echo "CONFIG_TARGET_${target}_${subtarget}=y" >> .config
echo "CONFIG_TARGET_DEVICE_${target}_${subtarget}_DEVICE_${BOARDTYPE}=y" >> .config