bare-metal-setup: take command to hide/show the bootdrive

- This allows the platform to use CPLD or other mechanism to
control the boot drive.
- The GPIO approach is kept since it is simple.
- It also fails the build if none of the vars are overridden

Tested:
- in BM mode:
```
root@bmc-node:~# systemctl status -l bare-metal-setup.service
○ bare-metal-setup.service - Bare Metal Readiness Setup
     Loaded: loaded (/usr/lib/systemd/system/bare-metal-setup.service; enabled; preset: enabled)
    Drop-In: /usr/lib/systemd/system/bare-metal-setup.service.d
             └─bare-metal-setup-override.conf
     Active: inactive (dead) since Mon 2024-06-24 22:42:57 PDT; 2s ago
    Process: 26841 ExecStart=/usr/bin/bare-metal-setup.sh (code=exited, status=0/SUCCESS)
   Main PID: 26841 (code=exited, status=0/SUCCESS)
        CPU: 234ms

Jun 24 22:42:53 bmc-node.prod.google.com systemd[1]: Starting Bare Metal Readiness Setup...
Jun 24 22:42:54 bmc-node.prod.google.com bare-metal-setup.sh[26841]: hiding the boot drive with '/usr/bin/bare_metal_mode_setting.sh hide'
Jun 24 22:42:54 bmc-node.prod.google.com bare-metal-setup.sh[26842]: Configure the bare metal mode setting.
Jun 24 22:42:54 bmc-node.prod.google.com bare-metal-setup.sh[26842]: Hide the bootdrive.
Jun 24 22:42:54 bmc-node.prod.google.com bare-metal-setup.sh[26841]: Successfully set the GPIO to hide cSSD/cnSSD creating /run/bm-ready.flag
Jun 24 22:42:57 bmc-node.prod.google.com systemd[1]: bare-metal-setup.service: Deactivated successfully.
Jun 24 22:42:57 bmc-node.prod.google.com systemd[1]: Finished Bare Metal Readiness Setup.
```
- in non-BM mode
```
root@bmc-node:~# rm /var/google/config-package/enable-bm.flag
root@bmc-node:~# systemctl restart bare-metal-setup.service
root@bmc-node:~# systemctl status -l bare-metal-setup.service
○ bare-metal-setup.service - Bare Metal Readiness Setup
     Loaded: loaded (/usr/lib/systemd/system/bare-metal-setup.service; enabled; preset: enabled)
    Drop-In: /usr/lib/systemd/system/bare-metal-setup.service.d
             └─bare-metal-setup-override.conf
     Active: inactive (dead) since Mon 2024-06-24 22:44:27 PDT; 6s ago
    Process: 27658 ExecStart=/usr/bin/bare-metal-setup.sh (code=exited, status=0/SUCCESS)
   Main PID: 27658 (code=exited, status=0/SUCCESS)
        CPU: 167ms

Jun 24 22:44:24 bmc-node.prod.google.com systemd[1]: Starting Bare Metal Readiness Setup...
Jun 24 22:44:27 bmc-node.prod.google.com bare-metal-setup.sh[27658]: Powering on the cSSD/cnSSD as we are not in BM mode - remove /run/bm-ready.flag
Jun 24 22:44:27 bmc-node.prod.google.com bare-metal-setup.sh[27658]: showing the boot drive with '/usr/bin/bare_metal_mode_setting.sh show'
Jun 24 22:44:27 bmc-node.prod.google.com bare-metal-setup.sh[27781]: Configure the bare metal mode setting.
Jun 24 22:44:27 bmc-node.prod.google.com bare-metal-setup.sh[27781]: Show the bootdrive.
Jun 24 22:44:27 bmc-node.prod.google.com systemd[1]: bare-metal-setup.service: Deactivated successfully.
Jun 24 22:44:27 bmc-node.prod.google.com systemd[1]: Finished Bare Metal Readiness Setup.
```

Fusion-Link: fusion2/e5c3ce54-cb5a-35ff-b039-3592c6941189
Fusion-Link: fusion2/0889ae64-e0ed-3ee2-b484-d2a9d7515782
Goolge-Bug-Id: 283220552
Google-Bug-Id: 346888923
Change-Id: Idb2d317ffe5d10e059ae097fcfa2848eb3eb9e21
Signed-off-by: Leo Tu <leotu@google.com>
diff --git a/recipes-google/bare-metal-setup/bare-metal-setup.bb b/recipes-google/bare-metal-setup/bare-metal-setup.bb
index 1789bfc..2bea979 100644
--- a/recipes-google/bare-metal-setup/bare-metal-setup.bb
+++ b/recipes-google/bare-metal-setup/bare-metal-setup.bb
@@ -23,18 +23,30 @@
     "
 
 BM_MODE ?= "0"
