ethernet_interface: Runtime detect uboot-env

We don't need a build time option as systems not using it don't include
uboot fw_setenv.

Change-Id: I922fb9ebb0309ab1a792892c28417794f5ed6ef0
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/meson.build b/meson.build
index 1ce272b..549b4df 100644
--- a/meson.build
+++ b/meson.build
@@ -10,7 +10,6 @@
 
 conf_data = configuration_data()
 conf_data.set_quoted('DEFAULT_BUSNAME', default_busname)
-conf_data.set('HAVE_UBOOT_ENV', get_option('uboot-env'))
 conf_data.set(
     'LINK_LOCAL_AUTOCONFIGURATION',
     get_option('default-link-local-autoconf'),
diff --git a/meson.options b/meson.options
index b7f2531..6cb3bf9 100644
--- a/meson.options
+++ b/meson.options
@@ -1,11 +1,6 @@
 option('tests', type: 'feature', description: 'Build tests')
 
 option(
-    'uboot-env',
-    type: 'boolean',
-    description: 'Update u-boot env for MAC changes',
-)
-option(
     'default-link-local-autoconf',
     type: 'boolean',
     description: 'Enable link local autoconfiguration by default',
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 9cef02f..c965ddc 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -966,17 +966,18 @@
         manager.get().reloadConfigs();
     }
 
-#ifdef HAVE_UBOOT_ENV
-    // Ensure that the valid address is stored in the u-boot-env
-    auto envVar = interfaceToUbootEthAddr(interface);
-    if (envVar)
+    std::error_code ec;
+    const auto fw_setenv = std::filesystem::path("/sbin/fw_setenv");
+    if (std::filesystem::exists(fw_setenv, ec))
     {
-        // Trimming MAC addresses that are out of range. eg: AA:FF:FF:FF:FF:100;
-        // and those having more than 6 bytes. eg: AA:AA:AA:AA:AA:AA:BB
-        execute("/sbin/fw_setenv", "fw_setenv", envVar->c_str(),
-                validMAC.c_str());
+        // Ensure that the valid address is stored in the u-boot-env
+        auto envVar = interfaceToUbootEthAddr(interface);
+        if (envVar)
+        {
+            execute(fw_setenv.native(), "fw_setenv", envVar->c_str(),
+                    validMAC.c_str());
+        }
     }
-#endif // HAVE_UBOOT_ENV
 
     return value;
 #else