aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/ramips/patches-4.14/0037-mtd-cfi-cmdset-0002-force-word-write.patch
blob: 478af4cbc919ed9c9f6ea6dd08f65734ba5e33ee (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
From ee9081b2726a5ca8cde5497afdc5425e21ff8f8b Mon Sep 17 00:00:00 2001
From: John Crispin <blogic@openwrt.org>
Date: Mon, 15 Jul 2013 00:39:21 +0200
Subject: [PATCH 37/53] mtd: cfi cmdset 0002 force word write

---
 drivers/mtd/chips/cfi_cmdset_0002.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -40,7 +40,7 @@
 #include <linux/mtd/xip.h>
 
 #define AMD_BOOTLOC_BUG
-#define FORCE_WORD_WRITE 0
+#define FORCE_WORD_WRITE 1
 
 #define MAX_RETRIES 3
 
@@ -51,7 +51,9 @@
 
 static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *);
 static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
+#if !FORCE_WORD_WRITE
 static int cfi_amdstd_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
+#endif
 static int cfi_amdstd_erase_chip(struct mtd_info *, struct erase_info *);
 static int cfi_amdstd_erase_varsize(struct mtd_info *, struct erase_info *);
 static void cfi_amdstd_sync (struct mtd_info *);
@@ -202,6 +204,7 @@ static void fixup_amd_bootblock(struct m
 }
 #endif
 
+#if !FORCE_WORD_WRITE
 static void fixup_use_write_buffers(struct mtd_info *mtd)
 {
 	struct map_info *map = mtd->priv;
@@ -211,6 +214,7 @@ static void fixup_use_write_buffers(stru
 		mtd->_write = cfi_amdstd_write_buffers;
 	}
 }
+#endif /* !FORCE_WORD_WRITE */
 
 /* Atmel chips don't use the same PRI format as AMD chips */
 static void fixup_convert_atmel_pri(struct mtd_info *mtd)
@@ -1798,6 +1802,7 @@ static int cfi_amdstd_write_words(struct
 /*
  * FIXME: interleaved mode not tested, and probably not supported!
  */
+#if !FORCE_WORD_WRITE
 static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip,
 				    unsigned long adr, const u_char *buf,
 				    int len)
@@ -1926,7 +1931,6 @@ static int __xipram do_write_buffer(stru
 	return ret;
 }
 
-
 static int cfi_amdstd_write_buffers(struct mtd_info *mtd, loff_t to, size_t len,
 				    size_t *retlen, const u_char *buf)
 {
@@ -2001,6 +2005,7 @@ static int cfi_amdstd_write_buffers(stru
 
 	return 0;
 }
+#endif /* !FORCE_WORD_WRITE */
 
 /*
  * Wait for the flash chip to become ready to write data
f0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
--- busybox/modutils/insmod.c	2007-05-11 12:10:43.000000000 +0200
+++ busybox/modutils/insmod.c	2007-05-11 12:12:15.000000000 +0200
@@ -75,6 +75,30 @@
 extern int insmod_ng_main( int argc, char **argv);
 #endif
 
+static char *m_filename;
+static char *m_fullName;
+#define _PATH_MODULES	"/lib/modules"
+
+static int check_module_name_match(const char *filename, struct stat *statbuf,
+				   void *userdata, int depth)
+{
+	char *fullname = (char *) userdata;
+
+	if (fullname[0] == '\0')
+		return FALSE;
+	else {
+		char *tmp, *tmp1 = xstrdup(filename);
+		tmp = bb_get_last_path_component(tmp1);
+		if (strcmp(tmp, fullname) == 0) {
+			free(tmp1);
+			/* Stop searching if we find a match */
+			m_filename = xstrdup(filename);
+			return FALSE;
+		}
+		free(tmp1);
+	}
+	return TRUE;
+}
 
 #if ENABLE_FEATURE_2_4_MODULES
 
@@ -680,7 +704,6 @@
 #endif
 
 
-#define _PATH_MODULES	"/lib/modules"
 enum { STRVERSIONLEN = 64 };
 
 /*======================================================================*/
@@ -793,37 +816,6 @@
 static int n_ext_modules_used;
 extern int delete_module(const char *);
 
