mkimage: get rid of parted; use sfdisk(8).

This commit is contained in:
Juan RP 2016-04-26 15:00:55 +02:00
parent be2251492f
commit 6372530837
2 changed files with 13 additions and 12 deletions

View File

@ -11,7 +11,6 @@ This repository contains utilities for Void Linux:
#### Dependencies #### Dependencies
* xbps>=0.45 * xbps>=0.45
* parted (for mkimage)
* qemu-user-static binaries (for mkrootfs) * qemu-user-static binaries (for mkrootfs)
#### Usage #### Usage

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
#- #-
# Copyright (c) 2013-2015 Juan Romero Pardines. # Copyright (c) 2013-2016 Juan Romero Pardines.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
@ -56,11 +56,11 @@ Usage: $PROGNAME [options] <rootfs-tarball>
The <rootfs-tarball> argument expects a tarball generated by void-mkrootfs. The <rootfs-tarball> argument expects a tarball generated by void-mkrootfs.
The platform is guessed automatically by its name. The platform is guessed automatically by its name.
Accepted sizes suffixes: K, M, G, T, E. Accepted sizes suffixes: KiB, MiB, GiB, TiB, EiB.
OPTIONS OPTIONS
-b <fstype> Set /boot filesystem type (defaults to FAT) -b <fstype> Set /boot filesystem type (defaults to FAT)
-B <bsize> Set /boot filesystem size (defaults to 64MB) -B <bsize> Set /boot filesystem size (defaults to 64MiB)
-r <fstype> Set / filesystem type (defaults to EXT4) -r <fstype> Set / filesystem type (defaults to EXT4)
-s <totalsize> Set total image size (defaults to 2GB) -s <totalsize> Set total image size (defaults to 2GB)
-o <output> Set image filename (guessed automatically) -o <output> Set image filename (guessed automatically)
@ -104,7 +104,7 @@ fi
: ${IMGSIZE:=2G} : ${IMGSIZE:=2G}
: ${BOOT_FSTYPE:=vfat} : ${BOOT_FSTYPE:=vfat}
: ${BOOT_FSSIZE:=64M} : ${BOOT_FSSIZE:=64MiB}
: ${ROOT_FSTYPE:=ext4} : ${ROOT_FSTYPE:=ext4}
if [ -z "$FILENAME" ]; then if [ -z "$FILENAME" ]; then
@ -117,7 +117,7 @@ case "$PLATFORM" in
*) die "The $PLATFORM is not supported, exiting..." *) die "The $PLATFORM is not supported, exiting..."
esac esac
for f in parted partx losetup mount mkfs.${BOOT_FSTYPE} mkfs.${ROOT_FSTYPE}; do for f in sfdisk partx losetup mount mkfs.${BOOT_FSTYPE} mkfs.${ROOT_FSTYPE}; do
if ! which ${f} >/dev/null; then if ! which ${f} >/dev/null; then
die "Cannot find ${f}, exiting." die "Cannot find ${f}, exiting."
fi fi
@ -143,17 +143,19 @@ if [ "$BOOT_FSTYPE" = "vfat" ]; then
fi fi
case "$PLATFORM" in case "$PLATFORM" in
cubieboard2|cubietruck|ci20*) cubieboard2|cubietruck|ci20*)
parted $FILENAME mkpart primary ext2 2048s ${ROOT_FSSIZE} 100% sfdisk ${FILENAME} <<_EOF
parted $FILENAME toggle 1 boot 2048,,L
_EOF
LOOPDEV=$(losetup --show --find --partscan $FILENAME) LOOPDEV=$(losetup --show --find --partscan $FILENAME)
mkfs.${ROOT_FSTYPE} $disable_journal ${LOOPDEV}p1 >/dev/null 2>&1 mkfs.${ROOT_FSTYPE} $disable_journal ${LOOPDEV}p1 >/dev/null 2>&1
mount ${LOOPDEV}p1 $ROOTFSDIR mount ${LOOPDEV}p1 $ROOTFSDIR
ROOT_UUID=$(blkid -o value -s UUID ${LOOPDEV}p1) ROOT_UUID=$(blkid -o value -s UUID ${LOOPDEV}p1)
;; ;;
*) *)
parted $FILENAME mkpart primary ${_btype} 2048s ${BOOT_FSSIZE} sfdisk ${FILENAME} <<_EOF
parted $FILENAME mkpart primary ext2 ${BOOT_FSSIZE} 100% 2048,${BOOT_FSSIZE},b
parted $FILENAME toggle 1 boot ${BOOT_SIZE},+,L,*
_EOF
LOOPDEV=$(losetup --show --find --partscan $FILENAME) LOOPDEV=$(losetup --show --find --partscan $FILENAME)
mkfs.${BOOT_FSTYPE} $_args ${LOOPDEV}p1 >/dev/null mkfs.${BOOT_FSTYPE} $_args ${LOOPDEV}p1 >/dev/null
case "$ROOT_FSTYPE" in case "$ROOT_FSTYPE" in
@ -201,7 +203,7 @@ usbarmory)
dd if=${ROOTFSDIR}/boot/u-boot.imx of=${LOOPDEV} bs=512 seek=2 conv=fsync >/dev/null 2>&1 dd if=${ROOTFSDIR}/boot/u-boot.imx of=${LOOPDEV} bs=512 seek=2 conv=fsync >/dev/null 2>&1
;; ;;
ci20) ci20)
ln -sf /boot/uImage ${ROOTFSDIR}/vmlinux.img cp -f ${ROOTFSDIR}/boot/uImage ${ROOTFSDIR}/boot/vmlinux.img
dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1 dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1
dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1 dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1
;; ;;