From: Neil Williams Date: Tue, 23 Dec 2014 16:15:20 +0000 (+0000) Subject: Allow space for a bootloader installed with dd X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=41ebf61957c1c3d168b5e048e465c6a7b0b57a1c;p=forks%2Fvmdebootstrap.git Allow space for a bootloader installed with dd Implement bootoffset to explcitly allow space for a bootloader to be installed in front of the first partition. Add support for cubietruck in the example to dd the Debian uboot image by adding a parameter to the customise script call. Increase size of boot partition to make upgrades easier. Allow the partition type to be specified. Use mib units as these are converted to 1024 instead of 1000. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..710c495 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.img +*.log diff --git a/examples/beagleboneblack.sh b/examples/beagleboneblack.sh index 3923949..30d0c4a 100755 --- a/examples/beagleboneblack.sh +++ b/examples/beagleboneblack.sh @@ -17,5 +17,5 @@ sudo vmdebootstrap \ --distribution sid \ --serial-console-command "'/sbin/getty -L ttyO0 115200 vt100'" \ --customize "beagleboneblack-customise.sh" \ - --bootsize 50m --boottype vfat \ + --bootsize 100mib --boottype vfat \ "$@" diff --git a/examples/cubietruck-customise.sh b/examples/cubietruck-customise.sh index 74a0d5b..4d436ae 100755 --- a/examples/cubietruck-customise.sh +++ b/examples/cubietruck-customise.sh @@ -3,10 +3,22 @@ set -e rootdir=$1 +image=$2 -# u-boot needs to be dd'd to the partition -#cp /usr/lib/u-boot/Cubietruck/uboot.elf /boot/ -#cp /usr/lib/u-boot/Cubietruck/u-boot-sunxi-with-spl.bin /boot/ +if [ -z "${image}" ]; then + echo "Image not specified" + exit +fi + +if [ ! -f '/usr/lib/u-boot/Cubietruck/u-boot-sunxi-with-spl.bin' ]; then + echo "Unable to find cubietruck u-boot file" + exit +fi + +# u-boot needs to be dd'd to the device, not a partition +# but kpartx does not setup the device, just the partitions + +dd if=/usr/lib/u-boot/Cubietruck/u-boot-sunxi-with-spl.bin of=${image} bs=1k seek=8 mkdir -p $rootdir/boot/dtbs cp $rootdir/usr/lib/linux-image-*-armmp/* $rootdir/boot/dtbs diff --git a/examples/cubietruck.sh b/examples/cubietruck.sh index 2da46af..a904e07 100755 --- a/examples/cubietruck.sh +++ b/examples/cubietruck.sh @@ -18,6 +18,6 @@ sudo vmdebootstrap \ --distribution sid \ --serial-console-command "/sbin/getty -L ttyS0 115200 vt100" \ --customize "cubietruck-customise.sh" \ - --serial-console-command \ - --bootsize 50m --boottype vfat \ + --bootoffset=2mib \ + --bootsize 100mib --boottype vfat \ "$@" diff --git a/vmdebootstrap b/vmdebootstrap index aae437a..6f104da 100755 --- a/vmdebootstrap +++ b/vmdebootstrap @@ -292,17 +292,41 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth str(self.settings['size'])]) def partition_image(self): + """ + Uses fat16 (msdos) partitioning by default, use part-type to change. + If bootoffset is specified, the first actual partition + starts at that offset to allow customisation scripts to + put bootloader images into the space, e.g. u-boot. + """ self.message('Creating partitions') self.runcmd(['parted', '-s', self.settings['image'], - 'mklabel', 'msdos']) + 'mklabel', self.settings['part-type']]) + partoffset = 0 + bootsize = 0 + if self.settings['bootoffset'] and self.settings['bootoffset'] is not '0': + # turn v.small offsets into something at least possible to create. + if self.settings['bootoffset'] < 1048576: + partoffset = 1 + logging.info( + "Setting bootoffset %smib to allow for %s bytes", + partoffset, self.settings['bootoffset']) + else: + partoffset = self.settings['bootoffset'] / (1024 * 1024) + self.message("Using bootoffset: %smib %s bytes" % (partoffset, self.settings['bootoffset'])) if self.settings['bootsize'] and self.settings['bootsize'] is not '0%': - bootsize = str(self.settings['bootsize'] / (1024 * 1024)) + bootsize = self.settings['bootsize'] / (1024 * 1024) + bootsize += partoffset + self.message("Using bootsize %smib: %s bytes" % (bootsize, self.settings['bootsize'])) + logging.debug("Starting boot partition at %sMb", bootsize) self.runcmd(['parted', '-s', self.settings['image'], - 'mkpart', 'primary', 'fat16', '0%', bootsize]) + 'mkpart', 'primary', 'fat16', str(partoffset), str(bootsize)]) + if partoffset == 0: + self.runcmd(['parted', '-s', self.settings['image'], + 'mkpart', 'primary', '0%', '100%']) else: - bootsize = '0%' - self.runcmd(['parted', '-s', self.settings['image'], - 'mkpart', 'primary', bootsize, '100%']) + logging.debug("Starting root partition at %sMb", partoffset) + self.runcmd(['parted', '-s', self.settings['image'], + 'mkpart', 'primary', str(bootsize), '100%']) self.runcmd(['parted', '-s', self.settings['image'], 'set', '1', 'boot', 'on']) @@ -662,8 +686,9 @@ append initrd=%(initrd)s root=UUID=%(uuid)s ro %(kserial)s return script = example self.message('Running customize script %s' % script) + logging.info("rootdir=%s image=%s", rootdir, self.settings['image']) with open('/dev/tty', 'w') as tty: - cliapp.runcmd([script, rootdir], stdout=tty, stderr=tty) + cliapp.runcmd([script, rootdir, self.settings['image']], stdout=tty, stderr=tty) def create_tarball(self, rootdir): # Create a tarball of the disk's contents