forked from polarfire-soc/hart-software-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hss_boot_init.c
636 lines (515 loc) · 18.1 KB
/
hss_boot_init.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
/*******************************************************************************
* Copyright 2019-2022 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
* MPFS HSS Embedded Software
*
*/
/**
* \file HSS Boot Initalization
* \brief Boot Initialization
*/
#include "config.h"
#include "hss_types.h"
#include "hss_init.h"
#include "hss_boot_service.h"
#include "hss_boot_init.h"
#include "hss_sys_setup.h"
#include "hss_progress.h"
#if IS_ENABLED(CONFIG_SERVICE_SPI)
# include <mss_sys_services.h>
# define SPI_FLASH_BOOT_ENABLED (CONFIG_SERVICE_BOOT_SPI_FLASH_OFFSET != 0xFFFFFFFF)
#else
# define SPI_FLASH_BOOT_ENABLED 0
#endif
#if IS_ENABLED(CONFIG_SERVICE_OPENSBI)
# include "opensbi_service.h"
#endif
#if IS_ENABLED(CONFIG_SERVICE_QSPI)
# include "qspi_service.h"
#endif
#if IS_ENABLED(CONFIG_SERVICE_MMC)
# include "mmc_service.h"
# include "gpt.h"
#endif
#if (SPI_FLASH_BOOT_ENABLED)
# include "mss_sys_services.h"
#endif
#include "hss_state_machine.h"
#include "hss_debug.h"
#include "hss_perfctr.h"
#include <string.h>
#include <assert.h>
#if IS_ENABLED(CONFIG_COMPRESSION)
# include "hss_decompress.h"
#endif
#if IS_ENABLED(CONFIG_CRYPTO_SIGNING)
# include "hss_boot_secure.h"
#endif
#include "hss_boot_pmp.h"
#include "hss_atomic.h"
//
// local module functions
#if IS_ENABLED(CONFIG_SERVICE_BOOT)
# if !IS_ENABLED(CONFIG_SERVICE_BOOT_USE_PAYLOAD)
typedef bool (*HSS_BootImageCopyFnPtr_t)(void *pDest, size_t srcOffset, size_t byteCount);
static bool copyBootImageToDDR_(struct HSS_BootImage *pBootImage, char *pDest,
size_t srcOffset, HSS_BootImageCopyFnPtr_t pCopyFunction);
# endif
static void printBootImageDetails_(struct HSS_BootImage const * const pBootImage);
static bool tryBootFunction_(struct HSS_Storage *pStorage, HSS_GetBootImageFnPtr_t getBootImageFunction);
#endif
static bool getBootImageFromQSPI_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage);
static bool getBootImageFromMMC_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage);
static bool getBootImageFromSpiFlash_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage);
static bool getBootImageFromPayload_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage);
//
//
#if IS_ENABLED(CONFIG_SERVICE_QSPI)
static struct HSS_Storage qspiStorage_ = {
.name = "QSPI",
.getBootImage = getBootImageFromQSPI_,
.init = HSS_CachedQSPIInit,
.readBlock = HSS_CachedQSPI_ReadBlock,
.writeBlock = HSS_CachedQSPI_WriteBlock,
.getInfo = HSS_CachedQSPI_GetInfo,
.flushWriteBuffer = HSS_CachedQSPI_FlushWriteBuffer
};
#endif
#if IS_ENABLED(CONFIG_SERVICE_MMC)
static struct HSS_Storage mmcStorage_ = {
.name = "MMC",
.getBootImage = getBootImageFromMMC_,
.init = HSS_MMCInit,
.readBlock = HSS_MMC_ReadBlock,
.writeBlock = HSS_MMC_WriteBlockSDMA,
.getInfo = HSS_MMC_GetInfo,
.flushWriteBuffer = NULL
};
#endif
#if IS_ENABLED(CONFIG_SERVICE_SPI)
static struct HSS_Storage spiStorage_ = {
.name = "SPI",
.getBootImage = getBootImageFromSpiFlash_,
.init = NULL,
.readBlock = NULL,
.writeBlock = NULL,
.getInfo = NULL,
.flushWriteBuffer = NULL
};
#endif
#if IS_ENABLED(CONFIG_SERVICE_BOOT_USE_PAYLOAD)
static struct HSS_Storage payloadStorage_ = {
.name = "Payload",
.getBootImage = getBootImageFromPayload_,
.init = NULL,
.readBlock = NULL,
.writeBlock = NULL,
.getInfo = NULL,
.flushWriteBuffer = NULL
};
#endif
static struct HSS_Storage *pStorages[] =
{
#if IS_ENABLED(CONFIG_SERVICE_QSPI)
&qspiStorage_,
#endif
#if IS_ENABLED(CONFIG_SERVICE_SPI)
&spiStorage_,
#endif
#if IS_ENABLED(CONFIG_SERVICE_MMC)
&mmcStorage_,
#endif
#if IS_ENABLED(CONFIG_SERVICE_BOOT_USE_PAYLOAD)
&payloadStorage_,
#endif
};
static struct HSS_Storage *pDefaultStorage = NULL;
#if IS_ENABLED(CONFIG_SERVICE_MMC) || IS_ENABLED(CONFIG_SERVICE_QSPI) || (IS_ENABLED(CONFIG_SERVICE_SPI) && (SPI_FLASH_BOOT_ENABLED))
struct HSS_BootImage bootImage __attribute__((aligned(8)));
#elif IS_ENABLED(CONFIG_SERVICE_BOOT_USE_PAYLOAD)
//
#else
# error Unable to determine boot mechanism
#endif
struct HSS_Storage *HSS_BootGetActiveStorage(void);
struct HSS_Storage *HSS_BootGetActiveStorage(void)
{
struct HSS_Storage *pResult = pDefaultStorage;
if (!pResult) {
pResult = pStorages[0];
}
return pResult;
}
void HSS_BootListStorageProviders(void)
{
for (uint32_t i = 0; i < ARRAY_SIZE(pStorages); i++) {
mHSS_DEBUG_PRINTF_EX(" - %s\n", pStorages[i]->name);
}
}
bool HSS_BootInit(void)
{
bool result = true;
#if IS_ENABLED(CONFIG_SERVICE_BOOT)
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Initializing Boot Image ...\n");
int perf_ctr_index = PERF_CTR_UNINITIALIZED;
HSS_PerfCtr_Allocate(&perf_ctr_index, "Boot Image Init");
if (pDefaultStorage) {
result = pDefaultStorage->init();
if (result) {
result = tryBootFunction_(pDefaultStorage, pDefaultStorage->getBootImage);
}
} else {
for (int i = 0; i < ARRAY_SIZE(pStorages); i++) {
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Trying to boot via %s ...\n", pStorages[i]->name);
if (pStorages[i]->init) {
result = pStorages[i]->init();
} else {
result = true;
}
if (result) {
result = tryBootFunction_(pStorages[i], pStorages[i]->getBootImage);
if (result) { break; }
}
}
}
HSS_PerfCtr_Lap(perf_ctr_index);
#endif
return result;
}
static bool postInit = false;
void HSS_BootInit_IndicatePostInit(void)
{
postInit = true;
}
bool HSS_BootInit_IsPostInit(void)
{
return postInit;
}
#if IS_ENABLED(CONFIG_SERVICE_BOOT)
bool tryBootFunction_(struct HSS_Storage *pStorage, HSS_GetBootImageFnPtr_t const bootImageFunction)
{
bool result = false;
(void)pStorage;
struct HSS_BootImage *pBootImage = NULL;
bool decompressedFlag = false;
(void)decompressedFlag;
result = bootImageFunction(pStorage, &pBootImage);
//
// check if this image is compressed...
// if so, decompress it to DDR
//
// for now, compression only works with a source already in DDR
# if IS_ENABLED(CONFIG_COMPRESSION)
if (result && pBootImage->magic == mHSS_COMPRESSED_MAGIC) {
decompressedFlag = true;
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "Failed to get boot image, cannot decompress\n");
} else if (!pBootImage) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "Boot Image NULL, ignoring\n");
result = false;
} else {
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Preparing to decompress to DDR ...\n");
void* const pInput = (void*)pBootImage;
void * const pOutputInDDR = (void *)(CONFIG_SERVICE_BOOT_DDR_TARGET_ADDR);
int outputSize = HSS_Decompress(pInput, pOutputInDDR);
mHSS_DEBUG_PRINTF(LOG_NORMAL, "decompressed %d bytes ...\n", outputSize);
if (outputSize) {
pBootImage = (struct HSS_BootImage *)pOutputInDDR;
} else {
pBootImage = NULL;
}
}
}
# endif
if (result) {
HSS_Register_Boot_Image(pBootImage);
mHSS_DEBUG_PRINTF(LOG_NORMAL, "%s: Boot Image registered ...\n", pStorage->name);
}
return result;
}
/////////////////////////////////////////////////////////////////////////////////////////
static void printBootImageDetails_(struct HSS_BootImage const * const pBootImage)
{
# ifdef BOOT_DEBUG
mHSS_DEBUG_PRINTF(LOG_NORMAL, " - set name is >>%s<<\n", pBootImage->set_name);
mHSS_DEBUG_PRINTF(LOG_NORMAL, " - magic is %08x\n", pBootImage->magic);
mHSS_DEBUG_PRINTF(LOG_NORMAL, " - length is %08x\n", pBootImage->bootImageLength);
# endif
}
#endif
#if IS_ENABLED(CONFIG_SERVICE_BOOT) && !IS_ENABLED(CONFIG_SERVICE_BOOT_USE_PAYLOAD)
static bool copyBootImageToDDR_(struct HSS_BootImage *pBootImage, char *pDest,
size_t srcOffset, HSS_BootImageCopyFnPtr_t pCopyFunction)
{
bool result = true;
printBootImageDetails_(pBootImage);
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Copying %lu bytes to 0x%lx\n",
pBootImage->bootImageLength, pDest);
result = pCopyFunction(pDest, srcOffset, pBootImage->bootImageLength);
return result;
}
#endif
static bool getBootImageFromMMC_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage)
{
bool result = false;
#if IS_ENABLED(CONFIG_SERVICE_BOOT) && IS_ENABLED(CONFIG_SERVICE_MMC)
assert(ppBootImage);
// if we are using MMC, then we need to do an initial copy of the
// boot header into our structure, for subsequent use
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Preparing to copy from MMC to DDR ...\n");
size_t srcLBAOffset = 0u;
assert(pStorage);
uint32_t blockSize, eraseSize, blockCount;
pStorage->getInfo(&blockSize, &eraseSize, &blockCount);
# if (IS_ENABLED(CONFIG_SERVICE_BOOT_MMC_USE_GPT))
{
HSS_GPT_t gpt;
gpt.lbaSize = blockSize;
GPT_Init(&gpt, pStorage);
result = GPT_ReadHeader(&gpt);
if (result) {
size_t srcIndex = 0u;
if (GPT_GetBootPartitionIndex(&gpt, &srcIndex)) {
mHSS_DEBUG_PRINTF(LOG_WARN, "Using manually set partition index\n");
} else {
result = GPT_FindBootSectorIndex(&gpt, &srcIndex, NULL);
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "GPT_FindBootSectorIndex() failed\n");
} else {
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Boot Partition found at index %lu\n",
srcIndex);
}
}
if (result) {
result = GPT_PartitionIdToLBAOffset(&gpt, srcIndex, &srcLBAOffset);
}
}
}
if (!result) {
mHSS_DEBUG_PRINTF(LOG_WARN, "GPT_PartitionIdToLBAOffset() failed - using offset %lu\n", srcLBAOffset);
} else {
//mHSS_DEBUG_PRINTF(LOG_WARN, "GPT_PartitionIdToLBAOffset() returned %lu\n", srcLBAOffset);
}
#endif
//
// Even if we have GPT enabled and it fails to find a GPT parttion, we'll still
// try to boot
{
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Attempting to read image header (%d bytes) ...\n",
sizeof(struct HSS_BootImage));
result = HSS_MMC_ReadBlock(&bootImage, srcLBAOffset * blockSize,
sizeof(struct HSS_BootImage));
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "HSS_MMC_ReadBlock() failed\n");
} else {
result = HSS_Boot_VerifyMagic(&bootImage);
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "HSS_Boot_VerifyMagic() failed\n");
} else {
int perf_ctr_index = PERF_CTR_UNINITIALIZED;
HSS_PerfCtr_Allocate(&perf_ctr_index, "Boot Image MMC Copy");
result = copyBootImageToDDR_(&bootImage,
(char *)(CONFIG_SERVICE_BOOT_DDR_TARGET_ADDR), srcLBAOffset * blockSize,
HSS_MMC_ReadBlock);
*ppBootImage = (struct HSS_BootImage *)(CONFIG_SERVICE_BOOT_DDR_TARGET_ADDR);
HSS_PerfCtr_Lap(perf_ctr_index);
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "copyBootImageToDDR_() failed\n");
}
}
}
}
#endif
return result;
}
void HSS_BootSelectSDCARD(void)
{
#if IS_ENABLED(CONFIG_SERVICE_MMC)
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Selecting SDCARD as boot source ...\n");
pDefaultStorage = &mmcStorage_;
HSS_MMC_SelectSDCARD();
#else
(void)getBootImageFromMMC_;
#endif
}
void HSS_BootSelectMMC(void)
{
#if IS_ENABLED(CONFIG_SERVICE_MMC)
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Selecting SDCARD/MMC (fallback) as boot source ...\n");
pDefaultStorage = &mmcStorage_;
HSS_MMC_SelectMMC();
#else
(void)getBootImageFromMMC_;
#endif
}
void HSS_BootSelectEMMC(void)
{
#if IS_ENABLED(CONFIG_SERVICE_MMC)
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Selecting EMMC as boot source ...\n");
pDefaultStorage = &mmcStorage_;
HSS_MMC_SelectEMMC();
#else
(void)getBootImageFromMMC_;
#endif
}
static bool getBootImageFromQSPI_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage)
{
bool result = false;
#if IS_ENABLED(CONFIG_SERVICE_BOOT) && IS_ENABLED(CONFIG_SERVICE_QSPI)
assert(ppBootImage);
// need to do an initial copy of the boot header into our structure, for subsequent use
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Preparing to copy from QSPI to DDR ...\n");
size_t srcLBAOffset = 0u;
assert(pStorage);
uint32_t blockSize, eraseSize, blockCount;
pStorage->getInfo(&blockSize, &eraseSize, &blockCount);
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Attempting to read image header (%d bytes) ...\n",
sizeof(struct HSS_BootImage));
result = HSS_QSPI_ReadBlock(&bootImage, srcLBAOffset * blockSize,
sizeof(struct HSS_BootImage));
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "HSS_QSPI_ReadBlock() failed\n");
} else {
result = HSS_Boot_VerifyMagic(&bootImage);
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "HSS_Boot_VerifyMagic() failed\n");
} else {
int perf_ctr_index = PERF_CTR_UNINITIALIZED;
HSS_PerfCtr_Allocate(&perf_ctr_index, "Boot Image QSPI Copy");
result = copyBootImageToDDR_(&bootImage,
(char *)(CONFIG_SERVICE_BOOT_DDR_TARGET_ADDR), srcLBAOffset * blockSize,
HSS_QSPI_ReadBlock);
*ppBootImage = (struct HSS_BootImage *)(CONFIG_SERVICE_BOOT_DDR_TARGET_ADDR);
HSS_PerfCtr_Lap(perf_ctr_index);
if (!result) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "copyBootImageToDDR_() failed\n");
}
}
}
#endif
return result;
}
void HSS_BootSelectQSPI(void)
{
#if IS_ENABLED(CONFIG_SERVICE_QSPI)
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Selecting QSPI as boot source ...\n");
pDefaultStorage = &qspiStorage_;
#else
(void)getBootImageFromQSPI_;
#endif
}
static bool getBootImageFromPayload_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage)
{
bool result = false;
(void)pStorage;
#if IS_ENABLED(CONFIG_SERVICE_BOOT) && IS_ENABLED(CONFIG_SERVICE_BOOT_USE_PAYLOAD)
assert(ppBootImage);
extern struct HSS_BootImage _payload_start;
*ppBootImage = (struct HSS_BootImage *)&_payload_start;
result = HSS_Boot_VerifyMagic(*ppBootImage);
printBootImageDetails_(*ppBootImage);
#endif
return result;
}
void HSS_BootSelectPayload(void)
{
#if IS_ENABLED(CONFIG_SERVICE_USE_PAYLOAD)
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Selecting Payload as boot source ...\n");
pDefaultStorage = &payloadStorage_;
#else
(void)getBootImageFromPayload_;
#endif
}
#if IS_ENABLED(CONFIG_SERVICE_BOOT) && IS_ENABLED(CONFIG_SERVICE_SPI)
static bool spiFlashReadBlock_(void *dst, size_t offs, size_t count) {
int retval = MSS_SYS_spi_copy((uintptr_t)dst, offs, count, /* options */ 3, /* mb_offset */ 0);
if (retval) {
mHSS_DEBUG_PRINTF(LOG_ERROR, "Failed to read 0x%lx bytes from SPI flash @0x%lx (error code %d)!\n", count, offs, retval);
}
return (retval == 0);
}
#endif
static bool getBootImageFromSpiFlash_(struct HSS_Storage *pStorage, struct HSS_BootImage **ppBootImage) {
bool result = false;
(void)pStorage;
#if IS_ENABLED(CONFIG_SERVICE_BOOT) && IS_ENABLED(CONFIG_SERVICE_SPI)
assert(ppBootImage);
size_t srcOffset = CONFIG_SERVICE_BOOT_SPI_FLASH_OFFSET;
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Preparing to copy from SPI Flash +0x%lx to DDR ...\n", srcOffset);
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Attempting to read image header (%d bytes) ...\n",
sizeof(struct HSS_BootImage));
MSS_SYS_select_service_mode(MSS_SYS_SERVICE_POLLING_MODE, NULL);
result = spiFlashReadBlock_(&bootImage, srcOffset, sizeof(struct HSS_BootImage));
if (!result) {
return false;
}
result = HSS_Boot_VerifyMagic(&bootImage);
if (!result) {
return false;
}
result = copyBootImageToDDR_(&bootImage, (char *)(CONFIG_SERVICE_BOOT_DDR_TARGET_ADDR),
srcOffset, spiFlashReadBlock_);
*ppBootImage = (struct HSS_BootImage *)(CONFIG_SERVICE_BOOT_DDR_TARGET_ADDR);
#endif
return result;
}
void HSS_BootSelectSPI(void)
{
#if IS_ENABLED(CONFIG_SERVICE_SPI)
mHSS_DEBUG_PRINTF(LOG_NORMAL, "Selecting SPI Flash as boot source ...\n");
pDefaultStorage = &spiStorage_;
#else
(void)getBootImageFromSpiFlash_;
#endif
}
bool HSS_Storage_Init(void);
bool HSS_Storage_ReadBlock(void *pDest, size_t srcOffset, size_t byteCount);
bool HSS_Storage_WriteBlock(size_t dstOffset, void *pSrc, size_t byteCount);
void HSS_Storage_GetInfo(uint32_t *pBlockSize, uint32_t *pEraseSize, uint32_t *pBlockCount);
void HSS_Storage_FlushWriteBuffer(void);
bool HSS_Storage_Init(void)
{
bool result = true;
struct HSS_Storage *pStorage = pDefaultStorage ? pDefaultStorage : pStorages[0];
assert(pStorage);
if (pStorage->init) {
mHSS_DEBUG_PRINTF(LOG_NORMAL, "initialize %s\n", pStorage->name);
result = pStorage->init();
}
return result;
}
bool HSS_Storage_ReadBlock(void *pDest, size_t srcOffset, size_t byteCount)
{
bool result = true;
struct HSS_Storage *pStorage = pDefaultStorage ? pDefaultStorage : pStorages[0];
assert(pStorage);
if (pStorage->readBlock) {
result = pStorage->readBlock(pDest, srcOffset, byteCount);
}
return result;
}
bool HSS_Storage_WriteBlock(size_t dstOffset, void *pSrc, size_t byteCount)
{
struct HSS_Storage *pStorage = pDefaultStorage ? pDefaultStorage : pStorages[0];
assert(pStorage);
return pStorage->writeBlock(dstOffset, pSrc, byteCount);
}
void HSS_Storage_GetInfo(uint32_t *pBlockSize, uint32_t *pEraseSize, uint32_t *pBlockCount)
{
struct HSS_Storage *pStorage = pDefaultStorage ? pDefaultStorage : pStorages[0];
assert(pStorage);
if (pStorage->getInfo) {
pStorage->getInfo(pBlockSize, pEraseSize, pBlockCount);
}
mHSS_DEBUG_PRINTF(LOG_NORMAL, "%s - %u byte pages, %u byte blocks, %u pages\n", pStorage->name, *pBlockSize, *pEraseSize, *pBlockCount);
}
void HSS_Storage_FlushWriteBuffer(void)
{
struct HSS_Storage *pStorage = pDefaultStorage ? pDefaultStorage : pStorages[0];
assert(pStorage);
if (pStorage->flushWriteBuffer) {
pStorage->flushWriteBuffer();
}
}