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
e3cefda3
Commit
e3cefda3
authored
2 years ago
by
Mattias Barthel
Browse files
Options
Downloads
Patches
Plain Diff
fdtextract: Add option -z to extract embedded image size
parent
0ebaf1e7
Branches
Branches containing commit
No related tags found
1 merge request
!10
fdtextract: Add option -z to extract embedded image size
Pipeline
#59791
passed
2 years ago
Stage: static_code_analysis
Stage: build
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+1
-0
1 addition, 0 deletions
README.md
fdtextract.c
+44
-3
44 additions, 3 deletions
fdtextract.c
with
45 additions
and
3 deletions
README.md
+
1
−
0
View file @
e3cefda3
...
@@ -11,6 +11,7 @@ Options: -[le:o:s:a:hV]
...
@@ -11,6 +11,7 @@ Options: -[le:o:s:a:hV]
-o, --out <arg> Output image name
-o, --out <arg> Output image name
-s, --hash <arg> Hash of image
-s, --hash <arg> Hash of image
-a, --attribute <arg> Get attribute of FIT
-a, --attribute <arg> Get attribute of FIT
-z --size <arg> Size of embedded image in FIT
-h, --help Print this help and exit
-h, --help Print this help and exit
-V, --version Print version and exit
-V, --version Print version and exit
```
```
...
...
This diff is collapsed.
Click to expand it.
fdtextract.c
+
44
−
3
View file @
e3cefda3
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
/* Usage related data. */
/* Usage related data. */
static
const
char
usage_synopsis
[]
=
"fdtextract [options] <file>"
;
static
const
char
usage_synopsis
[]
=
"fdtextract [options] <file>"
;
static
const
char
usage_short_opts
[]
=
"le:o:s:a:i:"
USAGE_COMMON_SHORT_OPTS
;
static
const
char
usage_short_opts
[]
=
"le:o:s:a:i:
z:
"
USAGE_COMMON_SHORT_OPTS
;
static
struct
option
const
usage_long_opts
[]
=
{
static
struct
option
const
usage_long_opts
[]
=
{
{
"list"
,
no_argument
,
NULL
,
'l'
},
{
"list"
,
no_argument
,
NULL
,
'l'
},
{
"extract"
,
a_argument
,
NULL
,
'e'
},
{
"extract"
,
a_argument
,
NULL
,
'e'
},
...
@@ -53,6 +53,7 @@ static struct option const usage_long_opts[] = {
...
@@ -53,6 +53,7 @@ static struct option const usage_long_opts[] = {
{
"hash"
,
a_argument
,
NULL
,
's'
},
{
"hash"
,
a_argument
,
NULL
,
's'
},
{
"attribute"
,
a_argument
,
NULL
,
'a'
},
{
"attribute"
,
a_argument
,
NULL
,
'a'
},
{
"image"
,
a_argument
,
NULL
,
'i'
},
{
"image"
,
a_argument
,
NULL
,
'i'
},
{
"size"
,
a_argument
,
NULL
,
'z'
},
USAGE_COMMON_LONG_OPTS
USAGE_COMMON_LONG_OPTS
};
};
static
const
char
*
const
usage_opts_help
[]
=
{
static
const
char
*
const
usage_opts_help
[]
=
{
...
@@ -62,6 +63,7 @@ static const char * const usage_opts_help[] = {
...
@@ -62,6 +63,7 @@ static const char * const usage_opts_help[] = {
"SHA256 hash of image"
,
"SHA256 hash of image"
,
"Get attribute of FIT"
,
"Get attribute of FIT"
,
"Use image in FIT to get attribute"
,
"Use image in FIT to get attribute"
,
"Size of embedded image in FIT"
,
USAGE_COMMON_OPTS_HELP
USAGE_COMMON_OPTS_HELP
};
};
...
@@ -91,6 +93,38 @@ static int list_images(char *buf)
...
@@ -91,6 +93,38 @@ static int list_images(char *buf)
return
0
;
return
0
;
}
}
/* Print the size of an image embedded in the FIT. */
static
int
get_size
(
char
*
buf
,
char
*
name
)
{
char
path
[
MAX_PATH_LEN
]
=
{
0
};
int
noffset
,
data_size
;
const
fdt32_t
*
val
;
snprintf
(
path
,
MAX_PATH_LEN
,
"/images/%s"
,
name
);
noffset
=
fdt_path_offset
(
buf
,
path
);
if
(
noffset
<
0
)
{
fprintf
(
stderr
,
"Error: could not find image: %s.
\n
"
,
name
);
return
-
1
;
}
val
=
fdt_getprop
(
buf
,
noffset
,
"data-size"
,
NULL
);
if
(
val
)
{
data_size
=
fdt32_to_cpu
(
*
val
);
}
else
{
fdt_getprop
(
buf
,
noffset
,
"data"
,
&
data_size
);
}
if
(
data_size
<
0
)
{
fprintf
(
stderr
,
"Error: Could not get image data size: %s.
\n
"
,
name
);
return
-
1
;
}
printf
(
"%d
\n
"
,
data_size
);
return
0
;
}
static
ssize_t
copy_data
(
int
out_fd
,
int
in_fd
,
ssize_t
size
)
static
ssize_t
copy_data
(
int
out_fd
,
int
in_fd
,
ssize_t
size
)
{
{
ssize_t
left
=
size
;
ssize_t
left
=
size
;
...
@@ -311,7 +345,7 @@ int main(int argc, char *argv[])
...
@@ -311,7 +345,7 @@ int main(int argc, char *argv[])
int
opt
,
ret
=
0
;
int
opt
,
ret
=
0
;
char
*
buf
,
*
name
=
NULL
,
*
out
=
NULL
,
*
imagename
=
NULL
;
char
*
buf
,
*
name
=
NULL
,
*
out
=
NULL
,
*
imagename
=
NULL
;
bool
list
=
false
,
extract
=
false
,
bool
list
=
false
,
extract
=
false
,
hash
=
false
,
attribute
=
false
;
hash
=
false
,
attribute
=
false
,
size
=
false
;
int
in_fd
,
out_fd
=
STDOUT_FILENO
;
int
in_fd
,
out_fd
=
STDOUT_FILENO
;
while
((
opt
=
util_getopt_long
())
!=
EOF
)
{
while
((
opt
=
util_getopt_long
())
!=
EOF
)
{
...
@@ -325,6 +359,10 @@ int main(int argc, char *argv[])
...
@@ -325,6 +359,10 @@ int main(int argc, char *argv[])
case
'l'
:
case
'l'
:
list
=
true
;
list
=
true
;
break
;
break
;
case
'z'
:
size
=
true
;
name
=
optarg
;
break
;
case
'e'
:
case
'e'
:
extract
=
true
;
extract
=
true
;
name
=
optarg
;
name
=
optarg
;
...
@@ -379,6 +417,9 @@ int main(int argc, char *argv[])
...
@@ -379,6 +417,9 @@ int main(int argc, char *argv[])
if
(
list
)
if
(
list
)
ret
=
list_images
(
buf
);
ret
=
list_images
(
buf
);
if
(
size
)
ret
=
get_size
(
buf
,
name
);
if
(
hash
)
if
(
hash
)
ret
=
get_hash
(
buf
,
name
);
ret
=
get_hash
(
buf
,
name
);
...
@@ -395,5 +436,5 @@ int main(int argc, char *argv[])
...
@@ -395,5 +436,5 @@ int main(int argc, char *argv[])
free
(
buf
);
free
(
buf
);
close
(
in_fd
);
close
(
in_fd
);
return
ret
;
return
ret
?
1
:
0
;
}
}
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