Utilise magic memory tree interface for butterfly.c

This commit is contained in:
Stefan Rueger
2024-04-18 17:23:08 +01:00
parent 5e221a1fd6
commit 3de5457718
2 changed files with 13 additions and 15 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

@@ -82,18 +82,12 @@ struct pdata
} while(0)
static void butterfly_setup(PROGRAMMER * pgm)
{
if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) {
pmsg_error("out of memory allocating private data\n");
exit(1);
}
memset(pgm->cookie, 0, sizeof(struct pdata));
static void butterfly_setup(PROGRAMMER * pgm) {
pgm->cookie = mmt_malloc(sizeof(struct pdata));
}
static void butterfly_teardown(PROGRAMMER * pgm)
{
free(pgm->cookie);
static void butterfly_teardown(PROGRAMMER * pgm) {
mmt_free(pgm->cookie);
}
static int butterfly_send(const PROGRAMMER *pgm, char *buf, size_t len) {
@@ -603,8 +597,8 @@ static int butterfly_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
return -1;
#endif
cmd = malloc(4+blocksize);
if (!cmd) return -1;
cmd = mmt_malloc(4+blocksize);
cmd[0] = 'B';
cmd[3] = isee? 'E': mem_is_flash(m)? 'F': 'U';
@@ -616,13 +610,16 @@ static int butterfly_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
cmd[1] = (blocksize >> 8) & 0xff;
cmd[2] = blocksize & 0xff;
EI(butterfly_send(pgm, cmd, 4+blocksize));
if (butterfly_vfy_cmd_sent(pgm, "write block") < 0)
if(butterfly_send(pgm, cmd, 4+blocksize) < 0 ||
butterfly_vfy_cmd_sent(pgm, "write block") < 0) {
mmt_free(cmd);
return -1;
}
addr += blocksize;
}
free(cmd);
mmt_free(cmd);
return n_bytes;
}