BootLib: DeviceInfo: set bootloader version during compile time

Change-Id: I3f669841e4c91ac44f6d19db73005d981269fdac
Signed-off-by: Alexander Martinz <amartinz@shiftphones.com>
diff --git a/AndroidBoot.mk b/AndroidBoot.mk
index 51d2f9b..25097db 100644
--- a/AndroidBoot.mk
+++ b/AndroidBoot.mk
@@ -79,6 +79,11 @@
 else
 	BOARD_BOOTLOADER_PRODUCT_MODEL := unknown
 endif
+ifneq ($(TARGET_BOOTLOADER_VERSION),)
+	BOARD_BOOTLOADER_VERSION := $(TARGET_BOOTLOADER_VERSION)
+else
+	BOARD_BOOTLOADER_VERSION := unknown
+endif
 
 ifneq ($(TARGET_BOARD_TYPE),auto)
 	TARGET_BOARD_TYPE_AUTO := TARGET_BOARD_TYPE_AUTO=0
@@ -174,4 +179,5 @@
 		TARGET_ARCHITECTURE=$(TARGET_ARCHITECTURE) \
 		BOARD_BOOTLOADER_PRODUCT_NAME=$(BOARD_BOOTLOADER_PRODUCT_NAME) \
 		BOARD_BOOTLOADER_PRODUCT_MODEL=$(BOARD_BOOTLOADER_PRODUCT_MODEL) \
+		BOARD_BOOTLOADER_VERSION=$(BOARD_BOOTLOADER_VERSION) \
 		USERDATAIMAGE_FILE_SYSTEM_TYPE=$(USERDATAIMAGE_FILE_SYSTEM_TYPE)
diff --git a/QcomModulePkg/Library/BootLib/DeviceInfo.c b/QcomModulePkg/Library/BootLib/DeviceInfo.c
index db265b5..074b970 100644
--- a/QcomModulePkg/Library/BootLib/DeviceInfo.c
+++ b/QcomModulePkg/Library/BootLib/DeviceInfo.c
@@ -240,14 +240,7 @@
 {
   EFI_STATUS Status = EFI_SUCCESS;
 
-  if (!StrCmp ((CONST CHAR16 *)Pname, (CONST CHAR16 *)L"bootloader")) {
-    AsciiStrnCpyS (DevInfo.bootloader_version, MAX_VERSION_LEN, PRODUCT_NAME,
-                   AsciiStrLen (PRODUCT_NAME));
-    AsciiStrnCatS (DevInfo.bootloader_version, MAX_VERSION_LEN, "-",
-                   AsciiStrLen ("-"));
-    AsciiStrnCatS (DevInfo.bootloader_version, MAX_VERSION_LEN, ImgVersion,
-                   AsciiStrLen (ImgVersion));
-  } else {
+  if (StrCmp ((CONST CHAR16 *)Pname, (CONST CHAR16 *)L"bootloader")) {
     AsciiStrnCpyS (DevInfo.radio_version, MAX_VERSION_LEN, PRODUCT_NAME,
                    AsciiStrLen (PRODUCT_NAME));
     AsciiStrnCatS (DevInfo.radio_version, MAX_VERSION_LEN, "-",
@@ -279,6 +272,9 @@
     FirstReadDevInfo = FALSE;
   }
 
+  AsciiStrnCpyS (DevInfo.bootloader_version, MAX_VERSION_LEN, PRODUCT_BOOTLOADER_VERSION,
+                 AsciiStrLen (PRODUCT_BOOTLOADER_VERSION));
+
   EnableChargingScreen (TRUE);
 
   if (CompareMem (DevInfo.magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) {
diff --git a/QcomModulePkg/QcomModulePkg.dsc b/QcomModulePkg/QcomModulePkg.dsc
index 210b274..b9ac2d2 100644
--- a/QcomModulePkg/QcomModulePkg.dsc
+++ b/QcomModulePkg/QcomModulePkg.dsc
@@ -96,6 +96,7 @@
   GCC:*_*_*_CC_FLAGS = -DZ_SOLO
   GCC:*_*_*_CC_FLAGS = -DPRODUCT_NAME=\"$(BOARD_BOOTLOADER_PRODUCT_NAME)\"
   GCC:*_*_*_CC_FLAGS = -DPRODUCT_MODEL=\"$(BOARD_BOOTLOADER_PRODUCT_MODEL)\"
+  GCC:*_*_*_CC_FLAGS = -DPRODUCT_BOOTLOADER_VERSION=\"$(BOARD_BOOTLOADER_VERSION)\"
 
   !if $(VERIFIED_BOOT)
       GCC:*_*_*_CC_FLAGS = -DVERIFIED_BOOT