summaryrefslogtreecommitdiffstats
path: root/meta/packages/uboot/u-boot-mkimage-openmoko-native/nand-otp.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/uboot/u-boot-mkimage-openmoko-native/nand-otp.patch')
-rw-r--r--meta/packages/uboot/u-boot-mkimage-openmoko-native/nand-otp.patch302
1 files changed, 302 insertions, 0 deletions
diff --git a/meta/packages/uboot/u-boot-mkimage-openmoko-native/nand-otp.patch b/meta/packages/uboot/u-boot-mkimage-openmoko-native/nand-otp.patch
new file mode 100644
index 0000000000..b0e9bf4c4b
--- /dev/null
+++ b/meta/packages/uboot/u-boot-mkimage-openmoko-native/nand-otp.patch
@@ -0,0 +1,302 @@
1Index: u-boot/common/cmd_nand.c
2===================================================================
3--- u-boot.orig/common/cmd_nand.c
4+++ u-boot/common/cmd_nand.c
5@@ -392,6 +392,14 @@
6 else
7 ret = nand->write_oob(nand, off, size, &size,
8 (u_char *) addr);
9+ } else if (s != NULL && !strcmp(s, ".otp")) {
10+ /* read out-of-band data */
11+ if (read)
12+ ret = nand->read_otp(nand, off, size, &size,
13+ (u_char *) addr);
14+ else
15+ ret = nand->write_otp(nand, off, size, &size,
16+ (u_char *) addr);
17 } else {
18 if (read)
19 ret = nand_read(nand, off, &size, (u_char *)addr);
20@@ -527,8 +535,9 @@
21 "nand - NAND sub-system\n",
22 "info - show available NAND devices\n"
23 "nand device [dev] - show or set current device\n"
24- "nand read[.jffs2] - addr off|partition size\n"
25- "nand write[.jffs2] - addr off|partiton size - read/write `size' bytes starting\n"
26+ "nand read[.jffs2, .oob, .otp] addr off|partition size\n"
27+ "nand write[.jffs2, .oob, .otp] addr off|partiton size\n"
28+ " - read/write `size' bytes starting\n"
29 " at offset `off' to/from memory address `addr'\n"
30 "nand erase [clean] [off size] - erase `size' bytes from\n"
31 " offset `off' (entire device if not specified)\n"
32Index: u-boot/cpu/arm920t/s3c24x0/nand.c
33===================================================================
34--- u-boot.orig/cpu/arm920t/s3c24x0/nand.c
35+++ u-boot/cpu/arm920t/s3c24x0/nand.c
36@@ -205,7 +205,7 @@
37 }
38 #endif
39
40-int board_nand_init(struct nand_chip *nand)
41+int s3c24x0_nand_init(struct nand_chip *nand)
42 {
43 u_int32_t cfg;
44 u_int8_t tacls, twrph0, twrph1;
45Index: u-boot/drivers/nand/nand_base.c
46===================================================================
47--- u-boot.orig/drivers/nand/nand_base.c
48+++ u-boot/drivers/nand/nand_base.c
49@@ -2042,6 +2042,32 @@
50 }
51 #endif
52
53+/*
54+ * See nand_read_oob and nand_write_oob
55+ */
56+
57+static int nand_read_otp(struct mtd_info *mtd, loff_t from, size_t len,
58+ size_t *retlen, u_char *buf)
59+{
60+ struct nand_chip *this = mtd->priv;
61+
62+ if (!this->read_otp)
63+ return -ENOSYS;
64+ return this->read_otp(mtd, from, len, retlen, buf);
65+
66+}
67+
68+static int nand_write_otp(struct mtd_info *mtd, loff_t to, size_t len,
69+ size_t *retlen, const u_char *buf)
70+{
71+ struct nand_chip *this = mtd->priv;
72+
73+ if (!this->write_otp)
74+ return -ENOSYS;
75+ return this->write_otp(mtd, to, len, retlen, buf);
76+}
77+
78+
79 /**
80 * single_erease_cmd - [GENERIC] NAND standard block erase command function
81 * @mtd: MTD device structure
82@@ -2613,6 +2639,8 @@
83 mtd->write_ecc = nand_write_ecc;
84 mtd->read_oob = nand_read_oob;
85 mtd->write_oob = nand_write_oob;
86+ mtd->read_otp = nand_read_otp;
87+ mtd->write_otp = nand_write_otp;
88 /* XXX U-BOOT XXX */
89 #if 0
90 mtd->readv = NULL;
91Index: u-boot/include/linux/mtd/mtd.h
92===================================================================
93--- u-boot.orig/include/linux/mtd/mtd.h
94+++ u-boot/include/linux/mtd/mtd.h
95@@ -95,6 +95,9 @@
96 int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
97 int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
98
99+ int (*read_otp) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
100+ int (*write_otp) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
101+
102 /*
103 * Methods to access the protection register area, present in some
104 * flash devices. The user data is one time programmable but the
105Index: u-boot/include/linux/mtd/nand.h
106===================================================================
107--- u-boot.orig/include/linux/mtd/nand.h
108+++ u-boot/include/linux/mtd/nand.h
109@@ -307,6 +307,10 @@
110 void (*enable_hwecc)(struct mtd_info *mtd, int mode);
111 void (*erase_cmd)(struct mtd_info *mtd, int page);
112 int (*scan_bbt)(struct mtd_info *mtd);
113+ int (*read_otp)(struct mtd_info *mtd, loff_t from,
114+ size_t len, size_t *retlen, u_char *buf);
115+ int (*write_otp) (struct mtd_info *mtd, loff_t to,
116+ size_t len, size_t *retlen, const u_char *buf);
117 int eccmode;
118 int eccsize;
119 int eccbytes;
120Index: u-boot/board/neo1973/gta01/Makefile
121===================================================================
122--- u-boot.orig/board/neo1973/gta01/Makefile
123+++ u-boot/board/neo1973/gta01/Makefile
124@@ -25,7 +25,7 @@
125
126 LIB = lib$(BOARD).a
127
128-OBJS := gta01.o pcf50606.o ../common/cmd_neo1973.o ../common/jbt6k74.o ../common/udc.o ../common/bootmenu.o
129+OBJS := gta01.o pcf50606.o nand.o ../common/cmd_neo1973.o ../common/jbt6k74.o ../common/udc.o ../common/bootmenu.o
130 SOBJS := ../common/lowlevel_init.o
131
132 .PHONY: all
133Index: u-boot/board/neo1973/gta01/nand.c
134===================================================================
135--- /dev/null
136+++ u-boot/board/neo1973/gta01/nand.c
137@@ -0,0 +1,121 @@
138+/*
139+ * nand.c - Board-specific NAND setup
140+ *
141+ * Copyright (C) 2007 by OpenMoko, Inc.
142+ * Written by Werner Almesberger <werner@openmoko.org>
143+ * All Rights Reserved
144+ *
145+ * This program is free software; you can redistribute it and/or
146+ * modify it under the terms of the GNU General Public License as
147+ * published by the Free Software Foundation; either version 2 of
148+ * the License, or (at your option) any later version.
149+ *
150+ * This program is distributed in the hope that it will be useful,
151+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
152+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153+ * GNU General Public License for more details.
154+ *
155+ * You should have received a copy of the GNU General Public License
156+ * along with this program; if not, write to the Free Software
157+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
158+ * MA 02111-1307 USA
159+ */
160+
161+
162+#include "config.h" /* nand.h needs NAND_MAX_CHIPS */
163+#include "linux/mtd/mtd.h"
164+#include "linux/mtd/nand.h"
165+#include "asm/errno.h"
166+
167+
168+int s3c24x0_nand_init(struct nand_chip *nand);
169+
170+
171+static void samsung_nand_begin_otp(struct mtd_info *mtd)
172+{
173+ struct nand_chip *this = mtd->priv;
174+
175+ /* @@@FIXME: this is ugly - we select the NAND chip to send the
176+ mode switch commands, knowing that it will be switched off later */
177+ this->select_chip(mtd, 0);
178+ /* "magic" mode change */
179+ this->cmdfunc(mtd, 0x30, -1, -1);
180+ this->cmdfunc(mtd, 0x65, -1, -1);
181+}
182+
183+
184+static void samsung_nand_end_otp(struct mtd_info *mtd)
185+{
186+ struct nand_chip *this = mtd->priv;
187+
188+ /* read/write deselected the chip so now we need to select again */
189+ this->select_chip(mtd, 0);
190+ this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
191+ this->select_chip(mtd, -1);
192+}
193+
194+
195+static loff_t otp_page[] = {
196+ 0x15, /* 00-XX-00-00, with XX = 15h-19h */
197+ 0x16,
198+ 0x17,
199+ 0x18,
200+ 0x19,
201+ 0x1b, /* 00-1B-00-00 */
202+};
203+
204+#define OTP_PAGES (sizeof(otp_page)/sizeof(*otp_page))
205+
206+
207+static int convert_otp_address(loff_t *addr, size_t *len)
208+{
209+ int page;
210+
211+ if (*len && *addr >> 9 != (*addr+*len-1) >> 9)
212+ return -EINVAL;
213+ if (*len > 512)
214+ return -EINVAL;
215+ page = *addr >> 9;
216+ if (page >= OTP_PAGES)
217+ return -EINVAL;
218+ *addr = otp_page[page] << 9;
219+ return 0;
220+}
221+
222+
223+static int samsung_nand_read_otp(struct mtd_info *mtd, loff_t from,
224+ size_t len, size_t *retlen, u_char *buf)
225+{
226+ int ret;
227+
228+ ret = convert_otp_address(&from, &len);
229+ if (ret)
230+ return ret;
231+ samsung_nand_begin_otp(mtd);
232+ ret = mtd->read(mtd, from, len, retlen, buf);
233+ samsung_nand_end_otp(mtd);
234+ return ret;
235+}
236+
237+
238+static int samsung_nand_write_otp(struct mtd_info *mtd, loff_t to,
239+ size_t len, size_t *retlen, const u_char *buf)
240+{
241+ int ret;
242+
243+ ret = convert_otp_address(&to, &len);
244+ if (ret)
245+ return ret;
246+ samsung_nand_begin_otp(mtd);
247+ ret = mtd->write(mtd, to, len, retlen, buf);
248+ samsung_nand_end_otp(mtd);
249+ return ret;
250+}
251+
252+
253+int board_nand_init(struct nand_chip *nand)
254+{
255+ nand->read_otp = samsung_nand_read_otp;
256+ nand->write_otp = samsung_nand_write_otp;
257+ return s3c24x0_nand_init(nand);
258+}
259Index: u-boot/board/neo1973/gta02/nand.c
260===================================================================
261--- /dev/null
262+++ u-boot/board/neo1973/gta02/nand.c
263@@ -0,0 +1,39 @@
264+/*
265+ * nand.c - Board-specific NAND setup
266+ *
267+ * Copyright (C) 2007 by OpenMoko, Inc.
268+ * Written by Werner Almesberger <werner@openmoko.org>
269+ * All Rights Reserved
270+ *
271+ * This program is free software; you can redistribute it and/or
272+ * modify it under the terms of the GNU General Public License as
273+ * published by the Free Software Foundation; either version 2 of
274+ * the License, or (at your option) any later version.
275+ *
276+ * This program is distributed in the hope that it will be useful,
277+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
278+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
279+ * GNU General Public License for more details.
280+ *
281+ * You should have received a copy of the GNU General Public License
282+ * along with this program; if not, write to the Free Software
283+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
284+ * MA 02111-1307 USA
285+ */
286+
287+
288+#include "config.h" /* nand.h needs NAND_MAX_CHIPS */
289+#include "linux/mtd/mtd.h"
290+#include "linux/mtd/nand.h"
291+
292+
293+int s3c24x0_nand_init(struct nand_chip *nand);
294+
295+
296+/* Add OTP et al later */
297+
298+
299+int board_nand_init(struct nand_chip *nand)
300+{
301+ return s3c24x0_nand_init(nand);
302+}