From patchwork Wed Nov 21 16:41:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1001238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23b; helo=mail-lj1-x23b.google.com; envelope-from=swupdate+bncbcxploxj6ikrbuev23pqkgqejscsipi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="fcBbTIaT"; dkim-atps=neutral Received: from mail-lj1-x23b.google.com (mail-lj1-x23b.google.com [IPv6:2a00:1450:4864:20::23b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 430Syq3BP7z9s3q for ; Thu, 22 Nov 2018 03:41:55 +1100 (AEDT) Received: by mail-lj1-x23b.google.com with SMTP id t7-v6sf2013236ljg.9 for ; Wed, 21 Nov 2018 08:41:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1542818512; cv=pass; d=google.com; s=arc-20160816; b=BQsSdYA5AOhbPcZB409rJRl1exdC2j6wgXolOB1w6HpUKVFSVS7Nl2Q+8qbhukrSIC URVDr88j4P1JihuCYnIOrt92M7SHgTK/MRn4j1UiI6/PI3xz75kM1pqpCf4Mo6DHtHYQ KEJO91rg8s6ch2PbzO61ouLsFQPfnwKSDIh2ddHGJMonVsZeopdSD2HnINZwcFSw7b7j i5cRYqg2p2cHEHAez5MxaZzJ7UDnrpkmG7Q/q52mvn+uMb7+cukNNSHb4yt7UB5JFt2y 78dep9lKsJ2TGRhwQPc0LiyJpHgW6Jo8i9/r4JditByiOpkQXCjp8Qh/9uEpKCKkd30K mrSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:mime-version:sender:dkim-signature; bh=0Ur8RAsw2qvMi6OiHj1wV30J/g1XPN/0lK4D/VAY3sE=; b=IRHPjxB52owD6TmxnbVnv4L8/sNuJcNhT7Eq001KPL5xwC7u7ziCJ8ZOJ2T+WoSLQk 4FnAad2Eyqh+WMIzhs80gWa7TEWVbzRADUG/llIvCIzVxo1A93wTbmjEXQEiyvxDmAL8 mC52sFpn9fsX5L/rqA5CnVvWVkHWPka+rArVVOcJXMyQlNckZGxe4KomVy95S0VE/2C1 wNW3kbcJF4y1ujG57BwN89efEbrEJKM43VeSGSS9gmvSHAA9n2mruv8JaqZoMltaIPFl gTzGnl3QScnpxV1f+LIebbrBibfWQLa7PtCV0SqbG+SlfVFADaMRLQFvr3GFuPRzwd/w Tlig== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0Ur8RAsw2qvMi6OiHj1wV30J/g1XPN/0lK4D/VAY3sE=; b=fcBbTIaTY/lmdghrckTKUqlbPpPDxMY6VLUOBzJa82EnujC/g2UV1L+te18o2ure1n x74s/GCNtsge0IcIUfwV4o9JjK/RDMFWIBWhvMBN3CNvzKfdxS8kMIz0adKNZcX9k2Jk GTEPZl/mDypze3jYS7ADUZrkrcQ0eZmKsjTpl5cU3toXF0/llcq7eRxulyV68ZGL7h1R sQ/TotvP3JRNYzTyIIDAvpPWzdYCP5+/6gQ+N3O6DRyZ8O3PZIfA95vo5HWtqax4olOc pLzwwbmMh1LntOz+WH2n4ZpfzjW5utSJhR2EVkZspnzfjcTotua0r5XBrodIpsKzuhnx eGuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=0Ur8RAsw2qvMi6OiHj1wV30J/g1XPN/0lK4D/VAY3sE=; b=MKCaJqhF8UwIZj9DPNT6nywiVJKnrwH5XzjPJfkbWCdmWQafPmhVHfUYGpVjJ4FjqM RB5bKSpROgRhiahbiG06mqo77p49UwIEBzTfDcRCjTXoJ2GjqDFV8D7Cl18U9zDz+mq5 w4Z/hG01uDHIrDmFWRfQ4IwaaRqpPHZhqKBuiGKJWfk0uPRMw4mRbIMV55fxQWL0rTnq 249+MxQI/QWSDqKb4cBii7MkBKcaatQcnWua/9pLVIQPEBu8VClS06mcd6Uei45HpuaL iU7ttoeSQPzrhOlSKDVbz6aA77aZWVsNLjW+8JyMRxTCLp80I+7BdPt2pUlFAOhRny5f grPw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AGRZ1gKtTC59+HlRZI3nxeXvnWyC49LigSqui5dkjZOKIYPBS+lMroIK MfF6S2DD0raMBCWlZvub9k4= X-Google-Smtp-Source: AJdET5cI53/8yyGG2LbEO4+f8wkH6i3srmQwQodRygLvyMBajUTn9b6SZPZ19XpYIsYh2yjim9X0cg== X-Received: by 2002:a19:ef16:: with SMTP id n22mr38286lfh.2.1542818512659; Wed, 21 Nov 2018 08:41:52 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:7b01:: with SMTP id w1ls611698lfc.9.gmail; Wed, 21 Nov 2018 08:41:51 -0800 (PST) X-Received: by 2002:ac2:4207:: with SMTP id y7mr654322lfh.7.1542818511790; Wed, 21 Nov 2018 08:41:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542818511; cv=none; d=google.com; s=arc-20160816; b=ujI8vmCYa9o7SWDVuC8rfDs3qiTruRk3FrtGJCrlSVLWepC78LrVFO8E59GGHFYik7 2bz6qcBoB9CMUWpxq5Ystm0HrhsdriaNX/kNd/ToBa4YLx5vwGYMAhXff26evDsfwAyR U++l2bHHJYQ+PpLPdR5LKLG2JoyMxAuHtSDOfiD83WyLYKGGYcjKnZ4TA5B6WaKZNKvV LQHEpUfshMHsrDm21BGoWkOdiL+wzqmmT6JleUllp/frym2b0dGnhz2xNhmAhNzx3zkl m9qgb8xYl2RpcFwIgvWTsRqCXyYNaaeEQJRkqgGg2VITraL/XomjF74nlIg1mu4iin3p qfdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=OFl8wL8deZsiAVlJJJ0B5PjG8OS2Ql4bmFC8xZuNYzI=; b=S9Bz8YR9Yiz7EBrmEKJPNzULjrYC1YWFARznCpZmshS6dza74jxqVL1GVuKfYlVKeG Bj+meWyWjDlVsSLSoIq5s9934XtDNBUCuBQ2a5hdHpxRuhQwh1m307NMtJPiTBXpYPh2 21UuAGYAK99+w6CcVkv/sXXU80FFU7VkGBYo0DLPTcTHG4cofwloEG3d+mPQ3O0yQgbX ZmCOgnHnQEFrye3lrpMW+DWq5RxAPIUbCwyQ38MFYWw06YTghWpHqYbyrfnFLDbGKcXC fnBKWhckzhzG+xQge7ufCK0aP1DIkvXuR07+QCIm5M1aZPHKR2TrRojlV+8PeGZ5kQYd wn9A== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id 205si1398957lfb.2.2018.11.21.08.41.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Nov 2018 08:41:51 -0800 (PST) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 430Syl0nSpz1qxJv; Wed, 21 Nov 2018 17:41:51 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 430Syl0ZyXz1qrnr; Wed, 21 Nov 2018 17:41:51 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id cQlpqzsUqaFl; Wed, 21 Nov 2018 17:41:50 +0100 (CET) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Wed, 21 Nov 2018 17:41:50 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id D2DB345400FB; Wed, 21 Nov 2018 17:41:49 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0FGO6wpe9p3J; Wed, 21 Nov 2018 17:41:46 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id C220745403AD; Wed, 21 Nov 2018 17:41:46 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 2/2] handler: bootloader: postpone setiing the environment Date: Wed, 21 Nov 2018 17:41:44 +0100 Message-Id: <20181121164144.8487-2-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181121164144.8487-1-sbabic@denx.de> References: <20181121164144.8487-1-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , The bootloader handler sets the environment using an image (ASCII file) with the list of variables to be set and their values. This can under some circunstances brick the target because the environment is set in the middle of un update and not at the end, as it happens when the variables are listed in the "bootenv" section of sw-description. The environment is in fact set for the new release and in case of a power cut or if simply the update is cancelled, the device after a reboot will try to start with the new environment. In most cases, the new environment points to the new version of the software that is at least corrupted orabsent. This patch changes the behavior and chekcs the values read from the ASCII file, but not set the environment. It puts the variables in the global list exactly as the parser does, and the environment will be set just at the end of the installation. Signed-off-by: Stefano Babic --- handlers/boot_handler.c | 49 +++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/handlers/boot_handler.c b/handlers/boot_handler.c index ac6e4e0..29fd190 100644 --- a/handlers/boot_handler.c +++ b/handlers/boot_handler.c @@ -7,12 +7,15 @@ #include #include +#include #include #include #include +#include #include "generated/autoconf.h" #include "swupdate.h" +#include "swupdate_dict.h" #include "handler.h" #include "util.h" #include "bootloader.h" @@ -25,7 +28,8 @@ static int install_boot_environment(struct img_type *img, { int ret; int fdout; - + FILE *fp; + char *buf; char filename[64]; struct stat statbuf; @@ -35,6 +39,11 @@ static int install_boot_environment(struct img_type *img, img->fname); return -1; } + + if (!img->bootloader) { + ERROR("Internal fault, please report !"); + return -EFAULT; + } ret = stat(filename, &statbuf); if (ret) { fdout = openfileoutput(filename); @@ -42,14 +51,40 @@ static int install_boot_environment(struct img_type *img, close(fdout); } - ret = bootloader_apply_list(filename); - if (ret != 0) { - ERROR("Error setting bootloader environment"); - } else { - TRACE("Bootloader environment from %s updated", img->fname); + /* + * Do not set now the bootloader environment + * because this can cause a corrupted environment + * if a successive handler fails. + * Just put the environment in a the global list + * and let that the core will update it at the end + * of install + */ + fp = fopen(filename, "r"); + if (!fp) + return -EACCES; + + buf = (char *)malloc(MAX_BOOT_SCRIPT_LINE_LENGTH); + if (!buf) { + ERROR("Out of memory, exiting !"); + fclose(fp); + return -ENOMEM; + } + + while (fgets(buf, MAX_BOOT_SCRIPT_LINE_LENGTH, fp)) { + char **pair = NULL; + unsigned int cnt; + + pair = string_split(buf, '='); + cnt = count_string_array((const char **)pair); + + if (cnt > 0 && strlen(pair[0])) + dict_set_value(img->bootloader, pair[0], pair[1]); + free(pair); } + fclose(fp); + free(buf); - return ret; + return 0; } __attribute__((constructor))