diff --git a/tools/build/cross-build/mkimg/Makefile b/tools/build/cross-build/mkimg/Makefile new file mode 100644 index 000000000000..932f6150f118 --- /dev/null +++ b/tools/build/cross-build/mkimg/Makefile @@ -0,0 +1,27 @@ +# $FreeBSD$ + +# allow building mkimg as a host tool. + +MKIMG_SRC = ${SRCTOP}/usr.bin/mkimg +.PATH: ${MKIMG_SRC} + +.if ${.MAKE.OS} == "Linux" +WARNS= 0 + +CFLAGS+= \ + -D"__FBSDID(x)=" \ + -D_XOPEN_SOURCE -D_GNU_SOURCE + +.PATH: ${SRCTOP}/lib/libutil +SRCS+= expand_number.c + +.endif + +MK_STAGING=no +MK_TESTS= no + +.include <${MKIMG_SRC}/Makefile> + +.if ${.MAKE.OS} == "Linux" +LDADD+= -lbsd +.endif diff --git a/tools/build/cross-build/mkimg/Makefile.depend b/tools/build/cross-build/mkimg/Makefile.depend new file mode 100644 index 000000000000..f80275d86ab1 --- /dev/null +++ b/tools/build/cross-build/mkimg/Makefile.depend @@ -0,0 +1,11 @@ +# $FreeBSD$ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + + +.include + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif 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 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);