From patchwork Tue May 17 15:52:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 623185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (caladan.dune.hu [78.24.191.180]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3r8MLf665Wz9t6F for ; Wed, 18 May 2016 01:53:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=open-mesh-com.20150623.gappssmtp.com header.i=@open-mesh-com.20150623.gappssmtp.com header.b=AXvJp6ph; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id E78C9B91DC9; Tue, 17 May 2016 17:52:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Tue, 17 May 2016 17:52:46 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 4717FB91DB7 for ; Tue, 17 May 2016 17:52:40 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 CL_IP_EQ_HELO_IP=-2 (check from: .open-mesh. - helo: .mail-wm0-f43.google. - helo-domain: .google.) FROM/MX_MATCHES_HELO(DOMAIN)=-2; rate: -7 Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Tue, 17 May 2016 17:52:40 +0200 (CEST) Received: by mail-wm0-f43.google.com with SMTP id a17so38719577wme.0 for ; Tue, 17 May 2016 08:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WgshO1+68NWTbsWFGWR38QP6OgT2vJ8lxjUg+Msis8o=; b=AXvJp6phZkv3e2VlDQl7L0PvhMCGA7LhbK+Lzp42u+uopfDzB4mGI/r/XTCdOERipp QjlEmW+6WAngBWf/SP1KQO0xoVLPHPVWVf6vEXu+RLEhzxZfmcLo23cy4Ma3tan8eWcj xSrS76/pUb2vBLF+lZ8DmBYqt3cQ3uK1Io3LTMCcM/OLcPinrRY32fk8KpRrVvj+K2dF My6ciNNuc7aTbWzOaB8TojNg8DuvEl77yqAusoOXMyErbSRjrq3SVg+VDp6CrZl9TJEO L9HUyYeNbHePKJF6n52qbo945OPLSOxohl59mn+aopB5OY8dLRkuAqu9pR4YytSdjQ4p 5Vuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WgshO1+68NWTbsWFGWR38QP6OgT2vJ8lxjUg+Msis8o=; b=Q1ANz9NNhnMvWQZcaVKYwmO+16BTiA8u6j1WnX1QD5lRJ+ur5wxRusTVE1vikGw4H4 eGpiMtgQZzNHTkn9/eQXRX4ZyImvVfGYpE2uS6wqGmgw2cEleFXSjlfPqHW37fS5jFXz 8Twe8dCJvufEu7eUkwI16vQlh8H8lFjzZ/BuWJffAUmeKCFU8Qs/VSzRQGYO5Eoykta4 jpbnPb9B2Gbgre8htExZZ5A09wydqaqed35k09K5YlW3l/seswc/g7I/IMi5MPjQu++p kshAIfmbmoCPI6k4DJodlsPN6zomRDPipWnTA/Tif5pTBcz6i5xB7dUpQNh4R0X3E6Wv kmCg== X-Gm-Message-State: AOPr4FXrXX7mxKe15xAVb/cDMxNOt2Z+A2tTfEYvID4NFi06m9H4ZMUVLMTLI1uzq4qZ5uDZ X-Received: by 10.28.46.209 with SMTP id u200mr2208991wmu.97.1463500359704; Tue, 17 May 2016 08:52:39 -0700 (PDT) Received: from sven-desktop.home.narfation.org (p549BC98B.dip0.t-ipconnect.de. [84.155.201.139]) by smtp.gmail.com with ESMTPSA id y3sm3787594wji.40.2016.05.17.08.52.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 May 2016 08:52:39 -0700 (PDT) From: Sven Eckelmann To: openwrt-devel@lists.openwrt.org Date: Tue, 17 May 2016 17:52:26 +0200 Message-Id: <1463500347-21432-3-git-send-email-sven.eckelmann@open-mesh.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1463500347-21432-1-git-send-email-sven.eckelmann@open-mesh.com> References: <1463500347-21432-1-git-send-email-sven.eckelmann@open-mesh.com> Subject: [OpenWrt-Devel] [PATCH 3/4] ar71xx: Move OpenMesh image target validation into subfunction X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sven Eckelmann MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" The platform_check_image_openmesh function used break statements to signal that the board name matched the image target. This worked because the sysupgrade binary checked the image inside a loop. The break statement stopped the loop and skipped any additional check. Instead the check should be done without such sideeffects by simply combining the board names and image targets. Only a mismatch should cause a negative result for the caller and skipping of the additional checks. Signed-off-by: Sven Eckelmann --- .../ar71xx/base-files/lib/upgrade/openmesh.sh | 71 ++++++++++++---------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/target/linux/ar71xx/base-files/lib/upgrade/openmesh.sh b/target/linux/ar71xx/base-files/lib/upgrade/openmesh.sh index 209cdaa..e026946 100644 --- a/target/linux/ar71xx/base-files/lib/upgrade/openmesh.sh +++ b/target/linux/ar71xx/base-files/lib/upgrade/openmesh.sh @@ -36,62 +36,46 @@ platform_add_ramfs_ubootenv() } append sysupgrade_pre_upgrade platform_add_ramfs_ubootenv -platform_check_image_openmesh() +platform_check_image_target_openmesh() { - local img_magic=$1 - local img_path=$2 - local fw_printenv=/usr/sbin/fw_printenv - local img_board_target= img_num_files= i=0 - local cfg_name= kernel_name= rootfs_name= - - case "$img_magic" in - # Combined Extended Image v1 - 43453031) - img_board_target=$(trim $(dd if="$img_path" bs=4 skip=1 count=8 2>/dev/null)) - img_num_files=$(trim $(dd if="$img_path" bs=2 skip=18 count=1 2>/dev/null)) - ;; - *) - echo "Invalid image ($img_magic). Use combined extended images on this platform" - return 1 - ;; - esac + img_board_target="$1" case "$img_board_target" in OM2P) - [ "$board" = "om2p" ] && break - [ "$board" = "om2pv2" ] && break - [ "$board" = "om2p-lc" ] && break - [ "$board" = "om2p-hs" ] && break - [ "$board" = "om2p-hsv2" ] && break + [ "$board" = "om2p" ] && return 0 + [ "$board" = "om2pv2" ] && return 0 + [ "$board" = "om2p-lc" ] && return 0 + [ "$board" = "om2p-hs" ] && return 0 + [ "$board" = "om2p-hsv2" ] && return 0 echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform" return 1 ;; OM5P) - [ "$board" = "om5p" ] && break - [ "$board" = "om5p-an" ] && break + [ "$board" = "om5p" ] && return 0 + [ "$board" = "om5p-an" ] && return 0 echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform" return 1 ;; OM5PAC) - [ "$board" = "om5p-ac" ] && break - [ "$board" = "om5p-acv2" ] && break + [ "$board" = "om5p-ac" ] && return 0 + [ "$board" = "om5p-acv2" ] && return 0 echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform" return 1 ;; MR1750) - [ "$board" = "mr1750" ] && break + [ "$board" = "mr1750" ] && return 0 echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform" return 1 ;; MR600) - [ "$board" = "mr600" ] && break - [ "$board" = "mr600v2" ] && break + [ "$board" = "mr600" ] && return 0 + [ "$board" = "mr600v2" ] && return 0 echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform" return 1 ;; MR900) - [ "$board" = "mr900" ] && break - [ "$board" = "mr900v2" ] && break + [ "$board" = "mr900" ] && return 0 + [ "$board" = "mr900v2" ] && return 0 echo "Invalid image board target ($img_board_target) for this platform: $board. Use the correct image for this platform" return 1 ;; @@ -100,6 +84,29 @@ platform_check_image_openmesh() return 1 ;; esac +} + +platform_check_image_openmesh() +{ + local img_magic=$1 + local img_path=$2 + local fw_printenv=/usr/sbin/fw_printenv + local img_board_target= img_num_files= i=0 + local cfg_name= kernel_name= rootfs_name= + + case "$img_magic" in + # Combined Extended Image v1 + 43453031) + img_board_target=$(trim $(dd if="$img_path" bs=4 skip=1 count=8 2>/dev/null)) + img_num_files=$(trim $(dd if="$img_path" bs=2 skip=18 count=1 2>/dev/null)) + ;; + *) + echo "Invalid image ($img_magic). Use combined extended images on this platform" + return 1 + ;; + esac + + platform_check_image_target_openmesh "$img_board_target" || return 1 [ $img_num_files -ne 3 ] && { echo "Invalid number of embedded images ($img_num_files). Use the correct image for this platform"