3 @@ -7,6 +7,11 @@ ifeq ($(WITHOUT_XATTR), 1)
4 CPPFLAGS += -DWITHOUT_XATTR
7 +ifeq ($(shell uname -o),Cygwin)
8 +CPPFLAGS += -I./include/cygwin
11 +ifneq ($(shell uname -o),Cygwin)
12 SUBDIRS = lib ubi-utils mkfs.ubifs
14 TARGETS = ftl_format flash_erase nanddump doc_loadbios \
15 @@ -17,6 +22,10 @@ TARGETS = ftl_format flash_erase nanddum
17 serve_image recv_image \
23 SCRIPTS = flash_eraseall
27 +++ b/include/cygwin/bits-byteswap.h
29 +/* Macros to swap the order of bytes in integer values.
30 + Copyright (C) 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
31 + This file is part of the GNU C Library.
33 + The GNU C Library is free software; you can redistribute it and/or
34 + modify it under the terms of the GNU Lesser General Public
35 + License as published by the Free Software Foundation; either
36 + version 2.1 of the License, or (at your option) any later version.
38 + The GNU C Library is distributed in the hope that it will be useful,
39 + but WITHOUT ANY WARRANTY; without even the implied warranty of
40 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41 + Lesser General Public License for more details.
43 + You should have received a copy of the GNU Lesser General Public
44 + License along with the GNU C Library; if not, write to the Free
45 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
48 +#if !defined _BYTESWAP_H && !defined _NETINET_IN_H
49 +# error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
52 +#ifndef _BITS_BYTESWAP_H
53 +#define _BITS_BYTESWAP_H 1
55 +/* Swap bytes in 16 bit value. */
56 +#define __bswap_constant_16(x) \
57 + ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
61 +# define __bswap_16(x) \
63 + ({ register unsigned short int __v, __x = (x); \
64 + if (__builtin_constant_p (__x)) \
65 + __v = __bswap_constant_16 (__x); \
67 + __asm__ ("rorw $8, %w0" \
73 +/* This is better than nothing. */
74 +# define __bswap_16(x) \
76 + ({ register unsigned short int __x = (x); __bswap_constant_16 (__x); }))
79 +static __inline unsigned short int
80 +__bswap_16 (unsigned short int __bsx)
82 + return __bswap_constant_16 (__bsx);
86 +/* Swap bytes in 32 bit value. */
87 +#define __bswap_constant_32(x) \
88 + ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
89 + (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
93 +/* To swap the bytes in a word the i486 processors and up provide the
94 + `bswap' opcode. On i386 we have to use three instructions. */
95 +# if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
96 +# define __bswap_32(x) \
98 + ({ register unsigned int __v, __x = (x); \
99 + if (__builtin_constant_p (__x)) \
100 + __v = __bswap_constant_32 (__x); \
102 + __asm__ ("rorw $8, %w0;" \
110 +# define __bswap_32(x) \
112 + ({ register unsigned int __v, __x = (x); \
113 + if (__builtin_constant_p (__x)) \
114 + __v = __bswap_constant_32 (__x); \
116 + __asm__ ("bswap %0" : "=r" (__v) : "0" (__x)); \
120 +# define __bswap_32(x) \
122 + ({ register unsigned int __x = (x); __bswap_constant_32 (__x); }))
125 +static __inline unsigned int
126 +__bswap_32 (unsigned int __bsx)
128 + return __bswap_constant_32 (__bsx);
133 +#if defined __GNUC__ && __GNUC__ >= 2
134 +/* Swap bytes in 64 bit value. */
135 +#define __bswap_constant_64(x) \
136 + ((((x) & 0xff00000000000000ull) >> 56) \
137 + | (((x) & 0x00ff000000000000ull) >> 40) \
138 + | (((x) & 0x0000ff0000000000ull) >> 24) \
139 + | (((x) & 0x000000ff00000000ull) >> 8) \
140 + | (((x) & 0x00000000ff000000ull) << 8) \
141 + | (((x) & 0x0000000000ff0000ull) << 24) \
142 + | (((x) & 0x000000000000ff00ull) << 40) \
143 + | (((x) & 0x00000000000000ffull) << 56))
145 +# define __bswap_64(x) \
147 + ({ union { __extension__ unsigned long long int __ll; \
148 + unsigned long int __l[2]; } __w, __r; \
149 + if (__builtin_constant_p (x)) \
150 + __r.__ll = __bswap_constant_64 (x); \
154 + __r.__l[0] = __bswap_32 (__w.__l[1]); \
155 + __r.__l[1] = __bswap_32 (__w.__l[0]); \
160 +#endif /* _BITS_BYTESWAP_H */
162 +++ b/include/cygwin/byteswap.h
164 +/* Copyright (C) 1997 Free Software Foundation, Inc.
165 + This file is part of the GNU C Library.
167 + The GNU C Library is free software; you can redistribute it and/or
168 + modify it under the terms of the GNU Lesser General Public
169 + License as published by the Free Software Foundation; either
170 + version 2.1 of the License, or (at your option) any later version.
172 + The GNU C Library is distributed in the hope that it will be useful,
173 + but WITHOUT ANY WARRANTY; without even the implied warranty of
174 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
175 + Lesser General Public License for more details.
177 + You should have received a copy of the GNU Lesser General Public
178 + License along with the GNU C Library; if not, write to the Free
179 + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
183 +#define _BYTESWAP_H 1
185 +/* Get the machine specific, optimized definitions. */
186 +#include "bits-byteswap.h"
189 +/* The following definitions must all be macros since otherwise some
190 + of the possible optimizations are not possible. */
192 +/* Return a value with all bytes in the 16 bit argument swapped. */
193 +#define bswap_16(x) __bswap_16 (x)
195 +/* Return a value with all bytes in the 32 bit argument swapped. */
196 +#define bswap_32(x) __bswap_32 (x)
198 +#if defined __GNUC__ && __GNUC__ >= 2
199 +/* Return a value with all bytes in the 64 bit argument swapped. */
200 +# define bswap_64(x) __bswap_64 (x)
203 +#endif /* byteswap.h */
205 +++ b/include/cygwin/endian.h
207 +#ifndef _CYGENDIAN_H_
208 +#define _CYGENDIAN_H_
212 +#include <sys/param.h>
214 +#ifndef __BIG_ENDIAN
215 +#define __BIG_ENDIAN 4321
218 +#ifndef __LITTLE_ENDIAN
219 +#define __LITTLE_ENDIAN 1234
222 +#ifndef __BYTE_ORDER
223 +#define __BYTE_ORDER __LITTLE_ENDIAN
227 +#define BYTE_ORDER __LITTLE_ENDIAN
230 +#endif /* __CYGWIN__ */
232 +#endif /* _CYGENDIAN_H_ */
234 +++ b/include/cygwin/ioctl.h
236 +#ifndef _CYGIOCTL_H_
237 +#define _CYGIOCTL_H_
241 +#define _IOC_NRBITS 8
242 +#define _IOC_TYPEBITS 8
243 +#define _IOC_SIZEBITS 14
244 +#define _IOC_DIRBITS 2
246 +#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
247 +#define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
248 +#define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
249 +#define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
251 +#define _IOC_NRSHIFT 0
252 +#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
253 +#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
254 +#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
256 +#define _IOC_NONE 0U
257 +#define _IOC_WRITE 1U
258 +#define _IOC_READ 2U
260 +#define _IOC(dir,type,nr,size) \
261 + (((dir) << _IOC_DIRSHIFT) | \
262 + ((type) << _IOC_TYPESHIFT) | \
263 + ((nr) << _IOC_NRSHIFT) | \
264 + ((size) << _IOC_SIZESHIFT))
266 +#define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
267 +#define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
268 +#define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
269 +#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
271 +#endif /* __CYGWIN__ */
273 +#endif /* _CYGIOCTL_H_ */
275 +++ b/include/cygwin/pread.c
282 +pread(int fd, void *p, size_t n, off_t off)
287 + if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
290 + n = read(fd, p, n);
293 + lseek(fd, ooff, SEEK_SET);
300 +pwrite(int fd, const void *p, size_t n, off_t off)
305 + if ((ooff = lseek(fd, off, SEEK_SET)) == -1)
308 + n = write(fd, p, n);
311 + lseek(fd, ooff, SEEK_SET);
317 +#endif /* __CYGWIN__ */
323 +# Generic configure replacement.
325 +# $Id: lnconf.sh,v 1.1 2004/04/05 21:55:59 igor Exp $
327 +# Copies all files from the script directory to the current one.
328 +# Intended to replace 'configure' for packages that don't have one, to
329 +# allow building outside of the source tree.
331 +# Note: this does not do any fancy things with detecting shells and
332 +# supporting other platforms. But it should work on Cygwin.
334 +# find out where the script is located
335 +tdir=`echo "$0" | sed 's%[\\/][^\\/][^\\/]*$%%'`
336 +test "x$tdir" = "x$0" && tdir=.
338 +a_srcdir=`cd $tdir; pwd`
342 +# are we in the script directory?
343 +test "x$a_srcdir" = "x$a_destdir" && exit 0
344 +# is there any chance that this is the script directory?
345 +test "x`cd "$a_srcdir" && /bin/ls -id`" = "x`/bin/ls -id`" && exit 0
347 +# try to find lndir and use it if it's available
348 +LNDIR="`which lndir 2>/dev/null`"
349 +if [ "x$LNDIR" = "x" ]; then
351 + test "x$1" = "x" && return 1
352 + # be careful of the current directory
353 + DINODE=`find . -maxdepth 0 -ls | sed 's/ .*$//'`
355 + "`cd "$1" && pwd`"/*) CUR="-type d -inum $DINODE -prune -o";;
357 + # duplicate the directory structure
358 + (cd "$1" && find . $CUR -type d -mindepth 1 -print) | xargs -tr mkdir -p
359 + # copy all symbolic links
360 + (cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri sh -c "ln -s \"\`readlink "$1/{}"\`\" \"{}\""
362 + #(cd "$1" && find . $CUR -type l -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
364 + (cd "$1" && find . $CUR -type f -mindepth 1 -print) | xargs -ri ln -s "$1"/{} {}
381 +#include <cygwin/ioctl.h>
382 +#include <cygwin/endian.h>
383 +#include <cygwin/pread.c>
384 +# define IFTODT(mode) (((mode) & 0170000) >> 12)
385 +# define DTTOIF(dirtype) ((dirtype) << 12)
386 +#endif /* __CYGWIN__ */
388 /* Do not use the weird XPG version of basename */
391 @@ -375,7 +383,7 @@ static struct filesystem_entry *recursiv
392 the following macros use it if available or use a hacky workaround...
396 +#if defined __GNUC__ && !defined __CYGWIN__
397 #define SCANF_PREFIX "a"
398 #define SCANF_STRING(s) (&s)
399 #define GETCWD_SIZE 0
400 @@ -458,6 +466,14 @@ static int interpret_table_entry(struct
402 entry = find_filesystem_entry(root, name, mode);
404 + /* Check the type */
405 + if ((mode & S_IFMT) != (entry->sb.st_mode & S_IFMT)) {
406 + error_msg ("skipping device_table entry '%s': type mismatch!", name);
412 /* Ok, we just need to fixup the existing entry
413 * and we will be all done... */
414 entry->sb.st_uid = uid;
415 @@ -467,11 +483,21 @@ static int interpret_table_entry(struct
416 entry->sb.st_rdev = makedev(major, minor);
419 + if (type == 'f' || type == 'l') {
420 + error_msg ("skipping device_table entry '%s': file does not exist!", name);
425 /* If parent is NULL (happens with device table entries),
426 * try and find our parent now) */
429 - parent = find_filesystem_entry(root, dir, S_IFDIR);
430 + if (!strcmp(dir, "/")) {
433 + parent = find_filesystem_entry(root, dir, S_IFDIR);
436 if (parent == NULL) {
437 errmsg ("skipping device_table entry '%s': no parent directory!", name);
438 @@ -485,6 +511,7 @@ static int interpret_table_entry(struct
439 add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
443 add_host_filesystem_entry(name, hostpath, uid, gid, mode, 0, parent);
446 --- a/ubi-utils/src/libubi.c
447 +++ b/ubi-utils/src/libubi.c
449 #include <sys/ioctl.h>
450 #include <sys/stat.h>
451 #include <sys/types.h>
453 +#include <cygwin/ioctl.h>
456 #include "libubi_int.h"