xref: /openbmc/u-boot/include/ubi_uboot.h (revision f62fb999)
1 /*
2  * Header file for UBI support for U-Boot
3  *
4  * Adaptation from kernel to U-Boot
5  *
6  *  Copyright (C) 2005-2007 Samsung Electronics
7  *  Kyungmin Park <kyungmin.park@samsung.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 
14 #ifndef __UBOOT_UBI_H
15 #define __UBOOT_UBI_H
16 
17 #include <common.h>
18 #include <malloc.h>
19 #include <div64.h>
20 #include <linux/crc32.h>
21 #include <linux/mtd/mtd.h>
22 
23 #ifdef CONFIG_CMD_ONENAND
24 #include <onenand_uboot.h>
25 #endif
26 
27 #include <asm/errno.h>
28 
29 #define DPRINTK(format, args...)					\
30 do {									\
31 	printf("%s[%d]: " format "\n", __func__, __LINE__, ##args);	\
32 } while (0)
33 
34 /* configurable */
35 #define CONFIG_MTD_UBI_WL_THRESHOLD	4096
36 #define CONFIG_MTD_UBI_BEB_RESERVE	1
37 #define UBI_IO_DEBUG			0
38 
39 /* debug options (Linux: drivers/mtd/ubi/Kconfig.debug) */
40 #undef CONFIG_MTD_UBI_DEBUG
41 #undef CONFIG_MTD_UBI_DEBUG_PARANOID
42 #undef CONFIG_MTD_UBI_DEBUG_MSG
43 #undef CONFIG_MTD_UBI_DEBUG_MSG_EBA
44 #undef CONFIG_MTD_UBI_DEBUG_MSG_WL
45 #undef CONFIG_MTD_UBI_DEBUG_MSG_IO
46 #undef CONFIG_MTD_UBI_DEBUG_MSG_BLD
47 #define CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
48 
49 /* compiler options */
50 #define uninitialized_var(x)		x = x
51 
52 /* build.c */
53 #define get_device(...)
54 #define put_device(...)
55 #define ubi_sysfs_init(...)		0
56 #define ubi_sysfs_close(...)		do { } while (0)
57 static inline int is_power_of_2(unsigned long n)
58 {
59 	return (n != 0 && ((n & (n - 1)) == 0));
60 }
61 
62 /* FIXME */
63 #define MKDEV(...)			0
64 #define MAJOR(dev)			0
65 #define MINOR(dev)			0
66 
67 #define alloc_chrdev_region(...)	0
68 #define unregister_chrdev_region(...)
69 
70 #define class_create(...)		__builtin_return_address(0)
71 #define class_create_file(...)		0
72 #define class_remove_file(...)
73 #define class_destroy(...)
74 #define misc_register(...)		0
75 #define misc_deregister(...)
76 
77 /* vmt.c */
78 #define device_register(...)		0
79 #define volume_sysfs_init(...)		0
80 #define volume_sysfs_close(...)		do { } while (0)
81 
82 /* kapi.c */
83 
84 /* eba.c */
85 
86 /* io.c */
87 #define init_waitqueue_head(...)	do { } while (0)
88 #define wait_event_interruptible(...)	0
89 #define wake_up_interruptible(...)	do { } while (0)
90 #define print_hex_dump(...)		do { } while (0)
91 #define dump_stack(...)			do { } while (0)
92 
93 /* wl.c */
94 #define task_pid_nr(x)			0
95 #define set_freezable(...)		do { } while (0)
96 #define try_to_freeze(...)		0
97 #define set_current_state(...)		do { } while (0)
98 #define kthread_should_stop(...)	0
99 #define schedule()			do { } while (0)
100 
101 /* upd.c */
102 static inline unsigned long copy_from_user(void *dest, const void *src,
103 					   unsigned long count)
104 {
105 	memcpy((void *)dest, (void *)src, count);
106 	return 0;
107 }
108 
109 /* common */
110 typedef int	spinlock_t;
111 typedef int	wait_queue_head_t;
112 #define spin_lock_init(...)
113 #define spin_lock(...)
114 #define spin_unlock(...)
115 
116 #define mutex_init(...)
117 #define mutex_lock(...)
118 #define mutex_unlock(...)
119 
120 #define init_rwsem(...)			do { } while (0)
121 #define down_read(...)			do { } while (0)
122 #define down_write(...)			do { } while (0)
123 #define down_write_trylock(...)		0
124 #define up_read(...)			do { } while (0)
125 #define up_write(...)			do { } while (0)
126 
127 struct kmem_cache { int i; };
128 #define kmem_cache_create(...)		1
129 #define kmem_cache_alloc(obj, gfp)	malloc(sizeof(struct ubi_wl_entry))
130 #define kmem_cache_free(obj, size)	free(size)
131 #define kmem_cache_destroy(...)
132 
133 #define cond_resched()			do { } while (0)
134 #define yield()				do { } while (0)
135 
136 #define KERN_WARNING
137 #define KERN_ERR
138 #define KERN_NOTICE
139 #define KERN_DEBUG
140 
141 #define GFP_KERNEL			0
142 #define GFP_NOFS			1
143 
144 #define __user
145 #define __init
146 #define __exit
147 
148 #define kthread_create(...)	__builtin_return_address(0)
149 #define kthread_stop(...)	do { } while (0)
150 #define wake_up_process(...)	do { } while (0)
151 
152 #define BUS_ID_SIZE		20
153 
154 struct rw_semaphore { int i; };
155 struct device {
156 	struct device		*parent;
157 	struct class		*class;
158 	char	bus_id[BUS_ID_SIZE];	/* position on parent bus */
159 	dev_t			devt;	/* dev_t, creates the sysfs "dev" */
160 	void	(*release)(struct device *dev);
161 };
162 struct mutex { int i; };
163 struct kernel_param { int i; };
164 
165 struct cdev {
166 	int owner;
167 	dev_t dev;
168 };
169 #define cdev_init(...)		do { } while (0)
170 #define cdev_add(...)		0
171 #define cdev_del(...)		do { } while (0)
172 
173 #define MAX_ERRNO		4095
174 #define IS_ERR_VALUE(x)		((x) >= (unsigned long)-MAX_ERRNO)
175 
176 static inline void *ERR_PTR(long error)
177 {
178 	return (void *) error;
179 }
180 
181 static inline long PTR_ERR(const void *ptr)
182 {
183 	return (long) ptr;
184 }
185 
186 static inline long IS_ERR(const void *ptr)
187 {
188 	return IS_ERR_VALUE((unsigned long)ptr);
189 }
190 
191 /* Force a compilation error if condition is true */
192 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
193 
194 /* module */
195 #define THIS_MODULE		0
196 #define try_module_get(...)	0
197 #define module_put(...)		do { } while (0)
198 #define module_init(...)
199 #define module_exit(...)
200 #define EXPORT_SYMBOL(...)
201 #define EXPORT_SYMBOL_GPL(...)
202 #define module_param_call(...)
203 #define MODULE_PARM_DESC(...)
204 #define MODULE_VERSION(...)
205 #define MODULE_DESCRIPTION(...)
206 #define MODULE_AUTHOR(...)
207 #define MODULE_LICENSE(...)
208 
209 #include "../drivers/mtd/ubi/ubi.h"
210 
211 /* functions */
212 extern int ubi_mtd_param_parse(const char *val, struct kernel_param *kp);
213 extern int ubi_init(void);
214 extern void ubi_exit(void);
215 
216 extern struct ubi_device *ubi_devices[];
217 
218 #endif
219