Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
openocd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
openocd
Commits
e9566a4a
Commit
e9566a4a
authored
15 years ago
by
Zachary T Welch
Browse files
Options
Downloads
Patches
Plain Diff
Improve flash.c command argument parsing.
parent
11e545f5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/flash/flash.c
+51
-68
51 additions, 68 deletions
src/flash/flash.c
with
51 additions
and
68 deletions
src/flash/flash.c
+
51
−
68
View file @
e9566a4a
...
@@ -307,10 +307,10 @@ static int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cm
...
@@ -307,10 +307,10 @@ static int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cm
c
->
target
=
target
;
c
->
target
=
target
;
c
->
driver
=
flash_drivers
[
i
];
c
->
driver
=
flash_drivers
[
i
];
c
->
driver_priv
=
NULL
;
c
->
driver_priv
=
NULL
;
c
->
base
=
strtoul
(
args
[
1
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
u32
,
args
[
1
],
c
->
base
);
c
->
size
=
strtoul
(
args
[
2
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
u32
,
args
[
2
],
c
->
size
);
c
->
chip_width
=
strtoul
(
args
[
3
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
int
,
args
[
3
],
c
->
chip_width
);
c
->
bus_width
=
strtoul
(
args
[
4
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
int
,
args
[
4
],
c
->
bus_width
);
c
->
num_sectors
=
0
;
c
->
num_sectors
=
0
;
c
->
sectors
=
NULL
;
c
->
sectors
=
NULL
;
c
->
next
=
NULL
;
c
->
next
=
NULL
;
...
@@ -360,13 +360,14 @@ static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cm
...
@@ -360,13 +360,14 @@ static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cm
int
retval
;
int
retval
;
if
(
argc
!=
1
)
if
(
argc
!=
1
)
{
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
unsigned
bank_nr
;
COMMAND_PARSE_NUMBER
(
uint
,
args
[
0
],
bank_nr
);
for
(
p
=
flash_banks
;
p
;
p
=
p
->
next
,
i
++
)
for
(
p
=
flash_banks
;
p
;
p
=
p
->
next
,
i
++
)
{
{
if
(
i
==
strtoul
(
args
[
0
],
NULL
,
0
)
)
if
(
i
==
bank_nr
)
{
{
char
buf
[
1024
];
char
buf
[
1024
];
...
@@ -415,7 +416,6 @@ static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cm
...
@@ -415,7 +416,6 @@ static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cm
static
int
handle_flash_probe_command
(
struct
command_context_s
*
cmd_ctx
,
char
*
cmd
,
char
**
args
,
int
argc
)
static
int
handle_flash_probe_command
(
struct
command_context_s
*
cmd_ctx
,
char
*
cmd
,
char
**
args
,
int
argc
)
{
{
flash_bank_t
*
p
;
int
retval
;
int
retval
;
if
(
argc
!=
1
)
if
(
argc
!=
1
)
...
@@ -423,7 +423,9 @@ static int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *c
...
@@ -423,7 +423,9 @@ static int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *c
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
}
p
=
get_flash_bank_by_num_noprobe
(
strtoul
(
args
[
0
],
NULL
,
0
));
unsigned
bank_nr
;
COMMAND_PARSE_NUMBER
(
uint
,
args
[
0
],
bank_nr
);
flash_bank_t
*
p
=
get_flash_bank_by_num_noprobe
(
bank_nr
);
if
(
p
)
if
(
p
)
{
{
if
((
retval
=
p
->
driver
->
probe
(
p
))
==
ERROR_OK
)
if
((
retval
=
p
->
driver
->
probe
(
p
))
==
ERROR_OK
)
...
@@ -451,15 +453,16 @@ static int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *c
...
@@ -451,15 +453,16 @@ static int handle_flash_probe_command(struct command_context_s *cmd_ctx, char *c
static
int
handle_flash_erase_check_command
(
struct
command_context_s
*
cmd_ctx
,
char
*
cmd
,
char
**
args
,
int
argc
)
static
int
handle_flash_erase_check_command
(
struct
command_context_s
*
cmd_ctx
,
char
*
cmd
,
char
**
args
,
int
argc
)
{
{
flash_bank_t
*
p
;
int
retval
;
if
(
argc
!=
1
)
if
(
argc
!=
1
)
{
{
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
}
p
=
get_flash_bank_by_num
(
strtoul
(
args
[
0
],
NULL
,
0
));
flash_bank_t
*
p
;
int
retval
=
flash_command_get_bank_by_num
(
cmd_ctx
,
args
[
0
],
&
p
);
if
(
ERROR_OK
!=
retval
)
return
retval
;
if
(
p
)
if
(
p
)
{
{
int
j
;
int
j
;
...
@@ -509,12 +512,10 @@ static int handle_flash_erase_address_command(struct command_context_s *cmd_ctx,
...
@@ -509,12 +512,10 @@ static int handle_flash_erase_address_command(struct command_context_s *cmd_ctx,
target_t
*
target
=
get_current_target
(
cmd_ctx
);
target_t
*
target
=
get_current_target
(
cmd_ctx
);
if
(
argc
!=
2
)
if
(
argc
!=
2
)
{
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
address
=
strtoul
(
args
[
0
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
int
,
args
[
0
],
address
);
length
=
strtoul
(
args
[
1
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
int
,
args
[
1
],
length
);
if
(
length
<=
0
)
if
(
length
<=
0
)
{
{
command_print
(
cmd_ctx
,
"Length must be >0"
);
command_print
(
cmd_ctx
,
"Length must be >0"
);
...
@@ -547,17 +548,17 @@ static int handle_flash_erase_address_command(struct command_context_s *cmd_ctx,
...
@@ -547,17 +548,17 @@ static int handle_flash_erase_address_command(struct command_context_s *cmd_ctx,
static
int
handle_flash_protect_check_command
(
struct
command_context_s
*
cmd_ctx
,
char
*
cmd
,
char
**
args
,
int
argc
)
static
int
handle_flash_protect_check_command
(
struct
command_context_s
*
cmd_ctx
,
char
*
cmd
,
char
**
args
,
int
argc
)
{
{
flash_bank_t
*
p
;
int
retval
;
if
(
argc
!=
1
)
if
(
argc
!=
1
)
{
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
p
=
get_flash_bank_by_num
(
strtoul
(
args
[
0
],
NULL
,
0
));
flash_bank_t
*
p
;
int
retval
=
flash_command_get_bank_by_num
(
cmd_ctx
,
args
[
0
],
&
p
);
if
(
ERROR_OK
!=
retval
)
return
retval
;
if
(
p
)
if
(
p
)
{
{
int
retval
;
if
((
retval
=
p
->
driver
->
protect_check
(
p
))
==
ERROR_OK
)
if
((
retval
=
p
->
driver
->
protect_check
(
p
))
==
ERROR_OK
)
{
{
command_print
(
cmd_ctx
,
"successfully checked protect state"
);
command_print
(
cmd_ctx
,
"successfully checked protect state"
);
...
@@ -571,10 +572,6 @@ static int handle_flash_protect_check_command(struct command_context_s *cmd_ctx,
...
@@ -571,10 +572,6 @@ static int handle_flash_protect_check_command(struct command_context_s *cmd_ctx,
command_print
(
cmd_ctx
,
"unknown error when checking protection state of flash bank '#%s' at 0x%8.8"
PRIx32
,
args
[
0
],
p
->
base
);
command_print
(
cmd_ctx
,
"unknown error when checking protection state of flash bank '#%s' at 0x%8.8"
PRIx32
,
args
[
0
],
p
->
base
);
}
}
}
}
else
{
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
return
ERROR_OK
;
return
ERROR_OK
;
}
}
...
@@ -605,23 +602,19 @@ static int handle_flash_erase_command(struct command_context_s *cmd_ctx,
...
@@ -605,23 +602,19 @@ static int handle_flash_erase_command(struct command_context_s *cmd_ctx,
uint32_t
bank_nr
;
uint32_t
bank_nr
;
uint32_t
first
;
uint32_t
first
;
uint32_t
last
;
uint32_t
last
;
int
retval
;
if
((
retval
=
parse_u32
(
args
[
0
],
&
bank_nr
))
!=
ERROR_OK
)
return
retval
;
COMMAND_PARSE_NUMBER
(
u32
,
args
[
0
],
bank_nr
);
flash_bank_t
*
p
=
get_flash_bank_by_num
(
bank_nr
);
flash_bank_t
*
p
=
get_flash_bank_by_num
(
bank_nr
);
if
(
!
p
)
if
(
!
p
)
return
ERROR_OK
;
return
ERROR_OK
;
if
((
retval
=
parse_u32
(
args
[
1
],
&
first
))
!=
ERROR_OK
)
COMMAND_PARSE_NUMBER
(
u32
,
args
[
1
],
first
);
return
retval
;
if
(
strcmp
(
args
[
2
],
"last"
)
==
0
)
if
(
strcmp
(
args
[
2
],
"last"
)
==
0
)
last
=
p
->
num_sectors
-
1
;
last
=
p
->
num_sectors
-
1
;
else
else
if
((
retval
=
parse_u32
(
args
[
2
],
&
last
))
!=
ERROR_OK
)
COMMAND_PARSE_NUMBER
(
u32
,
args
[
2
],
last
);
return
retval
;
int
retval
;
if
((
retval
=
flash_check_sector_parameters
(
cmd_ctx
,
if
((
retval
=
flash_check_sector_parameters
(
cmd_ctx
,
first
,
last
,
p
->
num_sectors
))
!=
ERROR_OK
)
first
,
last
,
p
->
num_sectors
))
!=
ERROR_OK
)
return
retval
;
return
retval
;
...
@@ -655,23 +648,18 @@ static int handle_flash_protect_command(struct command_context_s *cmd_ctx,
...
@@ -655,23 +648,18 @@ static int handle_flash_protect_command(struct command_context_s *cmd_ctx,
uint32_t
bank_nr
;
uint32_t
bank_nr
;
uint32_t
first
;
uint32_t
first
;
uint32_t
last
;
uint32_t
last
;
int
retval
;
int
set
;
int
set
;
if
((
retval
=
parse_u32
(
args
[
0
],
&
bank_nr
))
!=
ERROR_OK
)
COMMAND_PARSE_NUMBER
(
u32
,
args
[
0
],
bank_nr
);
return
retval
;
flash_bank_t
*
p
=
get_flash_bank_by_num
(
bank_nr
);
flash_bank_t
*
p
=
get_flash_bank_by_num
(
bank_nr
);
if
(
!
p
)
if
(
!
p
)
return
ERROR_OK
;
return
ERROR_OK
;
if
((
retval
=
parse_u32
(
args
[
1
],
&
first
))
!=
ERROR_OK
)
COMMAND_PARSE_NUMBER
(
u32
,
args
[
1
],
first
);
return
retval
;
if
(
strcmp
(
args
[
2
],
"last"
)
==
0
)
if
(
strcmp
(
args
[
2
],
"last"
)
==
0
)
last
=
p
->
num_sectors
-
1
;
last
=
p
->
num_sectors
-
1
;
else
else
if
((
retval
=
parse_u32
(
args
[
2
],
&
last
))
!=
ERROR_OK
)
COMMAND_PARSE_NUMBER
(
u32
,
args
[
2
],
last
);
return
retval
;
if
(
strcmp
(
args
[
3
],
"on"
)
==
0
)
if
(
strcmp
(
args
[
3
],
"on"
)
==
0
)
set
=
1
;
set
=
1
;
...
@@ -680,6 +668,7 @@ static int handle_flash_protect_command(struct command_context_s *cmd_ctx,
...
@@ -680,6 +668,7 @@ static int handle_flash_protect_command(struct command_context_s *cmd_ctx,
else
else
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
int
retval
;
if
((
retval
=
flash_check_sector_parameters
(
cmd_ctx
,
if
((
retval
=
flash_check_sector_parameters
(
cmd_ctx
,
first
,
last
,
p
->
num_sectors
))
!=
ERROR_OK
)
first
,
last
,
p
->
num_sectors
))
!=
ERROR_OK
)
return
retval
;
return
retval
;
...
@@ -755,7 +744,7 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
...
@@ -755,7 +744,7 @@ static int handle_flash_write_image_command(struct command_context_s *cmd_ctx, c
if
(
argc
>=
2
)
if
(
argc
>=
2
)
{
{
image
.
base_address_set
=
1
;
image
.
base_address_set
=
1
;
image
.
base_address
=
strtoul
(
args
[
1
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
int
,
args
[
1
],
image
.
base_address
);
}
}
else
else
{
{
...
@@ -818,13 +807,11 @@ static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cm
...
@@ -818,13 +807,11 @@ static int handle_flash_fill_command(struct command_context_s *cmd_ctx, char *cm
uint32_t
wordsize
;
uint32_t
wordsize
;
if
(
argc
!=
3
)
if
(
argc
!=
3
)
{
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
address
=
strtoul
(
args
[
0
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
u32
,
args
[
0
],
address
);
pattern
=
strtoul
(
args
[
1
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
u32
,
args
[
1
],
pattern
);
count
=
strtoul
(
args
[
2
],
NULL
,
0
);
COMMAND_PARSE_NUMBER
(
u32
,
args
[
2
],
count
);
if
(
count
==
0
)
if
(
count
==
0
)
return
ERROR_OK
;
return
ERROR_OK
;
...
@@ -928,23 +915,18 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
...
@@ -928,23 +915,18 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
duration_t
duration
;
duration_t
duration
;
char
*
duration_text
;
char
*
duration_text
;
int
retval
,
retvaltemp
;
flash_bank_t
*
p
;
if
(
argc
!=
3
)
if
(
argc
!=
3
)
{
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
duration_start_measure
(
&
duration
);
duration_start_measure
(
&
duration
);
offset
=
strtoul
(
args
[
2
],
NULL
,
0
);
flash_bank_t
*
p
;
p
=
get_flash_bank_by_num
(
strtoul
(
args
[
0
],
NULL
,
0
));
int
retval
=
flash_command_get_bank_by_num
(
cmd_ctx
,
args
[
0
],
&
p
);
if
(
!
p
)
if
(
ERROR_OK
!=
retval
)
{
return
retval
;
command_print
(
cmd_ctx
,
"flash bank '#%s' is out of bounds"
,
args
[
0
]);
return
ERROR_OK
;
COMMAND_PARSE_NUMBER
(
u32
,
args
[
2
],
offset
);
}
if
(
fileio_open
(
&
fileio
,
args
[
1
],
FILEIO_READ
,
FILEIO_BINARY
)
!=
ERROR_OK
)
if
(
fileio_open
(
&
fileio
,
args
[
1
],
FILEIO_READ
,
FILEIO_BINARY
)
!=
ERROR_OK
)
{
{
...
@@ -964,6 +946,7 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
...
@@ -964,6 +946,7 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
free
(
buffer
);
free
(
buffer
);
buffer
=
NULL
;
buffer
=
NULL
;
int
retvaltemp
;
if
((
retvaltemp
=
duration_stop_measure
(
&
duration
,
&
duration_text
))
!=
ERROR_OK
)
if
((
retvaltemp
=
duration_stop_measure
(
&
duration
,
&
duration_text
))
!=
ERROR_OK
)
{
{
fileio_close
(
&
fileio
);
fileio_close
(
&
fileio
);
...
@@ -971,14 +954,14 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
...
@@ -971,14 +954,14 @@ static int handle_flash_write_bank_command(struct command_context_s *cmd_ctx, ch
}
}
if
(
retval
==
ERROR_OK
)
if
(
retval
==
ERROR_OK
)
{
{
command_print
(
cmd_ctx
,
float
elapsed
=
(
float
)
duration
.
duration
.
tv_sec
;
"wrote %lld byte from file %s to flash bank %li at offset 0x%8.8"
PRIx32
" in %s (%f kb/s)"
,
elapsed
+=
(
float
)
duration
.
duration
.
tv_usec
/
1000000
.
0
;
fileio
.
size
,
float
speed
=
(
float
)
fileio
.
size
/
elapsed
;
args
[
1
]
,
command_print
(
cmd_ctx
,
strtoul
(
args
[
0
],
NULL
,
0
),
"wrote %lld byte from file %s to flash bank %u "
offset
,
"at
offset
0x%8.8"
PRIx32
" in %s (%f kb/s)"
,
duration_tex
t
,
fileio
.
size
,
args
[
1
],
p
->
bank_number
,
offse
t
,
(
float
)
fileio
.
size
/
1024
.
0
/
((
float
)
duration
.
duration
.
tv_sec
+
((
float
)
duration
.
duration
.
tv_usec
/
1000000
.
0
))
);
duration_text
,
speed
/
1024
);
}
}
free
(
duration_text
);
free
(
duration_text
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment