verify the image purpose with updater type

Verify the image purpose with updater type to make sure the correct
image is targeted for a given updater type.

Tested:
```
> curl -k -H "X-Auth-Token: $token" -H "Content-Type: application/octet-stream" -X POST -T bios_image.tar https://${bmc}/redfish/v1/UpdateService/update
{
  "@odata.id": "/redfish/v1/TaskService/Tasks/0",
  "@odata.type": "#Task.v1_4_3.Task",
  "Id": "0",
  "TaskState": "Running",
  "TaskStatus": "OK"
}

Nov 05 01:51:54 romulus phosphor-software-manager[582]: Purpose (xyz.openbmc_project.Software.Version.VersionPurpose.Host) is not supported
Nov 05 01:51:54 romulus phosphor-software-manager[582]: An error occurred processing the image.

curl -k -H "X-Auth-Token: $token" -X GET https://${bmc}/redfish/v1/TaskService/Tasks/0
{
  "@odata.id": "/redfish/v1/TaskService/Tasks/0",
  "@odata.type": "#Task.v1_4_3.Task",
  "EndTime": "2024-11-05T01:51:54+00:00",
  "HidePayload": false,
  "Id": "0",
  "Messages": [
    {
      "@odata.type": "#Message.v1_1_1.Message",
      "Message": "The task with Id '0' has started.",
      "MessageArgs": [
        "0"
      ],
      "MessageId": "TaskEvent.1.0.3.TaskStarted",
      "MessageSeverity": "OK",
      "Resolution": "None."
    },
    {
      "@odata.type": "#Message.v1_1_1.Message",
      "Message": "The task with Id '0' has completed with errors.",
      "MessageArgs": [
        "0"
      ],
      "MessageId": "TaskEvent.1.0.3.TaskAborted",
      "MessageSeverity": "Critical",
      "Resolution": "None."
    }
  ],
  "Name": "Task 0",
  "Payload": {
    "HttpHeaders": [],
    "HttpOperation": "POST",
    "JsonBody": "null",
    "TargetUri": "/redfish/v1/UpdateService/update"
  },
  "PercentComplete": 0,
  "StartTime": "2024-11-05T01:51:25+00:00",
  "TaskMonitor": "/redfish/v1/TaskService/TaskMonitors/0",
  "TaskState": "Exception",
  "TaskStatus": "Warning"
}
```

Change-Id: I9eada7cc929a5518b44f28249a1cf8c5a55a5384
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/item_updater.hpp b/item_updater.hpp
index fac41f3..6274abe 100644
--- a/item_updater.hpp
+++ b/item_updater.hpp
@@ -91,7 +91,7 @@
                 bool useUpdateDBusInterface = true) :
         ItemUpdaterInherit(ctx.get_bus(), path.c_str(),
                            ItemUpdaterInherit::action::defer_emit),
-        useUpdateDBusInterface(useUpdateDBusInterface), ctx(ctx),
+        type(type), useUpdateDBusInterface(useUpdateDBusInterface), ctx(ctx),
         bus(ctx.get_bus()), helper(bus)
     {
         if (!useUpdateDBusInterface)
@@ -273,6 +273,9 @@
     /** @brief The slot of running BMC image */
     uint32_t runningImageSlot = 0;
 
+    /** @brief The type of updater. */
+    UpdaterType type;
+
     /** @brief Flag to indicate if the update interface is used or not */
     bool useUpdateDBusInterface;
 
diff --git a/update_manager.cpp b/update_manager.cpp
index ebc451a..6ced2ca 100644
--- a/update_manager.cpp
+++ b/update_manager.cpp
@@ -40,6 +40,17 @@
                                        ActivationIntf::Activations::Invalid);
 }
 
+bool verifyImagePurpose(Version::VersionPurpose purpose,
+                        ItemUpdaterIntf::UpdaterType type)
+{
+    if (purpose == Version::VersionPurpose::Host)
+    {
+        return (type == ItemUpdaterIntf::UpdaterType::BIOS ||
+                type == ItemUpdaterIntf::UpdaterType::ALL);
+    }
+    return true;
+}
+
 // NOLINTNEXTLINE(readability-static-accessed-through-instance)
 auto Manager::processImage(sdbusplus::message::unix_fd image,
                            ApplyTimeIntf::RequestedApplyTimes applyTime,
@@ -147,6 +158,16 @@
     }
     auto purpose = convertedPurpose.value_or(Version::VersionPurpose::Unknown);
 
+    if (!verifyImagePurpose(purpose, itemUpdater.type))
+    {
+        error("Purpose ({PURPOSE}) is not supported", "PURPOSE", purpose);
+        processImageFailed(image, id);
+        report<SoftwareErrors::ImageFailure>(
+            ImageFail::FAIL("Purpose is not supported"),
+            ImageFail::PATH(manifestPath.string().c_str()));
+        co_return;
+    }
+
     // Get ExtendedVersion
     std::string extendedVersion =
         Version::getValue(manifestPath.string(), "ExtendedVersion");