blob: 8a28943a2184531c84d3e249587b074d56fa3ecf [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2018 MediaTek Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#if !defined(__KDUMP_SDHC_H__)
25#define __KDUMP_SDHC_H__
26
27#include <lib/bio.h>
28#include <stdbool.h>
29
30#define MaxFindFileClusNum 100
31
32typedef enum {
33 WRITE_FILE_DIRECT = 0,
34 FORMAT_BEF_WRITE = 1
35} FileWriteType;
36
37
38typedef enum FileSysType {
39 FAT_16 = 0,
40 FAT_32 = 1
41} FATType;
42
43typedef struct {
44 uint32_t BPB_BytsPerSec;
45 uint32_t BPB_SecPerClus;
46 uint32_t BPB_RsvdSecCnt;
47 uint32_t BPB_NumFATs;
48 uint32_t BPB_FATSz;
49 uint32_t BPB_RootEntCnt;
50 uint32_t BPB_RootClus;
51 uint32_t BPB_TotSec;
52 FATType FileSysType;
53 uint32_t BootStartSec;
54 uint32_t FATStartSec;
55 uint32_t RootDirStartSec;
56 uint32_t ClusStartSec;
57} FAT_Para;
58
59
60
61typedef struct {
62 uint8_t name[11]; // file name
63 uint8_t attr; // file attribute bits (system, hidden, etc.)
64 uint8_t NTflags; // ???
65 uint8_t createdTimeMsec; // ??? (milliseconds needs 11 bits for 0-2000)
66 uint16_t createdTime; // time of file creation
67 uint16_t createdDate; // date of file creation
68 uint16_t lastAccessDate; // date of last file access
69 uint16_t clusFirstHigh; // high word of first cluster
70 uint16_t time; // time of last file change
71 uint16_t date; // date of last file change
72 uint16_t clusFirst; // low word of first cluster
73 uint32_t size; // file size in bytes
74} DirEntry;
75
76typedef struct {
77 uint8_t seqNum; // sequence number
78 uint8_t name1[10]; // name characters (five UTF-16 characters)
79 uint8_t attr; // attributes (always 0x0F)
80 uint8_t NTflags; // reserved (alwyas 0x00)
81 uint8_t checksum; // checksum of DOS file name
82 uint8_t name2[12]; // name characters (six UTF-16 characters)
83 uint16_t clusFirst; // word of first cluster (always 0x0000)
84 uint8_t name3[4]; // name characters (2 UTF-16 characters)
85} LfnEntry;
86
87#define FAT_BUFSIZE 65536
88
89typedef struct {
90 uint8_t FileBuffer[FAT_BUFSIZE]; // File cluster cache, assume maximum cluster size is 64KB
91 uint8_t FATBuffer[512]; // FAT cache
92 uint32_t BufferLen; // data cached length in FileBuffer
93 uint32_t TotalLen; // File total length
94 uint32_t PrevClusterNum; // Prev cluster number
95 uint32_t CurrClusterNum; // Current cluster number
96 uint32_t FATSector; // Current FAT sector number
97 uint32_t CheckSum; // File write content checksum
98 bool DiskFull;
99} FileHandler;
100
101
102struct mrdump_dev {
103 const char *name;
104 void *handle;
105 bdev_t *bdev;
106
107 bool (*read)(struct mrdump_dev *dev, uint64_t sector_addr, uint8_t *pdBuf, int32_t blockLen);
108 bool (*write)(struct mrdump_dev *dev, uint64_t sector_addr, uint8_t *pdBuf, int32_t blockLen);
109};
110
111static inline int mrdump_dev_read(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen)
112{
113 return dev->read(dev, sector_addr, pdBuf, blockLen);
114}
115
116static inline int mrdump_dev_write(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen)
117{
118 return dev->write(dev, sector_addr, pdBuf, blockLen);
119}
120
121#endif