Support OCP debug card postcode display

Description:
 - Meson option postcode display path is supported
 - Support OCP debug card postcode display

Example of test process:
   1. Set postcode-display-path as /sys/bus/i2c/devices/12-
      000f/postcode-display-slot in project layer
   2. Press OCP debug card uart button to the host to check
   3. Host power on
   4. The postcode should start displaying on the OCP debug card screen
      with user-readable string representation for those codes
Note:
 - The postcode-display-path was setting by CLD driver, which
   will though CPLD setting ocp-debug card
   (link: https://lore.kernel.org/lkml/20230117094425.19004-1-Delphine_CC_Chiu@Wiwynn.com/)

Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Change-Id: I915c0ec29d763b8933835a9fdc8881648ca95d24
diff --git a/meson.build b/meson.build
index 5a078f8..0a42309 100644
--- a/meson.build
+++ b/meson.build
@@ -15,6 +15,7 @@
 conf_data = configuration_data()
 conf_data.set_quoted('DBUS_OBJECT_NAME', '/xyz/openbmc_project/State/Boot/PostCode')
 conf_data.set_quoted('DBUS_INTF_NAME','xyz.openbmc_project.State.Boot.PostCode')
+conf_data.set_quoted('POSTCODE_DISPLAY_PATH', get_option('postcode-display-path'))
 conf_data.set('MAX_BOOT_CYCLE_COUNT',get_option('max-boot-cycle-count'))
 conf_data.set('MAX_POST_CODE_SIZE_PER_CYCLE',get_option('max-post-code-size-per-cycle'))
 
diff --git a/meson_options.txt b/meson_options.txt
index d877b97..763b30f 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,4 @@
 option('max-boot-cycle-count', type:'integer', min:1, max: 100, description: 'Maximum boot cycles for which the post codes should be persisted', value:100)
 option('bios-post-code-log', type:'feature',description:'bios post code log',value:'disabled')
 option('max-post-code-size-per-cycle', type:'integer', min:64, max: 1024, description: 'Maximum post code file size per cycle', value:512)
+option('postcode-display-path', type:'string', description:'The sys path for postcode display on debug card')
diff --git a/src/post_code.cpp b/src/post_code.cpp
index 327e29e..ddabf30 100644
--- a/src/post_code.cpp
+++ b/src/post_code.cpp
@@ -112,6 +112,17 @@
         timer->start(std::chrono::microseconds(timeoutMicroSeconds));
     }
 
+    if (strlen(POSTCODE_DISPLAY_PATH) > 0)
+    {
+        std::string postCodeDisplayPath = POSTCODE_DISPLAY_PATH +
+                                          std::to_string(node);
+
+        std::ofstream postCodeDisplayFile(postCodeDisplayPath);
+        postCodeDisplayFile << "0x" << std::setfill('0') << std::setw(2)
+                            << std::hex << std::get<0>(code);
+        postCodeDisplayFile.close();
+    }
+
 #ifdef ENABLE_BIOS_POST_CODE_LOG
     uint64_t usTimeOffset = tsUS - firstPostCodeUsSinceEpoch;
     std::ostringstream hexCode;