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
a4c82fb6
Commit
a4c82fb6
authored
Feb 01, 2017
by
Alessandro Rubini
Committed by
Grzegorz Daniluk
Feb 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: added mapper
Signed-off-by:
Alessandro Rubini
<
rubini@gnudd.com
>
parent
4498a41f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
1 deletion
+69
-1
Makefile
tools/Makefile
+1
-1
mapper.c
tools/mapper.c
+68
-0
No files found.
tools/Makefile
View file @
a4c82fb6
...
...
@@ -6,7 +6,7 @@ LDFLAGS = -lutil
ALL
=
genraminit genramvhd genrammif wrpc-uart-sw
ALL
+=
wrpc-w1-read wrpc-w1-write
ALL
+=
pfilter-builder
ALL
+=
wrpc-dump
ALL
+=
wrpc-dump
mapper
ifneq
($(EB),no)
ALL
+=
eb-w1-write
...
...
tools/mapper.c
0 → 100644
View file @
a4c82fb6
/*
* mapper.c -- simple file that mmap()s a file region and prints it
* Alessandro Rubini 1997-2008
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
int
main
(
int
argc
,
char
**
argv
)
{
char
*
fname
;
FILE
*
f
;
int
pagesize
=
getpagesize
();
unsigned
int
pos
,
pos_pg
,
pos_off
;
unsigned
int
len
,
len_pg
,
len_off
;
void
*
address
;
char
*
rest
;
if
(
argc
!=
4
||
sscanf
(
argv
[
2
],
"%i"
,
&
pos
)
!=
1
||
sscanf
(
argv
[
3
],
"%i"
,
&
len
)
!=
1
)
{
fprintf
(
stderr
,
"%s: Usage
\"
%s <file> <offset> <len>
\"\n
"
,
argv
[
0
],
argv
[
0
]);
exit
(
1
);
}
/* note: pos may be more than 2G, so use strtoul */
pos
=
strtoul
(
argv
[
2
],
&
rest
,
0
);
if
(
rest
&&
*
rest
)
{
fprintf
(
stderr
,
"%s: Usage
\"
%s <file> <offset> <len>
\"\n
"
,
argv
[
0
],
argv
[
0
]);
exit
(
1
);
}
fname
=
argv
[
1
];
if
(
!
(
f
=
fopen
(
fname
,
"r"
)))
{
fprintf
(
stderr
,
"%s: %s: %s
\n
"
,
argv
[
0
],
fname
,
strerror
(
errno
));
exit
(
1
);
}
/* page-align our numbers, as we depend on the MMU */
pos_pg
=
pos
&
~
(
pagesize
-
1
);
pos_off
=
pos
&
(
pagesize
-
1
);
len_pg
=
(
len
+
pos_off
+
pagesize
-
1
)
&
~
(
pagesize
-
1
);
len_off
=
(
len
+
pos_off
)
&
(
pagesize
-
1
);
(
void
)
len_off
;
/* no, I don't use it. Prevent a warning */
address
=
mmap
(
0
,
len_pg
,
PROT_READ
,
MAP_FILE
|
MAP_PRIVATE
,
fileno
(
f
),
pos_pg
);
if
(
address
==
(
void
*
)
-
1
)
{
fprintf
(
stderr
,
"%s: mmap(): %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
exit
(
1
);
}
fclose
(
f
);
fprintf
(
stderr
,
"mapped
\"
%s
\"
from %i to %i (0x%x to 0x%x)
\n
"
,
fname
,
pos
,
pos
+
len
,
pos_pg
,
pos_pg
+
len_pg
);
if
(
fwrite
(
address
+
pos_off
,
1
,
len
,
stdout
)
!=
len
)
{
fprintf
(
stderr
,
"%s: write(): %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
exit
(
1
);
}
return
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