Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative fix proposal for #1832 #1835

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/serialupdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,11 @@ static int serialupdi_write_byte(const PROGRAMMER *pgm, const AVRPART *p, const
buffer[0]=value;
return updi_nvm_write_flash(pgm, p, mem->offset + addr, buffer, 1);
}
if (mem_is_bootrow(mem)) {
unsigned char buffer[1];
buffer[0]=value;
return updi_nvm_write_boot_row(pgm, p, mem->offset + addr, buffer, 1);
}
// Read-only memories
if(mem_is_readonly(mem)) {
unsigned char is;
Expand Down Expand Up @@ -841,6 +846,9 @@ static int serialupdi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
} else if (mem_is_userrow(m)) {
rc = serialupdi_write_userrow(pgm, p, m, page_size, write_offset,
remaining_bytes > m->page_size ? m->page_size : remaining_bytes);
} else if (mem_is_bootrow(m)) {
rc = updi_nvm_write_boot_row(pgm, p, m->offset + write_offset, m->buf + write_offset,
remaining_bytes > m->page_size ? m->page_size : remaining_bytes);
} else if (mem_is_fuses(m)) {
pmsg_debug("page write operation requested for fuses, falling back to byte-level write\n");
return -1;
Expand All @@ -866,6 +874,8 @@ static int serialupdi_paged_write(const PROGRAMMER *pgm, const AVRPART *p, const
rc = updi_nvm_write_flash(pgm, p, m->offset+addr, m->buf+addr, n_bytes);
} else if (mem_is_userrow(m)) {
rc = serialupdi_write_userrow(pgm, p, m, page_size, addr, n_bytes);
} else if (mem_is_bootrow(m)) {
rc = updi_nvm_write_boot_row(pgm, p, m->offset+addr, m->buf+addr, n_bytes);
} else if (mem_is_fuses(m)) {
pmsg_debug("page write operation requested for fuses, falling back to byte-level write\n");
rc = -1;
Expand Down
19 changes: 19 additions & 0 deletions src/updi_nvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ int updi_nvm_write_user_row(const PROGRAMMER *pgm, const AVRPART *p, uint32_t ad
}
}

int updi_nvm_write_boot_row(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
switch(updi_get_nvm_mode(pgm))
{
case UPDI_NVM_MODE_V0:
return updi_nvm_write_boot_row_V0(pgm, p, address, buffer, size);
case UPDI_NVM_MODE_V2:
return updi_nvm_write_boot_row_V2(pgm, p, address, buffer, size);
case UPDI_NVM_MODE_V3:
return updi_nvm_write_boot_row_V3(pgm, p, address, buffer, size);
case UPDI_NVM_MODE_V4:
return updi_nvm_write_boot_row_V4(pgm, p, address, buffer, size);
case UPDI_NVM_MODE_V5:
return updi_nvm_write_boot_row_V5(pgm, p, address, buffer, size);
default:
pmsg_error("invalid NVM Mode %d\n", updi_get_nvm_mode(pgm));
return -1;
}
}

int updi_nvm_write_eeprom(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
switch(updi_get_nvm_mode(pgm))
{
Expand Down
1 change: 1 addition & 0 deletions src/updi_nvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int updi_nvm_erase_eeprom(const PROGRAMMER *pgm, const AVRPART *p);
int updi_nvm_erase_user_row(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint16_t size);
int updi_nvm_write_flash(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_user_row(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_boot_row(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_eeprom(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_fuse(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint8_t value);
int updi_nvm_wait_ready(const PROGRAMMER *pgm, const AVRPART *p);
Expand Down
7 changes: 7 additions & 0 deletions src/updi_nvm_v0.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ int updi_nvm_write_user_row_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t
return updi_nvm_write_eeprom_V0(pgm, p, address, buffer, size);
}

int updi_nvm_write_boot_row_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
Perform write operation as if it was regular flash memory
*/
return nvm_write_V0(pgm, p, address, buffer, size, USE_WORD_ACCESS, USE_DEFAULT_COMMAND);
}

int updi_nvm_write_eeprom_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
def write_eeprom(self, address, data):
Expand Down
1 change: 1 addition & 0 deletions src/updi_nvm_v0.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int updi_nvm_erase_eeprom_V0(const PROGRAMMER *pgm, const AVRPART *p);
int updi_nvm_erase_user_row_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint16_t size);
int updi_nvm_write_flash_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_user_row_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_boot_row_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_eeprom_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_fuse_V0(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint8_t value);
int updi_nvm_wait_ready_V0(const PROGRAMMER *pgm, const AVRPART *p);
Expand Down
7 changes: 7 additions & 0 deletions src/updi_nvm_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,13 @@ int updi_nvm_write_user_row_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t
return nvm_write_V2(pgm, p, address, buffer, size, DONT_USE_WORD_ACCESS);
}

int updi_nvm_write_boot_row_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
Perform write operation as if it was regular flash memory
*/
return nvm_write_V2(pgm, p, address, buffer, size, USE_WORD_ACCESS);
}

int updi_nvm_write_eeprom_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
def write_eeprom(self, address, data):
Expand Down
1 change: 1 addition & 0 deletions src/updi_nvm_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int updi_nvm_erase_eeprom_V2(const PROGRAMMER *pgm, const AVRPART *p);
int updi_nvm_erase_user_row_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint16_t size);
int updi_nvm_write_flash_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_user_row_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_boot_row_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_eeprom_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_fuse_V2(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint8_t value);
int updi_nvm_wait_ready_V2(const PROGRAMMER *pgm, const AVRPART *p);
Expand Down
7 changes: 7 additions & 0 deletions src/updi_nvm_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ int updi_nvm_write_user_row_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t
return nvm_write_V3(pgm, p, address, buffer, size, USE_WORD_ACCESS, USE_DEFAULT_COMMAND);
}

