MCCI Trusted Bootloader
Simple trusted bootloader and tools for small embedded systems
mccibootloaderflash_mx25v8035f.c
Go to the documentation of this file.
1/*
2
3Module: mccibootloaderflash_mx25v8035f.c
4
5Function:
6 Bootloader driver for MX25V8035F (and similar) chips.
7
8Copyright and License:
9 This file copyright (C) 2021 by
10
11 MCCI Corporation
12 3520 Krums Corners Road
13 Ithaca, NY 14850
14
15 See accompanying LICENSE file for copyright and license information.
16
17Author:
18 Terry Moore, MCCI Corporation March 2021
19
20*/
21
23
24#include "flash_mx25v8035f.h"
26#include "mcci_bootloader.h"
27#include "mcci_flash_sfdp.h"
28
29/****************************************************************************\
30|
31| Manifest constants & typedefs.
32|
33\****************************************************************************/
34
35
36
37/****************************************************************************\
38|
39| Read-only data.
40|
41\****************************************************************************/
42
43
44
45/****************************************************************************\
46|
47| Variables.
48|
49\****************************************************************************/
50
51/*
52
53Name: McciBootloaderFlash_Mx25v8035f_storageInit()
54
55Function:
56 Initialize the flash chip by sending a reset.
57
58Definition:
59 void McciBootloaderFlash_Mx25v8035f_storageInit(
60 void
61 );
62
63Description:
64 Assuming the SPI bus is up and ready, we send reset enable,
65 followed by reset; then we delay for 100ms.
66
67Returns:
68 No explicit result.
69
70Notes:
71
72
73*/
74
75void
77 void
78 )
79 {
80 static const uint8_t kcResetEn[] = { MX25V8035F_CMD_RSTEN };
81 static const uint8_t kcReset[] = { MX25V8035F_CMD_RST };
82
83 // send the reset enable command.
85 /* RX */ NULL,
86 kcResetEn,
87 sizeof(kcResetEn),
88 /* continue? */ false
89 );
90
91 // send the reset command.
93 /* RX */ NULL,
94 kcReset,
95 sizeof(kcReset),
96 /* continue? */ false
97 );
98
99 // wait for flash to come back.
101
102 // read SFDP: address 3 plus a dummy byte.
103 static const uint8_t kcRdSfdp[5] = { MX25V8035F_CMD_RDSFDP, 0, 0, 0, 0 };
104
105 // read the SFDP
107 /* RX */ NULL,
108 kcRdSfdp,
109 sizeof(kcRdSfdp),
110 /* continue? */ true
111 );
112
113 // get the data
114 struct {
117 } sfdpData;
118
120 /* RX */ (uint8_t *)&sfdpData,
121 /* TX */ NULL,
122 sizeof(sfdpData),
123 /* continue? */ false
124 );
125
127 {
129 }
131 {
133 }
135 {
137 }
138 }
139
140/*
141
142Name: McciBootloaderFlash_Mx25v8035f_storageRead()
143
144Function:
145 Read a buffer from the specified flash byte address
146
147Definition:
148 void McciBootloaderFlash_Mx25v8035f_read(
149 McciBootloaderStorageAddress_t Address,
150 uint8_t *pBuffer,
151 size_t nBuffer
152 );
153
154Description:
155 This function reads a buffer from the specified flash
156 byte offset. There are no alignment constraints.
157
158Returns:
159 No explicit result.
160
161*/
162
163bool
166 uint8_t *pBuffer,
167 size_t nBuffer
168 )
169 {
170 uint8_t cmd[4];
171
172 cmd[0] = MX25V8035F_CMD_READ;
173 cmd[1] = (Address >> 16) & 0xFF;
174 cmd[2] = (Address >> 8) & 0xFF;
175 cmd[3] = Address & 0xFF;
176
178 /* RX */ NULL,
179 /* TX */ cmd,
180 /* size */ sizeof(cmd),
181 /* continue? */ true
182 );
184 pBuffer,
185 NULL,
186 nBuffer,
187 /* continue? */ false
188 );
189
190 return true;
191 }
192
193/**** end of mccibootloaderflash_mx25v8035f.c ****/
#define MX25V8035F_CMD_RDSFDP
#define MX25V8035F_CMD_RSTEN
#define MX25V8035F_CMD_READ
#define MX25V8035F_CMD_RST
@ McciBootloaderError_FlashNotFound
flash didn't reply properly to SFDP
@ McciBootloaderError_FlashNotSupported
flash SFDP contents are prior to JESD216B, or otherwise not suitable.
McciBootloaderPlatform_StorageReadFn_t McciBootloaderFlash_Mx25v8035f_storageRead
void MCCI_BOOTLOADER_NORETURN_PFX McciBootloaderPlatform_fail(McciBootloaderError_t errorCode) MCCI_BOOTLOADER_NORETURN_SFX
static void McciBootloaderPlatform_delayMs(uint32_t ms)
static void McciBootloaderPlatform_spiTransfer(uint8_t *pRx, const uint8_t *pTx, size_t nBytes, bool fContinue)
uint32_t McciBootloaderStorageAddress_t
Abstract type for storage byte addresses.
#define MCCI_FLASH_SFDP_HEADER_SIGNATURE
signature of a SFDP header
static uint32_t McciFlashSfdpHeader_getSignature(const mcci_flash_sfdp_header_t *p)
return the signature value from an SFDP header
static uint8_t McciFlashSfdpHeader_getProtocol(const mcci_flash_sfdp_header_t *p)
return the access protocol value from an SFDP header
#define MCCI_FLASH_SFDP_HEADER_PROPERTY_PROTOCOL_NOR
Legacy NOR, JESD216B, 3-byte SFDP command w/ 8 wait states.
#define MCCI_FLASH_SFDP_HEADER_PROPERTY_VERSION_JES216B
version for JESD216B
static uint16_t McciFlashSfdpHeader_getVersion(const mcci_flash_sfdp_header_t *p)
Get SFDP version compliance claimed by header.
void McciBootloaderFlash_Mx25v8035f_storageInit(void)
the SFDP parameter header