diff --git a/mbed-os-bootloader/BUILD/DISCO_H747I/GCC_ARM/mbed-os-bootloader.bin b/mbed-os-bootloader/BUILD/DISCO_H747I/GCC_ARM/mbed-os-bootloader.bin deleted file mode 100644 index f1e18f4..0000000 Binary files a/mbed-os-bootloader/BUILD/DISCO_H747I/GCC_ARM/mbed-os-bootloader.bin and /dev/null differ diff --git a/my_candidate_applications.cpp b/my_candidate_applications.cpp new file mode 100644 index 0000000..974bf01 --- /dev/null +++ b/my_candidate_applications.cpp @@ -0,0 +1,83 @@ +#include "my_candidate_applications.h" + +#include "mbed_trace.h" +#if MBED_CONF_MBED_TRACE_ENABLE +#define TRACE_GROUP "MyCandidateApplications" +#endif // MBED_CONF_MBED_TRACE_ENABLE + +update_client::CandidateApplications *createCandidateApplications( + BlockDevice &blockDevice, + mbed::bd_addr_t storageAddr, + mbed::bd_size_t storageSize, + uint32_t headerSize, + uint32_t nSlots +){ + tr_debug("Create my candidate application"); + update_client::CandidateApplications* candidate = new bike_computer::MyCandidateApplications(blockDevice, storageAddr, storageSize, headerSize, nSlots); + return candidate; +} + +namespace bike_computer { + +MyCandidateApplications::MyCandidateApplications( + BlockDevice &blockDevice, + mbed::bd_addr_t storageAddr, + mbed::bd_size_t storageSize, + uint32_t headerSize, + uint32_t nSlots +) : update_client::CandidateApplications(blockDevice, storageAddr, storageSize, headerSize, nSlots) { + +} + +uint32_t MyCandidateApplications::getSlotForCandidate() { + tr_debug("Get slot for candidate"); + + uint32_t nbrOfSlots = getNbrOfSlots(); + + for (uint32_t slotIndex = 0; slotIndex < nbrOfSlots; slotIndex++) { + if (! getBlockDeviceApplication(slotIndex).isValid()) { + return slotIndex; + } + } + + // return the slot of the oldest firmware candidates + uint32_t oldestSlotIndex = 0; + uint64_t oldestFirmwareVersion = getBlockDeviceApplication(oldestSlotIndex).getFirmwareVersion(); + for (uint32_t slotIndex = 1; slotIndex < nbrOfSlots; slotIndex++) { + mbed::bd_addr_t candidateAddress = 0; + mbed::bd_size_t slotSize = 0; + getCandidateAddress(slotIndex, candidateAddress, slotSize); + tr_debug("Checking application at slot %" PRIu32 " (address 0x%" PRIx64 ", size %" PRIu64 ")", + slotIndex, candidateAddress, slotSize); + + if (getBlockDeviceApplication(slotIndex).getFirmwareVersion() < oldestFirmwareVersion) { + oldestSlotIndex = slotIndex; + oldestFirmwareVersion = getBlockDeviceApplication(slotIndex).getFirmwareVersion(); + } + } + return oldestSlotIndex; +} + +//uint32_t MyCandidateApplications::getSlotForCandidate() { +// mbed::bd_addr_t _storageAddress = MBED_CONF_UPDATE_CLIENT_STORAGE_ADDRESS; +// tr_debug("Get slot for candidate"); +// +// FlashIAPBlockDevice flashIAPBlockDevice(MBED_ROM_START, MBED_ROM_SIZE); +// int ret = flashIAPBlockDevice.init(); +// +// if(ret == 0){ +// for (int i = 0; i < getNbrOfSlots(); i++) { +// mbed::bd_addr_t headerAddress = HEADER_ADDR - MBED_ROM_START; +// mbed::bd_addr_t applicationAddress = _storageAddress + i * getSlotSize(); +// update_client::BlockDeviceApplication activeApplication(flashIAPBlockDevice, headerAddress, applicationAddress); +// update_client::UCErrorCode rc = activeApplication.checkApplication(); +// +// if (update_client::UCErrorCode::UC_ERR_NONE != rc) { +// return _storageAddress + i * getSlotSize(); +// } +// } +// } +// return -1; +//} + +} \ No newline at end of file diff --git a/my_candidate_applications.h b/my_candidate_applications.h new file mode 100644 index 0000000..2b70fca --- /dev/null +++ b/my_candidate_applications.h @@ -0,0 +1,24 @@ +#pragma once +#include "update-client/candidate_applications.hpp" + +namespace bike_computer { +class MyCandidateApplications : public update_client::CandidateApplications { +public: + MyCandidateApplications( + BlockDevice &blockDevice, + mbed::bd_addr_t storageAddr, + mbed::bd_size_t storageSize, + uint32_t headerSize, + uint32_t nSlots + ); + virtual uint32_t getSlotForCandidate() override; +}; +} + +update_client::CandidateApplications *createCandidateApplications( + BlockDevice &blockDevice, + mbed::bd_addr_t storageAddr, + mbed::bd_size_t storageSize, + uint32_t headerSize, + uint32_t nSlots +);