Skip to content

Commit

Permalink
Fixed some compilation issues with GCC14
Browse files Browse the repository at this point in the history
Change-Id: I44ab4f4532d59a7201270e30e95ec2b5589168f3
  • Loading branch information
EmergReanimator committed Nov 10, 2024
1 parent 4449abc commit 168436e
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/flash/nor/ambiqmicro.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ FLASH_BANK_COMMAND_HANDLER(ambiqmicro_flash_bank_command)
if (CMD_ARGC < 6)
return ERROR_COMMAND_SYNTAX_ERROR;

ambiqmicro_info = calloc(sizeof(struct ambiqmicro_flash_bank), 1);
ambiqmicro_info = calloc(1, sizeof(struct ambiqmicro_flash_bank));

bank->driver_priv = ambiqmicro_info;

Expand Down
4 changes: 2 additions & 2 deletions src/flash/nor/kinetis.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ FLASH_BANK_COMMAND_HANDLER(kinetis_flash_bank_command)
k_chip = kinetis_get_chip(target);

if (!k_chip) {
k_chip = calloc(sizeof(struct kinetis_chip), 1);
k_chip = calloc(1, sizeof(struct kinetis_chip));
if (!k_chip) {
LOG_ERROR("No memory");
return ERROR_FAIL;
Expand Down Expand Up @@ -985,7 +985,7 @@ static int kinetis_create_missing_banks(struct kinetis_chip *k_chip)
bank_idx - k_chip->num_pflash_blocks);
}

bank = calloc(sizeof(struct flash_bank), 1);
bank = calloc(1, sizeof(struct flash_bank));
if (!bank)
return ERROR_FAIL;

Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/max32xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ FLASH_BANK_COMMAND_HANDLER(max32xxx_flash_bank_command)
return ERROR_FLASH_BANK_INVALID;
}

info = calloc(sizeof(struct max32xxx_flash_bank), 1);
info = calloc(1, sizeof(struct max32xxx_flash_bank));
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], info->flash_size);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[6], info->flc_base);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[7], info->sector_size);
Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/msp432.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ static int msp432_probe(struct flash_bank *bank)

if (is_main && MSP432P4 == msp432_bank->family_type) {
/* Create the info flash bank needed by MSP432P4 variants */
struct flash_bank *info = calloc(sizeof(struct flash_bank), 1);
struct flash_bank *info = calloc(1, sizeof(struct flash_bank));
if (!info)
return ERROR_FAIL;

Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/stellaris.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ FLASH_BANK_COMMAND_HANDLER(stellaris_flash_bank_command)
if (CMD_ARGC < 6)
return ERROR_COMMAND_SYNTAX_ERROR;

stellaris_info = calloc(sizeof(struct stellaris_flash_bank), 1);
stellaris_info = calloc(1, sizeof(struct stellaris_flash_bank));
bank->base = 0x0;
bank->driver_priv = stellaris_info;

Expand Down
2 changes: 1 addition & 1 deletion src/flash/nor/stm32f2x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ static int stm32x_probe(struct flash_bank *bank)
assert(num_sectors > 0);

bank->num_sectors = num_sectors;
bank->sectors = calloc(sizeof(struct flash_sector), num_sectors);
bank->sectors = calloc(num_sectors, sizeof(struct flash_sector));

if (stm32x_otp_is_f7(bank))
bank->size = STM32F7_OTP_SIZE;
Expand Down
3 changes: 1 addition & 2 deletions src/flash/nor/tcl.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ COMMAND_HANDLER(handle_flash_protect_check_command){

struct flash_bank *p;
int retval;
int num_blocks;

retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &p);
if (retval != ERROR_OK)
Expand All @@ -415,7 +414,7 @@ COMMAND_HANDLER(handle_flash_protect_check_command){
if(riscvchip==1)
wlink_softreset();
if((riscvchip==1)||(riscvchip==5)||(riscvchip==6)||(riscvchip==9)||(riscvchip==0x0c)||(riscvchip==0x0e)){
int retval=wlnik_protect_check();
retval=wlnik_protect_check();
if(retval==4)
LOG_INFO("Code Read-Protect Status Enable");
else
Expand Down
76 changes: 34 additions & 42 deletions src/flash/nor/wcharm.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ struct ch32x_flash_bank {
};




#if (0)
static int ch32x_mass_erase(struct flash_bank *bank);
#endif

static int ch32x_get_device_id(struct flash_bank *bank, uint32_t *device_id);
static int ch32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
uint32_t address, uint32_t count);
Expand All @@ -208,10 +209,12 @@ FLASH_BANK_COMMAND_HANDLER(ch32x_flash_bank_command)

return ERROR_OK;
}
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 *cmd)
{
return ERROR_OK;
}

static inline int ch32x_get_flash_reg(struct flash_bank *bank, uint32_t reg)
{
struct ch32x_flash_bank *ch32x_info = bank->driver_priv;
Expand Down Expand Up @@ -380,8 +383,6 @@ static int ch32x_erase_options(struct flash_bank *bank)

static int ch32x_write_options(struct flash_bank *bank)
{


struct ch32x_flash_bank *ch32x_info = bank->driver_priv;
struct target *target = bank->target;
uint16_t pbuf[8];
Expand All @@ -406,7 +407,7 @@ static int ch32x_write_options(struct flash_bank *bank)

/* program option bytes */
for(int i=0;i<8;i++){
retval = target_read_u16(target, ch32_OB_RDP+ 16*i , pbuf[i]);
retval = target_read_u16(target, ch32_OB_RDP+ 16*i , &pbuf[i]);
if (retval != ERROR_OK)
return retval;
}
Expand All @@ -419,7 +420,7 @@ static int ch32x_write_options(struct flash_bank *bank)
if (retval != ERROR_OK)
return retval;
for(int i=0;i<8;i++){
retval = target_write_u16(target, ch32_OB_RDP+16*i,pbuf[i]);
retval = target_write_u16(target, ch32_OB_RDP+16*i, pbuf[i]);
if (retval != ERROR_OK)
return retval;
}
Expand Down Expand Up @@ -452,33 +453,29 @@ 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 (size_t 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)
{


struct target *target = bank->target;
int i;
uint32_t cr_reg; uint32_t sr_reg;
uint32_t cr_reg;
if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
}

/* unlock flash registers */

int retval = target_write_u32(target, ch32x_get_flash_reg(bank, ch32_FLASH_KEYR), KEY1);
int retval = target_write_u32(target, ch32x_get_flash_reg(bank, ch32_FLASH_KEYR), KEY1);
if (retval != ERROR_OK)
return retval;

retval = target_write_u32(target, ch32x_get_flash_reg(bank, ch32_FLASH_KEYR), KEY2);
if (retval != ERROR_OK)
return retval;

return retval;

retval = target_read_u32(target, ch32_FLASH_CR_B0, &cr_reg);
if (retval != ERROR_OK)
Expand All @@ -494,26 +491,25 @@ static int ch32x_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK)
return retval;


retval = ch32x_wait_status_busy(bank, FLASH_ERASE_TIMEOUT);
if (retval != ERROR_OK)
return retval;


retval = target_read_u32(target, ch32_FLASH_CR_B0, &cr_reg);
if (retval != ERROR_OK)
return retval;

retval = target_write_u32(target, ch32_FLASH_CR_B0, (cr_reg)&(~(1<<2)));
if (retval != ERROR_OK)
return retval;

alive_sleep(300);

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;
struct ch32x_flash_bank *ch32x_info = bank->driver_priv;

Expand All @@ -532,7 +528,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 (size_t i = first; i <= last; i++) {
if (set)
ch32x_info->option_bytes.protection &= ~(1 << i);
else
Expand All @@ -544,13 +540,9 @@ static int ch32x_protect(struct flash_bank *bank, int set, int first, int last)

static int ch32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
uint32_t address, uint32_t count)
{

struct ch32x_flash_bank *ch32x_info = bank->driver_priv;
{
struct target *target = bank->target;
uint32_t buffer_size = 16384;
struct working_area *write_algorithm;
struct working_area *source;
struct reg_param reg_params[4];
struct armv7m_algorithm armv7m_info;
uint32_t basaddr=0x08000000;
Expand All @@ -573,7 +565,7 @@ static int ch32x_write_block(struct flash_bank *bank, const uint8_t *buffer,

retval = target_write_buffer(target, write_algorithm->address,
sizeof(ch32x_flash_write_code) , ch32x_flash_write_code);
LOG_INFO("write_algorithm->address%x",write_algorithm->address);
LOG_INFO("write_algorithm->address = 0x%" PRIx32, (unsigned int)write_algorithm->address);
if (retval != ERROR_OK) {
target_free_working_area(target, write_algorithm);
return retval;
Expand Down Expand Up @@ -609,6 +601,7 @@ static int ch32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
buffer1=malloc(len);
memcpy(buffer1,buffer,count);
}

while(len>0){
buf_set_u32(reg_params[0].value, 0, 32, basaddr);
if(len<256){
Expand All @@ -623,9 +616,10 @@ static int ch32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
basaddr +=256;

}

if (retval == ERROR_FLASH_OPERATION_FAILED) {
LOG_ERROR("flash write failed at address 0x%"PRIx32,
buf_get_u32(reg_params[4].value, 0, 32));
LOG_ERROR("flash write failed at address 0x%" PRIx32,
buf_get_u32(reg_params[3].value, 0, 32));

if (buf_get_u32(reg_params[0].value, 0, 32) & FLASH_PGERR) {
LOG_ERROR("flash memory not erased before writing");
Expand All @@ -640,7 +634,6 @@ static int ch32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
}
}

// target_free_working_area(target, source);
target_free_working_area(target, write_algorithm);

destroy_reg_param(&reg_params[0]);
Expand All @@ -653,10 +646,8 @@ 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)
{

struct target *target = bank->target;
uint8_t *new_buffer = NULL;
uint32_t choffset=offset;

if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED;
Expand Down Expand Up @@ -715,26 +706,26 @@ 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);
uint32_t flash_size;

int retval = target_read_u32(target, 0x1ffff7e0, &flash_size);
if (retval != ERROR_OK)
return retval;

*flash_size_in_kb = flash_size;

return retval;

}

static int ch32x_probe(struct flash_bank *bank)
{

struct ch32x_flash_bank *ch32x_info = bank->driver_priv;
uint16_t flash_size_in_kb;
uint16_t max_flash_size_in_kb;
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 Down Expand Up @@ -777,7 +768,7 @@ static int ch32x_probe(struct flash_bank *bank)
base_address = 0x08080000;
}
}
LOG_INFO("flash size = %dkbytes", flash_size_in_kb);
LOG_INFO("flash size = %d kbytes", flash_size_in_kb);

/* did we assign flash size? */
assert(flash_size_in_kb != 0xffff);
Expand Down Expand Up @@ -831,9 +822,10 @@ static int ch32x_auto_probe(struct flash_bank *bank)
return ERROR_OK;
return ch32x_probe(bank);
}

#if (0)
static int ch32x_mass_erase(struct flash_bank *bank)
{

struct target *target = bank->target;

if (target->state != TARGET_HALTED) {
Expand Down Expand Up @@ -868,7 +860,7 @@ static int ch32x_mass_erase(struct flash_bank *bank)

return ERROR_OK;
}

#endif

static const struct command_registration ch32x_command_handlers[] = {
{
Expand Down
Loading

0 comments on commit 168436e

Please sign in to comment.