From owner-svn-src-all@freebsd.org Fri Mar 3 01:56:56 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D0426CF50D9; Fri, 3 Mar 2017 01:56:56 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A6D3B1EC6; Fri, 3 Mar 2017 01:56:56 +0000 (UTC) (envelope-from sjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v231utRq003765; Fri, 3 Mar 2017 01:56:55 GMT (envelope-from sjg@FreeBSD.org) Received: (from sjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v231utup003760; Fri, 3 Mar 2017 01:56:55 GMT (envelope-from sjg@FreeBSD.org) Message-Id: <201703030156.v231utup003760@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sjg set sender to sjg@FreeBSD.org using -f From: "Simon J. Gerraty" Date: Fri, 3 Mar 2017 01:56:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314577 - in head: tools/build/cross-build/mkimg usr.bin/mkimg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2017 01:56:56 -0000 Author: sjg Date: Fri Mar 3 01:56:55 2017 New Revision: 314577 URL: https://svnweb.freebsd.org/changeset/base/314577 Log: 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 Added: head/tools/build/cross-build/mkimg/ head/tools/build/cross-build/mkimg/Makefile (contents, props changed) head/tools/build/cross-build/mkimg/Makefile.depend (contents, props changed) Modified: head/usr.bin/mkimg/Makefile head/usr.bin/mkimg/image.c head/usr.bin/mkimg/mkimg.h head/usr.bin/mkimg/uuid.c Added: head/tools/build/cross-build/mkimg/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/build/cross-build/mkimg/Makefile Fri Mar 3 01:56:55 2017 (r314577) @@ -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 Added: head/tools/build/cross-build/mkimg/Makefile.depend ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tools/build/cross-build/mkimg/Makefile.depend Fri Mar 3 01:56:55 2017 (r314577) @@ -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 Modified: head/usr.bin/mkimg/Makefile ============================================================================== --- head/usr.bin/mkimg/Makefile Fri Mar 3 01:50:10 2017 (r314576) +++ head/usr.bin/mkimg/Makefile Fri Mar 3 01:56:55 2017 (r314577) @@ -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 Modified: head/usr.bin/mkimg/image.c ============================================================================== --- head/usr.bin/mkimg/image.c Fri Mar 3 01:50:10 2017 (r314576) +++ head/usr.bin/mkimg/image.c Fri Mar 3 01:56:55 2017 (r314577) @@ -304,12 +304,20 @@ image_chunk_copyin(lba_t blk, void *buf, */ 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, u 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, u 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, u 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, u 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 coun 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; Modified: head/usr.bin/mkimg/mkimg.h ============================================================================== --- head/usr.bin/mkimg/mkimg.h Fri Mar 3 01:50:10 2017 (r314576) +++ head/usr.bin/mkimg/mkimg.h Fri Mar 3 01:56:55 2017 (r314577) @@ -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_ */ Modified: head/usr.bin/mkimg/uuid.c ============================================================================== --- head/usr.bin/mkimg/uuid.c Fri Mar 3 01:50:10 2017 (r314576) +++ head/usr.bin/mkimg/uuid.c Fri Mar 3 01:56:55 2017 (r314577) @@ -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);