Utilse magic memory tree interface

This commit is contained in:
Stefan Rueger
2024-04-22 13:58:54 +01:00
parent 8fe729f0a2
commit 76b4bf1fd6
2 changed files with 12 additions and 27 deletions

View File

@@ -44,6 +44,7 @@ extern const char *pgmid; // Programmer -c string
#define mmt_strdup(s) cfg_strdup(__func__, s)
#define mmt_malloc(n) cfg_malloc(__func__, n)
#define mmt_realloc(p, n) cfg_realloc(__func__, p, n)
#define mmt_free(p) free(p)
int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int msgmode, int msglvl, const char *format, ...);

View File

@@ -544,23 +544,15 @@ static int micronucleus_start(pdata_t* pdata)
//-----------------------------------------------------------------------------
static void micronucleus_setup(PROGRAMMER* pgm)
{
static void micronucleus_setup(PROGRAMMER *pgm) {
pmsg_debug("micronucleus_setup()\n");
if ((pgm->cookie = malloc(sizeof(pdata_t))) == 0)
{
pmsg_error("out of memory allocating private data\n");
exit(1);
}
memset(pgm->cookie, 0, sizeof(pdata_t));
pgm->cookie = mmt_malloc(sizeof(pdata_t));
}
static void micronucleus_teardown(PROGRAMMER* pgm)
{
static void micronucleus_teardown(PROGRAMMER* pgm) {
pmsg_debug("micronucleus_teardown()\n");
free(pgm->cookie);
mmt_free(pgm->cookie);
pgm->cookie = NULL;
}
static int micronucleus_initialize(const PROGRAMMER *pgm, const AVRPART *p) {
@@ -593,13 +585,10 @@ static void micronucleus_powerdown(const PROGRAMMER *pgm) {
{
pdata->write_last_page = false;
uint8_t* buffer = (unsigned char*)malloc(pdata->page_size);
if (buffer != NULL)
{
memset(buffer, 0xFF, pdata->page_size);
micronucleus_write_page(pdata, pdata->bootloader_start - pdata->page_size, buffer, pdata->page_size);
free(buffer);
}
uint8_t *buffer = (unsigned char *) mmt_malloc(pdata->page_size);
memset(buffer, 0xFF, pdata->page_size);
micronucleus_write_page(pdata, pdata->bootloader_start - pdata->page_size, buffer, pdata->page_size);
mmt_free(buffer);
}
if (pdata->start_program)
@@ -863,12 +852,7 @@ static int micronucleus_paged_write(const PROGRAMMER *pgm, const AVRPART *p, con
return -1;
}
uint8_t* page_buffer = (uint8_t*)malloc(pdata->page_size);
if (page_buffer == NULL)
{
pmsg_error("unable to allocate memory\n");
return -1;
}
uint8_t *page_buffer = (uint8_t *) mmt_malloc(pdata->page_size);
// Note: Page size reported by the bootloader may be smaller than device page size as configured in avrdude.conf.
int result = 0;
@@ -889,7 +873,7 @@ static int micronucleus_paged_write(const PROGRAMMER *pgm, const AVRPART *p, con
n_bytes -= chunk_size;
}
free(page_buffer);
mmt_free(page_buffer);
return result;
}
else