-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
110 lines (89 loc) · 2.38 KB
/
main.c
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
103
104
105
106
107
108
109
110
#include <stdio.h>
#include "config.h"
#include "samba.h"
#include "show.h"
#include "utils.h"
#include "inout.h"
#include "loader.h"
#include "firmware.h"
#define VALIDATE(expr) \
do \
{ \
res = (expr); \
if(res) \
goto error; \
}while(0)
#define UNUSED __attribute__((unused))
CHAR g_Buf[CFG_DATA_BUF_SIZE];
int main(int argc UNUSED, char *argv[] UNUSED)
{
UINT32 d_word;
IO_RES res;
CHIP_MEM_SIZES mem_sizes;
printf("\r\n");
printf(" ATMEL AT91SAM processors flash memory programming utility v.%s\r\n", CFG_SW_VERSION);
printf(" (c) PROTTOSS Electronic Laboratory 2010\r\n\r\n");
#if 1
printf("- Searching device...");
VALIDATE(OpenDevice());
printf("Found!\r\n");
printf("- Init SAM Boot Assistant...");
#if 1
res = cmdInit();
ShowResult(res);
#else
printf("OK!\r\n");
#endif
#if 1
printf("- CPU boot version: ");
VALIDATE(cmdVersion(g_Buf, CFG_DATA_BUF_SIZE));
printf("%s\r\n", g_Buf);
#endif
printf("- Get CPU ID-register at 0xFFFF:F240h... ");
VALIDATE(cmdReadWord(0xfffff240, &d_word));
printf("OK:\r\n\r\n");
ShowChipID(d_word, &mem_sizes);
printf("\r\n");
printf("- Check valid CPU... ");
VALIDATE(CheckCPU(d_word, &mem_sizes));
printf("OK\r\n");
if(d_word & 0x80000000)
{
printf("- Chip ID extended register value: ");
VALIDATE(cmdReadWord(0xfffff244, &d_word));
printf("0x%X\r\n", d_word);
}
printf("- Get CPU Master clock register at 0xFFFF:FC30h... ");
VALIDATE(cmdReadWord(0xfffffc30, &d_word));
printf("OK\r\n");
ShowMasterClock(d_word);
if(FALSE == SelectFirmware())
{
printf("Not selected item. Program exit...\r\n\r\n");
goto exit;
}
printf("- Proceed to download firmware? [y/n] ");
if(FALSE == UserWait())
{
printf("- Cancel operation\r\n");
printf("- Please replug board for trying programm the next time.\r\n");
printf("- Program exit...\r\n\r\n");
goto exit;
}
printf("\r\nSend loader at 0x%08X... ", CFG_LOADER_START);
VALIDATE(WriteMemBlock(CFG_LOADER_START, LDR_GetPtr(), LDR_GetSize(), TRUE));
printf(" OK\r\n");
#if 1
VALIDATE(WriteFirmware(g_Firmware, FW_GetSize(), mem_sizes.flash_page_size));
printf("\r\n");
printf("- Firmware complete! Please, replug board for start firmware.\r\n");
goto exit;
#endif
#endif
error:
ShowResult(res);
exit:
CloseDevice();
printf("\r\n");
return 0;
}