-static char *m_filename;
-static char *m_fullName;
-
-
-/*======================================================================*/
-
-
-static int check_module_name_match(const char *filename, struct stat *statbuf,
-				void *userdata, int depth)
-{
-	char *fullname = (char *) userdata;
-
-	if (fullname[0] == '\0')
-		return FALSE;
-	else {
-		char *tmp, *tmp1 = xstrdup(filename);
-		tmp = bb_get_last_path_component(tmp1);
-		if (strcmp(tmp, fullname) == 0) {
-			free(tmp1);
-			/* Stop searching if we find a match */
-			m_filename = xstrdup(filename);
-			return FALSE;
-		}
-		free(tmp1);
-	}
-	return TRUE;
-}
-
-
-/*======================================================================*/
-
 static struct obj_file *arch_new_file(void)
 {
 	struct arch_file *f;
@@ -4265,14 +4257,97 @@
 	long ret;
 	size_t len;
 	void *map;
-	char *filename, *options;
+	char *options, *tmp;
+	struct stat st;
+#if ENABLE_FEATURE_CLEAN_UP
+	FILE *fp = 0;
+#else
+	FILE *fp;
+#endif
+	int k_version = 0;
+	struct utsname myuname;
 
-	filename = *++argv;
-	if (!filename)
+	if (argc < 2)
 		bb_show_usage();
 
+#if !ENABLE_FEATURE_2_4_MODULES
+	/* Grab the module name */
+	tmp = basename(xstrdup(argv[1]));
+	len = strlen(tmp);
+
+	if (uname(&myuname) == 0) {
+		if (myuname.release[0] == '2') {
+			k_version = myuname.release[2] - '0';
+		}
+	}
+
+	if (len > 3 && tmp[len - 3] == '.' && tmp[len - 2] == 'k' && tmp[len - 1] == 'o') {
+		len -= 3;
+		tmp[len] = '\0';
+	   }
+
+
+		   m_fullName = xasprintf("%s.ko", tmp);
+
+		   /* Get a filedesc for the module.  Check we we have a complete path */
+		   if (stat(argv[1], &st) < 0 || !S_ISREG(st.st_mode)
+				     || (fp = fopen(argv[1], "r")) == NULL
+		      ) {
+		/* Hmm.  Could not open it.  First search under /lib/modules/`uname -r`,
+		* but do not error out yet if we fail to find it... */
+			   if (k_version) {	/* uname succeedd */
+				   char *module_dir;
+				   char *tmdn;
+				   char real_module_dir[FILENAME_MAX];
+
+				   tmdn = concat_path_file(_PATH_MODULES, myuname.release);
+			/* Jump through hoops in case /lib/modules/`uname -r`
+				   * is a symlink.  We do not want recursive_action to
+				   * follow symlinks, but we do want to follow the
+				   * /lib/modules/`uname -r` dir, So resolve it ourselves
+			* if it is a link... */
+				   if (realpath(tmdn, real_module_dir) == NULL)
+					   module_dir = tmdn;
+				   else
+					   module_dir = real_module_dir;
+				   recursive_action(module_dir, TRUE, FALSE, FALSE,
+						   check_module_name_match, 0, m_fullName, 0);
+				   free(tmdn);
+			   }
+
+			   /* Check if we have found anything yet */
+			   if (m_filename == 0 || ((fp = fopen(m_filename, "r")) == NULL)) {
+				   char module_dir[FILENAME_MAX];
+
+				   free(m_filename);
+				   m_filename = 0;
+				   if (realpath (_PATH_MODULES, module_dir) == NULL)
+					   strcpy(module_dir, _PATH_MODULES);
+			/* No module found under /lib/modules/`uname -r`, this
+			* time cast the net a bit wider.  Search /lib/modules/ */
+				   if (!recursive_action(module_dir, TRUE, FALSE, FALSE,
+					check_module_name_match, 0, m_fullName, 0)
+				      ) {
+					   if (m_filename == 0
+										|| ((fp = fopen(m_filename, "r")) == NULL)
+					      ) {
+						   bb_error_msg("%s: no module by that name found", m_fullName);
+#if ENABLE_FEATURE_CLEAN_UP
+							if(fp)
+								fclose(fp);
+							free(m_filename);
+#endif
+					      }
+				      } else
+					      bb_error_msg_and_die("%s: no module by that name found", m_fullName);
+			   }
+		      } else
+			      m_filename = xstrdup(argv[1]);
+#endif
+
 	/* Rest is options */
 	options = xstrdup("");
+	argv++;
 	while (*++argv) {
 		int optlen = strlen(options);
 		options = xrealloc(options, optlen + 2 + strlen(*argv) + 2);
@@ -4300,13 +4375,13 @@
 	}
 #else
 	len = MAXINT(ssize_t);
-	map = xmalloc_open_read_close(filename, &len);
+	map = xmalloc_open_read_close(m_filename, &len);
 #endif
 
 	ret = syscall(__NR_init_module, map, len, options);
 	if (ret != 0) {
 		bb_perror_msg_and_die("cannot insert '%s': %s (%li)",
-				filename, moderror(errno), ret);
+				m_filename, moderror(errno), ret);
 	}
 
 	return 0;