-GPIO_CHIP ?= "0"
-GPIO_LINE ?= "0"
+GPIO_CHIP ?= ""
+GPIO_LINE ?= ""
+# the command to hide the boot drive
+HIDE_BOOT_DRIVE ?= ""
+# the command to show (un-hide) the boot drive
+SHOW_BOOT_DRIVE ?= ""
 ENABLE_BM_FILE ?= "/var/google/config-package/enable-bm.flag"
 ENABLE_CONSOLE_FILE ?= "/var/google/config-package/enable-bm-console.flag"
 BMREADY_FILE ?= "/run/bm-ready.flag"
 
 do_install:append() {
+    if [ -z "${GPIO_CHIP}" -o -z "${GPIO_LINE}" ] && \
+        [ -z "${HIDE_BOOT_DRIVE}" -o -z "${SHOW_BOOT_DRIVE}" ]; then
+        echo "Invalid configuration: "
+        echo "either (GPIO_CHIP & GPIO_LINE) or (HIDE_BOOT_DRIVE & SHOW_BOOT_DRIVE) must be defined"
+        exit 1
+    fi
 
     sed bare-metal-setup.sh.in \
         -e "s#@BM_MODE@#${BM_MODE}#" \
         -e "s#@GPIO_CHIP@#${GPIO_CHIP}#" \
         -e "s#@GPIO_LINE@#${GPIO_LINE}#" \
+        -e "s#@HIDE_BOOT_DRIVE@#${HIDE_BOOT_DRIVE}#" \
+        -e "s#@SHOW_BOOT_DRIVE@#${SHOW_BOOT_DRIVE}#" \
         -e "s#@ENABLE_BM_FILE@#${ENABLE_BM_FILE}#" \
         -e "s#@ENABLE_CONSOLE_FILE@#${ENABLE_CONSOLE_FILE}#" \
         -e "s#@BMREADY_FILE@#${BMREADY_FILE}#" \
diff --git a/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in b/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in
index f29e5fb..b4d0336 100644
--- a/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in
+++ b/recipes-google/bare-metal-setup/files/bare-metal-setup.sh.in
@@ -5,6 +5,8 @@
 
 GPIO_CHIP="@GPIO_CHIP@"
 GPIO_LINE="@GPIO_LINE@"
+HIDE_BOOT_DRIVE="@HIDE_BOOT_DRIVE@"
+SHOW_BOOT_DRIVE="@SHOW_BOOT_DRIVE@"
 ENABLE_BM_FILE="@ENABLE_BM_FILE@"
 ENABLE_CONSOLE_FILE="@ENABLE_CONSOLE_FILE@"
 BMREADY_FILE="@BMREADY_FILE@"
@@ -92,12 +94,32 @@
 }
 
 function hide_boot_drive_in_bm_mode() {
+    if [[ -n "${HIDE_BOOT_DRIVE}" ]]; then
+        echo "hiding the boot drive with '${HIDE_BOOT_DRIVE}'" >&2
+        ${HIDE_BOOT_DRIVE}
+    else
+        echo "hiding the boot drive with GPIO (${GPIO_CHIP}/${GPIO_LINE})" >&2
+        gpioset --mode=signal --background "${GPIO_CHIP}" "${GPIO_LINE}"=0
+    fi
+}
+
+function show_boot_drive() {
+    if [[ -n "${SHOW_BOOT_DRIVE}" ]]; then
+        echo "showing the boot drive with '${SHOW_BOOT_DRIVE}'" >&2
+        ${SHOW_BOOT_DRIVE}
+    else
+        echo "showing the boot drive with GPIO (${GPIO_CHIP}/${GPIO_LINE})" >&2
+        gpioset --mode=time -s 1 "${GPIO_CHIP}" "${GPIO_LINE}"=1
+    fi
+}
+
+function main() {
     # In Bare Metal mode, power off the boot drive
     if [[ "$BM_MODE" -eq "1" || -f "$ENABLE_BM_FILE" ]]; then
         # Turn off the power to the boot drive
         # and keep asserting the power down
-        if ! gpioset --mode=signal --background "$GPIO_CHIP" "$GPIO_LINE"=0; then
-            echo "Unable to set the GPIO to hide cSSD/cnSSD - skip adding ${BMREADY_FILE}"
+        if ! hide_boot_drive_in_bm_mode; then
+            echo "Unable to hide cSSD/cnSSD - skip adding ${BMREADY_FILE}"
             exit 1
         fi
         echo "Successfully set the GPIO to hide cSSD/cnSSD creating ${BMREADY_FILE}"
@@ -121,10 +143,8 @@
         # Turn on the power to the boot drive
         echo "Powering on the cSSD/cnSSD as we are not in BM mode - remove ${BMREADY_FILE}"
         rm -f "${BMREADY_FILE}"
-        gpioset --mode=time -s 1 "$GPIO_CHIP" "$GPIO_LINE"=1
+        show_boot_drive
     fi
 }
 
-hide_boot_drive_in_bm_mode
-
-exit 0
+main "$@"