Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
openocd
Commits
bf71e34c
Commit
bf71e34c
authored
Mar 16, 2010
by
Øyvind Harboe
Browse files
target: faster mww operations
Signed-off-by:
Øyvind Harboe
<
oyvind.harboe@zylin.com
>
parent
099ffc75
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/target/target.c
View file @
bf71e34c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* Copyright (C) 2005 by Dominic Rath *
* Copyright (C) 2005 by Dominic Rath *
* Dominic.Rath@gmx.de *
* Dominic.Rath@gmx.de *
* *
* *
* Copyright (C) 2007-200
9
Øyvind Harboe *
* Copyright (C) 2007-20
1
0 Øyvind Harboe *
* oyvind.harboe@zylin.com *
* oyvind.harboe@zylin.com *
* *
* *
* Copyright (C) 2008, Duane Ellis *
* Copyright (C) 2008, Duane Ellis *
...
@@ -2294,6 +2294,74 @@ COMMAND_HANDLER(handle_md_command)
...
@@ -2294,6 +2294,74 @@ COMMAND_HANDLER(handle_md_command)
return
retval
;
return
retval
;
}
}
typedef
int
(
*
target_write_fn
)(
struct
target
*
target
,
uint32_t
address
,
uint32_t
size
,
uint32_t
count
,
uint8_t
*
buffer
);
static
int
target_write_memory_fast
(
struct
target
*
target
,
uint32_t
address
,
uint32_t
size
,
uint32_t
count
,
uint8_t
*
buffer
)
{
return
target_write_buffer
(
target
,
address
,
size
*
count
,
buffer
);
}
static
int
target_fill_mem
(
struct
target
*
target
,
uint32_t
address
,
target_write_fn
fn
,
unsigned
data_size
,
/* value */
uint32_t
b
,
/* count */
unsigned
c
)
{
/* We have to write in reasonably large chunks to be able
* to fill large memory areas with any sane speed */
const
unsigned
chunk_size
=
16384
;
uint8_t
*
target_buf
=
malloc
(
chunk_size
*
data_size
);
if
(
target_buf
==
NULL
)
{
LOG_ERROR
(
"Out of memory"
);
return
ERROR_FAIL
;
}
for
(
unsigned
i
=
0
;
i
<
chunk_size
;
i
++
)
{
switch
(
data_size
)
{
case
4
:
target_buffer_set_u32
(
target
,
target_buf
+
i
*
data_size
,
b
);
break
;
case
2
:
target_buffer_set_u16
(
target
,
target_buf
+
i
*
data_size
,
b
);
break
;
case
1
:
target_buffer_set_u8
(
target
,
target_buf
+
i
*
data_size
,
b
);
break
;
default:
exit
(
-
1
);
}
}
int
retval
=
ERROR_OK
;
for
(
unsigned
x
=
0
;
x
<
c
;
x
+=
chunk_size
)
{
unsigned
current
;
current
=
c
-
x
;
if
(
current
>
chunk_size
)
{
current
=
chunk_size
;
}
int
retval
=
fn
(
target
,
address
+
x
*
data_size
,
data_size
,
current
,
target_buf
);
if
(
retval
!=
ERROR_OK
)
{
break
;
}
}
free
(
target_buf
);
return
retval
;
}
COMMAND_HANDLER
(
handle_mw_command
)
COMMAND_HANDLER
(
handle_mw_command
)
{
{
if
(
CMD_ARGC
<
2
)
if
(
CMD_ARGC
<
2
)
...
@@ -2301,8 +2369,7 @@ COMMAND_HANDLER(handle_mw_command)
...
@@ -2301,8 +2369,7 @@ COMMAND_HANDLER(handle_mw_command)
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
}
bool
physical
=
strcmp
(
CMD_ARGV
[
0
],
"phys"
)
==
0
;
bool
physical
=
strcmp
(
CMD_ARGV
[
0
],
"phys"
)
==
0
;
int
(
*
fn
)(
struct
target
*
target
,
target_write_fn
fn
;
uint32_t
address
,
uint32_t
size
,
uint32_t
count
,
uint8_t
*
buffer
);
if
(
physical
)
if
(
physical
)
{
{
CMD_ARGC
--
;
CMD_ARGC
--
;
...
@@ -2310,7 +2377,7 @@ COMMAND_HANDLER(handle_mw_command)
...
@@ -2310,7 +2377,7 @@ COMMAND_HANDLER(handle_mw_command)
fn
=
target_write_phys_memory
;
fn
=
target_write_phys_memory
;
}
else
}
else
{
{
fn
=
target_write_memory
;
fn
=
target_write_memory
_fast
;
}
}
if
((
CMD_ARGC
<
2
)
||
(
CMD_ARGC
>
3
))
if
((
CMD_ARGC
<
2
)
||
(
CMD_ARGC
>
3
))
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
...
@@ -2327,35 +2394,22 @@ COMMAND_HANDLER(handle_mw_command)
...
@@ -2327,35 +2394,22 @@ COMMAND_HANDLER(handle_mw_command)
struct
target
*
target
=
get_current_target
(
CMD_CTX
);
struct
target
*
target
=
get_current_target
(
CMD_CTX
);
unsigned
wordsize
;
unsigned
wordsize
;
uint8_t
value_buf
[
4
];
switch
(
CMD_NAME
[
2
])
switch
(
CMD_NAME
[
2
])
{
{
case
'w'
:
case
'w'
:
wordsize
=
4
;
wordsize
=
4
;
target_buffer_set_u32
(
target
,
value_buf
,
value
);
break
;
break
;
case
'h'
:
case
'h'
:
wordsize
=
2
;
wordsize
=
2
;
target_buffer_set_u16
(
target
,
value_buf
,
value
);
break
;
break
;
case
'b'
:
case
'b'
:
wordsize
=
1
;
wordsize
=
1
;
value_buf
[
0
]
=
value
;
break
;
break
;
default:
default:
return
ERROR_COMMAND_SYNTAX_ERROR
;
return
ERROR_COMMAND_SYNTAX_ERROR
;
}
}
for
(
unsigned
i
=
0
;
i
<
count
;
i
++
)
{
int
retval
=
fn
(
target
,
address
+
i
*
wordsize
,
wordsize
,
1
,
value_buf
);
if
(
ERROR_OK
!=
retval
)
return
retval
;
keep_alive
();
}
return
ERROR_OK
;
return
target_fill_mem
(
target
,
address
,
fn
,
wordsize
,
value
,
count
);
}
}
static
COMMAND_HELPER
(
parse_load_image_command_CMD_ARGV
,
struct
image
*
image
,
static
COMMAND_HELPER
(
parse_load_image_command_CMD_ARGV
,
struct
image
*
image
,
...
@@ -3909,36 +3963,21 @@ static int jim_target_mw(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
...
@@ -3909,36 +3963,21 @@ static int jim_target_mw(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
}
}
struct
target
*
target
=
Jim_CmdPrivData
(
goi
.
interp
);
struct
target
*
target
=
Jim_CmdPrivData
(
goi
.
interp
);
u
int8_t
target_buf
[
32
]
;
u
nsigned
data_size
;
if
(
strcasecmp
(
cmd_name
,
"mww"
)
==
0
)
{
if
(
strcasecmp
(
cmd_name
,
"mww"
)
==
0
)
{
target_buffer_set_u32
(
target
,
target_buf
,
b
);
data_size
=
4
;
b
=
4
;
}
}
else
if
(
strcasecmp
(
cmd_name
,
"mwh"
)
==
0
)
{
else
if
(
strcasecmp
(
cmd_name
,
"mwh"
)
==
0
)
{
target_buffer_set_u16
(
target
,
target_buf
,
b
);
data_size
=
2
;
b
=
2
;
}
}
else
if
(
strcasecmp
(
cmd_name
,
"mwb"
)
==
0
)
{
else
if
(
strcasecmp
(
cmd_name
,
"mwb"
)
==
0
)
{
target_buffer_set_u8
(
target
,
target_buf
,
b
);
data_size
=
1
;
b
=
1
;
}
else
{
}
else
{
LOG_ERROR
(
"command '%s' unknown: "
,
cmd_name
);
LOG_ERROR
(
"command '%s' unknown: "
,
cmd_name
);
return
JIM_ERR
;
return
JIM_ERR
;
}
}
for
(
jim_wide
x
=
0
;
x
<
c
;
x
++
)
return
(
target_fill_mem
(
target
,
a
,
target_write_memory_fast
,
data_size
,
b
,
c
)
==
ERROR_OK
)
?
JIM_OK
:
JIM_ERR
;
{
e
=
target_write_memory
(
target
,
a
,
b
,
1
,
target_buf
);
if
(
e
!=
ERROR_OK
)
{
Jim_SetResult_sprintf
(
interp
,
"Error writing @ 0x%08x: %d
\n
"
,
(
int
)(
a
),
e
);
return
JIM_ERR
;
}
/* b = width */
a
=
a
+
b
;
}
return
JIM_OK
;
}
}
static
int
jim_target_md
(
Jim_Interp
*
interp
,
int
argc
,
Jim_Obj
*
const
*
argv
)
static
int
jim_target_md
(
Jim_Interp
*
interp
,
int
argc
,
Jim_Obj
*
const
*
argv
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment