- Replace '){' with ') {'.
git-svn-id: svn://svn.berlios.de/openocd/trunk@2397 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
parent
f11b1ff485
commit
2428bc2a5c
|
@ -237,21 +237,21 @@ get_current_sam3(struct command_context_s *cmd_ctx)
|
||||||
static struct sam3_chip *p;
|
static struct sam3_chip *p;
|
||||||
|
|
||||||
t = get_current_target(cmd_ctx);
|
t = get_current_target(cmd_ctx);
|
||||||
if (!t){
|
if (!t) {
|
||||||
command_print(cmd_ctx, "No current target?");
|
command_print(cmd_ctx, "No current target?");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = all_sam3_chips;
|
p = all_sam3_chips;
|
||||||
if (!p){
|
if (!p) {
|
||||||
// this should not happen
|
// this should not happen
|
||||||
// the command is not registered until the chip is created?
|
// the command is not registered until the chip is created?
|
||||||
command_print(cmd_ctx, "No SAM3 chips exist?");
|
command_print(cmd_ctx, "No SAM3 chips exist?");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (p){
|
while (p) {
|
||||||
if (p->target == t){
|
if (p->target == t) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
p = p->next;
|
p = p->next;
|
||||||
|
@ -563,7 +563,7 @@ EFC_GetResult(struct sam3_bank_private *pPrivate, uint32_t *v)
|
||||||
int r;
|
int r;
|
||||||
uint32_t rv;
|
uint32_t rv;
|
||||||
r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FRR, &rv);
|
r = target_read_u32(pPrivate->pChip->target, pPrivate->controller_address + offset_EFC_FRR, &rv);
|
||||||
if (v){
|
if (v) {
|
||||||
*v = rv;
|
*v = rv;
|
||||||
}
|
}
|
||||||
LOG_DEBUG("Result: 0x%08x", ((unsigned int)(rv)));
|
LOG_DEBUG("Result: 0x%08x", ((unsigned int)(rv)));
|
||||||
|
@ -593,14 +593,14 @@ EFC_StartCommand(struct sam3_bank_private *pPrivate,
|
||||||
case AT91C_EFC_FCMD_SLB:
|
case AT91C_EFC_FCMD_SLB:
|
||||||
case AT91C_EFC_FCMD_CLB:
|
case AT91C_EFC_FCMD_CLB:
|
||||||
n = (pPrivate->size_bytes / pPrivate->page_size);
|
n = (pPrivate->size_bytes / pPrivate->page_size);
|
||||||
if (argument >= n){
|
if (argument >= n) {
|
||||||
LOG_ERROR("*BUG*: Embedded flash has only %u pages", (unsigned)(n));
|
LOG_ERROR("*BUG*: Embedded flash has only %u pages", (unsigned)(n));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AT91C_EFC_FCMD_SFB:
|
case AT91C_EFC_FCMD_SFB:
|
||||||
case AT91C_EFC_FCMD_CFB:
|
case AT91C_EFC_FCMD_CFB:
|
||||||
if (argument >= pPrivate->pChip->details.n_gpnvms){
|
if (argument >= pPrivate->pChip->details.n_gpnvms) {
|
||||||
LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs",
|
LOG_ERROR("*BUG*: Embedded flash has only %d GPNVMs",
|
||||||
pPrivate->pChip->details.n_gpnvms);
|
pPrivate->pChip->details.n_gpnvms);
|
||||||
}
|
}
|
||||||
|
@ -612,7 +612,7 @@ EFC_StartCommand(struct sam3_bank_private *pPrivate,
|
||||||
case AT91C_EFC_FCMD_GFB:
|
case AT91C_EFC_FCMD_GFB:
|
||||||
case AT91C_EFC_FCMD_STUI:
|
case AT91C_EFC_FCMD_STUI:
|
||||||
case AT91C_EFC_FCMD_SPUI:
|
case AT91C_EFC_FCMD_SPUI:
|
||||||
if (argument != 0){
|
if (argument != 0) {
|
||||||
LOG_ERROR("Argument is meaningless for cmd: %d", command);
|
LOG_ERROR("Argument is meaningless for cmd: %d", command);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -621,7 +621,7 @@ EFC_StartCommand(struct sam3_bank_private *pPrivate,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command == AT91C_EFC_FCMD_SPUI){
|
if (command == AT91C_EFC_FCMD_SPUI) {
|
||||||
// this is a very special situation.
|
// this is a very special situation.
|
||||||
// Situation (1) - error/retry - see below
|
// Situation (1) - error/retry - see below
|
||||||
// And we are being called recursively
|
// And we are being called recursively
|
||||||
|
@ -629,11 +629,11 @@ EFC_StartCommand(struct sam3_bank_private *pPrivate,
|
||||||
} else {
|
} else {
|
||||||
// it should be "ready"
|
// it should be "ready"
|
||||||
EFC_GetStatus(pPrivate, &v);
|
EFC_GetStatus(pPrivate, &v);
|
||||||
if (v & 1){
|
if (v & 1) {
|
||||||
// then it is ready
|
// then it is ready
|
||||||
// we go on
|
// we go on
|
||||||
} else {
|
} else {
|
||||||
if (retry){
|
if (retry) {
|
||||||
// we have done this before
|
// we have done this before
|
||||||
// the controller is not responding.
|
// the controller is not responding.
|
||||||
LOG_ERROR("flash controller(%d) is not ready! Error", pPrivate->bank_number);
|
LOG_ERROR("flash controller(%d) is not ready! Error", pPrivate->bank_number);
|
||||||
|
@ -656,7 +656,7 @@ EFC_StartCommand(struct sam3_bank_private *pPrivate,
|
||||||
r = target_write_u32(pPrivate->pBank->target,
|
r = target_write_u32(pPrivate->pBank->target,
|
||||||
pPrivate->controller_address + offset_EFC_FCR,
|
pPrivate->controller_address + offset_EFC_FCR,
|
||||||
v);
|
v);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_DEBUG("Error Write failed");
|
LOG_DEBUG("Error Write failed");
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
@ -681,12 +681,12 @@ EFC_PerformCommand(struct sam3_bank_private *pPrivate,
|
||||||
long long ms_now, ms_end;
|
long long ms_now, ms_end;
|
||||||
|
|
||||||
// default
|
// default
|
||||||
if (status){
|
if (status) {
|
||||||
*status = 0;
|
*status = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = EFC_StartCommand(pPrivate, command, argument);
|
r = EFC_StartCommand(pPrivate, command, argument);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,11 +695,11 @@ EFC_PerformCommand(struct sam3_bank_private *pPrivate,
|
||||||
|
|
||||||
do {
|
do {
|
||||||
r = EFC_GetStatus(pPrivate, &v);
|
r = EFC_GetStatus(pPrivate, &v);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
ms_now = timeval_ms();
|
ms_now = timeval_ms();
|
||||||
if (ms_now > ms_end){
|
if (ms_now > ms_end) {
|
||||||
// error
|
// error
|
||||||
LOG_ERROR("Command timeout");
|
LOG_ERROR("Command timeout");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
|
@ -709,7 +709,7 @@ EFC_PerformCommand(struct sam3_bank_private *pPrivate,
|
||||||
;
|
;
|
||||||
|
|
||||||
// error bits..
|
// error bits..
|
||||||
if (status){
|
if (status) {
|
||||||
*status = (v & 0x6);
|
*status = (v & 0x6);
|
||||||
}
|
}
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
@ -741,15 +741,15 @@ FLASHD_ReadUniqueID (struct sam3_bank_private *pPrivate)
|
||||||
|
|
||||||
LOG_DEBUG("Begin");
|
LOG_DEBUG("Begin");
|
||||||
r = EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_STUI, 0);
|
r = EFC_StartCommand(pPrivate, AT91C_EFC_FCMD_STUI, 0);
|
||||||
if (r < 0){
|
if (r < 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0 ; x < 4 ; x++){
|
for (x = 0 ; x < 4 ; x++) {
|
||||||
r = target_read_u32(pPrivate->pChip->target,
|
r = target_read_u32(pPrivate->pChip->target,
|
||||||
pPrivate->pBank->base + (x * 4),
|
pPrivate->pBank->base + (x * 4),
|
||||||
&v);
|
&v);
|
||||||
if (r < 0){
|
if (r < 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
pPrivate->pChip->cfg.unique_id[x] = v;
|
pPrivate->pChip->cfg.unique_id[x] = v;
|
||||||
|
@ -792,12 +792,12 @@ FLASHD_GetGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm, unsigned *pu
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
LOG_DEBUG("Here");
|
LOG_DEBUG("Here");
|
||||||
if (pPrivate->bank_number != 0){
|
if (pPrivate->bank_number != 0) {
|
||||||
LOG_ERROR("GPNVM only works with Bank0");
|
LOG_ERROR("GPNVM only works with Bank0");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpnvm >= pPrivate->pChip->details.n_gpnvms){
|
if (gpnvm >= pPrivate->pChip->details.n_gpnvms) {
|
||||||
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
|
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
|
||||||
gpnvm,pPrivate->pChip->details.n_gpnvms);
|
gpnvm,pPrivate->pChip->details.n_gpnvms);
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
|
@ -805,14 +805,14 @@ FLASHD_GetGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm, unsigned *pu
|
||||||
|
|
||||||
// Get GPNVMs status
|
// Get GPNVMs status
|
||||||
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GFB, 0, NULL);
|
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GFB, 0, NULL);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_ERROR("Failed");
|
LOG_ERROR("Failed");
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = EFC_GetResult(pPrivate, &v);
|
r = EFC_GetResult(pPrivate, &v);
|
||||||
|
|
||||||
if (puthere){
|
if (puthere) {
|
||||||
// Check if GPNVM is set
|
// Check if GPNVM is set
|
||||||
// get the bit and make it a 0/1
|
// get the bit and make it a 0/1
|
||||||
*puthere = (v >> gpnvm) & 1;
|
*puthere = (v >> gpnvm) & 1;
|
||||||
|
@ -836,19 +836,19 @@ FLASHD_ClrGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm)
|
||||||
unsigned v;
|
unsigned v;
|
||||||
|
|
||||||
LOG_DEBUG("Here");
|
LOG_DEBUG("Here");
|
||||||
if (pPrivate->bank_number != 0){
|
if (pPrivate->bank_number != 0) {
|
||||||
LOG_ERROR("GPNVM only works with Bank0");
|
LOG_ERROR("GPNVM only works with Bank0");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpnvm >= pPrivate->pChip->details.n_gpnvms){
|
if (gpnvm >= pPrivate->pChip->details.n_gpnvms) {
|
||||||
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
|
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
|
||||||
gpnvm,pPrivate->pChip->details.n_gpnvms);
|
gpnvm,pPrivate->pChip->details.n_gpnvms);
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v);
|
r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_DEBUG("Failed: %d",r);
|
LOG_DEBUG("Failed: %d",r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -869,22 +869,22 @@ FLASHD_SetGPNVM(struct sam3_bank_private *pPrivate, unsigned gpnvm)
|
||||||
int r;
|
int r;
|
||||||
unsigned v;
|
unsigned v;
|
||||||
|
|
||||||
if (pPrivate->bank_number != 0){
|
if (pPrivate->bank_number != 0) {
|
||||||
LOG_ERROR("GPNVM only works with Bank0");
|
LOG_ERROR("GPNVM only works with Bank0");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpnvm >= pPrivate->pChip->details.n_gpnvms){
|
if (gpnvm >= pPrivate->pChip->details.n_gpnvms) {
|
||||||
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
|
LOG_ERROR("Invalid GPNVM %d, max: %d, ignored",
|
||||||
gpnvm,pPrivate->pChip->details.n_gpnvms);
|
gpnvm,pPrivate->pChip->details.n_gpnvms);
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v);
|
r = FLASHD_GetGPNVM(pPrivate, gpnvm, &v);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
if (v){
|
if (v) {
|
||||||
// already set
|
// already set
|
||||||
r = ERROR_OK;
|
r = ERROR_OK;
|
||||||
} else {
|
} else {
|
||||||
|
@ -907,7 +907,7 @@ FLASHD_GetLockBits(struct sam3_bank_private *pPrivate, uint32_t *v)
|
||||||
int r;
|
int r;
|
||||||
LOG_DEBUG("Here");
|
LOG_DEBUG("Here");
|
||||||
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GLB, 0, NULL);
|
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_GLB, 0, NULL);
|
||||||
if (r == ERROR_OK){
|
if (r == ERROR_OK) {
|
||||||
r = EFC_GetResult(pPrivate, v);
|
r = EFC_GetResult(pPrivate, v);
|
||||||
}
|
}
|
||||||
LOG_DEBUG("End: %d",r);
|
LOG_DEBUG("End: %d",r);
|
||||||
|
@ -934,7 +934,7 @@ FLASHD_Unlock(struct sam3_bank_private *pPrivate,
|
||||||
pages_per_sector = pPrivate->sector_size / pPrivate->page_size;
|
pages_per_sector = pPrivate->sector_size / pPrivate->page_size;
|
||||||
|
|
||||||
/* Unlock all pages */
|
/* Unlock all pages */
|
||||||
while (start_sector <= end_sector){
|
while (start_sector <= end_sector) {
|
||||||
pg = start_sector * pages_per_sector;
|
pg = start_sector * pages_per_sector;
|
||||||
|
|
||||||
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_CLB, pg, &status);
|
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_CLB, pg, &status);
|
||||||
|
@ -968,7 +968,7 @@ FLASHD_Lock(struct sam3_bank_private *pPrivate,
|
||||||
pages_per_sector = pPrivate->sector_size / pPrivate->page_size;
|
pages_per_sector = pPrivate->sector_size / pPrivate->page_size;
|
||||||
|
|
||||||
/* Lock all pages */
|
/* Lock all pages */
|
||||||
while (start_sector <= end_sector){
|
while (start_sector <= end_sector) {
|
||||||
pg = start_sector * pages_per_sector;
|
pg = start_sector * pages_per_sector;
|
||||||
|
|
||||||
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SLB, pg, &status);
|
r = EFC_PerformCommand(pPrivate, AT91C_EFC_FCMD_SLB, pg, &status);
|
||||||
|
@ -990,7 +990,7 @@ sam3_sprintf(struct sam3_chip *pChip , const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap,fmt);
|
va_start(ap,fmt);
|
||||||
if (pChip->mbuf == NULL){
|
if (pChip->mbuf == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1013,7 +1013,7 @@ sam3_reg_fieldname(struct sam3_chip *pChip,
|
||||||
// extract the field
|
// extract the field
|
||||||
v = value >> shift;
|
v = value >> shift;
|
||||||
v = v & ((1 << width)-1);
|
v = v & ((1 << width)-1);
|
||||||
if (width <= 16){
|
if (width <= 16) {
|
||||||
hwidth = 4;
|
hwidth = 4;
|
||||||
dwidth = 5;
|
dwidth = 5;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1139,7 +1139,7 @@ static const char * const nvptype[] = {
|
||||||
|
|
||||||
static const char *_yes_or_no(uint32_t v)
|
static const char *_yes_or_no(uint32_t v)
|
||||||
{
|
{
|
||||||
if (v){
|
if (v) {
|
||||||
return "YES";
|
return "YES";
|
||||||
} else {
|
} else {
|
||||||
return "NO";
|
return "NO";
|
||||||
|
@ -1170,8 +1170,8 @@ sam3_explain_ckgr_mor(struct sam3_chip *pChip)
|
||||||
_rc_freq[v]);
|
_rc_freq[v]);
|
||||||
|
|
||||||
pChip->cfg.rc_freq = 0;
|
pChip->cfg.rc_freq = 0;
|
||||||
if (rcen){
|
if (rcen) {
|
||||||
switch (v){
|
switch (v) {
|
||||||
default:
|
default:
|
||||||
pChip->cfg.rc_freq = 0;
|
pChip->cfg.rc_freq = 0;
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -1224,8 +1224,8 @@ sam3_explain_chipid_cidr(struct sam3_chip *pChip)
|
||||||
|
|
||||||
v = sam3_reg_fieldname(pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8);
|
v = sam3_reg_fieldname(pChip, "ARCH", pChip->cfg.CHIPID_CIDR, 20, 8);
|
||||||
cp = _unknown;
|
cp = _unknown;
|
||||||
for (x = 0 ; archnames[x].name ; x++){
|
for (x = 0 ; archnames[x].name ; x++) {
|
||||||
if (v == archnames[x].value){
|
if (v == archnames[x].value) {
|
||||||
cp = archnames[x].name;
|
cp = archnames[x].name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1271,11 +1271,11 @@ sam3_explain_ckgr_plla(struct sam3_chip *pChip)
|
||||||
mula = sam3_reg_fieldname(pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11);
|
mula = sam3_reg_fieldname(pChip, "MULA", pChip->cfg.CKGR_PLLAR, 16, 11);
|
||||||
sam3_sprintf(pChip,"\n");
|
sam3_sprintf(pChip,"\n");
|
||||||
pChip->cfg.plla_freq = 0;
|
pChip->cfg.plla_freq = 0;
|
||||||
if (mula == 0){
|
if (mula == 0) {
|
||||||
sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula = 0)\n");
|
sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,mula = 0)\n");
|
||||||
} else if (diva == 0){
|
} else if (diva == 0) {
|
||||||
sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva = 0)\n");
|
sam3_sprintf(pChip,"\tPLLA Freq: (Disabled,diva = 0)\n");
|
||||||
} else if (diva == 1){
|
} else if (diva == 1) {
|
||||||
pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula + 1));
|
pChip->cfg.plla_freq = (pChip->cfg.mainosc_freq * (mula + 1));
|
||||||
sam3_sprintf(pChip,"\tPLLA Freq: %3.03f MHz\n",
|
sam3_sprintf(pChip,"\tPLLA Freq: %3.03f MHz\n",
|
||||||
_tomhz(pChip->cfg.plla_freq));
|
_tomhz(pChip->cfg.plla_freq));
|
||||||
|
@ -1291,7 +1291,7 @@ sam3_explain_mckr(struct sam3_chip *pChip)
|
||||||
const char *cp;
|
const char *cp;
|
||||||
|
|
||||||
css = sam3_reg_fieldname(pChip, "CSS", pChip->cfg.PMC_MCKR, 0, 2);
|
css = sam3_reg_fieldname(pChip, "CSS", pChip->cfg.PMC_MCKR, 0, 2);
|
||||||
switch (css & 3){
|
switch (css & 3) {
|
||||||
case 0:
|
case 0:
|
||||||
fin = pChip->cfg.slow_freq;
|
fin = pChip->cfg.slow_freq;
|
||||||
cp = "slowclk";
|
cp = "slowclk";
|
||||||
|
@ -1305,7 +1305,7 @@ sam3_explain_mckr(struct sam3_chip *pChip)
|
||||||
cp = "plla";
|
cp = "plla";
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (pChip->cfg.CKGR_UCKR & (1 << 16)){
|
if (pChip->cfg.CKGR_UCKR & (1 << 16)) {
|
||||||
fin = 480 * 1000 * 1000;
|
fin = 480 * 1000 * 1000;
|
||||||
cp = "upll";
|
cp = "upll";
|
||||||
} else {
|
} else {
|
||||||
|
@ -1319,7 +1319,7 @@ sam3_explain_mckr(struct sam3_chip *pChip)
|
||||||
cp,
|
cp,
|
||||||
_tomhz(fin));
|
_tomhz(fin));
|
||||||
pres = sam3_reg_fieldname(pChip, "PRES", pChip->cfg.PMC_MCKR, 4, 3);
|
pres = sam3_reg_fieldname(pChip, "PRES", pChip->cfg.PMC_MCKR, 4, 3);
|
||||||
switch (pres & 0x07){
|
switch (pres & 0x07) {
|
||||||
case 0:
|
case 0:
|
||||||
pdiv = 1;
|
pdiv = 1;
|
||||||
cp = "selected clock";
|
cp = "selected clock";
|
||||||
|
@ -1369,13 +1369,13 @@ target2sam3(target_t *pTarget)
|
||||||
{
|
{
|
||||||
struct sam3_chip *pChip;
|
struct sam3_chip *pChip;
|
||||||
|
|
||||||
if (pTarget == NULL){
|
if (pTarget == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pChip = all_sam3_chips;
|
pChip = all_sam3_chips;
|
||||||
while (pChip){
|
while (pChip) {
|
||||||
if (pChip->target == pTarget){
|
if (pChip->target == pTarget) {
|
||||||
break; // return below
|
break; // return below
|
||||||
} else {
|
} else {
|
||||||
pChip = pChip->next;
|
pChip = pChip->next;
|
||||||
|
@ -1443,7 +1443,7 @@ sam3_GetReg(struct sam3_chip *pChip, uint32_t *goes_here)
|
||||||
const struct sam3_reg_list *pReg;
|
const struct sam3_reg_list *pReg;
|
||||||
|
|
||||||
pReg = &(sam3_all_regs[0]);
|
pReg = &(sam3_all_regs[0]);
|
||||||
while (pReg->name){
|
while (pReg->name) {
|
||||||
uint32_t *pPossible;
|
uint32_t *pPossible;
|
||||||
|
|
||||||
// calculate where this one go..
|
// calculate where this one go..
|
||||||
|
@ -1452,7 +1452,7 @@ sam3_GetReg(struct sam3_chip *pChip, uint32_t *goes_here)
|
||||||
pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) + pReg->struct_offset));
|
pPossible = ((uint32_t *)(((char *)(&(pChip->cfg))) + pReg->struct_offset));
|
||||||
|
|
||||||
// well? Is it this register
|
// well? Is it this register
|
||||||
if (pPossible == goes_here){
|
if (pPossible == goes_here) {
|
||||||
// Jump for joy!
|
// Jump for joy!
|
||||||
return pReg;
|
return pReg;
|
||||||
}
|
}
|
||||||
|
@ -1473,12 +1473,12 @@ sam3_ReadThisReg(struct sam3_chip *pChip, uint32_t *goes_here)
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
pReg = sam3_GetReg(pChip, goes_here);
|
pReg = sam3_GetReg(pChip, goes_here);
|
||||||
if (!pReg){
|
if (!pReg) {
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = target_read_u32(pChip->target, pReg->address, goes_here);
|
r = target_read_u32(pChip->target, pReg->address, goes_here);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_ERROR("Cannot read SAM3 register: %s @ 0x%08x, Err: %d\n",
|
LOG_ERROR("Cannot read SAM3 register: %s @ 0x%08x, Err: %d\n",
|
||||||
pReg->name, (unsigned)(pReg->address), r);
|
pReg->name, (unsigned)(pReg->address), r);
|
||||||
}
|
}
|
||||||
|
@ -1494,10 +1494,10 @@ sam3_ReadAllRegs(struct sam3_chip *pChip)
|
||||||
const struct sam3_reg_list *pReg;
|
const struct sam3_reg_list *pReg;
|
||||||
|
|
||||||
pReg = &(sam3_all_regs[0]);
|
pReg = &(sam3_all_regs[0]);
|
||||||
while (pReg->name){
|
while (pReg->name) {
|
||||||
r = sam3_ReadThisReg(pChip,
|
r = sam3_ReadThisReg(pChip,
|
||||||
sam3_get_reg_ptr(&(pChip->cfg), pReg));
|
sam3_get_reg_ptr(&(pChip->cfg), pReg));
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_ERROR("Cannot read SAM3 registere: %s @ 0x%08x, Error: %d\n",
|
LOG_ERROR("Cannot read SAM3 registere: %s @ 0x%08x, Error: %d\n",
|
||||||
pReg->name, ((unsigned)(pReg->address)), r);
|
pReg->name, ((unsigned)(pReg->address)), r);
|
||||||
return r;
|
return r;
|
||||||
|
@ -1520,7 +1520,7 @@ sam3_GetInfo(struct sam3_chip *pChip)
|
||||||
|
|
||||||
|
|
||||||
pReg = &(sam3_all_regs[0]);
|
pReg = &(sam3_all_regs[0]);
|
||||||
while (pReg->name){
|
while (pReg->name) {
|
||||||
// display all regs
|
// display all regs
|
||||||
LOG_DEBUG("Start: %s", pReg->name);
|
LOG_DEBUG("Start: %s", pReg->name);
|
||||||
regval = *sam3_get_reg_ptr(&(pChip->cfg), pReg);
|
regval = *sam3_get_reg_ptr(&(pChip->cfg), pReg);
|
||||||
|
@ -1529,7 +1529,7 @@ sam3_GetInfo(struct sam3_chip *pChip)
|
||||||
pReg->name,
|
pReg->name,
|
||||||
pReg->address,
|
pReg->address,
|
||||||
regval);
|
regval);
|
||||||
if (pReg->explain_func){
|
if (pReg->explain_func) {
|
||||||
(*(pReg->explain_func))(pChip);
|
(*(pReg->explain_func))(pChip);
|
||||||
}
|
}
|
||||||
LOG_DEBUG("End: %s", pReg->name);
|
LOG_DEBUG("End: %s", pReg->name);
|
||||||
|
@ -1563,13 +1563,13 @@ sam3_erase_check(struct flash_bank_s *bank)
|
||||||
LOG_ERROR("Target not halted");
|
LOG_ERROR("Target not halted");
|
||||||
return ERROR_TARGET_NOT_HALTED;
|
return ERROR_TARGET_NOT_HALTED;
|
||||||
}
|
}
|
||||||
if (0 == bank->num_sectors){
|
if (0 == bank->num_sectors) {
|
||||||
LOG_ERROR("Target: not supported/not probed\n");
|
LOG_ERROR("Target: not supported/not probed\n");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("sam3 - supports auto-erase, erase_check ignored");
|
LOG_INFO("sam3 - supports auto-erase, erase_check ignored");
|
||||||
for (x = 0 ; x < bank->num_sectors ; x++){
|
for (x = 0 ; x < bank->num_sectors ; x++) {
|
||||||
bank->sectors[x].is_erased = 1;
|
bank->sectors[x].is_erased = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1592,21 +1592,21 @@ sam3_protect_check(struct flash_bank_s *bank)
|
||||||
}
|
}
|
||||||
|
|
||||||
pPrivate = get_sam3_bank_private(bank);
|
pPrivate = get_sam3_bank_private(bank);
|
||||||
if (!pPrivate){
|
if (!pPrivate) {
|
||||||
LOG_ERROR("no private for this bank?");
|
LOG_ERROR("no private for this bank?");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
if (!(pPrivate->probed)){
|
if (!(pPrivate->probed)) {
|
||||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
return ERROR_FLASH_BANK_NOT_PROBED;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = FLASHD_GetLockBits(pPrivate , &v);
|
r = FLASHD_GetLockBits(pPrivate , &v);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_DEBUG("Failed: %d",r);
|
LOG_DEBUG("Failed: %d",r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0 ; x < pPrivate->nsectors ; x++){
|
for (x = 0 ; x < pPrivate->nsectors ; x++) {
|
||||||
bank->sectors[x].is_protected = (!!(v & (1 << x)));
|
bank->sectors[x].is_protected = (!!(v & (1 << x)));
|
||||||
}
|
}
|
||||||
LOG_DEBUG("Done");
|
LOG_DEBUG("Done");
|
||||||
|
@ -1625,17 +1625,17 @@ sam3_flash_bank_command(struct command_context_s *cmd_ctx,
|
||||||
pChip = all_sam3_chips;
|
pChip = all_sam3_chips;
|
||||||
|
|
||||||
// is this an existing chip?
|
// is this an existing chip?
|
||||||
while (pChip){
|
while (pChip) {
|
||||||
if (pChip->target == bank->target){
|
if (pChip->target == bank->target) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pChip = pChip->next;
|
pChip = pChip->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pChip){
|
if (!pChip) {
|
||||||
// this is a *NEW* chip
|
// this is a *NEW* chip
|
||||||
pChip = calloc(1, sizeof(struct sam3_chip));
|
pChip = calloc(1, sizeof(struct sam3_chip));
|
||||||
if (!pChip){
|
if (!pChip) {
|
||||||
LOG_ERROR("NO RAM!");
|
LOG_ERROR("NO RAM!");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
@ -1648,13 +1648,13 @@ sam3_flash_bank_command(struct command_context_s *cmd_ctx,
|
||||||
pChip->cfg.slow_freq = 32768;
|
pChip->cfg.slow_freq = 32768;
|
||||||
pChip->probed = 0;
|
pChip->probed = 0;
|
||||||
pChip->mbuf = membuf_new();
|
pChip->mbuf = membuf_new();
|
||||||
if (!(pChip->mbuf)){
|
if (!(pChip->mbuf)) {
|
||||||
LOG_ERROR("no memory");
|
LOG_ERROR("no memory");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (bank->base){
|
switch (bank->base) {
|
||||||
default:
|
default:
|
||||||
LOG_ERROR("Address 0x%08x invalid bank address (try 0x%08x or 0x%08x)",
|
LOG_ERROR("Address 0x%08x invalid bank address (try 0x%08x or 0x%08x)",
|
||||||
((unsigned int)(bank->base)),
|
((unsigned int)(bank->base)),
|
||||||
|
@ -1693,14 +1693,14 @@ sam3_GetDetails(struct sam3_bank_private *pPrivate)
|
||||||
|
|
||||||
LOG_DEBUG("Begin");
|
LOG_DEBUG("Begin");
|
||||||
pDetails = all_sam3_details;
|
pDetails = all_sam3_details;
|
||||||
while (pDetails->name){
|
while (pDetails->name) {
|
||||||
if (pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR){
|
if (pDetails->chipid_cidr == pPrivate->pChip->cfg.CHIPID_CIDR) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
pDetails++;
|
pDetails++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pDetails->name == NULL){
|
if (pDetails->name == NULL) {
|
||||||
LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can this chip?)",
|
LOG_ERROR("SAM3 ChipID 0x%08x not found in table (perhaps you can this chip?)",
|
||||||
(unsigned int)(pPrivate->pChip->cfg.CHIPID_CIDR));
|
(unsigned int)(pPrivate->pChip->cfg.CHIPID_CIDR));
|
||||||
// Help the victim, print details about the chip
|
// Help the victim, print details about the chip
|
||||||
|
@ -1710,7 +1710,7 @@ sam3_GetDetails(struct sam3_bank_private *pPrivate)
|
||||||
pPrivate->pChip->cfg.CHIPID_CIDR);
|
pPrivate->pChip->cfg.CHIPID_CIDR);
|
||||||
sam3_explain_chipid_cidr(pPrivate->pChip);
|
sam3_explain_chipid_cidr(pPrivate->pChip);
|
||||||
cp = membuf_strtok(pPrivate->pChip->mbuf, "\n", &vp);
|
cp = membuf_strtok(pPrivate->pChip->mbuf, "\n", &vp);
|
||||||
while (cp){
|
while (cp) {
|
||||||
LOG_INFO("%s", cp);
|
LOG_INFO("%s", cp);
|
||||||
cp = membuf_strtok(NULL, "\n", &vp);
|
cp = membuf_strtok(NULL, "\n", &vp);
|
||||||
}
|
}
|
||||||
|
@ -1730,7 +1730,7 @@ sam3_GetDetails(struct sam3_bank_private *pPrivate)
|
||||||
//
|
//
|
||||||
|
|
||||||
// save the "bank" pointers
|
// save the "bank" pointers
|
||||||
for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){
|
for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++) {
|
||||||
saved_banks[ x ] = pChip->details.bank[x].pBank;
|
saved_banks[ x ] = pChip->details.bank[x].pBank;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1740,7 +1740,7 @@ sam3_GetDetails(struct sam3_bank_private *pPrivate)
|
||||||
sizeof(pPrivate->pChip->details));
|
sizeof(pPrivate->pChip->details));
|
||||||
|
|
||||||
// now fix the ghosted pointers
|
// now fix the ghosted pointers
|
||||||
for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){
|
for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++) {
|
||||||
pChip->details.bank[x].pChip = pChip;
|
pChip->details.bank[x].pChip = pChip;
|
||||||
pChip->details.bank[x].pBank = saved_banks[x];
|
pChip->details.bank[x].pBank = saved_banks[x];
|
||||||
}
|
}
|
||||||
|
@ -1769,48 +1769,48 @@ _sam3_probe(struct flash_bank_s *bank, int noise)
|
||||||
}
|
}
|
||||||
|
|
||||||
pPrivate = get_sam3_bank_private(bank);
|
pPrivate = get_sam3_bank_private(bank);
|
||||||
if (!pPrivate){
|
if (!pPrivate) {
|
||||||
LOG_ERROR("Invalid/unknown bank number\n");
|
LOG_ERROR("Invalid/unknown bank number\n");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sam3_ReadAllRegs(pPrivate->pChip);
|
r = sam3_ReadAllRegs(pPrivate->pChip);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LOG_DEBUG("Here");
|
LOG_DEBUG("Here");
|
||||||
r = sam3_GetInfo(pPrivate->pChip);
|
r = sam3_GetInfo(pPrivate->pChip);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
if (!(pPrivate->pChip->probed)){
|
if (!(pPrivate->pChip->probed)) {
|
||||||
pPrivate->pChip->probed = 1;
|
pPrivate->pChip->probed = 1;
|
||||||
LOG_DEBUG("Here");
|
LOG_DEBUG("Here");
|
||||||
r = sam3_GetDetails(pPrivate);
|
r = sam3_GetDetails(pPrivate);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the flash bank size
|
// update the flash bank size
|
||||||
for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++){
|
for (x = 0 ; x < SAM3_MAX_FLASH_BANKS ; x++) {
|
||||||
if (bank->base == pPrivate->pChip->details.bank[0].base_address){
|
if (bank->base == pPrivate->pChip->details.bank[0].base_address) {
|
||||||
bank->size = pPrivate->pChip->details.bank[0].size_bytes;
|
bank->size = pPrivate->pChip->details.bank[0].size_bytes;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bank->sectors == NULL){
|
if (bank->sectors == NULL) {
|
||||||
bank->sectors = calloc(pPrivate->nsectors, (sizeof((bank->sectors)[0])));
|
bank->sectors = calloc(pPrivate->nsectors, (sizeof((bank->sectors)[0])));
|
||||||
if (bank->sectors == NULL){
|
if (bank->sectors == NULL) {
|
||||||
LOG_ERROR("No memory!");
|
LOG_ERROR("No memory!");
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
bank->num_sectors = pPrivate->nsectors;
|
bank->num_sectors = pPrivate->nsectors;
|
||||||
|
|
||||||
for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++){
|
for (x = 0 ; ((int)(x)) < bank->num_sectors ; x++) {
|
||||||
bank->sectors[x].size = pPrivate->sector_size;
|
bank->sectors[x].size = pPrivate->sector_size;
|
||||||
bank->sectors[x].offset = x * (pPrivate->sector_size);
|
bank->sectors[x].offset = x * (pPrivate->sector_size);
|
||||||
// mark as unknown
|
// mark as unknown
|
||||||
|
@ -1822,13 +1822,13 @@ _sam3_probe(struct flash_bank_s *bank, int noise)
|
||||||
pPrivate->probed = 1;
|
pPrivate->probed = 1;
|
||||||
|
|
||||||
r = sam3_protect_check(bank);
|
r = sam3_protect_check(bank);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG("Bank = %d, nbanks = %d",
|
LOG_DEBUG("Bank = %d, nbanks = %d",
|
||||||
pPrivate->bank_number , pPrivate->pChip->details.n_banks);
|
pPrivate->bank_number , pPrivate->pChip->details.n_banks);
|
||||||
if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks){
|
if ((pPrivate->bank_number + 1) == pPrivate->pChip->details.n_banks) {
|
||||||
// read unique id,
|
// read unique id,
|
||||||
// it appears to be associated with the *last* flash bank.
|
// it appears to be associated with the *last* flash bank.
|
||||||
FLASHD_ReadUniqueID(pPrivate);
|
FLASHD_ReadUniqueID(pPrivate);
|
||||||
|
@ -1864,17 +1864,17 @@ sam3_erase(struct flash_bank_s *bank, int first, int last)
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sam3_auto_probe(bank);
|
r = sam3_auto_probe(bank);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_DEBUG("Here,r=%d",r);
|
LOG_DEBUG("Here,r=%d",r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
pPrivate = get_sam3_bank_private(bank);
|
pPrivate = get_sam3_bank_private(bank);
|
||||||
if (!(pPrivate->probed)){
|
if (!(pPrivate->probed)) {
|
||||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
return ERROR_FLASH_BANK_NOT_PROBED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((first == 0) && ((last + 1)== ((int)(pPrivate->nsectors)))){
|
if ((first == 0) && ((last + 1)== ((int)(pPrivate->nsectors)))) {
|
||||||
// whole chip
|
// whole chip
|
||||||
LOG_DEBUG("Here");
|
LOG_DEBUG("Here");
|
||||||
return FLASHD_EraseEntireBank(pPrivate);
|
return FLASHD_EraseEntireBank(pPrivate);
|
||||||
|
@ -1896,11 +1896,11 @@ sam3_protect(struct flash_bank_s *bank, int set, int first, int last)
|
||||||
}
|
}
|
||||||
|
|
||||||
pPrivate = get_sam3_bank_private(bank);
|
pPrivate = get_sam3_bank_private(bank);
|
||||||
if (!(pPrivate->probed)){
|
if (!(pPrivate->probed)) {
|
||||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
return ERROR_FLASH_BANK_NOT_PROBED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set){
|
if (set) {
|
||||||
r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last));
|
r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last));
|
||||||
} else {
|
} else {
|
||||||
r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last));
|
r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last));
|
||||||
|
@ -1937,7 +1937,7 @@ sam3_page_read(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *bu
|
||||||
4, /* THIS*MUST*BE* in 32bit values */
|
4, /* THIS*MUST*BE* in 32bit values */
|
||||||
pPrivate->page_size / 4,
|
pPrivate->page_size / 4,
|
||||||
buf);
|
buf);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_ERROR("SAM3: Flash program failed to read page phys address: 0x%08x", (unsigned int)(adr));
|
LOG_ERROR("SAM3: Flash program failed to read page phys address: 0x%08x", (unsigned int)(adr));
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
@ -2051,7 +2051,7 @@ sam3_page_write(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *b
|
||||||
4, /* THIS*MUST*BE* in 32bit values */
|
4, /* THIS*MUST*BE* in 32bit values */
|
||||||
pPrivate->page_size / 4,
|
pPrivate->page_size / 4,
|
||||||
buf);
|
buf);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_ERROR("SAM3: Failed to write (buffer) page at phys address 0x%08x", (unsigned int)(adr));
|
LOG_ERROR("SAM3: Failed to write (buffer) page at phys address 0x%08x", (unsigned int)(adr));
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -2062,14 +2062,14 @@ sam3_page_write(struct sam3_bank_private *pPrivate, unsigned pagenum, uint8_t *b
|
||||||
pagenum,
|
pagenum,
|
||||||
&status);
|
&status);
|
||||||
|
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_ERROR("SAM3: Error performing Erase & Write page @ phys address 0x%08x", (unsigned int)(adr));
|
LOG_ERROR("SAM3: Error performing Erase & Write page @ phys address 0x%08x", (unsigned int)(adr));
|
||||||
}
|
}
|
||||||
if (status & (1 << 2)){
|
if (status & (1 << 2)) {
|
||||||
LOG_ERROR("SAM3: Page @ Phys address 0x%08x is locked", (unsigned int)(adr));
|
LOG_ERROR("SAM3: Page @ Phys address 0x%08x is locked", (unsigned int)(adr));
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
if (status & (1 << 1)){
|
if (status & (1 << 1)) {
|
||||||
LOG_ERROR("SAM3: Flash Command error @phys address 0x%08x", (unsigned int)(adr));
|
LOG_ERROR("SAM3: Flash Command error @phys address 0x%08x", (unsigned int)(adr));
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
|
@ -2095,7 +2095,7 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
uint8_t *pagebuffer;
|
uint8_t *pagebuffer;
|
||||||
|
|
||||||
// ignore dumb requests
|
// ignore dumb requests
|
||||||
if (count == 0){
|
if (count == 0) {
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2105,12 +2105,12 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
}
|
}
|
||||||
|
|
||||||
pPrivate = get_sam3_bank_private(bank);
|
pPrivate = get_sam3_bank_private(bank);
|
||||||
if (!(pPrivate->probed)){
|
if (!(pPrivate->probed)) {
|
||||||
return ERROR_FLASH_BANK_NOT_PROBED;
|
return ERROR_FLASH_BANK_NOT_PROBED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((offset + count) > pPrivate->size_bytes){
|
if ((offset + count) > pPrivate->size_bytes) {
|
||||||
LOG_ERROR("Flash write error - past end of bank");
|
LOG_ERROR("Flash write error - past end of bank");
|
||||||
LOG_ERROR(" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x",
|
LOG_ERROR(" offset: 0x%08x, count 0x%08x, BankEnd: 0x%08x",
|
||||||
(unsigned int)(offset),
|
(unsigned int)(offset),
|
||||||
|
@ -2136,10 +2136,10 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
// (3) non-aligned end.
|
// (3) non-aligned end.
|
||||||
|
|
||||||
// Handle special case - all one page.
|
// Handle special case - all one page.
|
||||||
if (page_cur == page_end){
|
if (page_cur == page_end) {
|
||||||
LOG_DEBUG("Special case, all in one page");
|
LOG_DEBUG("Special case, all in one page");
|
||||||
r = sam3_page_read(pPrivate, page_cur, pagebuffer);
|
r = sam3_page_read(pPrivate, page_cur, pagebuffer);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2149,7 +2149,7 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
count);
|
count);
|
||||||
|
|
||||||
r = sam3_page_write(pPrivate, page_cur, pagebuffer);
|
r = sam3_page_write(pPrivate, page_cur, pagebuffer);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
|
@ -2157,11 +2157,11 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
|
|
||||||
// non-aligned start
|
// non-aligned start
|
||||||
page_offset = offset & (pPrivate->page_size - 1);
|
page_offset = offset & (pPrivate->page_size - 1);
|
||||||
if (page_offset){
|
if (page_offset) {
|
||||||
LOG_DEBUG("Not-Aligned start");
|
LOG_DEBUG("Not-Aligned start");
|
||||||
// read the partial
|
// read the partial
|
||||||
r = sam3_page_read(pPrivate, page_cur, pagebuffer);
|
r = sam3_page_read(pPrivate, page_cur, pagebuffer);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2172,7 +2172,7 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
n);
|
n);
|
||||||
|
|
||||||
r = sam3_page_write(pPrivate, page_cur, pagebuffer);
|
r = sam3_page_write(pPrivate, page_cur, pagebuffer);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2189,9 +2189,9 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
(int)page_cur, (int)page_end, (unsigned int)(count));
|
(int)page_cur, (int)page_end, (unsigned int)(count));
|
||||||
|
|
||||||
while ((page_cur < page_end) &&
|
while ((page_cur < page_end) &&
|
||||||
(count >= pPrivate->page_size)){
|
(count >= pPrivate->page_size)) {
|
||||||
r = sam3_page_write(pPrivate, page_cur, buffer);
|
r = sam3_page_write(pPrivate, page_cur, buffer);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
count -= pPrivate->page_size;
|
count -= pPrivate->page_size;
|
||||||
|
@ -2200,17 +2200,17 @@ sam3_write(struct flash_bank_s *bank,
|
||||||
}
|
}
|
||||||
|
|
||||||
// terminal partial page?
|
// terminal partial page?
|
||||||
if (count){
|
if (count) {
|
||||||
LOG_DEBUG("Terminal partial page, count = 0x%08x", (unsigned int)(count));
|
LOG_DEBUG("Terminal partial page, count = 0x%08x", (unsigned int)(count));
|
||||||
// we have a partial page
|
// we have a partial page
|
||||||
r = sam3_page_read(pPrivate, page_cur, pagebuffer);
|
r = sam3_page_read(pPrivate, page_cur, pagebuffer);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
// data goes at start
|
// data goes at start
|
||||||
memcpy(pagebuffer, buffer, count);
|
memcpy(pagebuffer, buffer, count);
|
||||||
r = sam3_page_write(pPrivate, page_cur, pagebuffer);
|
r = sam3_page_write(pPrivate, page_cur, pagebuffer);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
buffer += count;
|
buffer += count;
|
||||||
|
@ -2230,14 +2230,14 @@ sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
pChip = get_current_sam3(cmd_ctx);
|
pChip = get_current_sam3(cmd_ctx);
|
||||||
if (!pChip){
|
if (!pChip) {
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = 0;
|
r = 0;
|
||||||
|
|
||||||
// bank0 must exist before we can do anything
|
// bank0 must exist before we can do anything
|
||||||
if (pChip->details.bank[0].pBank == NULL){
|
if (pChip->details.bank[0].pBank == NULL) {
|
||||||
x = 0;
|
x = 0;
|
||||||
need_define:
|
need_define:
|
||||||
command_print(cmd_ctx,
|
command_print(cmd_ctx,
|
||||||
|
@ -2248,9 +2248,9 @@ sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
|
||||||
}
|
}
|
||||||
|
|
||||||
// if bank 0 is not probed, then probe it
|
// if bank 0 is not probed, then probe it
|
||||||
if (!(pChip->details.bank[0].probed)){
|
if (!(pChip->details.bank[0].probed)) {
|
||||||
r = sam3_auto_probe(pChip->details.bank[0].pBank);
|
r = sam3_auto_probe(pChip->details.bank[0].pBank);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2260,29 +2260,29 @@ sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
|
||||||
|
|
||||||
|
|
||||||
// auto-probe other banks, 0 done above
|
// auto-probe other banks, 0 done above
|
||||||
for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++){
|
for (x = 1 ; x < SAM3_MAX_FLASH_BANKS ; x++) {
|
||||||
// skip banks not present
|
// skip banks not present
|
||||||
if (!(pChip->details.bank[x].present)){
|
if (!(pChip->details.bank[x].present)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pChip->details.bank[x].pBank == NULL){
|
if (pChip->details.bank[x].pBank == NULL) {
|
||||||
goto need_define;
|
goto need_define;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pChip->details.bank[x].probed){
|
if (pChip->details.bank[x].probed) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sam3_auto_probe(pChip->details.bank[x].pBank);
|
r = sam3_auto_probe(pChip->details.bank[x].pBank);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
r = sam3_GetInfo(pChip);
|
r = sam3_GetInfo(pChip);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
LOG_DEBUG("Sam3Info, Failed %d\n",r);
|
LOG_DEBUG("Sam3Info, Failed %d\n",r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -2290,7 +2290,7 @@ sam3_handle_info_command(struct command_context_s *cmd_ctx, char *cmd, char **ar
|
||||||
|
|
||||||
// print results
|
// print results
|
||||||
cp = membuf_strtok(pChip->mbuf, "\n", &vp);
|
cp = membuf_strtok(pChip->mbuf, "\n", &vp);
|
||||||
while (cp){
|
while (cp) {
|
||||||
command_print(cmd_ctx,"%s", cp);
|
command_print(cmd_ctx,"%s", cp);
|
||||||
cp = membuf_strtok(NULL, "\n", &vp);
|
cp = membuf_strtok(NULL, "\n", &vp);
|
||||||
}
|
}
|
||||||
|
@ -2306,30 +2306,30 @@ sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **a
|
||||||
struct sam3_chip *pChip;
|
struct sam3_chip *pChip;
|
||||||
|
|
||||||
pChip = get_current_sam3(cmd_ctx);
|
pChip = get_current_sam3(cmd_ctx);
|
||||||
if (!pChip){
|
if (!pChip) {
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pChip->target->state != TARGET_HALTED){
|
if (pChip->target->state != TARGET_HALTED) {
|
||||||
LOG_ERROR("sam3 - target not halted");
|
LOG_ERROR("sam3 - target not halted");
|
||||||
return ERROR_TARGET_NOT_HALTED;
|
return ERROR_TARGET_NOT_HALTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (pChip->details.bank[0].pBank == NULL){
|
if (pChip->details.bank[0].pBank == NULL) {
|
||||||
command_print(cmd_ctx, "Bank0 must be defined first via: flash bank %s ...",
|
command_print(cmd_ctx, "Bank0 must be defined first via: flash bank %s ...",
|
||||||
at91sam3_flash.name);
|
at91sam3_flash.name);
|
||||||
return ERROR_FAIL;
|
return ERROR_FAIL;
|
||||||
}
|
}
|
||||||
if (!pChip->details.bank[0].probed){
|
if (!pChip->details.bank[0].probed) {
|
||||||
r = sam3_auto_probe(pChip->details.bank[0].pBank);
|
r = sam3_auto_probe(pChip->details.bank[0].pBank);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (argc){
|
switch (argc) {
|
||||||
default:
|
default:
|
||||||
command_print(cmd_ctx,"Too many parameters\n");
|
command_print(cmd_ctx,"Too many parameters\n");
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
@ -2342,11 +2342,11 @@ sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **a
|
||||||
who = -1;
|
who = -1;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if ((0 == strcmp(argv[0], "show")) && (0 == strcmp(argv[1], "all"))){
|
if ((0 == strcmp(argv[0], "show")) && (0 == strcmp(argv[1], "all"))) {
|
||||||
who = -1;
|
who = -1;
|
||||||
} else {
|
} else {
|
||||||
r = parse_u32(argv[1], &v32);
|
r = parse_u32(argv[1], &v32);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
command_print(cmd_ctx, "Not a number: %s", argv[1]);
|
command_print(cmd_ctx, "Not a number: %s", argv[1]);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -2355,19 +2355,19 @@ sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **a
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == strcmp("show", argv[0])){
|
if (0 == strcmp("show", argv[0])) {
|
||||||
if (who == -1){
|
if (who == -1) {
|
||||||
showall:
|
showall:
|
||||||
for (x = 0 ; x < pChip->details.n_gpnvms ; x++){
|
for (x = 0 ; x < pChip->details.n_gpnvms ; x++) {
|
||||||
r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v);
|
r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v);
|
||||||
if (r != ERROR_OK){
|
if (r != ERROR_OK) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
command_print(cmd_ctx, "sam3-gpnvm%u: %u", x, v);
|
command_print(cmd_ctx, "sam3-gpnvm%u: %u", x, v);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)){
|
if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)) {
|
||||||
r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v);
|
r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v);
|
||||||
command_print(cmd_ctx, "sam3-gpnvm%u: %u", who, v);
|
command_print(cmd_ctx, "sam3-gpnvm%u: %u", who, v);
|
||||||
return r;
|
return r;
|
||||||
|
@ -2377,15 +2377,15 @@ sam3_handle_gpnvm_command(struct command_context_s *cmd_ctx, char *cmd, char **a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (who == -1){
|
if (who == -1) {
|
||||||
command_print(cmd_ctx, "Missing GPNVM number");
|
command_print(cmd_ctx, "Missing GPNVM number");
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == strcmp("set", argv[0])){
|
if (0 == strcmp("set", argv[0])) {
|
||||||
r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who);
|
r = FLASHD_SetGPNVM(&(pChip->details.bank[0]), who);
|
||||||
} else if ((0 == strcmp("clr", argv[0])) ||
|
} else if ((0 == strcmp("clr", argv[0])) ||
|
||||||
(0 == strcmp("clear", argv[0]))){ // quietly accept both
|
(0 == strcmp("clear", argv[0]))) { // quietly accept both
|
||||||
r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who);
|
r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who);
|
||||||
} else {
|
} else {
|
||||||
command_print(cmd_ctx, "Unkown command: %s", argv[0]);
|
command_print(cmd_ctx, "Unkown command: %s", argv[0]);
|
||||||
|
@ -2403,19 +2403,19 @@ sam3_handle_slowclk_command(struct command_context_s *cmd_ctx, char *cmd, char *
|
||||||
struct sam3_chip *pChip;
|
struct sam3_chip *pChip;
|
||||||
|
|
||||||
pChip = get_current_sam3(cmd_ctx);
|
pChip = get_current_sam3(cmd_ctx);
|
||||||
if (!pChip){
|
if (!pChip) {
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (argc){
|
switch (argc) {
|
||||||
case 0:
|
case 0:
|
||||||
// show
|
// show
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
// set
|
// set
|
||||||
r = parse_u32(argv[0], &v);
|
r = parse_u32(argv[0], &v);
|
||||||
if (v > 200000){
|
if (v > 200000) {
|
||||||
// absurd slow clock of 200Khz?
|
// absurd slow clock of 200Khz?
|
||||||
command_print(cmd_ctx,"Absurd/illegal slow clock freq: %d\n", (int)(v));
|
command_print(cmd_ctx,"Absurd/illegal slow clock freq: %d\n", (int)(v));
|
||||||
return ERROR_COMMAND_SYNTAX_ERROR;
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
||||||
|
@ -2443,7 +2443,7 @@ sam3_register_commands(struct command_context_s *cmd_ctx)
|
||||||
command_t *pCmd;
|
command_t *pCmd;
|
||||||
|
|
||||||
// only register once
|
// only register once
|
||||||
if (!sam3_registered){
|
if (!sam3_registered) {
|
||||||
sam3_registered++;
|
sam3_registered++;
|
||||||
|
|
||||||
pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL);
|
pCmd = register_command(cmd_ctx, NULL, "at91sam3", NULL, COMMAND_ANY, NULL);
|
||||||
|
|
|
@ -55,7 +55,7 @@ membuf_datapointer(struct membuf *pBuf)
|
||||||
const char *
|
const char *
|
||||||
membuf_strtok(struct membuf *pBuf, const char *sep, void **pLast)
|
membuf_strtok(struct membuf *pBuf, const char *sep, void **pLast)
|
||||||
{
|
{
|
||||||
if (pBuf){
|
if (pBuf) {
|
||||||
pBuf->_strtoklast = NULL;
|
pBuf->_strtoklast = NULL;
|
||||||
*pLast = pBuf;
|
*pLast = pBuf;
|
||||||
return strtok_r(((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast));
|
return strtok_r(((char *)(pBuf->buf)), sep, &(pBuf->_strtoklast));
|
||||||
|
@ -75,10 +75,10 @@ membuf_new(void)
|
||||||
struct membuf *pBuf;
|
struct membuf *pBuf;
|
||||||
|
|
||||||
pBuf = calloc(1, sizeof(*pBuf));
|
pBuf = calloc(1, sizeof(*pBuf));
|
||||||
if (pBuf){
|
if (pBuf) {
|
||||||
// we *ALWAYS* allocate +1 for null terminator.
|
// we *ALWAYS* allocate +1 for null terminator.
|
||||||
pBuf->buf = calloc(DEFAULT_BUFSIZE + 1, sizeof(char));
|
pBuf->buf = calloc(DEFAULT_BUFSIZE + 1, sizeof(char));
|
||||||
if (pBuf->buf == NULL){
|
if (pBuf->buf == NULL) {
|
||||||
free(pBuf);
|
free(pBuf);
|
||||||
pBuf = NULL;
|
pBuf = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -99,13 +99,13 @@ membuf_grow(struct membuf *pBuf, int n)
|
||||||
newsize = ((int)(pBuf->maxlen)) + n;
|
newsize = ((int)(pBuf->maxlen)) + n;
|
||||||
|
|
||||||
// do not go negative, or too small
|
// do not go negative, or too small
|
||||||
if (newsize < DEFAULT_BUFSIZE){
|
if (newsize < DEFAULT_BUFSIZE) {
|
||||||
newsize = DEFAULT_BUFSIZE;
|
newsize = DEFAULT_BUFSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// always alloc +1 for the null terminator
|
// always alloc +1 for the null terminator
|
||||||
vp = realloc(pBuf->buf, newsize + 1);
|
vp = realloc(pBuf->buf, newsize + 1);
|
||||||
if (vp){
|
if (vp) {
|
||||||
pBuf->buf = vp;
|
pBuf->buf = vp;
|
||||||
pBuf->maxlen = newsize;
|
pBuf->maxlen = newsize;
|
||||||
return pBuf;
|
return pBuf;
|
||||||
|
@ -123,8 +123,8 @@ void membuf_reset(struct membuf *pBuf)
|
||||||
|
|
||||||
void membuf_delete(struct membuf *pBuf)
|
void membuf_delete(struct membuf *pBuf)
|
||||||
{
|
{
|
||||||
if (pBuf){
|
if (pBuf) {
|
||||||
if (pBuf->buf){
|
if (pBuf->buf) {
|
||||||
// wack data so it cannot be reused
|
// wack data so it cannot be reused
|
||||||
memset(pBuf->buf,0,pBuf->maxlen);
|
memset(pBuf->buf,0,pBuf->maxlen);
|
||||||
free(pBuf->buf);
|
free(pBuf->buf);
|
||||||
|
@ -163,7 +163,7 @@ membuf_vsprintf(struct membuf *pBuf, const char *fmt, va_list ap)
|
||||||
sa,
|
sa,
|
||||||
fmt,
|
fmt,
|
||||||
ap);
|
ap);
|
||||||
if ((r > 0) && (((size_t)(r)) < sa)){
|
if ((r > 0) && (((size_t)(r)) < sa)) {
|
||||||
// Success!
|
// Success!
|
||||||
pBuf->curlen += ((size_t)(r));
|
pBuf->curlen += ((size_t)(r));
|
||||||
// remember: We always alloc'ed +1
|
// remember: We always alloc'ed +1
|
||||||
|
@ -174,7 +174,7 @@ membuf_vsprintf(struct membuf *pBuf, const char *fmt, va_list ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// failure
|
// failure
|
||||||
if (r < 0){
|
if (r < 0) {
|
||||||
// Option(A) format error
|
// Option(A) format error
|
||||||
// Option(B) glibc2.0 bug
|
// Option(B) glibc2.0 bug
|
||||||
// assume (B).
|
// assume (B).
|
||||||
|
@ -182,13 +182,13 @@ membuf_vsprintf(struct membuf *pBuf, const char *fmt, va_list ap)
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't do this again
|
// don't do this again
|
||||||
if (grew){
|
if (grew) {
|
||||||
r = -1;
|
r = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
grew = 1;
|
grew = 1;
|
||||||
pBuf = membuf_grow(pBuf, r);
|
pBuf = membuf_grow(pBuf, r);
|
||||||
if (pBuf == NULL){
|
if (pBuf == NULL) {
|
||||||
// grow failed
|
// grow failed
|
||||||
r = -1;
|
r = -1;
|
||||||
break;
|
break;
|
||||||
|
@ -213,13 +213,13 @@ membuf_append(struct membuf *pBuf, const void *pData, size_t len)
|
||||||
sa = space_avail(pBuf);
|
sa = space_avail(pBuf);
|
||||||
|
|
||||||
// will it fit?
|
// will it fit?
|
||||||
if (sa < len){
|
if (sa < len) {
|
||||||
// if not, how much do we need?
|
// if not, how much do we need?
|
||||||
r = ((int)(sa - len));
|
r = ((int)(sa - len));
|
||||||
// do the grow.
|
// do the grow.
|
||||||
pBuf = membuf_grow(pBuf, r);
|
pBuf = membuf_grow(pBuf, r);
|
||||||
// failed?
|
// failed?
|
||||||
if (pBuf == NULL){
|
if (pBuf == NULL) {
|
||||||
return pBuf;
|
return pBuf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue