diff options
author | 2016-11-11 12:00:01 -0500 | |
---|---|---|
committer | 2016-11-11 12:00:01 -0500 | |
commit | 696b24e24fe9f39d98c975d6f2f08bccdb8e1c58 (patch) | |
tree | ceaec3d3a55bcde3f7743fc83b424ec0d5194e59 | |
parent | a9d260cf145b5f0912d6b489a8b1605d45b59d63 (diff) |
[Imgtool] Fixed a recently introduced bug which caused image types that do not support partitions to function incorrectly
-rw-r--r-- | src/tools/imgtool/imgtool.cpp | 16 | ||||
-rw-r--r-- | src/tools/imgtool/imgtool.h | 2 | ||||
-rw-r--r-- | src/tools/imgtool/library.h | 14 |
3 files changed, 18 insertions, 14 deletions
diff --git a/src/tools/imgtool/imgtool.cpp b/src/tools/imgtool/imgtool.cpp index 57a702dd17b..12adfe533d3 100644 --- a/src/tools/imgtool/imgtool.cpp +++ b/src/tools/imgtool/imgtool.cpp @@ -518,7 +518,7 @@ imgtoolerr_t imgtool::image::list_partitions(std::vector<imgtool::partition_info else { // default implementation - partitions.emplace_back(unknown_partition_get_info, 0, ~0); + partitions.emplace_back(module().imgclass, 0, ~0); } return IMGTOOLERR_SUCCESS; } @@ -560,9 +560,8 @@ uint64_t imgtool::image::rand() // imgtool::partition ctor //------------------------------------------------- -imgtool::partition::partition(imgtool::image &image, imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count) +imgtool::partition::partition(imgtool::image &image, const imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count) : m_image(image) - //, m_partition_index(partition_index) , m_base_block(base_block) , m_block_count(block_count) , m_imgclass(imgclass) @@ -635,9 +634,7 @@ imgtoolerr_t imgtool::partition::open(imgtool::image &image, int partition_index { imgtoolerr_t err = (imgtoolerr_t)IMGTOOLERR_SUCCESS; imgtool::partition::ptr p; - imgtool_class imgclass; std::vector<imgtool::partition_info> partitions; - uint64_t base_block, block_count; imgtoolerr_t (*open_partition)(imgtool::partition &partition, uint64_t first_block, uint64_t block_count); // list the partitions @@ -646,14 +643,13 @@ imgtoolerr_t imgtool::partition::open(imgtool::image &image, int partition_index return err; // is this an invalid index? - if ((partition_index < 0) || (partition_index >= partitions.size()) || !partitions[partition_index].get_info()) + if ((partition_index < 0) || (partition_index >= partitions.size()) || (!partitions[partition_index].imgclass().get_info && !partitions[partition_index].imgclass().derived_get_info)) return IMGTOOLERR_INVALIDPARTITION; // use this partition - memset(&imgclass, 0, sizeof(imgclass)); - imgclass.get_info = partitions[partition_index].get_info(); - base_block = partitions[partition_index].base_block(); - block_count = partitions[partition_index].block_count(); + const imgtool_class &imgclass(partitions[partition_index].imgclass()); + uint64_t base_block = partitions[partition_index].base_block(); + uint64_t block_count = partitions[partition_index].block_count(); // allocate the new partition object try { p = std::make_unique<imgtool::partition>(image, imgclass, partition_index, base_block, block_count); } diff --git a/src/tools/imgtool/imgtool.h b/src/tools/imgtool/imgtool.h index b1b09462c42..8d40e109fb8 100644 --- a/src/tools/imgtool/imgtool.h +++ b/src/tools/imgtool/imgtool.h @@ -144,7 +144,7 @@ namespace imgtool typedef std::unique_ptr<partition> ptr; // ctor/dtor - partition(imgtool::image &image, imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count); + partition(imgtool::image &image, const imgtool_class &imgclass, int partition_index, uint64_t base_block, uint64_t block_count); ~partition(); static imgtoolerr_t open(imgtool::image &image, int partition_index, ptr &partition); diff --git a/src/tools/imgtool/library.h b/src/tools/imgtool/library.h index e7ddf46ade0..59b75be447d 100644 --- a/src/tools/imgtool/library.h +++ b/src/tools/imgtool/library.h @@ -244,18 +244,26 @@ namespace imgtool { public: partition_info(imgtool_get_info get_info, uint64_t base_block, uint64_t block_count) - : m_get_info(get_info) + : m_base_block(base_block) + , m_block_count(block_count) + { + memset(&m_imgclass, 0, sizeof(m_imgclass)); + m_imgclass.get_info = get_info; + } + + partition_info(imgtool_class imgclass, uint64_t base_block, uint64_t block_count) + : m_imgclass(imgclass) , m_base_block(base_block) , m_block_count(block_count) { } - imgtool_get_info get_info() const { return m_get_info; } + const imgtool_class &imgclass() const { return m_imgclass; } uint64_t base_block() const { return m_base_block; } uint64_t block_count() const { return m_block_count; } private: - imgtool_get_info m_get_info; + imgtool_class m_imgclass; uint64_t m_base_block; uint64_t m_block_count; }; |