Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
8b976a25
Commit
8b976a25
authored
Apr 24, 2020
by
Grzegorz Daniluk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools/gensdbfs: generate sdbfs image as C header
parent
73499adc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
2 deletions
+45
-2
gensdbfs.c
tools/gensdbfs.c
+45
-2
No files found.
tools/gensdbfs.c
View file @
8b976a25
...
...
@@ -503,13 +503,46 @@ static struct sdbf *prepare_dir(char *name, struct sdbf *parent)
return
tree
;
}
/*
* Generate C header file from sdbfs binary
*/
static
int
gen_header
(
char
*
bin_name
,
char
*
h_name
)
{
FILE
*
b_file
,
*
h_file
;
unsigned
int
buf
;
int
bytes
;
b_file
=
fopen
(
bin_name
,
"r"
);
h_file
=
fopen
(
h_name
,
"w"
);
if
(
!
b_file
||
!
h_file
)
{
fprintf
(
stderr
,
"Could not open binary file or create header file
\n
"
);
return
-
1
;
}
fprintf
(
h_file
,
"// generated by tools/gensdbfs. Don't hand-edit unless you know what you're doing...
\n
"
);
while
(
!
feof
(
b_file
))
{
buf
=
0
;
bytes
=
fread
(
&
buf
,
1
,
4
,
b_file
);
if
(
bytes
>
0
)
fprintf
(
h_file
,
"0x%08X,
\n
"
,
htonl
(
buf
));
}
/* remove last "," */
fseek
(
h_file
,
-
2
,
SEEK_END
);
fprintf
(
h_file
,
"
\n
"
);
fclose
(
b_file
);
fclose
(
h_file
);
return
1
;
}
/* From now on, it's trivial main program management */
static
int
usage
(
char
*
prgname
)
{
fprintf
(
stderr
,
"%s: Use
\"
%s [<options>] <inputdir> <output>
\"\n
"
,
fprintf
(
stderr
,
"%s: Use
\"
%s [<options>] <inputdir> <output
binary
>
\"\n
"
,
prgname
,
prgname
);
fprintf
(
stderr
,
" -b <number> : block size (default 64)
\n
"
);
fprintf
(
stderr
,
" -s <number> : device size (default: as needed)
\n
"
);
fprintf
(
stderr
,
" -c <output header> : create C header file with the binary
\n
"
);
fprintf
(
stderr
,
" a file called
\"
"
CFG_NAME
"
\"
, in each "
"subdir is used as configuration file
\n
"
);
exit
(
1
);
...
...
@@ -522,9 +555,11 @@ int main(int argc, char **argv)
FILE
*
fout
;
char
*
rest
;
struct
sdbf
*
tree
;
int
gen_c
=
0
;
char
*
h_filename
;
prgname
=
argv
[
0
];
while
(
(
c
=
getopt
(
argc
,
argv
,
"b:s:"
))
!=
-
1
)
{
while
(
(
c
=
getopt
(
argc
,
argv
,
"b:s:
c:
"
))
!=
-
1
)
{
switch
(
c
)
{
case
'b'
:
blocksize
=
strtol
(
optarg
,
&
rest
,
0
);
...
...
@@ -542,6 +577,10 @@ int main(int argc, char **argv)
exit
(
1
);
}
break
;
case
'c'
:
h_filename
=
optarg
;
gen_c
=
1
;
break
;
}
}
if
(
optind
!=
argc
-
2
)
...
...
@@ -589,5 +628,9 @@ int main(int argc, char **argv)
" (0x%lx)
\n
"
,
prgname
,
lastwritten
,
devsize
);
exit
(
1
);
}
if
(
gen_c
)
gen_header
(
argv
[
optind
+
1
],
h_filename
);
exit
(
0
);
}
Write
Preview
Markdown
is supported
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