int updi_nvm_write_boot_row_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
Perform the operation as the regular flash write
*/
return nvm_write_V3(pgm, p, address, buffer, size, USE_WORD_ACCESS, USE_DEFAULT_COMMAND);
}

int updi_nvm_write_eeprom_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
def write_eeprom(self, address, data):
Expand Down
1 change: 1 addition & 0 deletions src/updi_nvm_v3.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int updi_nvm_erase_eeprom_V3(const PROGRAMMER *pgm, const AVRPART *p);
int updi_nvm_erase_user_row_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint16_t size);
int updi_nvm_write_flash_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_user_row_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_boot_row_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_eeprom_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_fuse_V3(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint8_t value);
int updi_nvm_wait_ready_V3(const PROGRAMMER *pgm, const AVRPART *p);
Expand Down
7 changes: 7 additions & 0 deletions src/updi_nvm_v4.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ int updi_nvm_write_user_row_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t
return nvm_write_V4(pgm, p, address, buffer, size, DONT_USE_WORD_ACCESS);
}

int updi_nvm_write_boot_row_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
Write it as a regular flash page
*/
return nvm_write_V4(pgm, p, address, buffer, size, USE_WORD_ACCESS);
}

int updi_nvm_write_eeprom_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
def write_eeprom(self, address, data):
Expand Down
1 change: 1 addition & 0 deletions src/updi_nvm_v4.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int updi_nvm_erase_eeprom_V4(const PROGRAMMER *pgm, const AVRPART *p);
int updi_nvm_erase_user_row_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint16_t size);
int updi_nvm_write_flash_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_user_row_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_boot_row_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_eeprom_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_fuse_V4(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint8_t value);
int updi_nvm_wait_ready_V4(const PROGRAMMER *pgm, const AVRPART *p);
Expand Down
7 changes: 7 additions & 0 deletions src/updi_nvm_v5.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ int updi_nvm_write_user_row_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t
return nvm_write_V5(pgm, p, address, buffer, size, USE_WORD_ACCESS, USE_DEFAULT_COMMAND);
}

int updi_nvm_write_boot_row_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
Perform the operation as the regular flash write
*/
return nvm_write_V5(pgm, p, address, buffer, size, USE_WORD_ACCESS, USE_DEFAULT_COMMAND);
}

int updi_nvm_write_eeprom_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size) {
/*
def write_eeprom(self, address, data):
Expand Down
1 change: 1 addition & 0 deletions src/updi_nvm_v5.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ int updi_nvm_erase_eeprom_V5(const PROGRAMMER *pgm, const AVRPART *p);
int updi_nvm_erase_user_row_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint16_t size);
int updi_nvm_write_flash_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_user_row_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_boot_row_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_eeprom_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, unsigned char *buffer, uint16_t size);
int updi_nvm_write_fuse_V5(const PROGRAMMER *pgm, const AVRPART *p, uint32_t address, uint8_t value);
int updi_nvm_wait_ready_V5(const PROGRAMMER *pgm, const AVRPART *p);
Expand Down
Loading