meta-bletchley: phosphor-nvme: add nvme config script

In Bletchley, we use PCIE_PWR_EN pin as NVME power good pin from each
interposer board. Because PCIE_PWR_EN is form the I/O expander, it
won't have fixed GPIO pin number.

Add script to generate a nvme_config.json with correct GPIO pin number
before nvme management service start.

Tested:

- nvme_config.json generated
```
root@bletchley:~# cat /etc/nvme/nvme_config.json
{
    "config": [
        {
            "NVMeDriveIndex": 1,
            "NVMeDriveBusID": 0,
            "NVMeDrivePwrGoodPin": 779
        },
        {
            "NVMeDriveIndex": 2,
            "NVMeDriveBusID": 1,
            "NVMeDrivePwrGoodPin": 759
        },
        {
            "NVMeDriveIndex": 3,
            "NVMeDriveBusID": 2,
            "NVMeDrivePwrGoodPin": 739
        },
        {
            "NVMeDriveIndex": 4,
            "NVMeDriveBusID": 3,
            "NVMeDrivePwrGoodPin": 719
        },
        {
            "NVMeDriveIndex": 5,
            "NVMeDriveBusID": 4,
            "NVMeDrivePwrGoodPin": 699
        },
        {
            "NVMeDriveIndex": 6,
            "NVMeDriveBusID": 5,
            "NVMeDrivePwrGoodPin": 679
        }
    ],
    "threshold": [
        {
            "criticalHigh": 68,
            "criticalLow": 0,
            "warningHigh": 67,
            "warningLow": 1,
            "maxValue": 127,
            "minValue": -127
        }
    ]
}
```
- nvme sensor available (host on)
```
root@bletchley:~# busctl introspect xyz.openbmc_project.nvme.manager \
< /xyz/openbmc_project/sensors/temperature/nvme6 \
< xyz.openbmc_project.Sensor.Value
NAME                                             TYPE      SIGNATURE RESULT/VALUE                             FLAGS
xyz.openbmc_project.Sensor.Value                 interface -         -                                        -
.MaxValue                                        property  d         127                                      emits-change writable
.MinValue                                        property  d         -127                                     emits-change writable
.Unit                                            property  s         "xyz.openbmc_project.Sensor.Value.Uni... emits-change writable
.Value                                           property  d         36                                       emits-change writable
root@bletchley:~# busctl introspect xyz.openbmc_project.nvme.manager \
> /xyz/openbmc_project/sensors/temperature/nvme6 \
> xyz.openbmc_project.State.Decorator.Availability
NAME                                             TYPE      SIGNATURE RESULT/VALUE FLAGS
.Available                                       property  b         true         emits-change writable
```

- nvme sensor not available (host off)
```
root@bletchley:~# busctl introspect xyz.openbmc_project.nvme.manager \
> /xyz/openbmc_project/sensors/temperature/nvme6 \
> xyz.openbmc_project.Sensor.Value
NAME                             TYPE      SIGNATURE RESULT/VALUE                             FLAGS
.MaxValue                        property  d         127                                      emits-change writable
.MinValue                        property  d         -127                                     emits-change writable
.Unit                            property  s         "xyz.openbmc_project.Sensor.Value.Uni... emits-change writable
.Value                           property  d         -127                                     emits-change writable
root@bletchley:~# busctl introspect xyz.openbmc_project.nvme.manager \
> /xyz/openbmc_project/sensors/temperature/nvme6 \
> xyz.openbmc_project.State.Decorator.Availability
NAME                                             TYPE      SIGNATURE RESULT/VALUE FLAGS
.Available                                       property  b         false        emits-change writable
```

Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I2cda2e5e252fdfdd66ba6f9e0ea006c425cbf43b
diff --git a/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-nvme/nvme-json-rewrite b/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-nvme/nvme-json-rewrite
new file mode 100644
index 0000000..d30ed89
--- /dev/null
+++ b/meta-facebook/meta-bletchley/recipes-phosphor/sensors/phosphor-nvme/nvme-json-rewrite
@@ -0,0 +1,72 @@
+#!/bin/bash
+
+TARGET_FILE_NAME="/etc/nvme/nvme_config.json"
+
+export_gpio() {
+  if [ ! -d "/sys/class/gpio/gpio$1" ]; then
+    echo "$1" >/sys/class/gpio/export
+  fi
+}
+
+for i in {0..5}
+do
+    SLED_NVME_PCIE_EN[$i]=0
+    for file in /sys/bus/i2c/drivers/pca953x/"$i"-0041/gpio/gpiochip*/base
+    do
+        if [ -f "$file" ]; then
+            GPIOCHIP_BASE="$(cat /sys/bus/i2c/drivers/pca953x/"$i"-0041/gpio/gpiochip*/base)"
+            SLED_NVME_PCIE_EN[$i]=$((GPIOCHIP_BASE+3))
+            export_gpio ${SLED_NVME_PCIE_EN[$i]}
+            break
+        fi
+    done
+done
+
+cat > $TARGET_FILE_NAME << EOF1
+{
+    "maxSmbusErrorRetry": 3,
+    "config": [
+        {
+            "NVMeDriveIndex": 1,
+            "NVMeDriveBusID": 0,
+            "NVMeDrivePwrGoodPin": ${SLED_NVME_PCIE_EN[0]}
+        },
+        {
+            "NVMeDriveIndex": 2,
+            "NVMeDriveBusID": 1,
+            "NVMeDrivePwrGoodPin": ${SLED_NVME_PCIE_EN[1]}
+        },
+        {
+            "NVMeDriveIndex": 3,
+            "NVMeDriveBusID": 2,
+            "NVMeDrivePwrGoodPin": ${SLED_NVME_PCIE_EN[2]}
+        },
+        {
+            "NVMeDriveIndex": 4,
+            "NVMeDriveBusID": 3,
+            "NVMeDrivePwrGoodPin": ${SLED_NVME_PCIE_EN[3]}
+        },
+        {
+            "NVMeDriveIndex": 5,
+            "NVMeDriveBusID": 4,
+            "NVMeDrivePwrGoodPin": ${SLED_NVME_PCIE_EN[4]}
+        },
+        {
+            "NVMeDriveIndex": 6,
+            "NVMeDriveBusID": 5,
+            "NVMeDrivePwrGoodPin": ${SLED_NVME_PCIE_EN[5]}
+        }
+    ],
+    "threshold": [
+        {
+            "criticalHigh": 68,
+            "criticalLow": 0,
+            "warningHigh": 67,
+            "warningLow": 1,
+            "maxValue": 127,
+            "minValue": -127
+        }
+    ]
+}
+
+EOF1