-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmm_dump.c
680 lines (598 loc) · 27.7 KB
/
mm_dump.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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/************************************************************************
* NASA Docket No. GSC-18,923-1, and identified as “Core Flight
* System (cFS) Memory Manager Application version 2.5.1”
*
* Copyright (c) 2021 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
/**
* @file
* Functions used for processing CFS Memory Manager memory dump commands
*/
/*************************************************************************
** Includes
*************************************************************************/
#include "mm_app.h"
#include "mm_dump.h"
#include "mm_events.h"
#include "mm_mem32.h"
#include "mm_mem16.h"
#include "mm_mem8.h"
#include "mm_utils.h"
#include "mm_mission_cfg.h"
#include <string.h>
/*************************************************************************
** External Data
*************************************************************************/
extern MM_AppData_t MM_AppData;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Memory peek command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_PeekCmd(const CFE_SB_Buffer_t *BufPtr)
{
bool Valid;
const MM_PeekCmd_t *CmdPtr;
cpuaddr SrcAddress = 0;
size_t ExpectedLength = sizeof(MM_PeekCmd_t);
bool Result = false;
MM_SymAddr_t SrcSymAddress;
/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_PeekCmd_t *)BufPtr);
SrcSymAddress = CmdPtr->SrcSymAddress;
/* Resolve the symbolic address in command message */
Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress);
if (Valid == true)
{
/* Run necessary checks on command parameters */
Valid = MM_VerifyPeekPokeParams(SrcAddress, CmdPtr->MemType, CmdPtr->DataSize);
/* Check the specified memory type and call the appropriate routine */
if (Valid == true)
{
/*
** We use this single peek routine for all memory types
** (including the optional ones)
*/
Result = MM_PeekMem(CmdPtr, SrcAddress);
}
} /* end MM_ResolveSymAddr if */
else
{
CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR,
"Symbolic address can't be resolved: Name = '%s'", CmdPtr->SrcSymAddress.SymName);
}
} /* end MM_VerifyCmdLength if */
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Read 8,16, or 32 bits of data from any given input address */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_PeekMem(const MM_PeekCmd_t *CmdPtr, cpuaddr SrcAddress)
{
bool ValidPeek = false;
uint8 ByteValue = 0;
uint16 WordValue = 0;
uint32 DWordValue = 0;
int32 PSP_Status = 0;
size_t BytesProcessed = 0;
uint32 DataValue = 0;
size_t DataSize = 0;
uint32 EventID = 0;
/*
** Read the requested number of bytes and report in an event message
*/
switch (CmdPtr->DataSize)
{
case MM_BYTE_BIT_WIDTH:
PSP_Status = CFE_PSP_MemRead8(SrcAddress, &ByteValue);
DataSize = 8;
if (PSP_Status == CFE_PSP_SUCCESS)
{
DataValue = (uint32)ByteValue;
BytesProcessed = sizeof(uint8);
EventID = MM_PEEK_BYTE_INF_EID;
ValidPeek = true;
}
break;
case MM_WORD_BIT_WIDTH:
PSP_Status = CFE_PSP_MemRead16(SrcAddress, &WordValue);
DataSize = 16;
if (PSP_Status == CFE_PSP_SUCCESS)
{
DataValue = (uint32)WordValue;
BytesProcessed = sizeof(uint16);
EventID = MM_PEEK_WORD_INF_EID;
ValidPeek = true;
}
break;
case MM_DWORD_BIT_WIDTH:
PSP_Status = CFE_PSP_MemRead32(SrcAddress, &DWordValue);
DataSize = 32;
if (PSP_Status == CFE_PSP_SUCCESS)
{
DataValue = DWordValue;
BytesProcessed = sizeof(uint32);
EventID = MM_PEEK_DWORD_INF_EID;
ValidPeek = true;
}
break;
/*
** We don't need a default case, a bad DataSize will get caught
** in the MM_VerifyPeekPokeParams function and we won't get here
*/
default:
break;
}
if (ValidPeek)
{
MM_AppData.HkPacket.LastAction = MM_PEEK;
MM_AppData.HkPacket.MemType = CmdPtr->MemType;
MM_AppData.HkPacket.Address = SrcAddress;
MM_AppData.HkPacket.BytesProcessed = BytesProcessed;
MM_AppData.HkPacket.DataValue = DataValue;
CFE_EVS_SendEvent(EventID, CFE_EVS_EventType_INFORMATION,
"Peek Command: Addr = %p Size = %u bits Data = 0x%08X", (void *)SrcAddress,
(unsigned int)DataSize, (unsigned int)DataValue);
}
else
{
CFE_EVS_SendEvent(MM_PSP_READ_ERR_EID, CFE_EVS_EventType_ERROR,
"PSP read memory error: RC=%d, Address=%p, MemType=MEM%u", PSP_Status, (void *)SrcAddress,
(unsigned int)DataSize);
}
return ValidPeek;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Dump memory to file command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_DumpMemToFileCmd(const CFE_SB_Buffer_t *BufPtr)
{
bool Valid = false;
int32 OS_Status;
osal_id_t FileHandle = OS_OBJECT_ID_UNDEFINED;
cpuaddr SrcAddress = 0;
char FileName[OS_MAX_PATH_LEN];
MM_SymAddr_t SrcSymAddress;
const MM_DumpMemToFileCmd_t *CmdPtr;
CFE_FS_Header_t CFEFileHeader;
MM_LoadDumpFileHeader_t MMFileHeader;
size_t ExpectedLength = sizeof(MM_DumpMemToFileCmd_t);
/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_DumpMemToFileCmd_t *)BufPtr);
SrcSymAddress = CmdPtr->SrcSymAddress;
/* Make sure strings are null terminated before attempting to process them */
CFE_SB_MessageStringGet(FileName, CmdPtr->FileName, NULL, sizeof(FileName), sizeof(CmdPtr->FileName));
/* Resolve the symbolic address in command message */
Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress);
if (Valid == true)
{
/* Run necessary checks on command parameters */
Valid = MM_VerifyLoadDumpParams(SrcAddress, CmdPtr->MemType, CmdPtr->NumOfBytes, MM_VERIFY_DUMP);
if (Valid == true)
{
/*
** Initialize the cFE primary file header structure
*/
CFE_FS_InitHeader(&CFEFileHeader, MM_CFE_HDR_DESCRIPTION, MM_CFE_HDR_SUBTYPE);
/*
** Initialize the MM secondary file header structure
*/
memset(&MMFileHeader, 0, sizeof(MMFileHeader));
MMFileHeader.SymAddress.SymName[0] = MM_CLEAR_SYMNAME;
/*
** Copy command data to file secondary header
*/
MMFileHeader.SymAddress.Offset = SrcAddress;
MMFileHeader.MemType = CmdPtr->MemType;
MMFileHeader.NumOfBytes = CmdPtr->NumOfBytes;
/*
** Create and open dump file
*/
OS_Status =
OS_OpenCreate(&FileHandle, FileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_READ_WRITE);
if (OS_Status == OS_SUCCESS)
{
/* Write the file headers */
Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader);
if (Valid == true)
{
switch (MMFileHeader.MemType)
{
case MM_RAM:
case MM_EEPROM:
Valid = MM_DumpMemToFile(FileHandle, FileName, &MMFileHeader);
break;
#ifdef MM_OPT_CODE_MEM32_MEMTYPE
case MM_MEM32:
Valid = MM_DumpMem32ToFile(FileHandle, FileName, &MMFileHeader);
break;
#endif /* MM_OPT_CODE_MEM32_MEMTYPE */
#ifdef MM_OPT_CODE_MEM16_MEMTYPE
case MM_MEM16:
Valid = MM_DumpMem16ToFile(FileHandle, FileName, &MMFileHeader);
break;
#endif /* MM_OPT_CODE_MEM16_MEMTYPE */
#ifdef MM_OPT_CODE_MEM8_MEMTYPE
case MM_MEM8:
Valid = MM_DumpMem8ToFile(FileHandle, FileName, &MMFileHeader);
break;
#endif /* MM_OPT_CODE_MEM8_MEMTYPE */
default:
/* This branch will never be executed. MMFileHeader.MemType will always
* be valid value for this switch statement it is verified via
* MM_VerifyFileLoadDumpParams */
Valid = false;
break;
}
if (Valid == true)
{
/*
** Compute CRC of dumped data
*/
OS_Status = OS_lseek(
FileHandle, (sizeof(CFE_FS_Header_t) + sizeof(MM_LoadDumpFileHeader_t)), OS_SEEK_SET);
if (OS_Status != (sizeof(CFE_FS_Header_t) + sizeof(MM_LoadDumpFileHeader_t)))
{
Valid = false;
}
else
{
OS_Status = MM_ComputeCRCFromFile(FileHandle, &MMFileHeader.Crc, MM_DUMP_FILE_CRC_TYPE);
if (OS_Status == OS_SUCCESS)
{
/*
** Rewrite the file headers. The subfunctions will take care of moving
** the file pointer to the beginning of the file so we don't need to do it
** here.
*/
Valid = MM_WriteFileHeaders(FileName, FileHandle, &CFEFileHeader, &MMFileHeader);
} /* end MM_ComputeCRCFromFile if */
else
{
Valid = false;
CFE_EVS_SendEvent(MM_COMPUTECRCFROMFILE_ERR_EID, CFE_EVS_EventType_ERROR,
"MM_ComputeCRCFromFile error received: RC = 0x%08X File = '%s'",
(unsigned int)OS_Status, FileName);
}
}
} /* end Valid == true if */
if (Valid == true)
{
CFE_EVS_SendEvent(
MM_DMP_MEM_FILE_INF_EID, CFE_EVS_EventType_INFORMATION,
"Dump Memory To File Command: Dumped %d bytes from address %p to file '%s'",
(int)MM_AppData.HkPacket.BytesProcessed, (void *)SrcAddress, FileName);
/*
** Update last action statistics
*/
MM_AppData.HkPacket.LastAction = MM_DUMP_TO_FILE;
strncpy(MM_AppData.HkPacket.FileName, FileName, OS_MAX_PATH_LEN);
MM_AppData.HkPacket.MemType = CmdPtr->MemType;
MM_AppData.HkPacket.Address = SrcAddress;
MM_AppData.HkPacket.BytesProcessed = CmdPtr->NumOfBytes;
}
} /* end MM_WriteFileHeaders if */
/* Close dump file */
if ((OS_Status = OS_close(FileHandle)) != OS_SUCCESS)
{
Valid = false;
CFE_EVS_SendEvent(MM_OS_CLOSE_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_close error received: RC = 0x%08X File = '%s'", (unsigned int)OS_Status,
FileName);
}
} /* end OS_OpenCreate if */
else
{
Valid = false;
CFE_EVS_SendEvent(MM_OS_CREAT_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_OpenCreate error received: RC = %d File = '%s'", (int)OS_Status, FileName);
}
} /* end MM_VerifyFileLoadDumpParams if */
} /* end MM_ResolveSymAddr if */
else
{
Valid = false;
CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR,
"Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName);
}
} /* end MM_VerifyCmdLength if */
return Valid;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Dump the requested number of bytes from memory to a file */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_DumpMemToFile(osal_id_t FileHandle, const char *FileName, const MM_LoadDumpFileHeader_t *FileHeader)
{
bool ValidDump = false;
int32 OS_Status;
uint32 BytesRemaining = FileHeader->NumOfBytes;
size_t BytesProcessed = 0;
size_t SegmentSize = MM_MAX_DUMP_DATA_SEG;
uint8 *SourcePtr = (uint8 *)(FileHeader->SymAddress.Offset);
uint8 *ioBuffer = (uint8 *)&MM_AppData.DumpBuffer[0];
while (BytesRemaining != 0)
{
if (BytesRemaining < MM_MAX_DUMP_DATA_SEG)
{
SegmentSize = BytesRemaining;
}
memcpy(ioBuffer, SourcePtr, SegmentSize);
OS_Status = OS_write(FileHandle, ioBuffer, SegmentSize);
if (OS_Status == SegmentSize)
{
SourcePtr += SegmentSize;
BytesRemaining -= SegmentSize;
BytesProcessed += SegmentSize;
/* Prevent CPU hogging between dump segments */
if (BytesRemaining != 0)
{
MM_SegmentBreak();
}
}
else
{
BytesRemaining = 0;
CFE_EVS_SendEvent(MM_OS_WRITE_EXP_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_write error received: RC = %d, Expected = %u, File = '%s'", OS_Status,
(unsigned int)SegmentSize, FileName);
}
}
/* Update last action statistics */
if (BytesProcessed == FileHeader->NumOfBytes)
{
ValidDump = true;
MM_AppData.HkPacket.LastAction = MM_DUMP_TO_FILE;
MM_AppData.HkPacket.MemType = FileHeader->MemType;
MM_AppData.HkPacket.Address = FileHeader->SymAddress.Offset;
MM_AppData.HkPacket.BytesProcessed = BytesProcessed;
strncpy(MM_AppData.HkPacket.FileName, FileName, OS_MAX_PATH_LEN);
}
return ValidDump;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Write the cFE primary and MM secondary file headers */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_WriteFileHeaders(const char *FileName, osal_id_t FileHandle, CFE_FS_Header_t *CFEHeader,
const MM_LoadDumpFileHeader_t *MMHeader)
{
bool Valid = true;
int32 OS_Status;
/*
** Write out the primary cFE file header
*/
OS_Status = CFE_FS_WriteHeader(FileHandle, CFEHeader);
if (OS_Status != sizeof(CFE_FS_Header_t))
{
/* We either got an error or didn't write as much data as expected */
Valid = false;
CFE_EVS_SendEvent(MM_CFE_FS_WRITEHDR_ERR_EID, CFE_EVS_EventType_ERROR,
"CFE_FS_WriteHeader error received: RC = %d Expected = %d File = '%s'", OS_Status,
(int)sizeof(CFE_FS_Header_t), FileName);
} /* end CFE_FS_WriteHeader if */
else
{
/*
** Write out the secondary MM file header
*/
OS_Status = OS_write(FileHandle, MMHeader, sizeof(MM_LoadDumpFileHeader_t));
if (OS_Status != sizeof(MM_LoadDumpFileHeader_t))
{
/* We either got an error or didn't read as much data as expected */
Valid = false;
CFE_EVS_SendEvent(MM_OS_WRITE_EXP_ERR_EID, CFE_EVS_EventType_ERROR,
"OS_write error received: RC = %d Expected = %u File = '%s'", OS_Status,
(unsigned int)sizeof(MM_LoadDumpFileHeader_t), FileName);
} /* end OS_write if */
} /* end CFE_FS_WriteHeader else */
return Valid;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Dump memory in event message command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_DumpInEventCmd(const CFE_SB_Buffer_t *BufPtr)
{
bool Valid = false;
const MM_DumpInEventCmd_t *CmdPtr;
uint32 i;
int32 EventStringTotalLength = 0;
cpuaddr SrcAddress = 0;
size_t ExpectedLength = sizeof(MM_DumpInEventCmd_t);
uint8 * BytePtr;
char TempString[MM_DUMPINEVENT_TEMP_CHARS];
const char HeaderString[] = "Memory Dump: ";
static char EventString[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
MM_SymAddr_t SrcSymAddress;
/*
** Allocate a dump buffer. It's declared this way to ensure it stays
** longword aligned since MM_MAX_DUMP_INEVENT_BYTES can be adjusted
** by changing the maximum event message string size.
*/
uint32 DumpBuffer[(MM_MAX_DUMP_INEVENT_BYTES + 3) / 4];
/* Verify command packet length */
if (MM_VerifyCmdLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((MM_DumpInEventCmd_t *)BufPtr);
SrcSymAddress = CmdPtr->SrcSymAddress;
/* Resolve the symbolic source address in the command message */
Valid = MM_ResolveSymAddr(&(SrcSymAddress), &SrcAddress);
if (Valid == true)
{
/* Run necessary checks on command parameters */
Valid = MM_VerifyLoadDumpParams(SrcAddress, CmdPtr->MemType, CmdPtr->NumOfBytes, MM_VERIFY_EVENT);
if (Valid == true)
{
/* Fill a local data buffer with the dump words */
Valid = MM_FillDumpInEventBuffer(SrcAddress, CmdPtr, (uint8 *)DumpBuffer);
if (Valid == true)
{
/*
** Prepare event message string header
** 13 characters, not counting NUL terminator
*/
CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], HeaderString, NULL,
sizeof(EventString) - EventStringTotalLength, sizeof(HeaderString));
EventStringTotalLength = strlen(EventString);
/*
** Build dump data string
** Each byte of data requires 5 characters of string space
** Note this really only allows up to ~15 bytes using default config
*/
BytePtr = (uint8 *)DumpBuffer;
for (i = 0; i < CmdPtr->NumOfBytes; i++)
{
snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "%02X ", *BytePtr);
CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], TempString, NULL,
sizeof(EventString) - EventStringTotalLength, sizeof(TempString));
EventStringTotalLength = strlen(EventString);
BytePtr++;
}
/*
** Append tail
** This adds up to 33 characters depending on pointer representation including the NUL terminator
*/
snprintf(TempString, MM_DUMPINEVENT_TEMP_CHARS, "from address: %p", (void *)SrcAddress);
CFE_SB_MessageStringGet(&EventString[EventStringTotalLength], TempString, NULL,
sizeof(EventString) - EventStringTotalLength, sizeof(TempString));
/* Send it out */
CFE_EVS_SendEvent(MM_DUMP_INEVENT_INF_EID, CFE_EVS_EventType_INFORMATION, "%s", EventString);
/* Update telemetry */
MM_AppData.HkPacket.LastAction = MM_DUMP_INEVENT;
MM_AppData.HkPacket.MemType = CmdPtr->MemType;
MM_AppData.HkPacket.Address = SrcAddress;
MM_AppData.HkPacket.BytesProcessed = CmdPtr->NumOfBytes;
} /* end MM_FillDumpInEventBuffer if */
} /* end MM_VerifyFileLoadDumpParams if */
} /* end MM_ResolveSymAddr if */
else
{
CFE_EVS_SendEvent(MM_SYMNAME_ERR_EID, CFE_EVS_EventType_ERROR,
"Symbolic address can't be resolved: Name = '%s'", SrcSymAddress.SymName);
}
} /* end MM_VerifyCmdLength if */
return Valid;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Fill a buffer with data to be dumped in an event message string */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool MM_FillDumpInEventBuffer(cpuaddr SrcAddress, const MM_DumpInEventCmd_t *CmdPtr, void *DumpBuffer)
{
#if defined(MM_OPT_CODE_MEM8_MEMTYPE) || defined(MM_OPT_CODE_MEM16_MEMTYPE) || defined(MM_OPT_CODE_MEM32_MEMTYPE)
uint32 i;
#endif
/* cppcheck-suppress unusedVariable */
int32 PSP_Status;
bool Valid = true;
/* Initialize buffer */
memset(DumpBuffer, 0, MM_MAX_DUMP_INEVENT_BYTES);
switch (CmdPtr->MemType)
{
case MM_RAM:
case MM_EEPROM:
memcpy((void *)DumpBuffer, (void *)SrcAddress, CmdPtr->NumOfBytes);
break;
#ifdef MM_OPT_CODE_MEM32_MEMTYPE
case MM_MEM32:
for (i = 0; i < (CmdPtr->NumOfBytes / 4); i++)
{
PSP_Status = CFE_PSP_MemRead32(SrcAddress, (uint32 *)DumpBuffer);
if (PSP_Status == CFE_PSP_SUCCESS)
{
SrcAddress += sizeof(uint32);
DumpBuffer = (uint8 *)DumpBuffer + sizeof(uint32);
}
else
{
/* CFE_PSP_MemRead32 error */
Valid = false;
CFE_EVS_SendEvent(MM_PSP_READ_ERR_EID, CFE_EVS_EventType_ERROR,
"PSP read memory error: RC=%d, Src=%p, Tgt=%p, Type=MEM32", PSP_Status,
(void *)SrcAddress, (void *)DumpBuffer);
/* Stop load dump buffer loop */
break;
}
}
break;
#endif /* MM_OPT_CODE_MEM32_MEMTYPE */
#ifdef MM_OPT_CODE_MEM16_MEMTYPE
case MM_MEM16:
for (i = 0; i < (CmdPtr->NumOfBytes / 2); i++)
{
PSP_Status = CFE_PSP_MemRead16(SrcAddress, (uint16 *)DumpBuffer);
if (PSP_Status == CFE_PSP_SUCCESS)
{
SrcAddress += sizeof(uint16);
DumpBuffer = (uint8 *)DumpBuffer + sizeof(uint16);
}
else
{
/* CFE_PSP_MemRead16 error */
Valid = false;
CFE_EVS_SendEvent(MM_PSP_READ_ERR_EID, CFE_EVS_EventType_ERROR,
"PSP read memory error: RC=%d, Src=%p, Tgt=%p, Type=MEM16", PSP_Status,
(void *)SrcAddress, (void *)DumpBuffer);
/* Stop load dump buffer loop */
break;
}
}
break;
#endif /* MM_OPT_CODE_MEM16_MEMTYPE */
#ifdef MM_OPT_CODE_MEM8_MEMTYPE
case MM_MEM8:
for (i = 0; i < CmdPtr->NumOfBytes; i++)
{
PSP_Status = CFE_PSP_MemRead8(SrcAddress, (uint8 *)DumpBuffer);
if (PSP_Status == CFE_PSP_SUCCESS)
{
SrcAddress++;
DumpBuffer = (uint8 *)DumpBuffer + 1;
}
else
{
/* CFE_PSP_MemRead8 error */
Valid = false;
CFE_EVS_SendEvent(MM_PSP_READ_ERR_EID, CFE_EVS_EventType_ERROR,
"PSP read memory error: RC=%d, Src=%p, Tgt=%p, Type=MEM8", PSP_Status,
(void *)SrcAddress, (void *)DumpBuffer);
/* Stop load dump buffer loop */
break;
}
}
break;
#endif /* MM_OPT_CODE_MEM8_MEMTYPE */
default:
/* This branch will never be executed. CmdPtr->MemType will always
* be valid value for this switch statement it is verified via
* MM_VerifyFileLoadDumpParams */
Valid = false;
break;
} /* end CmdPtr->MemType switch */
return Valid;
}