• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  *    conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *    of conditions and the following disclaimer in the documentation and/or other materials
12  *    provided with the distribution.
13  *
14  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15  *    to endorse or promote products derived from this software without specific prior written
16  *    permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef MTD_LEGACY_LITE_H
32 #define MTD_LEGACY_LITE_H
33 
34 #include "hdf_base.h"
35 #include "mtd/mtd_core.h"
36 #include "fs/driver.h"
37 
38 typedef struct erase_info {
39     int scrub;
40     struct erase_info *next;
41     unsigned char state;
42     unsigned long priv;
43     void (*callback)(struct erase_info *self);
44     unsigned int cell;
45     unsigned int dev;
46     unsigned long retries;
47     unsigned long time;
48     uint64_t fail_addr;
49     uint64_t len;
50     uint64_t addr;
51     struct mtd_info *mtd;
52 } EraseInfoLegacy;
53 
54 typedef struct mtd_info {
55     void *priv;
56     uint8_t type;
57     const char *name;
58     uint32_t flags;
59     uint64_t size;
60     uint32_t erasesize;
61     uint32_t writesize;
62     uint32_t oobsize;
63     int (*erase)(struct mtd_info *mtd, struct erase_info *instr);
64     int (*read)(struct mtd_info *mtd, off_t from, size_t len, size_t *retlen, char *buf);
65     int (*write)(struct mtd_info *mtd, off_t to, size_t len, size_t *retlen, const char *buf);
66     int (*read_oob)(struct mtd_info *mtd, off_t from, size_t len, size_t *retlen, char *buf);
67     int (*write_oob)(struct mtd_info *mtd, off_t to, size_t len, size_t *retlen, const char *buf);
68     int (*block_isbad)(struct mtd_info *mtd, off_t ofs);
69     int (*block_markbad)(struct mtd_info *mtd, off_t ofs);
70 } MtdInfoLegacy;
71 
72 extern MtdInfoLegacy *nand_mtd;
73 
74 const struct file_operations_vfs *GetMtdCharFops(void);
75 const struct block_operations *GetDevSpinorOps(void);
76 const struct block_operations *GetDevNandOps(void);
77 void MtdDeviceLegacyFillMtdInfo(struct MtdDevice *mtdDevice);
78 
79 #define MTD_NORFLASH                3
80 #define MTD_NANDFLASH               4
81 
82 #define MTD_WRITEABLE               0x400
83 #define MTD_CAP_NANDFLASH           (MTD_WRITEABLE)
84 
85 #define MTD_FAIL_ADDR_UNKNOWN       (-1LL)
86 
87 #define GOOD_BLOCK                  0
88 
89 
90 #endif /* MTD_LEGACY_LITE_H */
91