Skip to contentSkip to conversation

UBI: Add basic UBI support to U-Boot (Part 6/8)

PATCH New Stefan Roese 1 participant 1 message Nov 19, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 7/11 UBI: Add basic UBI support to U-Boot (Part 6/8)

From: Kyungmin Park <[email protected]>

This patch adds basic UBI (Unsorted Block Image) support to U-Boot. It's based on the Linux UBI version and basically has a "OS" translation wrapper that defines most Linux specific calls (spin_lock() etc.) into no-ops. Some source code parts have been uncommented by "#ifdef UBI_LINUX". This makes it easier to compare this version with the Linux version and simplifies future UBI ports/bug-fixes from the Linux version.

---
 include/exports.h              |    1 +
 include/jffs2/load_kernel.h    |    5 +
 include/linux/crc32.h          |   27 +++++
 include/linux/mtd/partitions.h |   84 +++++++++++++++
 include/linux/types.h          |   24 +++++
 include/ubi_uboot.h            |  217 ++++++++++++++++++++++++++++++++++++++++
 lib_generic/vsprintf.c         |   23 ++++
 7 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/crc32.h
 create mode 100644 include/linux/mtd/partitions.h
 create mode 100644 include/ubi_uboot.h
include/exports.h +1 -0
index 6377875..0620e9e 100644
@@ -25,6 +25,7 @@ char *getenv (char *name);
 int setenv (char *varname, char *varvalue);
 long simple_strtol(const char *cp,char **endp,unsigned int base);
 int strcmp(const char * cs,const char * ct);
+int ustrtoul(const char *cp, char **endp, unsigned int base);
 #ifdef CONFIG_HAS_UID
 void forceenv (char *varname, char *varvalue);
 #endif
include/jffs2/load_kernel.h +5 -0
index 551fd0c..e9b7d6e 100644
@@ -73,4 +73,9 @@ struct mtdids {
 #define putLabeledWord(x, y)	printf("%s %08x\n", x, (unsigned int)y)
 #define led_blink(x, y, z, a)
 
+/* common/cmd_jffs2.c */
+extern int mtdparts_init(void);
+extern int find_dev_and_part(const char *id, struct mtd_device **dev,
+				u8 *part_num, struct part_info **part);
+
 #endif /* load_kernel_h */
include/linux/crc32.h new file +27 -0
new file mode 100644
index 0000000..e133157
@@ -0,0 +1,27 @@
+/*
+ * crc32.h
+ * See linux/lib/crc32.c for license and changes
+ */
+#ifndef _LINUX_CRC32_H
+#define _LINUX_CRC32_H
+
+#include <linux/types.h>
+//#include <linux/bitrev.h>
+
+extern u32  crc32_le(u32 crc, unsigned char const *p, size_t len);
+//extern u32  crc32_be(u32 crc, unsigned char const *p, size_t len);
+
+#define crc32(seed, data, length)  crc32_le(seed, (unsigned char const *)data, length)
+
+/*
+ * Helpers for hash table generation of ethernet nics:
+ *
+ * Ethernet sends the least significant bit of a byte first, thus crc32_le
+ * is used. The output of crc32_le is bit reversed [most significant bit
+ * is in bit nr 0], thus it must be reversed before use. Except for
+ * nics that bit swap the result internally...
+ */
+//#define ether_crc(length, data)    bitrev32(crc32_le(~0, data, length))
+//#define ether_crc_le(length, data) crc32_le(~0, data, length)
+
+#endif /* _LINUX_CRC32_H */
include/linux/mtd/partitions.h new file +84 -0

84 lines not on this page · raw message

include/linux/types.h +24 -0
index df4808f..1b0b4a4 100644
@@ -119,6 +119,30 @@ typedef		__s64		int64_t;
  * Below are truly Linux-specific types that should never collide with
  * any application/library that wants linux/types.h.
  */
+#ifdef __CHECKER__
+#define __bitwise__ __attribute__((bitwise))
+#else
+#define __bitwise__
+#endif
+#ifdef __CHECK_ENDIAN__
+#define __bitwise __bitwise__
+#else
+#define __bitwise
+#endif
+
+typedef __u16 __bitwise __le16;
+typedef __u16 __bitwise __be16;
+typedef __u32 __bitwise __le32;
+typedef __u32 __bitwise __be32;
+#if defined(__GNUC__)
+typedef __u64 __bitwise __le64;
+typedef __u64 __bitwise __be64;
+#endif
+typedef __u16 __bitwise __sum16;
+typedef __u32 __bitwise __wsum;
+
+
+typedef unsigned __bitwise__	gfp_t;
 
 struct ustat {
 	__kernel_daddr_t	f_tfree;
include/ubi_uboot.h new file +217 -0

217 lines not on this page · raw message

lib_generic/vsprintf.c +23 -0
index 6e903db..767dde1 100644
@@ -55,6 +55,29 @@ long simple_strtol(const char *cp,char **endp,unsigned int base)
 	return simple_strtoul(cp,endp,base);
 }
 
+int ustrtoul(const char *cp, char **endp, unsigned int base)
+{
+	unsigned long result = simple_strtoul(cp, endp, base);
+	switch (**endp) {
+	case 'G' :
+		result *= 1024;
+		/* fall through */
+	case 'M':
+		result *= 1024;
+		/* fall through */
+	case 'K':
+	case 'k':
+		result *= 1024;
+		if ((*endp)[1] == 'i') {
+			if ((*endp)[2] == 'B')
+				(*endp) += 3;
+			else
+				(*endp) += 2;
+		}
+	}
+	return result;
+}
+
 #ifdef CONFIG_SYS_64BIT_STRTOUL
 unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int base)
 {
Signature · 1 line
1.6.0.4