/* * Copyright (c) 2022-2023, Arm Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ #ifndef FWU_DUT_H #define FWU_DUT_H #include #include "common/uuid/uuid.h" #include "service/fwu/agent/fw_directory.h" #include "service/fwu/test/fwu_client/fwu_client.h" #include "service/fwu/test/metadata_checker/metadata_checker.h" /* * An fwu_dut represents a device-under-test for the purpose of testing * firmware update functionality. The fwu_dut presents a common interface * that decouples test cases from details of the concrete device under test. */ class fwu_dut { public: fwu_dut(); fwu_dut(unsigned int metadata_version); virtual ~fwu_dut(); /** * \brief Simulates a boot of the DUT. * * Mimics boot loader FWU metadata usage and performs a simple verification * of fw images installed in the bank corresponding to the selected boot * index. Initializes the update_agent in the same way as with a real * deployment. * * \param[in] from_active_bank Where to boot from */ virtual void boot(bool from_active_bank = true) = 0; /** * \brief Simulates a shutdown of the DUT * * The update_agent is de-initialized but image and metadata storage is * left alone. Simulates a physical device shutdown. */ virtual void shutdown(void) = 0; /** * \brief Returns boot info seen by the boot loader * * \return A boot_info structure */ virtual struct boot_info get_boot_info(void) const = 0; /** * \brief Factory method to construct a metadata_checker * * To decouple test code from different versions of FWU metadata, the * metadata_checker class can be used to provide a neutral interface. * This method creates a concrete metadata_checker that is compatible * with the version generated by the DUT. The caller is responsible for * destroying the metadata_checker using delete. * * \param[in] is_primary True to use the primary, false the backup copy * * \return The constructed metadata_checker */ virtual metadata_checker *create_metadata_checker(bool is_primary = true) const = 0; /** * \brief Factory method to construct a fwu_client * * Constructs a fwu_client to provide an interface for interacting with * the fwu service provider associated with the DUT. The caller is * responsible for destroying the fwu_client using delete. * * \return The constructed fwu_client */ virtual fwu_client *create_fwu_client(void) = 0; /** * \brief Generate fw image data * * Generates a fake image that can be checked during dut boot for * validity. Use to provide image data for update testing * * \param[in] image_data Image data written to the provided vector * \param[in] image_size The required image size */ void generate_image_data(std::vector *image_data, size_t image_size = 4096); /** * \brief Returns image type UUIDs * * Image type UUIDS for updatable whole volume images. Assumes * one whole volume image type per location. * * \param[in] location_index 0..num_locations-1 * \param[out] uuid Outputs the GUID octets */ virtual void whole_volume_image_type_uuid(unsigned int location_index, struct uuid_octets *uuid) const; protected: /** * \brief Create a metadata_checker for the configured metadata version * * Creates a metadata_checker using 'new' that is compatible with the metadata * version specified for the DUT on construction. Uses the provided metadata_fetcher * to fetch the metadata prior to checking. * * \param[in] metadata_fetcher To fetch the metadata * \param[in] num_images The expected number of images */ metadata_checker *create_metadata_checker(metadata_fetcher *metadata_fetcher, unsigned int num_images) const; /** * \brief Returns the configured FWU metadata version * * In a real system, the bootloader will advertise the metadata version that it * understands. * * \return Metadata version */ unsigned int metadata_version(void) const; static const char *VALID_IMAGE_HEADER; private: unsigned int m_generated_image_count; unsigned int m_metadata_version; }; #endif /* FWU_DUT_H */