meta-quanta: gbs: improve overwrite fan hwmon to json config

update the fan hwmon variables to be wrapped in @@ to
avoid any mis-replacement

Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: I6ecfb868fe1b58b2918bdb2760462250f0c4ae3a
diff --git a/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/config-sku.json b/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/config.json.in
similarity index 97%
rename from meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/config-sku.json
rename to meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/config.json.in
index e5040ca..21ba368 100644
--- a/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/config-sku.json
+++ b/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/config.json.in
@@ -1,11 +1,11 @@
 {
-    "version": "R04",
+    "version": "R05",
     "sensors": [
         {
             "name": "fan0",
             "type": "fan",
             "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan0",
-            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/Fan_0_To_4_Hwmon/pwm1",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/@Fan_0_To_4_Hwmon@/pwm1",
             "min": 0,
             "max": 255
         },
@@ -13,7 +13,7 @@
             "name": "fan1",
             "type": "fan",
             "readPath": "/xyz/openbmc_project/sensors/fan_tach/fan1",
-            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/Fan_0_To_4_Hwmon/pwm2",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/@Fan_0_To_4_Hwmon@/pwm2",
             "min": 0,
             "max": 255
         },
@@ -21,7 +21,7 @@
             "name": "fb_fan0",
             "type": "fan",
             "readPath": "/xyz/openbmc_project/sensors/fan_tach/fb_fan0",
-            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/Fan_0_To_4_Hwmon/pwm3",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/@Fan_0_To_4_Hwmon@/pwm3",
             "min": 0,
             "max": 255
         },
@@ -29,7 +29,7 @@
             "name": "fb_fan1",
             "type": "fan",
             "readPath": "/xyz/openbmc_project/sensors/fan_tach/fb_fan1",
-            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/Fan_0_To_4_Hwmon/pwm4",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/@Fan_0_To_4_Hwmon@/pwm4",
             "min": 0,
             "max": 255
         },
@@ -37,7 +37,7 @@
             "name": "fb_fan2",
             "type": "fan",
             "readPath": "/xyz/openbmc_project/sensors/fan_tach/fb_fan2",
-            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/Fan_0_To_4_Hwmon/pwm5",
+            "writePath": "/sys/devices/platform/ahb/ahb:apb/f0103000.pwm-fan-controller/hwmon/@Fan_0_To_4_Hwmon@/pwm5",
             "min": 0,
             "max": 255
         },
diff --git a/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/fan-table-init.sh b/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/fan-table-init.sh
index 624bb4e..9617d0d 100644
--- a/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/fan-table-init.sh
+++ b/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control/fan-table-init.sh
@@ -1,10 +1,8 @@
 #!/bin/bash
 
-FAN_TABLE_SKU_FILE="/usr/share/swampd/config-sku.json"
-FAN_TABLE_FILE="/usr/share/swampd/config.json"
-
-# determine sku
-cp $FAN_TABLE_SKU_FILE $FAN_TABLE_FILE
+FAN_TABLE_FILE_IN="/usr/share/swampd/config.json.in"
+TEMP_FILE="$(mktemp)"
+cp "$FAN_TABLE_FILE_IN" "$TEMP_FILE"
 
 # wait for fan dbus
 mapper wait /xyz/openbmc_project/sensors/fan_tach/fan0
@@ -14,12 +12,15 @@
 mapper wait /xyz/openbmc_project/sensors/fan_tach/fb_fan2
 
 # generate fan table writePath
-Fan_0_To_4_Hwmon="$(ls /sys/devices/platform/ahb/ahb\:apb/f0103000.pwm-fan-controller/hwmon/)"
+Fan_0_To_4_Hwmon="$(ls /sys/devices/platform/ahb/ahb\:*/*pwm-fan-controller/hwmon/)"
 
 if [[ "$Fan_0_To_4_Hwmon" != "" ]]; then
-     sed -i "s/Fan_0_To_4_Hwmon/$Fan_0_To_4_Hwmon/g" $FAN_TABLE_FILE
+     sed -i "s/@Fan_0_To_4_Hwmon@/$Fan_0_To_4_Hwmon/g" $TEMP_FILE
 fi
 
+# Use shell parameter expansion to trim the ".in" suffix
+mv "$TEMP_FILE" "${FAN_TABLE_FILE_IN%".in"}"
+
 # start read margin temp wait
 /usr/bin/read-margin-temp-wait.sh &
 
diff --git a/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control_%.bbappend b/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control_%.bbappend
index 25e102c..e617f86 100644
--- a/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control_%.bbappend
+++ b/meta-quanta/meta-gbs/recipes-phosphor/fans/phosphor-pid-control_%.bbappend
@@ -1,10 +1,10 @@
 FILESEXTRAPATHS_prepend_gbs := "${THISDIR}/${PN}:"
-SRC_URI_append_gbs = " file://config-sku.json \
+SRC_URI_append_gbs = " file://config.json.in \
                        file://fan-table-init.sh \
                        file://phosphor-pid-control.service \
                      "
 
-FILES_${PN}_append_gbs = " ${datadir}/swampd/config-sku.json"
+FILES_${PN}_append_gbs = " ${datadir}/swampd/config.json.in"
 FILES_${PN}_append_gbs = " ${bindir}/fan-table-init.sh"
 
 RDEPENDS_${PN} += "bash"
@@ -16,8 +16,8 @@
     install -m 0755 ${WORKDIR}/fan-table-init.sh ${D}/${bindir}
 
     install -d ${D}${datadir}/swampd
-    install -m 0644 -D ${WORKDIR}/config-sku.json \
-        ${D}${datadir}/swampd/config-sku.json
+    install -m 0644 -D ${WORKDIR}/config.json.in \
+        ${D}${datadir}/swampd/
 
     install -d ${D}${systemd_system_unitdir}
     install -m 0644 ${WORKDIR}/phosphor-pid-control.service \