From patchwork Fri Dec 1 21:41:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 843757 X-Patchwork-Delegate: blogic@openwrt.org 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="BZCNPnd/"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="G0ayEL/e"; 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 3ypSQm0lF0z9s72 for ; Sat, 2 Dec 2017 08:41:52 +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=l+sE17g5nBZWztzwfadBhfErq9dET+K9DE0HB/Y7FUI=; b=BZCNPnd/TY5H7zFKfPu4eusCAf /zdbeF2+M8NUNPMBvVg8kbPcOYg9ABmwHtw0eEy8WW06bdFWtO/osu9UVMttuH7acRgV3VxYLhJJB HWslt5jlsVnVlTzneXJUEqDq5dY3/e1+dJvvS9swtRqwKd4bs4e2O3JTD8mEk4Sa+T1hLXcJBQLlc iwK0uxFqzZ86WvTIRokp5RhSrmLO+AEYRJL2aFzMQb4FkcCzVcXW99DFmQkYxhyVCtyplVBTyrIhO NoAriIRVE+OON+BZGNRQCVGlTDU7BoxfsJixpGWVn5I38ynFgzgKLjGQexL4yh/564DjMot5ge7NH rvL2JxLA==; 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 1eKt41-0000ei-Eo; Fri, 01 Dec 2017 21:41:41 +0000 Received: from mail-wr0-x22d.google.com ([2a00:1450:400c:c0c::22d]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eKt3x-0000dN-1R for lede-dev@lists.infradead.org; Fri, 01 Dec 2017 21:41:40 +0000 Received: by mail-wr0-x22d.google.com with SMTP id x49so11468086wrb.13 for ; Fri, 01 Dec 2017 13:41:16 -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; bh=gyH/cBANuPBS1RB3pGmT/PAXRsW4NCTOZafYFThfLZ4=; b=G0ayEL/e/lJruB7ybo0l4D+11mfDfphrSLMMRV5YjBA5O/GzCK94JpvjWap+6JHC4b SuNZbydfoQZFOdwqMYuHMPtLx4mdTANC6MpoVH3ZNm6OlFPD/soJhqlPwP6PyJElGJ/T 974nRRKG2pF0tHbfsTF1KyH+R1UyhYw2J00NyAxcubX4FzYKb5CmnPtr0G5/iqpwxdpf l/HpNv1G7jagO59v3xLdl6+JOCPG5LMBSuZQnj3x4MI/3LqKAunhzusGICYQEkmAdNTW 10McvV/12PAeMgRzXqg0cW+Q28AUS6T52nsB5mP61SEV2IuXLDQ8xQc+aqw9etNVKt/D 3exQ== 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; bh=gyH/cBANuPBS1RB3pGmT/PAXRsW4NCTOZafYFThfLZ4=; b=pjAT9f8+kNZVSn3XP3KlTsZ1BmJi8pkH6ukrIqT4eocou1jaBR6dOK8rSO3EasSm2O 11oKQkiaYlOTTVr1XqEGCrMO26uTKu1MoIl4G+AM1d7TPPjFbs3xOupYG1RnENxUH626 ntdI7DuKPcmDW2IvZI2ByVZc12jz7ffZ4Y4uDk00OxVUncvrmMbYWEHFS1j7+rC4KUk9 bxyfxK4WfuohB42AvaXb+lTUrAdPiSntmJOEeW/vbIErsJAwoMAssAqwwSURcMdVwgkk XLBNJg653cWulNIsKxVl+bjNxLSto+oiwE/DQL2NbxF/NT4xtjGWU2fEydVDEioU5qLm uMyw== X-Gm-Message-State: AJaThX4n/b5XQDWC3Qf9gCw+yUFJNkrR4px8F9q+4tM41J/Py7ejdHrX /loRnaxrhp90qkQTCMxS+Vz7Qm0Y X-Google-Smtp-Source: AGs4zMYcocBNi1IDU+1L/zvrin6WzGihY3v/DtI/zbXCh25Q2zJo/WDXDpA43F3S8+j6sn/bBqcgvQ== X-Received: by 10.223.188.141 with SMTP id g13mr6731464wrh.169.1512164473595; Fri, 01 Dec 2017 13:41:13 -0800 (PST) Received: from debian64.daheim (p200300D5FBC215FC0000000000000830.dip0.t-ipconnect.de. [2003:d5:fbc2:15fc::830]) by smtp.gmail.com with ESMTPSA id l25sm2068934wmi.35.2017.12.01.13.41.12 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Dec 2017 13:41:12 -0800 (PST) Received: from chuck by debian64.daheim with local (Exim 4.89) (envelope-from ) id 1eKt3X-0000Ge-OK for lede-dev@lists.infradead.org; Fri, 01 Dec 2017 22:41:11 +0100 From: Christian Lamparter To: lede-dev@lists.infradead.org Date: Fri, 1 Dec 2017 22:41:11 +0100 Message-Id: <20171201214111.982-1-chunkeey@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <06fdac286208441c5ff0f2b28ec69e8ab9093bb0.1511905744.git.chunkeey@gmail.com> References: <06fdac286208441c5ff0f2b28ec69e8ab9093bb0.1511905744.git.chunkeey@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171201_134137_297002_EFE76DCC X-CRM114-Status: GOOD ( 14.84 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:22d listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (chunkeey[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -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 v2] 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 has to be written manually onto the disk. Please don't forget to backup your configuration in this cases. Note2: This patch requires "base-files: upgrade: make get_partitions() endian agnostic" Note3: If your current installation does not host the two changes, sysupgrading will wipe the existing partition layout. Don't forget to backup your data! Signed-off-by: Christian Lamparter --- v2: - delete dead get_magic_at function - fixed mbl_do_platform_check() complaining about "Invalid partition table on image" --- .../apm821xx/base-files/lib/upgrade/platform.sh | 2 +- .../apm821xx/base-files/lib/upgrade/wdbook.sh | 99 ++++++++++++++++++---- 2 files changed, 82 insertions(+), 19 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..2287e0619d 100644 --- a/target/linux/apm821xx/base-files/lib/upgrade/wdbook.sh +++ b/target/linux/apm821xx/base-files/lib/upgrade/wdbook.sh @@ -1,36 +1,99 @@ . /lib/functions.sh -get_magic_at() { - local file="$1" - local pos="$2" - get_image "$file" | dd bs=1 count=2 skip="$pos" 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"' -} +# copied from x86's platform.sh 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 "$@" | 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 }