From 18f6c4affc150133d4ef5b719071e23cfdb269b0 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Sat, 29 Dec 2018 18:36:41 +0800 Subject: [PATCH] common: mkimage: Fix mkimage failed with non root user For ntfs, the buildroot should contains: 83c061e7c9 rockchip: Select host-ntfs-3g 93224ddae4 ntfs-3g: Add host package b034138f2d ntfs-3g: Support directory copy Change-Id: Iaa5daf89272409904bb35b638b4c042246820b6e Signed-off-by: Jeffy Chen --- common/mk-image.sh | 70 +++++++++++++++++++++++++++------------------- common/mke2img.sh | 24 ---------------- 2 files changed, 41 insertions(+), 53 deletions(-) delete mode 100755 common/mke2img.sh diff --git a/common/mk-image.sh b/common/mk-image.sh index f38e13b..302df30 100755 --- a/common/mk-image.sh +++ b/common/mk-image.sh @@ -1,8 +1,13 @@ #!/bin/bash +if [ -d "$TARGET_OUTPUT_DIR" ];then + HOST_DIR=$TARGET_OUTPUT_DIR/host + export PATH=$HOST_DIR/usr/sbin:$HOST_DIR/usr/bin:$HOST_DIR/sbin:$HOST_DIR/bin:$PATH +fi + fatal() { - echo $@ + echo -e "FATAL: " $@ exit 1 } @@ -42,39 +47,46 @@ mkimage_auto_sized() done } -create_image() +copy_to_ntfs() { - dd of=$TARGET bs=1M seek=$SIZE count=0 2>&1 || fatal "Failed to dd image!" - case $FS_TYPE in - ext[234]) - # Set max-mount-counts to 2, and disable the time-dependent checking. - mke2fs $TARGET && tune2fs -c 2 -i 0 $TARGET - ;; - msdos|fat|vfat) - # Use fat32 by default - mkfs.vfat -F 32 $TARGET - ;; - ntfs) - # Enable compression - mkntfs -FCQ $TARGET - ;; - esac + DEPTH=1 + while true;do + DIRS=$(find $SRC_DIR -maxdepth $DEPTH -mindepth $DEPTH -type d|xargs) + [ $DIRS ] || break + for dir in $DIRS;do + ntfscp $TARGET $dir ${dir#$SRC_DIR} || \ + fatal "Please update buildroot to: \n83c061e7c9 rockchip: Select host-ntfs-3g" + done + DEPTH=$(($DEPTH + 1)) + done + + FILES=$(find $SRC_DIR -type f|xargs) + for file in $FILES;do + ntfscp $TARGET $file ${file#$SRC_DIR} || \ + fatal "Failed to do ntfscp!" + done } mkimage() { echo "Making $TARGET from $SRC_DIR with size(${SIZE}M)" - create_image >/dev/null|| fatal "Failed to create empty image!" - - FAILED= - mkdir $TEMP - mount $TARGET $TEMP - cp -rp $SRC_DIR/* $TEMP || FAILED=1 - umount $TEMP - rm -rf $TEMP - - [ "$FAILED" ] && fatal "Failed to copy files!" - echo "Generated $TARGET" + dd of=$TARGET bs=1M seek=$SIZE count=0 2>&1 || fatal "Failed to dd image!" + case $FS_TYPE in + ext[234]) + # Set max-mount-counts to 2, and disable the time-dependent checking. + mke2fs $TARGET -d $SRC_DIR && tune2fs -c 2 -i 0 $TARGET + ;; + msdos|fat|vfat) + # Use fat32 by default + mkfs.vfat -F 32 $TARGET && \ + MTOOLS_SKIP_CHECK=1 \ + mcopy -bspmn -D s -i $TARGET $SRC_DIR/* ::/ + ;; + ntfs) + # Enable compression + mkntfs -FCQ $TARGET && copy_to_ntfs + ;; + esac } rm -rf $TARGET @@ -86,7 +98,7 @@ case $FS_TYPE in if [ ! "$SIZE" ]; then mkimage_auto_sized else - mkimage + mkimage && echo "Generated $TARGET" fi ;; *) diff --git a/common/mke2img.sh b/common/mke2img.sh deleted file mode 100755 index 2cb2b09..0000000 --- a/common/mke2img.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -SRC=$1 -DST=$2 -SIZE=`du -sk --apparent-size $SRC | cut --fields=1` -inode_counti=`find $SRC | wc -l` -inode_counti=$[inode_counti+512] -EXTRA_SIZE=$[inode_counti*4] - -MAX_RETRY=10 -RETRY=0 -while true;do - SIZE=$[SIZE+EXTRA_SIZE] - echo "genext2fs -b $SIZE -N $inode_counti -d $SRC $DST" - genext2fs -b $SIZE -N $inode_counti -d $SRC $DST && break - - RETRY=$[RETRY+1] - [ ! $RETRY -lt $MAX_RETRY ] && { echo "Failed to make e2fs image! "; exit; } - echo "Retring with increased size....($RETRY/$MAX_RETRY)" -done - -tune2fs -c 1 -i 0 $DST -resize2fs -M $DST -e2fsck -fy $DST