From a22898c92bb9283ccbad9ee74a770c28bbd052e0 Mon Sep 17 00:00:00 2001 From: Andreas Gnau Date: Wed, 29 Mar 2023 14:42:39 +0200 Subject: [PATCH] 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 --- iop/scripts/genconfig.sh | 23 ++++++++++++++++++++--- iop/scripts/genconfig_min.sh | 25 +++++++++++++++++++++---- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/iop/scripts/genconfig.sh b/iop/scripts/genconfig.sh index 5df1f9580..6d21bb468 100755 --- a/iop/scripts/genconfig.sh +++ b/iop/scripts/genconfig.sh @@ -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 diff --git a/iop/scripts/genconfig_min.sh b/iop/scripts/genconfig_min.sh index d46219603..ffc3ab6ba 100644 --- a/iop/scripts/genconfig_min.sh +++ b/iop/scripts/genconfig_min.sh @@ -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 @@ -316,15 +334,14 @@ function genconfig_min { # Special handling for targets which use TARGET_DEVICES case "$target" in - airoha | iopsys_mediatek | brcmbca | ipq95xx) + 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