diff options
author | Simon J. Gerraty <sjg@FreeBSD.org> | 2017-03-03 01:56:55 +0000 |
---|---|---|
committer | Simon J. Gerraty <sjg@FreeBSD.org> | 2017-03-03 01:56:55 +0000 |
commit | baf4abfc39b23cff5f51a217d67848605187f690 (patch) | |
tree | 8c31ab2452310d6587c36cc1203cd2d3c1039a10 /usr.bin | |
parent | 6d6e8a4a09747233468805ce373dc67ed37a8f49 (diff) | |
download | src-baf4abfc39b23cff5f51a217d67848605187f690.tar.gz src-baf4abfc39b23cff5f51a217d67848605187f690.zip |
Allow building mkimg as cross-tool
For linux the mmap offset must also be page aligned, and we
need to disable macros like __FBSDID()
Change the linux osdep_uuidgen() to use more portable gettimeofday().
Reviewed by: marcel
Notes
Notes:
svn path=/head/; revision=314577
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mkimg/Makefile | 2 | ||||
-rw-r--r-- | usr.bin/mkimg/image.c | 40 | ||||
-rw-r--r-- | usr.bin/mkimg/mkimg.h | 6 | ||||
-rw-r--r-- | usr.bin/mkimg/uuid.c | 8 |
4 files changed, 38 insertions, 18 deletions
diff --git a/usr.bin/mkimg/Makefile b/usr.bin/mkimg/Makefile index 492b451f3fe0..8edfc9bb76be 100644 --- a/usr.bin/mkimg/Makefile +++ b/usr.bin/mkimg/Makefile @@ -3,7 +3,7 @@ .include <src.opts.mk> PROG= mkimg -SRCS= format.c image.c mkimg.c scheme.c uuid.c +SRCS+= format.c image.c mkimg.c scheme.c uuid.c MAN= mkimg.1 MKIMG_VERSION=20161016 diff --git a/usr.bin/mkimg/image.c b/usr.bin/mkimg/image.c index 3e132e862eee..b9e51ebe9f3a 100644 --- a/usr.bin/mkimg/image.c +++ b/usr.bin/mkimg/image.c @@ -304,12 +304,20 @@ image_chunk_copyin(lba_t blk, void *buf, size_t sz, off_t ofs, int fd) */ static void * -image_file_map(int fd, off_t ofs, size_t sz) +image_file_map(int fd, off_t ofs, size_t sz, off_t *iofp) { void *ptr; size_t unit; int flags, prot; - + off_t x; + + /* On Linux anyway ofs must also be page aligned */ + if ((x = (ofs % image_swap_pgsz)) != 0) { + ofs -= x; + sz += x; + *iofp = x; + } else + *iofp = 0; unit = (secsz > image_swap_pgsz) ? secsz : image_swap_pgsz; assert((unit & (unit - 1)) == 0); @@ -347,6 +355,7 @@ image_copyin_stream(lba_t blk, int fd, uint64_t *sizep) size_t iosz; ssize_t rdsz; int error; + off_t iof; /* * This makes sure we're doing I/O in multiples of the page @@ -361,12 +370,12 @@ image_copyin_stream(lba_t blk, int fd, uint64_t *sizep) swofs = image_swap_alloc(iosz); if (swofs == -1LL) return (errno); - buffer = image_file_map(image_swap_fd, swofs, iosz); + buffer = image_file_map(image_swap_fd, swofs, iosz, &iof); if (buffer == NULL) return (errno); - rdsz = read(fd, buffer, iosz); + rdsz = read(fd, &buffer[iof], iosz); if (rdsz > 0) - error = image_chunk_copyin(blk, buffer, rdsz, swofs, + error = image_chunk_copyin(blk, &buffer[iof], rdsz, swofs, image_swap_fd); else if (rdsz < 0) error = errno; @@ -389,8 +398,9 @@ image_copyin_stream(lba_t blk, int fd, uint64_t *sizep) static int image_copyin_mapped(lba_t blk, int fd, uint64_t *sizep) { - off_t cur, data, end, hole, pos; - void *buf; + off_t cur, data, end, hole, pos, iof; + void *mp; + char *buf; uint64_t bytesize; size_t iosz, sz; int error; @@ -450,11 +460,12 @@ image_copyin_mapped(lba_t blk, int fd, uint64_t *sizep) sz = (pos - data > (off_t)iosz) ? iosz : (size_t)(pos - data); - buf = image_file_map(fd, data, sz); - if (buf != NULL) { + buf = mp = image_file_map(fd, data, sz, &iof); + if (mp != NULL) { + buf += iof; error = image_chunk_copyin(blk, buf, sz, data, fd); - image_file_unmap(buf, sz); + image_file_unmap(mp, sz); } else error = errno; @@ -564,19 +575,22 @@ image_copyout_zeroes(int fd, size_t count) static int image_copyout_file(int fd, size_t size, int ifd, off_t iofs) { - void *buf; + void *mp; + char *buf; size_t iosz, sz; int error; + off_t iof; iosz = secsz * image_swap_pgsz; while (size > 0) { sz = (size > iosz) ? iosz : size; - buf = image_file_map(ifd, iofs, sz); + buf = mp = image_file_map(ifd, iofs, sz, &iof); if (buf == NULL) return (errno); + buf += iof; error = image_copyout_memory(fd, sz, buf); - image_file_unmap(buf, sz); + image_file_unmap(mp, sz); if (error) return (error); size -= sz; diff --git a/usr.bin/mkimg/mkimg.h b/usr.bin/mkimg/mkimg.h index 70b14e3a113d..fc13828be869 100644 --- a/usr.bin/mkimg/mkimg.h +++ b/usr.bin/mkimg/mkimg.h @@ -104,4 +104,10 @@ typedef struct mkimg_uuid mkimg_uuid_t; void mkimg_uuid(mkimg_uuid_t *); void mkimg_uuid_enc(void *, const mkimg_uuid_t *); +#ifdef __linux__ +# if !defined(__unused) +# define __unused __attribute__ ((__unused__)) +# endif +#endif + #endif /* _MKIMG_MKIMG_H_ */ diff --git a/usr.bin/mkimg/uuid.c b/usr.bin/mkimg/uuid.c index 437675dbefef..e82135584d86 100644 --- a/usr.bin/mkimg/uuid.c +++ b/usr.bin/mkimg/uuid.c @@ -66,16 +66,16 @@ osdep_uuidgen(mkimg_uuid_t *uuid) static void osdep_uuidgen(mkimg_uuid_t *uuid) { - struct timespec tp; + struct timeval tv; uint64_t time = 0x01B21DD213814000LL; u_int i; uint16_t seq; - if (clock_gettime(CLOCK_REALTIME, &tp) == -1) + if (gettimeofday(&tv, NULL) == -1) abort(); - time += (uint64_t)tp.tv_sec * 10000000LL; - time += tp.tv_nsec / 100; + time += (uint64_t)tv.tv_sec * 10000000LL; + time += tv.tv_usec * 10; uuid->time_low = (uint32_t)time; uuid->time_mid = (uint16_t)(time >> 32); |