Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef FWU_METADATA_READER_H |
| 8 | #define FWU_METADATA_READER_H |
| 9 | |
| 10 | #include <cstdint> |
| 11 | #include <vector> |
| 12 | |
| 13 | /* |
| 14 | * A version specific metadata reader. Before using get methods to extract |
| 15 | * metadata attributes, is_supported() should be called to verify that the |
| 16 | * input metadata version is supported. |
| 17 | */ |
| 18 | class metadata_version_specific_reader { |
| 19 | |
| 20 | public: |
| 21 | |
| 22 | virtual ~metadata_version_specific_reader() {} |
| 23 | |
| 24 | virtual bool is_supported( |
| 25 | const uint8_t *buf, |
| 26 | size_t data_len) const = 0; |
| 27 | |
| 28 | virtual void get_version( |
| 29 | const uint8_t *buf, |
| 30 | size_t data_len, |
| 31 | unsigned int &version) const = 0; |
| 32 | |
| 33 | virtual void get_active_index( |
| 34 | const uint8_t *buf, |
| 35 | size_t data_len, |
| 36 | unsigned int &active_index) const = 0; |
| 37 | }; |
| 38 | |
| 39 | /* |
| 40 | * A singleton that provides a common interface for reading fwu metadata. |
| 41 | * The caller doesn't need to worry about the version of metadata being used. |
| 42 | */ |
| 43 | class metadata_reader { |
| 44 | |
| 45 | public: |
| 46 | |
| 47 | static metadata_reader *instance(); |
| 48 | ~metadata_reader(); |
| 49 | |
| 50 | void register_reader(metadata_version_specific_reader *reader); |
| 51 | |
| 52 | int get_boot_info( |
| 53 | unsigned int &active_index, |
| 54 | unsigned int &metadata_version) const; |
| 55 | |
| 56 | private: |
| 57 | metadata_reader(); |
| 58 | |
| 59 | std::vector<metadata_version_specific_reader *> registered_readers; |
| 60 | }; |
| 61 | |
| 62 | #endif /* FWU_METADATA_READER_H */ |