Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ti-connected-launchpad
lm4tools_public
Commits
34526459
Commit
34526459
authored
Jun 14, 2013
by
Fabio Utzig
Browse files
Add -S option to pass the starting address were fw should be written to
parent
0e55c4f9
Changes
1
Show whitespace changes
Inline
Side-by-side
lm4flash/lm4flash.c
View file @
34526459
...
@@ -92,7 +92,7 @@ static union {
...
@@ -92,7 +92,7 @@ static union {
void
show_version
(
void
)
void
show_version
(
void
)
{
{
printf
(
"%s"
,
printf
(
"%s"
,
"LM4Flash version 0.1.
1
- Flasher for Stellaris Launchpad ICDI boards
\n
"
"LM4Flash version 0.1.
2
- Flasher for Stellaris Launchpad ICDI boards
\n
"
"Copyright (C) 2012 Fabio Utzig <fabio@utzig.net>
\n
"
"Copyright (C) 2012 Fabio Utzig <fabio@utzig.net>
\n
"
"Copyright (C) 2012 Peter Stuge <peter@stuge.se>
\n
"
"Copyright (C) 2012 Peter Stuge <peter@stuge.se>
\n
"
"This is free software; see the source for copying conditions. There is NO
\n
"
"This is free software; see the source for copying conditions. There is NO
\n
"
...
@@ -116,6 +116,7 @@ static uint32_t le32_to_cpu(const uint32_t x)
...
@@ -116,6 +116,7 @@ static uint32_t le32_to_cpu(const uint32_t x)
static
int
do_verify
=
0
;
static
int
do_verify
=
0
;
static
int
erase_used
=
0
;
static
int
erase_used
=
0
;
static
uint32_t
start_addr
=
0
;
#define cpu_to_le32 le32_to_cpu
#define cpu_to_le32 le32_to_cpu
...
@@ -505,7 +506,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
...
@@ -505,7 +506,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
if
(
erase_used
)
{
if
(
erase_used
)
{
fseek
(
f
,
0
,
SEEK_END
);
fseek
(
f
,
0
,
SEEK_END
);
size
=
ftell
(
f
);
size
=
ftell
(
f
);
for
(
addr
=
0
;
addr
<
size
;
addr
+=
FLASH_ERASE_SIZE
)
for
(
addr
=
start_addr
;
addr
<
(
start_addr
+
size
)
;
addr
+=
FLASH_ERASE_SIZE
)
FLASH_ERASE
(
addr
,
FLASH_ERASE_SIZE
);
FLASH_ERASE
(
addr
,
FLASH_ERASE_SIZE
);
fseek
(
f
,
0
,
SEEK_SET
);
fseek
(
f
,
0
,
SEEK_SET
);
}
else
{
}
else
{
...
@@ -521,7 +522,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
...
@@ -521,7 +522,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
MEM_WRITE
(
ROMCTL
,
0x0
);
MEM_WRITE
(
ROMCTL
,
0x0
);
MEM_READ
(
DHCSR
,
&
val
);
MEM_READ
(
DHCSR
,
&
val
);
for
(
addr
=
0
;
!
feof
(
f
);
addr
+=
sizeof
(
flash_block
))
{
for
(
addr
=
start_addr
;
!
feof
(
f
);
addr
+=
sizeof
(
flash_block
))
{
rdbytes
=
fread
(
flash_block
,
1
,
sizeof
(
flash_block
),
f
);
rdbytes
=
fread
(
flash_block
,
1
,
sizeof
(
flash_block
),
f
);
if
(
rdbytes
<
sizeof
(
flash_block
)
&&
!
feof
(
f
))
{
if
(
rdbytes
<
sizeof
(
flash_block
)
&&
!
feof
(
f
))
{
...
@@ -540,7 +541,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
...
@@ -540,7 +541,7 @@ static int write_firmware(libusb_device_handle *handle, FILE *f)
if
(
do_verify
)
{
if
(
do_verify
)
{
fseek
(
f
,
0
,
SEEK_SET
);
fseek
(
f
,
0
,
SEEK_SET
);
for
(
addr
=
0
;
!
feof
(
f
);
addr
+=
sizeof
(
flash_block
))
{
for
(
addr
=
start_addr
;
!
feof
(
f
);
addr
+=
sizeof
(
flash_block
))
{
rdbytes
=
fread
(
flash_block
,
1
,
sizeof
(
flash_block
),
f
);
rdbytes
=
fread
(
flash_block
,
1
,
sizeof
(
flash_block
),
f
);
if
(
rdbytes
<
sizeof
(
flash_block
)
&&
!
feof
(
f
))
{
if
(
rdbytes
<
sizeof
(
flash_block
)
&&
!
feof
(
f
))
{
...
@@ -701,6 +702,8 @@ static void flasher_usage()
...
@@ -701,6 +702,8 @@ static void flasher_usage()
printf
(
"
\t\t
Enables verification after write
\n
"
);
printf
(
"
\t\t
Enables verification after write
\n
"
);
printf
(
"
\t
-E
\n
"
);
printf
(
"
\t
-E
\n
"
);
printf
(
"
\t\t
Only erase blocks where binary file will be written
\n
"
);
printf
(
"
\t\t
Only erase blocks where binary file will be written
\n
"
);
printf
(
"
\t
-S address
\n
"
);
printf
(
"
\t\t
Write binary at the given address (in hexadecimal)
\n
"
);
printf
(
"
\t
-s SERIAL
\n
"
);
printf
(
"
\t
-s SERIAL
\n
"
);
printf
(
"
\t\t
Flash device with the following serial
\n
"
);
printf
(
"
\t\t
Flash device with the following serial
\n
"
);
}
}
...
@@ -784,7 +787,7 @@ int main(int argc, char *argv[])
...
@@ -784,7 +787,7 @@ int main(int argc, char *argv[])
const
char
*
rom_name
=
NULL
;
const
char
*
rom_name
=
NULL
;
int
opt
;
int
opt
;
while
((
opt
=
getopt
(
argc
,
argv
,
"VEhvs:"
))
!=
-
1
)
{
while
((
opt
=
getopt
(
argc
,
argv
,
"VE
S:
hvs:"
))
!=
-
1
)
{
switch
(
opt
)
{
switch
(
opt
)
{
case
'V'
:
case
'V'
:
show_version
();
show_version
();
...
@@ -795,6 +798,11 @@ int main(int argc, char *argv[])
...
@@ -795,6 +798,11 @@ int main(int argc, char *argv[])
case
'E'
:
case
'E'
:
erase_used
=
1
;
erase_used
=
1
;
break
;
break
;
case
'S'
:
start_addr
=
strtol
(
optarg
,
NULL
,
16
);
/* force erasing only the used blocks */
erase_used
=
1
;
break
;
case
'v'
:
case
'v'
:
do_verify
=
1
;
do_verify
=
1
;
break
;
break
;
...
@@ -813,5 +821,10 @@ int main(int argc, char *argv[])
...
@@ -813,5 +821,10 @@ int main(int argc, char *argv[])
}
else
}
else
rom_name
=
argv
[
optind
];
rom_name
=
argv
[
optind
];
if
(
start_addr
&&
(
start_addr
%
FLASH_ERASE_SIZE
))
{
printf
(
"Address given to -S must be 0x%x aligned
\n
"
,
FLASH_ERASE_SIZE
);
return
EXIT_FAILURE
;
}
return
flasher_flash
(
serial
,
rom_name
);
return
flasher_flash
(
serial
,
rom_name
);
}
}
Write
Preview
Supports
Markdown
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