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
30d1aedc
Commit
30d1aedc
authored
4 years ago
by
Jonas Höglund
Browse files
Options
Downloads
Patches
Plain Diff
Get hash of image.
parent
b5bb0eb2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fdtextract.c
+31
-3
31 additions, 3 deletions
fdtextract.c
with
31 additions
and
3 deletions
fdtextract.c
+
31
−
3
View file @
30d1aedc
...
...
@@ -40,20 +40,23 @@
#define FDT_MAGIC_SIZE 4
#define MAX_VERSION 17
#define MAX_PATH_LEN 100
#define SHA_256_LEN 32
/* Usage related data. */
static
const
char
usage_synopsis
[]
=
"fdtextract [options] <file>"
;
static
const
char
usage_short_opts
[]
=
"le:o:"
USAGE_COMMON_SHORT_OPTS
;
static
const
char
usage_short_opts
[]
=
"le:o:
s:
"
USAGE_COMMON_SHORT_OPTS
;
static
struct
option
const
usage_long_opts
[]
=
{
{
"list"
,
no_argument
,
NULL
,
'l'
},
{
"extract"
,
a_argument
,
NULL
,
'e'
},
{
"out"
,
a_argument
,
NULL
,
'o'
},
{
"hash"
,
a_argument
,
NULL
,
's'
},
USAGE_COMMON_LONG_OPTS
};
static
const
char
*
const
usage_opts_help
[]
=
{
"List images embedded in FIT"
,
"Extract image from FIT"
,
"Output image name"
,
"Hash of image"
,
USAGE_COMMON_OPTS_HELP
};
...
...
@@ -142,13 +145,31 @@ static int extract_image(char *buf, char *name, char *out)
return
0
;
}
static
int
get_hash
(
char
*
buf
,
char
*
name
)
{
char
path
[
MAX_PATH_LEN
];
int
noffset
,
i
;
uint8_t
*
val
;
snprintf
(
path
,
MAX_PATH_LEN
,
"/images/%s/hash-1"
,
name
);
noffset
=
fdt_path_offset
(
buf
,
path
);
if
(
noffset
<
0
)
{
printf
(
"Error: could not find image hash: %s.
\n
"
,
name
);
return
-
1
;
}
val
=
(
uint8_t
*
)
fdt_getprop
(
buf
,
noffset
,
"value"
,
NULL
);
for
(
i
=
0
;
i
<
SHA_256_LEN
;
i
++
)
printf
(
"%x"
,
val
[
i
]);
printf
(
"
\n
"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
file
;
int
opt
;
char
*
buf
,
*
name
=
NULL
,
*
out
=
NULL
;
bool
list
=
false
;
bool
extract
=
false
;
bool
list
=
false
,
extract
=
false
,
hash
=
false
;
size_t
len
;
while
((
opt
=
util_getopt_long
())
!=
EOF
)
{
...
...
@@ -165,6 +186,10 @@ int main(int argc, char *argv[])
case
'o'
:
out
=
optarg
;
break
;
case
's'
:
hash
=
true
;
name
=
optarg
;
break
;
}
}
if
(
optind
!=
argc
-
1
)
...
...
@@ -186,5 +211,8 @@ int main(int argc, char *argv[])
if
(
extract
)
extract_image
(
buf
,
name
,
out
);
if
(
hash
)
get_hash
(
buf
,
name
);
return
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