blob: 20506cab38406122852f59032249c2da9c799890 [file] [log] [blame]
Weijie Gaocadb1a82022-09-09 20:00:21 +08001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * MediaTek BootROM NAND header definitions
4 *
5 * Copyright (C) 2022 MediaTek Inc.
6 * Author: Weijie Gao <weijie.gao@mediatek.com>
7 */
8
9#ifndef _MTK_NAND_HEADERS_H
10#define _MTK_NAND_HEADERS_H
11
12#include <stdint.h>
13#include <stdbool.h>
14
15struct nand_header_info {
16 uint32_t page_size;
17 uint32_t spare_size;
18 uint32_t gfh_offset;
19};
20
21/* AP BROM Header for NAND */
22union nand_boot_header {
23 struct {
24 char name[12];
25 char version[4];
26 char id[8];
27 uint16_t ioif; /* I/O interface */
28 uint16_t pagesize; /* NAND page size */
29 uint16_t addrcycles; /* Address cycles */
30 uint16_t oobsize; /* NAND page spare size */
31 uint16_t pages_of_block; /* Pages of one block */
32 uint16_t numblocks; /* Total blocks of NAND chip */
33 uint16_t writesize_shift;
34 uint16_t erasesize_shift;
35 uint8_t dummy[60];
36 uint8_t ecc_parity[28]; /* ECC parity of this header */
37 };
38
39 uint8_t data[0x80];
40};
41
42#define NAND_BOOT_NAME "BOOTLOADER!"
43#define NAND_BOOT_VERSION "V006"
44#define NAND_BOOT_ID "NFIINFO"
45
46/* Find nand header data by name */
47const union nand_boot_header *mtk_nand_header_find(const char *name);
48
49/* Device header size using this nand header */
50uint32_t mtk_nand_header_size(const union nand_boot_header *hdr_nand);
51
52/* Get nand info from nand header (page size, spare size, ...) */
53int mtk_nand_header_info(const void *ptr, struct nand_header_info *info);
54
55/* Whether given header data is valid */
56bool is_mtk_nand_header(const void *ptr);
57
58/* Generate Device header using give nand header */
59uint32_t mtk_nand_header_put(const union nand_boot_header *hdr_nand, void *ptr);
60
61#endif /* _MTK_NAND_HEADERS_H */