aboutsummaryrefslogtreecommitdiffstats
path: root/package/boot/uboot-mediatek/patches/100-29-board-mediatek-wire-up-NMBM-support.patch
blob: b561a7994441088a6138db00f7288746946712dc (plain)
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
From 6792b57b3ba61ca6d69ea4a13a58bed65fc5da87 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Sun, 7 Aug 2022 04:04:46 +0200
Subject: [PATCH] board: mediatek: wire-up NMBM support

---
 board/mediatek/mt7622/mt7622_rfb.c | 38 +++++++++++++++++++++
 board/mediatek/mt7629/mt7629_rfb.c | 38 +++++++++++++++++++++
 board/mediatek/mt7981/mt7981_rfb.c | 52 ++++++++++++++++++++++++++++
 board/mediatek/mt7986/mt7986_rfb.c | 54 ++++++++++++++++++++++++++++++
 4 files changed, 182 insertions(+)

--- a/board/mediatek/mt7622/mt7622_rfb.c
+++ b/board/mediatek/mt7622/mt7622_rfb.c
@@ -10,6 +10,11 @@
 #include <init.h>
 #include <asm/global_data.h>
 
+#include <mtd.h>
+#include <linux/mtd/mtd.h>
+#include <nmbm/nmbm.h>
+#include <nmbm/nmbm-mtd.h>
+
 DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
@@ -24,3 +29,36 @@ int board_late_init(void)
 	env_relocate();
 	return 0;
 }
+
+int board_nmbm_init(void)
+{
+#ifdef CONFIG_ENABLE_NAND_NMBM
+	struct mtd_info *lower, *upper;
+	int ret;
+
+	printf("\n");
+	printf("Initializing NMBM ...\n");
+
+	mtd_probe_devices();
+
+	lower = get_mtd_device_nm("spi-nand0");
+	if (IS_ERR(lower) || !lower) {
+		printf("Lower MTD device 'spi-nand0' not found\n");
+		return 0;
+	}
+
+	ret = nmbm_attach_mtd(lower,
+			      NMBM_F_CREATE | NMBM_F_EMPTY_PAGE_ECC_OK,
+			      CONFIG_NMBM_MAX_RATIO,
+			      CONFIG_NMBM_MAX_BLOCKS, &upper);
+
+	printf("\n");
+
+	if (ret)
+		return 0;
+
+	add_mtd_device(upper);
+#endif
+
+	return 0;
+}
--- a/board/mediatek/mt7629/mt7629_rfb.c
+++ b/board/mediatek/mt7629/mt7629_rfb.c
@@ -6,6 +6,11 @@
 #include <common.h>
 #include <asm/global_data.h>
 
+#include <mtd.h>
+#include <linux/mtd/mtd.h>
+#include <nmbm/nmbm.h>
+#include <nmbm/nmbm-mtd.h>
+
 DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
@@ -20,3 +25,36 @@ uint32_t spl_nand_get_uboot_raw_page(voi
 {
 	return CONFIG_SPL_PAD_TO;
 }
+
+int board_nmbm_init(void)
+{
+#ifdef CONFIG_ENABLE_NAND_NMBM
+	struct mtd_info *lower, *upper;
+	int ret;
+
+	printf("\n");
+	printf("Initializing NMBM ...\n");
+
+	mtd_probe_devices();
+
+	lower = get_mtd_device_nm("spi-nand0");
+	if (IS_ERR(lower) || !lower) {
+		printf("Lower MTD device 'spi-nand0' not found\n");
+		return 0;
+	}
+
+	ret = nmbm_attach_mtd(lower,
+			      NMBM_F_CREATE | NMBM_F_EMPTY_PAGE_ECC_OK,
+			      CONFIG_NMBM_MAX_RATIO,
+			      CONFIG_NMBM_MAX_BLOCKS, &upper);
+
+	printf("\n");
+
+	if (ret)
+		return 0;
+
+	add_mtd_device(upper);
+#endif
+
+	return 0;
+}
--- a/board/mediatek/mt7981/mt7981_rfb.c
+++ b/board/mediatek/mt7981/mt7981_rfb.c
@@ -4,7 +4,58 @@
  * Author: Sam Shih <sam.shih@mediatek.com>
  */
 
+#include <common.h>
+#include <config.h>
+#include <env.h>
+#include <init.h>
+#include <asm/global_data.h>
+
+#include <mtd.h>
+#include <linux/mtd/mtd.h>
+#include <nmbm/nmbm.h>
+#include <nmbm/nmbm-mtd.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
 int board_init(void)
 {
 	return 0;
 }
+
+int board_late_init(void)
+{
+	gd->env_valid = 1; //to load environment variable from persistent store
+	env_relocate();
+	return 0;
+}
+
+int board_nmbm_init(void)
+{
+#ifdef CONFIG_ENABLE_NAND_NMBM
+	struct mtd_info *lower, *upper;
+	int ret;
+
+	printf("\n");
+	printf("Initializing NMBM ...\n");
+
+	mtd_probe_devices();
+
+	lower = get_mtd_device_nm("spi-nand0");
+	if (IS_ERR(lower) || !lower) {
+		printf("Lower MTD device 'spi-nand0' not found\n");
+		return 0;
+	}
+
+	ret = nmbm_attach_mtd(lower, NMBM_F_CREATE, CONFIG_NMBM_MAX_RATIO,
+		CONFIG_NMBM_MAX_BLOCKS, &upper);
+
+	printf("\n");
+
+	if (ret)
+		return 0;
+
+	add_mtd_device(upper);
+#endif
+
+	return 0;
+}
--- a/board/mediatek/mt7986/mt7986_rfb.c
+++ b/board/mediatek/mt7986/mt7986_rfb.c
@@ -4,7 +4,60 @@
  * Author: Sam Shih <sam.shih@mediatek.com>
  */
 
+#include <common.h>
+#include <config.h>
+#include <env.h>
+#include <init.h>
+#include <asm/global_data.h>
+
+#include <mtd.h>
+#include <linux/mtd/mtd.h>
+#include <nmbm/nmbm.h>
+#include <nmbm/nmbm-mtd.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
 int board_init(void)
 {
 	return 0;
 }
+
+int board_late_init(void)
+{
+	gd->env_valid = 1; //to load environment variable from persistent store
+	env_relocate();
+	return 0;
+}
+
+int board_nmbm_init(void)
+{
+#ifdef CONFIG_ENABLE_NAND_NMBM
+	struct mtd_info *lower, *upper;
+	int ret;
+
+	printf("\n");
+	printf("Initializing NMBM ...\n");
+
+	mtd_probe_devices();
+
+	lower = get_mtd_device_nm("spi-nand0");
+	if (IS_ERR(lower) || !lower) {
+		printf("Lower MTD device 'spi-nand0' not found\n");
+		return 0;
+	}
+
+	ret = nmbm_attach_mtd(lower,
+			      NMBM_F_CREATE | NMBM_F_EMPTY_PAGE_ECC_OK,
+			      CONFIG_NMBM_MAX_RATIO,
+			      CONFIG_NMBM_MAX_BLOCKS, &upper);
+
+	printf("\n");
+
+	if (ret)
+		return 0;
+
+	add_mtd_device(upper);
+#endif
+
+	return 0;
+}