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
6b658153
Commit
6b658153
authored
Oct 29, 2012
by
Fabio Utzig
Browse files
Coding style fixes
parent
ca6cb63d
Changes
1
Hide whitespace changes
Inline
Side-by-side
lm4flash/lm4flash.c
View file @
6b658153
...
@@ -491,8 +491,7 @@ enum flasher_error {
...
@@ -491,8 +491,7 @@ enum flasher_error {
};
};
static
static
enum
flasher_error
enum
flasher_error
flasher_find_matching_device
(
flasher_find_matching_device
(
libusb_context
*
ctx
,
libusb_context
*
ctx
,
libusb_device
**
matching_device_out
,
libusb_device
**
matching_device_out
,
...
@@ -513,13 +512,13 @@ flasher_find_matching_device(
...
@@ -513,13 +512,13 @@ flasher_find_matching_device(
int
device_count
;
int
device_count
;
int
device_index
;
int
device_index
;
/* Enum
b
erate all USB devices */
/* Enumerate all USB devices */
retval
=
libusb_get_device_list
(
ctx
,
&
device_list
);
retval
=
libusb_get_device_list
(
ctx
,
&
device_list
);
if
(
retval
<
0
)
{
if
(
retval
<
0
)
{
libusb_error
=
retval
;
libusb_error
=
retval
;
flasher_error
=
FLASHER_ERR_LIBUSB_FAILURE
;
flasher_error
=
FLASHER_ERR_LIBUSB_FAILURE
;
fprintf
(
stderr
,
"Unable to get enumerate USB devices: %s
\n
"
,
fprintf
(
stderr
,
"Unable to get enumerate USB devices: %s
\n
"
,
libusb_error_name
(
libusb_error
));
libusb_error_name
(
libusb_error
));
goto
out
;
goto
out
;
}
else
{
}
else
{
device_count
=
retval
;
device_count
=
retval
;
...
@@ -533,24 +532,24 @@ flasher_find_matching_device(
...
@@ -533,24 +532,24 @@ flasher_find_matching_device(
/* Walk the list of devices and try to match some */
/* Walk the list of devices and try to match some */
for
(
device_index
=
0
;
device_index
<
device_count
;
++
device_index
)
{
for
(
device_index
=
0
;
device_index
<
device_count
;
++
device_index
)
{
retval
=
libusb_get_device_descriptor
(
retval
=
libusb_get_device_descriptor
(
device_list
[
device_index
],
&
device_descriptor
);
device_list
[
device_index
],
&
device_descriptor
);
if
(
retval
<
0
)
{
if
(
retval
<
0
)
{
fprintf
(
stderr
,
"Unable to get device descritor: %s
\n
"
,
fprintf
(
stderr
,
"Unable to get device descritor: %s
\n
"
,
libusb_error_name
(
retval
));
libusb_error_name
(
retval
));
libusb_error
=
retval
;
libusb_error
=
retval
;
flasher_error
=
FLASHER_ERR_LIBUSB_FAILURE
;
flasher_error
=
FLASHER_ERR_LIBUSB_FAILURE
;
goto
out
;
goto
out
;
}
}
/* Skip devices that have incorrect vendor and product IDs */
/* Skip devices that have incorrect vendor and product IDs */
if
(
device_descriptor
.
idVendor
!=
vendor_id
||
if
(
device_descriptor
.
idVendor
!=
vendor_id
||
device_descriptor
.
idProduct
!=
product_id
)
{
device_descriptor
.
idProduct
!=
product_id
)
{
continue
;
continue
;
}
}
/* Open each device so that we can read the serial number */
/* Open each device so that we can read the serial number */
retval
=
libusb_open
(
device_list
[
device_index
],
&
handle
);
retval
=
libusb_open
(
device_list
[
device_index
],
&
handle
);
if
(
retval
<
0
)
{
if
(
retval
<
0
)
{
fprintf
(
stderr
,
"Unable to open USB device: %s
\n
"
,
fprintf
(
stderr
,
"Unable to open USB device: %s
\n
"
,
libusb_error_name
(
retval
));
libusb_error_name
(
retval
));
continue
;
continue
;
}
}
/* Read the serial number */
/* Read the serial number */
...
@@ -561,7 +560,7 @@ flasher_find_matching_device(
...
@@ -561,7 +560,7 @@ flasher_find_matching_device(
libusb_close
(
handle
);
libusb_close
(
handle
);
if
(
retval
<
0
)
{
if
(
retval
<
0
)
{
fprintf
(
stderr
,
"Unable to get device serial number: %s
\n
"
,
fprintf
(
stderr
,
"Unable to get device serial number: %s
\n
"
,
libusb_error_name
(
retval
));
libusb_error_name
(
retval
));
continue
;
continue
;
}
}
printf
(
"Found ICDI device with serial: %s
\n
"
,
descriptor_buffer
);
printf
(
"Found ICDI device with serial: %s
\n
"
,
descriptor_buffer
);
...
@@ -597,9 +596,7 @@ out:
...
@@ -597,9 +596,7 @@ out:
}
}
static
static
void
flasher_usage
()
void
flasher_usage
()
{
{
printf
(
"usage: lm4flash [-v] [-s serial] <binary-file>
\n
"
);
printf
(
"usage: lm4flash [-v] [-s serial] <binary-file>
\n
"
);
printf
(
"
\t
-v - Enables verification after write
\n
"
);
printf
(
"
\t
-v - Enables verification after write
\n
"
);
...
@@ -607,13 +604,7 @@ flasher_usage()
...
@@ -607,13 +604,7 @@ flasher_usage()
}
}
static
static
int
flasher_flash
(
const
char
*
serial
,
const
char
*
rom_name
)
int
flasher_flash
(
int
do_verify
,
const
char
*
serial
,
const
char
*
rom_name
)
{
{
libusb_context
*
ctx
=
NULL
;
libusb_context
*
ctx
=
NULL
;
libusb_device
*
device
=
NULL
;
libusb_device
*
device
=
NULL
;
...
@@ -625,40 +616,40 @@ flasher_flash(
...
@@ -625,40 +616,40 @@ flasher_flash(
if
(
retval
!=
0
)
{
if
(
retval
!=
0
)
{
fprintf
(
stderr
,
"Error initializing libusb: %s
\n
"
,
fprintf
(
stderr
,
"Error initializing libusb: %s
\n
"
,
libusb_error_name
(
retval
));
libusb_error_name
(
retval
));
goto
done
;
goto
done
;
}
}
switch
(
flasher_find_matching_device
(
switch
(
flasher_find_matching_device
(
ctx
,
&
device
,
&
retval
,
ICDI_VID
,
ICDI_PID
,
serial
))
{
ctx
,
&
device
,
&
retval
,
ICDI_VID
,
ICDI_PID
,
serial
))
{
case
FLASHER_SUCCESS
:
case
FLASHER_SUCCESS
:
break
;
break
;
case
FLASHER_ERR_LIBUSB_FAILURE
:
case
FLASHER_ERR_LIBUSB_FAILURE
:
fprintf
(
stderr
,
"Error while matching ICDI devices: %s
\n
"
,
fprintf
(
stderr
,
"Error while matching ICDI devices: %s
\n
"
,
libusb_error_name
(
retval
));
libusb_error_name
(
retval
));
goto
done
;
goto
done
;
case
FLASHER_ERR_NO_DEVICES
:
case
FLASHER_ERR_NO_DEVICES
:
fprintf
(
stderr
,
"Unable to find any ICDI devices
\n
"
);
fprintf
(
stderr
,
"Unable to find any ICDI devices
\n
"
);
goto
done
;
goto
done
;
case
FLASHER_ERR_MULTIPLE_DEVICES
:
case
FLASHER_ERR_MULTIPLE_DEVICES
:
if
(
serial
==
NULL
)
if
(
serial
==
NULL
)
fprintf
(
stderr
,
"Found multiple ICDI devices
\n
"
);
fprintf
(
stderr
,
"Found multiple ICDI devices
\n
"
);
else
else
fprintf
(
stderr
,
"Found ICDI serial number collision!
\n
"
);
fprintf
(
stderr
,
"Found ICDI serial number collision!
\n
"
);
goto
done
;
goto
done
;
}
}
retval
=
libusb_open
(
device
,
&
handle
);
retval
=
libusb_open
(
device
,
&
handle
);
if
(
retval
!=
0
)
{
if
(
retval
!=
0
)
{
fprintf
(
stderr
,
"Error opening selected device: %s
\n
"
,
fprintf
(
stderr
,
"Error opening selected device: %s
\n
"
,
libusb_error_name
(
retval
));
libusb_error_name
(
retval
));
goto
done
;
goto
done
;
}
}
retval
=
libusb_claim_interface
(
handle
,
INTERFACE_NR
);
retval
=
libusb_claim_interface
(
handle
,
INTERFACE_NR
);
if
(
retval
!=
0
)
{
if
(
retval
!=
0
)
{
fprintf
(
stderr
,
"Error claiming interface: %s
\n
"
,
fprintf
(
stderr
,
"Error claiming interface: %s
\n
"
,
libusb_error_name
(
retval
));
libusb_error_name
(
retval
));
goto
done
;
goto
done
;
}
}
...
@@ -694,21 +685,23 @@ int main(int argc, char *argv[])
...
@@ -694,21 +685,23 @@ int main(int argc, char *argv[])
while
((
opt
=
getopt
(
argc
,
argv
,
"vs:"
))
!=
-
1
)
{
while
((
opt
=
getopt
(
argc
,
argv
,
"vs:"
))
!=
-
1
)
{
switch
(
opt
)
{
switch
(
opt
)
{
case
'v'
:
case
'v'
:
do_verify
=
1
;
do_verify
=
1
;
break
;
break
;
case
's'
:
case
's'
:
serial
=
optarg
;
serial
=
optarg
;
break
;
break
;
default:
default:
flasher_usage
();
flasher_usage
();
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
}
}
if
(
optind
>=
argc
)
{
if
(
optind
>=
argc
)
{
flasher_usage
();
flasher_usage
();
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
else
}
else
rom_name
=
argv
[
optind
];
rom_name
=
argv
[
optind
];
return
flasher_flash
(
do_verify
,
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