summaryrefslogtreecommitdiff
path: root/tools/mtk_nand_headers.h
diff options
context:
space:
mode:
authorWeijie Gao <weijie.gao@mediatek.com>2022-09-09 20:00:21 +0800
committerTom Rini <trini@konsulko.com>2022-09-23 15:09:16 -0400
commitcadb1a858d071e4ec6afdacc9ad5c7057cae699d (patch)
tree923911ac82276a2369c0d3b5d19112b7f24b09cf /tools/mtk_nand_headers.h
parent687e10ec49eb0231c9b2b59ee86bbefc0b86e6e1 (diff)
tools: mtk_image: split the code of generating NAND header into a new file
The predefined NAND headers take too much spaces in the mtk_image.c. Moving them into a new file can significantly improve the readability of both mtk_image.c and the new mtk_nand_headers.c. This is a preparation for adding more NAND headers. Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Daniel Golle <daniel@makrotopia.org> Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
Diffstat (limited to 'tools/mtk_nand_headers.h')
-rw-r--r--tools/mtk_nand_headers.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/mtk_nand_headers.h b/tools/mtk_nand_headers.h
new file mode 100644
index 00000000000..20506cab384
--- /dev/null
+++ b/tools/mtk_nand_headers.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * MediaTek BootROM NAND header definitions
+ *
+ * Copyright (C) 2022 MediaTek Inc.
+ * Author: Weijie Gao <weijie.gao@mediatek.com>
+ */
+
+#ifndef _MTK_NAND_HEADERS_H
+#define _MTK_NAND_HEADERS_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+struct nand_header_info {
+ uint32_t page_size;
+ uint32_t spare_size;
+ uint32_t gfh_offset;
+};
+
+/* AP BROM Header for NAND */
+union nand_boot_header {
+ struct {
+ char name[12];
+ char version[4];
+ char id[8];
+ uint16_t ioif; /* I/O interface */
+ uint16_t pagesize; /* NAND page size */
+ uint16_t addrcycles; /* Address cycles */
+ uint16_t oobsize; /* NAND page spare size */
+ uint16_t pages_of_block; /* Pages of one block */
+ uint16_t numblocks; /* Total blocks of NAND chip */
+ uint16_t writesize_shift;
+ uint16_t erasesize_shift;
+ uint8_t dummy[60];
+ uint8_t ecc_parity[28]; /* ECC parity of this header */
+ };
+
+ uint8_t data[0x80];
+};
+
+#define NAND_BOOT_NAME "BOOTLOADER!"
+#define NAND_BOOT_VERSION "V006"
+#define NAND_BOOT_ID "NFIINFO"
+
+/* Find nand header data by name */
+const union nand_boot_header *mtk_nand_header_find(const char *name);
+
+/* Device header size using this nand header */
+uint32_t mtk_nand_header_size(const union nand_boot_header *hdr_nand);
+
+/* Get nand info from nand header (page size, spare size, ...) */
+int mtk_nand_header_info(const void *ptr, struct nand_header_info *info);
+
+/* Whether given header data is valid */
+bool is_mtk_nand_header(const void *ptr);
+
+/* Generate Device header using give nand header */
+uint32_t mtk_nand_header_put(const union nand_boot_header *hdr_nand, void *ptr);
+
+#endif /* _MTK_NAND_HEADERS_H */