Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/flash/nand/davinci.c
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ static int davinci_write_page_ecc4infix(struct nand_device *nand, uint32_t page,
davinci_write_block_data(nand, oob, 16);
oob += 16;
oob_size -= 16;
(void) oob_size;

} while (data_size);

Expand Down
3 changes: 0 additions & 3 deletions src/flash/nor/dsp5680xx_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@

static int dsp5680xx_build_sector_list(struct flash_bank *bank)
{
uint32_t offset = HFM_FLASH_BASE_ADDR;

bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);

for (unsigned int i = 0; i < bank->num_sectors; ++i) {
bank->sectors[i].offset = i * HFM_SECTOR_SIZE;
bank->sectors[i].size = HFM_SECTOR_SIZE;
offset += bank->sectors[i].size;
bank->sectors[i].is_erased = -1;
bank->sectors[i].is_protected = -1;
}
Expand Down
55 changes: 29 additions & 26 deletions src/flash/nor/wcharm.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,27 +395,28 @@ static int ch32x_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;

for (int i = 0; i < bank->num_prot_blocks; i++)
for (unsigned int i = 0; i < bank->num_prot_blocks; i++)
bank->prot_blocks[i].is_protected = (protection & (1 << i)) ? 0 : 1;

return ERROR_OK;
}

static int ch32x_erase(struct flash_bank *bank, int first, int last)
static int ch32x_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
{
if(armchip)
{
if(noloadflag)
return ERROR_OK;
// TODO: This function doesn't erase anything on !arm. That's probably bad.
if (armchip) {
if (noloadflag) {
return ERROR_OK;
}

int ret=wlink_armerase();

int ret = wlink_armerase();
return ret;

}
}
return ERROR_OK;
}

static int ch32x_protect(struct flash_bank *bank, int set, int first, int last)
static int ch32x_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last)
{

struct target *target = bank->target;
Expand All @@ -436,7 +437,7 @@ static int ch32x_protect(struct flash_bank *bank, int set, int first, int last)
return retval;
}

for (int i = first; i <= last; i++) {
for (unsigned int i = first; i <= last; i++) {
if (set)
ch32x_info->option_bytes.protection &= ~(1 << i);
else
Expand All @@ -455,13 +456,16 @@ static int ch32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
static int ch32x_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t offset, uint32_t count)
{
if(armchip)
{
if(noloadflag)
return ERROR_OK;
// TODO: This doesn't write anything for !arm. Is that intended?
if (armchip) {
if (noloadflag) {
return ERROR_OK;
}
int ret=wlink_armwrite(buffer,bank->base + offset,count);
return ret;
}
}

return ERROR_OK;

}

Expand All @@ -471,7 +475,6 @@ static int ch32x_get_device_id(struct flash_bank *bank, uint32_t *device_id)
* the M0 from the M3 devices. */

struct target *target = bank->target;
uint32_t cpuid, device_id_register = 0;
uint32_t testid=0;
uint32_t tmp,tmp1,tmp2=0;
uint8_t user_cfg,config;
Expand Down Expand Up @@ -510,9 +513,13 @@ static int ch32x_get_device_id(struct flash_bank *bank, uint32_t *device_id)
static int ch32x_get_flash_size(struct flash_bank *bank, uint16_t *flash_size_in_kb)
{
struct target *target = bank->target;
uint32_t cpuid, flash_size_reg;
uint32_t temp;
int retval = target_read_u32(target, 0x1ffff7e0, flash_size_in_kb);
// FIXME: this is almost certainly an actual bug and I'm applying pain killer
// to it.
// target_read_u32 reads 32 bits and stores it in the pointee of the final arg.
// The final argument here is a uint16_t as it is in the caller. I'm going to
// change this to read 16 bits, but this could cause synchronization issues.
// Orig: int retval = target_read_u32(target, 0x1ffff7e0, flash_size_in_kb);
int retval = target_read_u16(target, 0x1ffff7e0, flash_size_in_kb);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without debug docs from WCH, we don't know if this is wrong or right. It might only allow a 32bit read, even if they are only interested in the lower 16bits. Is the code gross? yes! is this code actually wrong? we have no idea!

if (retval != ERROR_OK)
return retval;

Expand All @@ -527,7 +534,6 @@ static int ch32x_probe(struct flash_bank *bank)
uint32_t device_id;
int page_size;
uint32_t base_address = 0x08000000;
uint32_t rid=0;
ch32x_info->probed = 0;
ch32x_info->register_base = FLASH_REG_BASE_B0;
ch32x_info->user_data_offset = 10;
Expand All @@ -541,7 +547,6 @@ static int ch32x_probe(struct flash_bank *bank)
return retval;

LOG_INFO("device id = 0x%08" PRIx32 "", device_id);
rid=device_id & 0xfff ;
/* set page size, protection granularity and max flash size depending on family */
switch (device_id & 0xfff) {
case 0x410: /* medium density */
Expand Down Expand Up @@ -646,7 +651,7 @@ COMMAND_HANDLER(ch32x_handle_part_id_command)
}
#endif

static int get_ch32x_info(struct flash_bank *bank, char *buf, int buf_size)
static int get_ch32x_info(struct flash_bank *bank, struct command_invocation *buf_size)
{


Expand Down Expand Up @@ -983,8 +988,6 @@ static int ch32x_mass_erase(struct flash_bank *bank)

COMMAND_HANDLER(ch32x_handle_mass_erase_command)
{
int i;

if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR;

Expand All @@ -996,7 +999,7 @@ COMMAND_HANDLER(ch32x_handle_mass_erase_command)
retval = ch32x_mass_erase(bank);
if (retval == ERROR_OK) {
/* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++)
for (unsigned i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1;

command_print(CMD, "ch32x mass erase complete");
Expand Down
10 changes: 5 additions & 5 deletions src/flash/nor/wchriscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <target/algorithm.h>
extern int wlink_erase(void);
extern unsigned char riscvchip;
extern int wlink_reset();
extern int wlink_reset(void);
extern void wlink_getromram(uint32_t *rom,uint32_t *ram);
extern int wlink_write(const uint8_t *buffer, uint32_t offset, uint32_t count);
extern int noloadflag;
Expand Down Expand Up @@ -68,11 +68,12 @@ FLASH_BANK_COMMAND_HANDLER(ch32vx_flash_bank_command)
return ERROR_OK;
}

static int ch32vx_erase(struct flash_bank *bank, int first, int last)
static int ch32vx_erase(struct flash_bank *bank, unsigned int first, unsigned int last)
{

if(noloadflag)
if (noloadflag){
return ERROR_OK;
}
wlink_reset();
int ret = wlink_erase();
target_halt(bank->target);
Expand Down Expand Up @@ -128,7 +129,6 @@ static int ch32vx_probe(struct flash_bank *bank)
uint32_t ram=0;
int page_size;
uint32_t base_address = 0x00000000;
uint32_t rid = 0;
ch32vx_info->probed = 0;
/* read ch32 device id register */
int retval = ch32vx_get_device_id(bank, &device_id);
Expand All @@ -140,7 +140,7 @@ static int ch32vx_probe(struct flash_bank *bank)
ch32vx_info->ppage_size = 4;
/* get flash size from target. */
retval = ch32vx_get_flash_size(bank, &flash_size_in_kb);
if(flash_size_in_kb)
if (flash_size_in_kb)
LOG_INFO("flash size = %dkbytes", flash_size_in_kb);
else
flash_size_in_kb=delfault_max_flash_size;
Expand Down
Loading