Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
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
White Rabbit Switch - Software
Commits
a8379d91
Commit
a8379d91
authored
Jan 19, 2012
by
Alessandro Rubini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: added lm32-loader
parent
0605e5d2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
140 additions
and
0 deletions
+140
-0
lm32-loader.c
tools/lm32-loader.c
+140
-0
No files found.
tools/lm32-loader.c
0 → 100644
View file @
a8379d91
/*
* Copyright (c) 2011 Grzegorz Daniluk <g.daniluk@elproma.com.pl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/stat.h>
#define BASE_FPGA 0x10000000
#define SIZE_FPGA 0x20000
#define LM32_RAM_BASE 0x0
#define GPIO_BASE 0x10300
#define GPIO_COR 0x0
#define GPIO_SOR 0x4
#define LM32_RESET_PIN 2
static
void
*
base_fpga
;
static
void
fpga_writel
(
uint32_t
data
,
uint32_t
addr
)
{
*
(
volatile
uint32_t
*
)(
base_fpga
+
addr
)
=
data
;
}
static
uint32_t
fpga_readl
(
uint32_t
addr
)
{
return
*
(
volatile
uint32_t
*
)(
base_fpga
+
addr
);
}
int
conv_endian
(
int
x
)
{
return
((
x
&
0xff000000
)
>>
24
)
+
((
x
&
0x00ff0000
)
>>
8
)
+
((
x
&
0x0000ff00
)
<<
8
)
+
((
x
&
0x000000ff
)
<<
24
);
}
void
rst_lm32
(
int
rst
)
{
fpga_writel
(
1
<<
LM32_RESET_PIN
,
GPIO_BASE
+
(
rst
?
GPIO_SOR
:
GPIO_COR
));
}
void
copy_lm32
(
uint32_t
*
buf
,
int
buf_nwords
,
uint32_t
base_addr
)
{
int
i
;
printf
(
"Writing memory: "
);
for
(
i
=
0
;
i
<
buf_nwords
;
i
++
)
{
fpga_writel
(
conv_endian
(
buf
[
i
]),
base_addr
+
i
*
4
);
if
(
!
(
i
&
0xfff
))
{
printf
(
"."
);
fflush
(
stdout
);
}
}
printf
(
"
\n
Verifing memory: "
);
for
(
i
=
0
;
i
<
buf_nwords
;
i
++
)
{
uint32_t
x
=
fpga_readl
(
base_addr
+
i
*
4
);
if
(
conv_endian
(
buf
[
i
])
!=
x
)
{
printf
(
"Verify failed (%x vs %x)
\n
"
,
conv_endian
(
buf
[
i
]),
x
);
return
;
}
if
(
!
(
i
&
0xfff
))
{
printf
(
"."
);
fflush
(
stdout
);
}
}
printf
(
"OK.
\n
"
);
}
int
main
(
int
argc
,
char
**
argv
)
{
uint32_t
*
buf
;
FILE
*
f
;
int
fdmem
;
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"No parameters specified !
\n
"
);
fprintf
(
stderr
,
"Usage:
\n\t
%s <binary file>
\n
"
,
argv
[
0
]);
return
0
;
}
/* /dev/mem for mmap of both gpio and spi1 */
if
((
fdmem
=
open
(
"/dev/mem"
,
O_RDWR
|
O_SYNC
))
<
0
)
{
fprintf
(
stderr
,
"%s: /dev/mem: %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
exit
(
1
);
}
/* map a whole page (4kB, but we called getpagesize to know it) */
base_fpga
=
mmap
(
0
,
SIZE_FPGA
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
fdmem
,
BASE_FPGA
);
if
(
base_fpga
==
MAP_FAILED
)
{
fprintf
(
stderr
,
"%s: mmap(/dev/mem): %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
exit
(
1
);
}
f
=
fopen
(
argv
[
1
],
"rb"
);
if
(
!
f
)
{
fprintf
(
stderr
,
"Input file not found.
\n
"
);
return
-
1
;
}
fseek
(
f
,
0
,
SEEK_END
);
int
size
=
ftell
(
f
);
rewind
(
f
);
buf
=
malloc
(
size
+
4
);
fread
(
buf
,
1
,
size
,
f
);
fclose
(
f
);
rst_lm32
(
1
);
copy_lm32
(
buf
,
(
size
+
3
)
/
4
,
0
);
rst_lm32
(
0
);
// mbn_stats(mb_handle);
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