Skip to content

Commit

Permalink
Bootloader test code in place
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed May 5, 2024
1 parent 4c75fd7 commit 857c5fa
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 323 deletions.
132 changes: 66 additions & 66 deletions src/vscp/common/mdf.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/vscp/common/register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ CUserRegisters::remoteVarFromRegToString(CMDF_RemoteVariable &remoteVar, std::st
pstr = new uint8_t[remoteVar.getTypeByteCount() + 1];
if (nullptr == pstr)
return false;
memset(pstr, 0, sizeof(pstr));
memset(pstr, 0, remoteVar.getTypeByteCount() + 1);
for (unsigned int i = remoteVar.getOffset(); i < (remoteVar.getOffset() + remoteVar.getTypeByteCount()); i++) {
pstr[i] = ppage->getReg(i);
}
Expand Down
16 changes: 11 additions & 5 deletions src/vscp/common/vscp_bootdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,23 +322,29 @@ CBootDevice::getMinMaxForRange(uint32_t start, uint32_t end, uint32_t *pmin, uin
}

///////////////////////////////////////////////////////////////////////////////
// fillBlock
// fillMemoryBuffer
//

int
CBootDevice::fillBlock(uint8_t *pblock, uint32_t size, uint32_t start, uint8_t fill)
CBootDevice::fillMemoryBuffer(uint8_t *pmem, uint32_t size, uint32_t start, uint8_t fill)
{
if (nullptr == pblock) {
// Check pointers
if (nullptr == pmem) {
return VSCP_ERROR_INVALID_POINTER;
}

// Check size
if (!size) {
return VSCP_ERROR_SIZE;
}

// Fill block with void value (0xff for flash)
memset(pblock, fill, size);
memset(pmem, fill, size);

for (auto const &pblk : m_memblkList) {
if ((pblk->getStartAddress() >= start) && (pblk->getStartAddress() < (start + size))) {
for (uint8_t pos = 0; pos < pblk->getSize(); pos++) {
pblock[(pblk->getStartAddress() - start) + pos] = *(pblk->getBlock() + pos);
pmem[(pblk->getStartAddress() - start) + pos] = *(pblk->getBlock() + pos);
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/vscp/common/vscp_bootdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,16 @@ class CBootDevice {
virtual int getMinMaxForRange(uint32_t start, uint32_t end, uint32_t *pmin, uint32_t *pmax);

/*!
Fill block with firmware data
@param pblock Pointer to the beginning of an allocated block
Fill memory buffer with firmware data
The memory buffer is an area that hold an image of the memory on a remote
device. Typically for one type of memory.
@param pmem Pointer to the beginning of an allocated memory buffer
@param size Total size of block
@param start Logical start address
@param fill Value to initialize block with- 0xff is default
@return VSCP_ERROR_SUCCESS or errorcode otherwise.
*/
int fillBlock(uint8_t *pblock, uint32_t size, uint32_t start, uint8_t fill = 0xff);
int fillMemoryBuffer(uint8_t *pmem, uint32_t size, uint32_t start, uint8_t fill = 0xff);

/*!
Get info for hex file in html format
Expand Down
14 changes: 7 additions & 7 deletions src/vscp/common/vscp_bootdevice_pic1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#include "vscp_bootdevice_pic1.h"

#include "spdlog/fmt/bin_to_hex.h"
#include <spdlog/async.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
// #include <spdlog/async.h>
// #include <spdlog/sinks/rotating_file_sink.h>
// #include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -824,7 +824,7 @@ CBootDevice_PIC1::writeFirmwareBlock(uint32_t start, uint32_t end)
}

// Init the block
if (VSCP_ERROR_SUCCESS != (rv = fillBlock(pbuf, size, start))) {
if (VSCP_ERROR_SUCCESS != (rv = fillMemoryBuffer(pbuf, size, start))) {
spdlog::error("writeFirmwareBlock: Failed to fill code block with data.");
if (nullptr != m_statusCallback) {
m_statusCallback(-1,
Expand Down Expand Up @@ -880,13 +880,13 @@ CBootDevice_PIC1::deviceLoad(std::function<void(int, const char *)> statusCallba

m_checksum = 0;
uint32_t progress = 0;
uint32_t addr;
uint32_t addr = 0;
std::string strStatus;

uint8_t pbuf[BUFFER_SIZE_CODE];
uint32_t nPackets;
uint32_t minAddr;
uint32_t maxAddr;
// uint32_t minAddr;
// uint32_t maxAddr;

if (nullptr != m_statusCallback) {
m_statusCallback(0, "Starting firmware download");
Expand Down
Loading

0 comments on commit 857c5fa

Please sign in to comment.