diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-01-07 00:56:11 +0100 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-07-05 20:17:21 +0200 |
commit | 89ab0d27c99ce4899829ab45001c0955db1149ab (patch) | |
tree | 9735cdba5977682103614a1c99992f1c1009bed7 /libre/uboot4extlinux-sunxi/install-uboot4extlinux.sh.in | |
parent | 5f989c87ef5056135de96820f697d825980d13e3 (diff) | |
download | abslibre-89ab0d27c99ce4899829ab45001c0955db1149ab.tar.gz abslibre-89ab0d27c99ce4899829ab45001c0955db1149ab.tar.bz2 abslibre-89ab0d27c99ce4899829ab45001c0955db1149ab.zip |
libre: uboot4extlinux-sunxi: lower maintenance costs
- We can now do cross builds of u-boot:
- We can now more easily work on the package as we don't need
an ARM computer for that anymore.
- It also enable people already using Parabola on x86 to more
easily install, test, or repair u-boot for an ARM computer
as users can simply install it on microSD cards without
needing to use ARM chroots.
- There is now an install script to install u-boot:
- It makes things easier for users as it is more similar to
grub-install than dd commands.
- It also does many checks at the same time to avoid data loss.
- The commands to split packages are now shared between all
package_ functions. This lower maintenance.
- How to add a new board has been made more clear.
Comparison with other distributions (for consistency):
- u-boot doesn't have anything to handle the installation and
update of u-boot binaries if UEFI is not used.
- Debian has an u-boot-install-sunxi script which handles way more
cases than what I wrote (it even handles GPT and so on and even
has a manual), but there seems to be no tools to update u-boot.
- Openembedded doesn't seem to have anything special in
the u-boot recipe in openembedded-core
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'libre/uboot4extlinux-sunxi/install-uboot4extlinux.sh.in')
-rw-r--r-- | libre/uboot4extlinux-sunxi/install-uboot4extlinux.sh.in | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/libre/uboot4extlinux-sunxi/install-uboot4extlinux.sh.in b/libre/uboot4extlinux-sunxi/install-uboot4extlinux.sh.in new file mode 100644 index 000000000..1c744f313 --- /dev/null +++ b/libre/uboot4extlinux-sunxi/install-uboot4extlinux.sh.in @@ -0,0 +1,88 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (C) 2020 Denis 'GNUtoo' Carikli + +progname="install-uboot4extlinux.sh" +u_boot_with_spl="@u_boot_with_spl@" +u_boot_with_spl_offset=@u_boot_with_spl_offset@ + +usage() +{ + echo "Usage: ${progname} [INSTALL_DEVICE]" +} + +install_image() +{ + install_device="$1" + offset="$2" + image="$3" + + # We need root permissions for now: + # - blkid is used to bypass caching and it needs root access + if [ "$(id -u)" != 0 ] ; then + echo "Error: This script needs to be run as root" + exit 1 + fi + + # We only support MBR for now + # It will also catch errors like /dev/sdb1 and mmcbk0p1 as they + # don't have the PTTYPE tag + PTTYPE="$(blkid --probe --match-tag PTTYPE ${install_device} | \ + awk '{print $2}' | sed 's#^PTTYPE="##' | sed 's#"$##')" + if [ -z "${PTTYPE}" ] ; then + echo "Error: Could not find an (MBR) formating inside " \ + "${install_device}" + echo " Possible causes:" + echo " - Maybe {instal_device} is a partition" + echo " - or Maybe it's completelyor unformated" + exit 1 + elif [ "${PTTYPE}" != "dos" ] ; then + echo "Error: ${install_device} is not in MBR format" + echo " Currently, only the MBR format is supported" + exit 1 + fi + + # Check if offset > MBR partition table part end + if [ ${offset} -lt 512 ] ; then + echo "Error: The offset (${offset}) is < 512" + echo " offsets < 512 aren't supported (yet)" + exit 1 + fi + + # Get the image size + image_size="$(du --bytes --apparent-size ${image} | awk '{print $1}')" + + # With MBR, most partitioning tools leave makes the first partition + # start at 1MiB. So we need to check if the bootloader doesn't end + # up overwriting the first partition. + if [ $(expr ${image_size} + ${offset}) -gt $(expr 1024 \* 1024) ] ; then + echo "Error: ${image} is too big:" + echo " offset: ${offset}" + echo " size: ${image_size}" + echo " By default, "\ + "partitioing tools makes the first partition start at 1MiB" + echo " Instaling ${images} "\ + "would overwrite that first partition (if it's present)." + echo " Please contact the Parabola developers " \ + "so they could fix that issue" + exit 1 + fi + + # Copies with with a block size of 1 can be quite slow in practice + if [ "$(expr ${offset} % 512)" = 0 ] ; then + dd conv=notrunc "if=${image}" "of=${install_device}" \ + bs=512 "seek=$(expr ${offset} / 512)" + else + echo "Warning: slow copy" + dd conv=notrunc "if=${image}" "of=${install_device}" \ + bs=1 "seek=${offset}" + fi + + sync "${install_device}" +} + +if [ $# -ne 1 ] ; then + usage +else + install_image "$1" "${u_boot_with_spl_offset}" "${u_boot_with_spl}" +fi |