From patchwork Tue Nov 28 21:51:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 842334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uzNz+wlY"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="B0PdN+Pg"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ymcnj4YJhz9ryr for ; Wed, 29 Nov 2017 08:51:53 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=XpVjMqF05K4ieSkqb7sl5a6/L3ZBbJyJJL0C4BSMorw=; b=uzNz+wlYAKjMQHlJa0Q2asghy5 2YWHRI4oIaSQDQifpSr8qHgxZZkjl6VJTH+trruvZ3MdvOso6e1t35Ec2AORFq/hO2IG7EDhG7n6H oOiuCaj8snYItpjmOHZ/Ji6X6wIO1+9aRuqmMLDxsw8tLc4kKC2yqaQGw4edG8f3Qxv3+yFbVv7zY UJ07cUAZ6GhuJE1lx8zEu3xL40+QDIDZwdZi9RbY4my1jYHxBq+cdPGSw0ubW9iF5N+6YwRhksJRH G5zDKkKtzTrAsbLGjgWlzJo37V6TcLw+n448wbqhc44E8mOCqqNVx0TT1F1r3b/Yu7+nUCVNNtCFz E/UfQwJw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eJnnD-0003ft-I7; Tue, 28 Nov 2017 21:51:51 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eJnmw-0003CJ-LJ for lede-dev@lists.infradead.org; Tue, 28 Nov 2017 21:51:37 +0000 Received: by mail-wm0-x22a.google.com with SMTP id g130so33678473wme.0 for ; Tue, 28 Nov 2017 13:51:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=iO+w4LqdmGNrpbzpNuKNKAc+4fWWrR/7OMtjCY3QkWw=; b=B0PdN+PgytQAr75+DFrJnG5PM03pAeWNP1ZGhGGfEo3huNuOH68K5CPIP4Ey/SvuIh Sjfl3Rp66IpBS7xcgv7EVw9lH6h7c4aP/CY1/Tbg1PKC40U4c54ligBN5mV4Nid5bhfi 4Vkf5AfE+w5OeEXkcEVyVulNC8/lmYAQ1aXTL62T92STFDtehZPxkl4gAPx32Qu2VFLo S4ODOIDxnKExRVRGXfNDHf/2PScDVIisSXJd9Bg9shKfTXsUtIybo36KV1XKsWYz6pzi kBkCEfD0eiIa8uTSpyvcZPYEHwei/VuYTrlMolwp25XbbdYJCFZJEE/NTrMuw/2CzmFL nV3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=iO+w4LqdmGNrpbzpNuKNKAc+4fWWrR/7OMtjCY3QkWw=; b=fIOQBo3chFBQTIBCZnAJM3bPHHTC6XEEPZZ/0qYj7NiOraKixE5MOXPA+7YDoai7Tb p71xbfTPwxr/g09YTt5+cxQMUcCOqd53mibiZbqfnDS4n5BSy5JnoP1iVR6QKVnBjDXd GdzqlpQtHQ64m0IsqsRhqVqMFeAnoQ7ECNB4sc4WNDjGISHgAY+4w2gjZs2DFoJIyJ+X vCXW9yVq1sI/wnbTkhKmUeXT1zyiUzXPQmm+Qw1OySk9LXMEtTvglAvKt3bFvSr3PRH/ Gms5sGZ7DQy9T+n+7HvlMgVK/BQh+GZrfy/KH2E2cgAs9zD4j2QMTYsT+4ec4WV0vYvc EHhw== X-Gm-Message-State: AJaThX7eBFzLVC+6VUvVWE/ndh1ccFv4qi4DDTBUzM2VPOKWuZfmKRZD DWewZIiSrw1wsCNxzzTjbot0QT71 X-Google-Smtp-Source: AGs4zMaZ+s0np71IsOkmfkVOxlYWm8YVJEPuExGJC4MfB1a8l0USBFH+7nrkUgcjyFPEuelJuNIjhg== X-Received: by 10.28.239.12 with SMTP id n12mr732415wmh.140.1511905871441; Tue, 28 Nov 2017 13:51:11 -0800 (PST) Received: from debian64.daheim (p200300D5FBC552FC0000000000000830.dip0.t-ipconnect.de. [2003:d5:fbc5:52fc::830]) by smtp.gmail.com with ESMTPSA id r14sm110728wrb.43.2017.11.28.13.51.09 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Nov 2017 13:51:10 -0800 (PST) Received: from chuck by debian64.daheim with local (Exim 4.89) (envelope-from ) id 1eJnmX-0001xA-Gy for lede-dev@lists.infradead.org; Tue, 28 Nov 2017 22:51:09 +0100 From: Christian Lamparter To: lede-dev@lists.infradead.org Date: Tue, 28 Nov 2017 22:51:08 +0100 Message-Id: <06fdac286208441c5ff0f2b28ec69e8ab9093bb0.1511905744.git.chunkeey@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <9bf13786bcddfa7a6edebe1a685d57ce0c1f6f94.1511905744.git.chunkeey@gmail.com> References: <9bf13786bcddfa7a6edebe1a685d57ce0c1f6f94.1511905744.git.chunkeey@gmail.com> In-Reply-To: References: <9bf13786bcddfa7a6edebe1a685d57ce0c1f6f94.1511905744.git.chunkeey@gmail.com> <4ab7bbf6c1c3b16972fe0431106ab82a88de50fe.1511905744.git.chunkeey@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171128_135134_927722_B90D985C X-CRM114-Status: GOOD ( 15.78 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:22a listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (chunkeey[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Subject: [LEDE-DEV] [PATCH 4/5] apm821xx: use x86's upgrade scripts for MyBook Live X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Advantages: - preserves existing partition layout. On the hard-drive. Only the boot and rootfs partition will be overwritten. Disadvantages: - The upgrade process takes much longer to run. from 2-3 seconds to 15-25 seconds. Please note that sysupgrade will refuse to upgrade, if the existing installation has an incompatible partition layout. Future changes to the bootfs and/or rootfs partition size will likely cause breakage to the sysupgrade procedure. In these cases, the ext4-rootfs.img.gz install procedure will have to be used. Please don't forget to backup your configuration in this case. Note2: This patch requires "base-files: upgrade: make get_partitions() endian agnostic" Note3: If your current installation does not host the two changes, sysupgradeing will then wipe the existing partition layout. Don't forget to backup your data! Signed-off-by: Christian Lamparter --- .../apm821xx/base-files/lib/upgrade/platform.sh | 2 +- .../apm821xx/base-files/lib/upgrade/wdbook.sh | 95 +++++++++++++++++++--- 2 files changed, 83 insertions(+), 14 deletions(-) diff --git a/target/linux/apm821xx/base-files/lib/upgrade/platform.sh b/target/linux/apm821xx/base-files/lib/upgrade/platform.sh index 55f8ffa75d..8c716bf44e 100755 --- a/target/linux/apm821xx/base-files/lib/upgrade/platform.sh +++ b/target/linux/apm821xx/base-files/lib/upgrade/platform.sh @@ -9,7 +9,7 @@ platform_check_image() { case "$board" in mbl) - mbl_do_platform_check $board "$1" + mbl_do_platform_check "$1" return $?; ;; diff --git a/target/linux/apm821xx/base-files/lib/upgrade/wdbook.sh b/target/linux/apm821xx/base-files/lib/upgrade/wdbook.sh index d7347516cb..b84f80f326 100644 --- a/target/linux/apm821xx/base-files/lib/upgrade/wdbook.sh +++ b/target/linux/apm821xx/base-files/lib/upgrade/wdbook.sh @@ -1,5 +1,7 @@ . /lib/functions.sh +# copied from x86's platform.sh + get_magic_at() { local file="$1" local pos="$2" @@ -7,30 +9,97 @@ get_magic_at() { } mbl_do_platform_check() { - local board="$1" - local file="$2" - local magic + local diskdev partdev diff - magic=$(get_magic_at "$file" 510) + [ "$#" -gt 1 ] && return 1 - [ "$magic" != "55aa" ] && { - echo "Failed to verify MBR boot signature." + export_bootdevice && export_partdevice diskdev -2 || { + echo "Unable to determine upgrade device" return 1 } + get_partitions "/dev/$diskdev" bootdisk + + #extract the boot sector from the image + get_image "$file" | dd of=/tmp/image.bs count=1 bs=512b 2>/dev/null + + get_partitions /tmp/image.bs image + + #compare tables + diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)" + + rm -f /tmp/image.bs /tmp/partmap.bootdisk /tmp/partmap.image + + if [ -n "$diff" ]; then + echo "Partition layout has changed. Full image will be written." + ask_bool 0 "Abort" && exit 1 + return 0 + fi + return 0; } mbl_do_upgrade() { + local diskdev partdev diff + + export_bootdevice && export_partdevice diskdev -2 || { + echo "Unable to determine upgrade device" + return 1 + } + sync - get_image "$1" | dd of=/dev/sda bs=2M conv=fsync - sleep 1 + + if [ "$SAVE_PARTITIONS" = "1" ]; then + get_partitions "/dev/$diskdev" bootdisk + + #extract the boot sector from the image + get_image "$@" | dd of=/tmp/image.bs count=1 bs=512b + + get_partitions /tmp/image.bs image + + #compare tables + diff="$(grep -F -x -v -f /tmp/partmap.bootdisk /tmp/partmap.image)" + else + diff=1 + fi + + if [ -n "$diff" ]; then + get_image "$@" | dd of="/dev/$diskdev" bs=4096 conv=fsync + + # Separate removal and addtion is necessary; otherwise, partition 1 + # will be missing if it overlaps with the old partition 2 + partx -d - "/dev/$diskdev" + partx -a - "/dev/$diskdev" + + return 0 + fi + + #iterate over each partition from the image and write it to the boot disk + while read part start size; do + # root is /dev/sd[a|b]2 and not /dev/sd[a|b] this causes some problem + # one of which is this offset, I'm not sure what's the best fix, so + # here's a WA. + let part=$((part - 2)) + if export_partdevice partdev $part; then + echo "Writing image to /dev/$partdev..." + get_image "$@" | dd of="/dev/$partdev" ibs="512" obs=1M skip="$start" count="$size" conv=fsync + else + echo "Unable to find partition $part device, skipped." + fi + done < /tmp/partmap.image + + #copy partition uuid + echo "Writing new UUID to /dev/$diskdev..." + get_image "$@" | dd of="/dev/$diskdev" bs=1 skip=440 count=4 seek=440 conv=fsync } mbl_copy_config() { - mkdir -p /boot - [ -f /boot/uImage ] || mount -t ext4 -o rw,noatime /dev/sda1 /boot - cp -af "$CONF_TAR" /boot/ - sync - umount /boot + local partdev + + # Same as above /dev/sd[a|b]2 is root, so /boot is -1 + if export_partdevice partdev -1; then + mount -t ext4 -o rw,noatime "/dev/$partdev" /mnt + cp -af "$CONF_TAR" /mnt/ + umount /mnt + fi }