Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fdtextract
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue 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
system
fdtextract
Commits
573bf954
Commit
573bf954
authored
4 years ago
by
Jonas Höglund
Browse files
Options
Downloads
Patches
Plain Diff
Only read the FIT header when possible to speed up reading attributes.
parent
485a38bc
No related branches found
No related tags found
1 merge request
!2
Only read the FIT header when possible to speed up reading attributes.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fdtextract.c
+48
-8
48 additions, 8 deletions
fdtextract.c
with
48 additions
and
8 deletions
fdtextract.c
+
48
−
8
View file @
573bf954
/*
/*
*
dumpimage
-- Tool to extract sub images from FIT image.
*
fdtextract
-- Tool to extract sub images from FIT image.
*
*
* Copyright (C) 2021 IOPSYS Software Solutions AB. All rights reserved.
* Copyright (C) 2021 IOPSYS Software Solutions AB. All rights reserved.
*
*
...
@@ -89,12 +89,19 @@ static int list_images(char *buf)
...
@@ -89,12 +89,19 @@ static int list_images(char *buf)
}
}
/* Extract an image embedded in the FIT. */
/* Extract an image embedded in the FIT. */
static
int
extract_image
(
char
*
buf
,
char
*
name
,
char
*
out
)
static
int
extract_image
(
const
char
*
file
,
char
*
name
,
char
*
out
)
{
{
char
path
[
MAX_PATH_LEN
];
char
path
[
MAX_PATH_LEN
];
int
noffset
,
fd
,
count
;
int
noffset
,
fd
,
count
;
unsigned
int
data_size
,
data_offset
;
unsigned
int
data_size
,
data_offset
;
const
fdt32_t
*
val
;
const
fdt32_t
*
val
;
char
*
buf
;
size_t
len
;
buf
=
utilfdt_read
(
file
,
&
len
);
if
(
!
buf
)
{
die
(
"could not read: %s
\n
"
,
file
);
}
snprintf
(
path
,
MAX_PATH_LEN
,
"/images/%s"
,
name
);
snprintf
(
path
,
MAX_PATH_LEN
,
"/images/%s"
,
name
);
noffset
=
fdt_path_offset
(
buf
,
path
);
noffset
=
fdt_path_offset
(
buf
,
path
);
...
@@ -205,6 +212,38 @@ static int get_attribute(char *buf, char *name)
...
@@ -205,6 +212,38 @@ static int get_attribute(char *buf, char *name)
return
0
;
return
0
;
}
}
char
*
read_header
(
const
char
*
file
)
{
char
*
buf
;
int
fd
,
total_size
;
size_t
len
;
fd
=
open
(
file
,
O_RDONLY
);
if
(
fd
<
0
)
return
NULL
;
/* Read minimal static struct */
buf
=
malloc
(
FDT_V1_SIZE
);
if
(
!
buf
)
return
NULL
;
len
=
read
(
fd
,
buf
,
FDT_V1_SIZE
);
if
(
len
<
FDT_V1_SIZE
)
return
NULL
;
/* Read rest of header */
total_size
=
fdt_totalsize
(
buf
);
buf
=
realloc
(
buf
,
total_size
);
if
(
!
buf
)
return
NULL
;
len
=
read
(
fd
,
buf
+
FDT_V1_SIZE
,
total_size
-
FDT_V1_SIZE
);
if
(
len
<
total_size
-
FDT_V1_SIZE
)
return
NULL
;
return
buf
;
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
const
char
*
file
;
const
char
*
file
;
...
@@ -212,7 +251,6 @@ int main(int argc, char *argv[])
...
@@ -212,7 +251,6 @@ int main(int argc, char *argv[])
char
*
buf
,
*
name
=
NULL
,
*
out
=
NULL
;
char
*
buf
,
*
name
=
NULL
,
*
out
=
NULL
;
bool
list
=
false
,
extract
=
false
,
bool
list
=
false
,
extract
=
false
,
hash
=
false
,
attribute
=
false
;
hash
=
false
,
attribute
=
false
;
size_t
len
;
while
((
opt
=
util_getopt_long
())
!=
EOF
)
{
while
((
opt
=
util_getopt_long
())
!=
EOF
)
{
switch
(
opt
)
{
switch
(
opt
)
{
...
@@ -242,26 +280,28 @@ int main(int argc, char *argv[])
...
@@ -242,26 +280,28 @@ int main(int argc, char *argv[])
usage
(
"missing input filename"
);
usage
(
"missing input filename"
);
file
=
argv
[
optind
];
file
=
argv
[
optind
];
buf
=
utilfdt_r
ead
(
file
,
&
len
);
buf
=
read_h
ead
er
(
file
);
if
(
!
buf
)
{
if
(
!
buf
)
{
die
(
"could not read: %s
\n
"
,
file
);
die
(
"could not read
header from
: %s
\n
"
,
file
);
}
}
if
(
fdt_check_header
(
buf
))
{
if
(
fdt_check_header
(
buf
))
{
die
(
"Bad header in %s
\n
"
,
file
);
die
(
"Bad header in %s
\n
"
,
file
);
}
}
/* Pass the pointer to the header to read attributes. */
if
(
list
)
if
(
list
)
ret
=
list_images
(
buf
);
ret
=
list_images
(
buf
);
if
(
extract
)
ret
=
extract_image
(
buf
,
name
,
out
);
if
(
hash
)
if
(
hash
)
ret
=
get_hash
(
buf
,
name
);
ret
=
get_hash
(
buf
,
name
);
if
(
attribute
)
if
(
attribute
)
ret
=
get_attribute
(
buf
,
name
);
ret
=
get_attribute
(
buf
,
name
);
/* Let extract image read the entire file. */
if
(
extract
)
ret
=
extract_image
(
file
,
name
,
out
);
return
ret
;
return
ret
;
}
}
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