1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xstatus.h"
#include "ff.h"
u32 FlashReadBaseAddress;
static FIL fil; /* File object */
static FATFS fatfs;
static char buffer[32];
static char *boot_file = buffer;
char *strcpy_rom(char *Dest, const char *Src)
{
unsigned i;
for (i=0; Src[i] != '\0'; ++i)
Dest[i] = Src[i];
Dest[i] = '\0';
return Dest;
}
u32 InitSD(const char *filename)
{
FRESULT rc;
/* Register volume work area, initialize device */
rc = f_mount(&fatfs,2,1);
//fsbl_printf(DEBUG_INFO,"SD: rc= %.8x\n\r", rc);
if (rc != FR_OK) {
return XST_FAILURE;
}
strcpy_rom(buffer, filename);
boot_file = (char *)filename;
FlashReadBaseAddress = XPAR_PS7_SD_0_BASEADDR;
rc = f_open(&fil, boot_file, FA_READ);
if (rc) {
xil_printf("SD: Unable to open file %s: %d\n", boot_file, rc);
//fsbl_printf(DEBUG_GENERAL,"SD: Unable to open file %s: %d\n", boot_file, rc);
return XST_FAILURE;
}
return XST_SUCCESS;
}
u32 SDAccess( u32 SourceAddress, u32 DestinationAddress, u32 LengthBytes)
{
FRESULT rc; /* Result code */
UINT br;
rc = f_lseek(&fil, SourceAddress);
if (rc) {
xil_printf("SD: Unable to seek to %x\n", SourceAddress);
//fsbl_printf(DEBUG_INFO,"SD: Unable to seek to %x\n", SourceAddress);
return XST_FAILURE;
}
rc = f_read(&fil, (void*)DestinationAddress, LengthBytes, &br);
if (rc) {
//fsbl_printf(DEBUG_GENERAL,"*** ERROR: f_read returned %d\r\n", rc);
xil_printf("*** ERROR: f_read returned %d\r\n", rc);
}
return XST_SUCCESS;
} /* End of SDAccess */
void ReleaseSD(void) {
f_close(&fil);
return;
}
int main()
{
char imageval[128];
disable_caches();
InitSD("image.txt");
SDAccess(0,(u32)imageval,32);
xil_printf("%s\n\r",imageval);
enable_caches();
init_platform();
print("Hello World\n\r");
cleanup_platform();
return 0;
}
|