-
Notifications
You must be signed in to change notification settings - Fork 2
/
Flashloader_IMXRT.c
166 lines (151 loc) · 3.86 KB
/
Flashloader_IMXRT.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*************************************************************************
*
* Used with ICCARM and AARM.
*
* (c) Copyright IAR Systems 2017
*
* File name : Flashloader_IMXRT.c
* Description : iMX.RT Series flash loader
*
* History :
* 1. Date : April, 2018
* Author : Alex Yzhov
* Description : Initial revision
*
*
* $Revision: 5068 $
**************************************************************************/
/** include files **/
#include <intrinsics.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "flash_loader.h" // The flash loader framework API declarations.
#include "flash_loader_extra.h"
#include "device.h"
static const device_t *device;
/*************************************************************************
* Function Name: FlashInit
* Parameters: Flash Base Address
*
* Return: 0 - Init Successful
* 1 - Init Fail
* Description: Init flash and build layout.
*
*************************************************************************/
#if USE_ARGC_ARGV
uint32_t FlashInit(void *base_of_flash, uint32_t image_size,
uint32_t link_address, uint32_t flags,
int argc, char const *argv[])
#else
uint32_t FlashInit(void *base_of_flash, uint32_t image_size,
uint32_t link_address, uint32_t flags)
#endif /* USE_ARGC_ARGV */
{
uint32_t result;
/**/
#if defined(MCIMXRT1020)
if( 2 > ((SRC_SBMR1>>1) & 0x7))
#elif defined(CPU_MIMXRT1052)
if( 2 > ((SRC->SBMR1>>8) & 0x7))
#endif
{
#if defined(IMXRT1052_EVK)
device = &QSPIFlash_IS25WP064;
#elif defined(SPHINX_EVK)
device = &QSPIFlash_25Q256JVEQ;
#elif defined(SHAREBOARD)
device = &QSPIFlash_25Q128JVSQ;
#endif
}
else
{
#if defined(IMXRT1052_EVK)
device = &HyperFlash_S26KS512;
#elif defined(SPHINX_EVK)
device = &OctaFlash_MX25UM;
#elif defined(SHAREBOARD)
#warning "ShareBoard do not support HyperFlash!"
#endif
}
/*init*/
#if USE_ARGC_ARGV
result = device->init(base_of_flash, argc,argv);
#else
result = device->init(base_of_flash);
#endif /* USE_ARGC_ARGV */
if(RESULT_ERROR != result)
{
if (FLAG_ERASE_ONLY & flags)
{
if(device->erase_chip)
{
result = device->erase_chip();
}
}
}
return result;
}
/*************************************************************************
* Function Name: FlashWrite
* Parameters: block base address, offet in block, data size, ram buffer
* pointer
* Return: RESULT_OK - Write Successful
* RESULT_ERROR - Write Fail
* Description. Writes data in to NOR
*************************************************************************/
uint32_t FlashWrite(void *block_start,
uint32_t offset_into_block,
uint32_t count,
char const *buffer)
{
return device->write((uint32_t)block_start+offset_into_block, count, buffer);
}
/*************************************************************************
* Function Name: FlashErase
* Parameters: Block Address, Block Size
*
* Return: RESULT_OK - Erase Successful
* RESULT_ERROR - Erase Fail
* Description: Erase block
*************************************************************************/
uint32_t FlashErase(void *block_start,
uint32_t block_size)
{
return device->erase(block_start);
}
OPTIONAL_SIGNOFF
uint32_t FlashSignoff(void)
{
uint32_t result = RESULT_OK;
if(device->signoff)
{
result = device->signoff();
}
return result;
}
#if USE_ARGC_ARGV
const char* FlFindOption(char* option, int with_value, int argc, char const* argv[])
{
int i;
for (i = 0; i < argc; i++)
{
if (strcmp(option, argv[i]) == 0)
{
if (with_value)
{
if (i + 1 < argc)
return argv[i + 1]; // The next argument is the value.
else
return 0; // The option was found but there is no value to return.
}
else
{
return argv[i]; // Return the flag argument itself just to get a non-zero pointer.
}
}
}
return 0;
}
#endif /*USE_ARGC_ARGV*/