From patchwork Wed Sep 20 15:12:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 1837326 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=SY7KkHSG; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=nqZ8eaE1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::113c; helo=mail-yw1-x113c.google.com; envelope-from=swupdate+bncbcl4hcw73qcbb6mxvsuamgqervvhxay@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-yw1-x113c.google.com (mail-yw1-x113c.google.com [IPv6:2607:f8b0:4864:20::113c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RrMV60JLtz1ynZ for ; Thu, 21 Sep 2023 01:13:00 +1000 (AEST) Received: by mail-yw1-x113c.google.com with SMTP id 00721157ae682-594e1154756sf85347677b3.2 for ; Wed, 20 Sep 2023 08:13:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1695222778; cv=pass; d=google.com; s=arc-20160816; b=WgGUG+DNftMqgPInkjWMxjmDUOVpnaXjoxZ1fPP9Sn4IvA/bqbpgpjBImsD1LwsaEA 9HqUxPn7ojjv5M1D2WMNCQKaPoO/LHKrcERz52XXpTCYzfWeFehf4TfqCuqsbssF8ppA 4iaI+D0sn2s9TB9NT/3yFYAK2P7Pp/bdGLPNskock1+qtNxPr1no4mx9nVeM9Is/fREq Z0Eqqvd9rWdSkh+1SF/v9aZVYbm3vyYBX6jEhb0Uwshu8WlfkgieHt+8xO64ylPJoRMv LV58qV+Cjb7BiXf4gAxtJZnWhtxutzb0+tgSI1dhhKLbgicFG6VsJt5ofbw61nEJNp2w Lxeg== 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:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature:dkim-signature; bh=HmVAbxrBShJuHLQR5gEo6Ne5AQru2jPNp+4AXEeW/u0=; fh=KPrAw848PoyEggiIX82ubXk7sJG2UD396EeWf1FQVUo=; b=znPfpIqTtU0qf/Sis2jKBN42JFBVfhmaHYM8SEphuV1mYexRkPBSzPeNQgjQbq2nSt H9GMuUVf+2BLBhA8ZsJXKxKO460WjdJ7Zjzuukno0adsn1Tyjgt1toI90KskmyvxvGEd PfIgOSfEq3Y6JMaAkiBsYzp1ZdfILC0gUCspo8dyx0WTdPYyZosdScA47iJN+uM2CXCl TZQv+tWSsxarpO2HjG49tBPNsC0B1aNJD66gpq/p0njgjSc0HnEPFA9j4wyEUXbs00Cv k25vvAjtIa8DZ6y/P9Fa7jwY2CJ1b/oG2apDQRmIwAIqrGN1J33+W2UHrm2/cAdkmDCa 0lRg== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="d/X5nxQB"; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d2a as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1695222778; x=1695827578; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=HmVAbxrBShJuHLQR5gEo6Ne5AQru2jPNp+4AXEeW/u0=; b=SY7KkHSGCZhOpFuWq6c5tiRoCxCytfFDKNPLk79EVBysxUw6lNRxlF25cye8IXLB42 ucQDNWQlM+ixEIbICW5D3RDUx0s5XTv4GSto08tdIZgiC+v/hs0Rz85A+YQyW3rYVZ4m sFULUEkARIhFXN20p3tcayWav1+meqeNLT35zR0LgO80uNYaqSWdPTRS/bjkNxIbfTIC qlAYcdo/UPRDH6AOsYFMOBeZH3q9d4cZxCZbJngj36/3tToYH1byb4qbTNOYEGd8t1zh KTxmjTZN+xDXMrz4CP507hHPSzrg894KSsi1/85iFUcx4KRu9E+/Yafptgv+J0FBu9po vMZg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695222778; x=1695827578; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=HmVAbxrBShJuHLQR5gEo6Ne5AQru2jPNp+4AXEeW/u0=; b=nqZ8eaE1PK/chZCqHZi5WA4FeSeyssYEQvNUb9nylGfMJ+RR4nixuL5sB3wryKoooX /jgbYRBc+IJQW0pylrtoERtyH4vnnC+PUgelYpQ1CWtowMR+PxrYpUlOnwRVVaSI9lZs 9oPo8YYb092F7QwAPCublOzva0xK9NAMvwaDXEcF7UXVY2K5dUO0O8u4mTF3O0WKg8lW JNNIel/yu21iuFRuD/ZvG5LPdBqahx7+IXfWss0Sj6qy8Ka2D776BMed24KativPRJmb X3CM0uTap0NSNvusZ7RNlKytMT2OyKDdy51wxR3eh0xPdUseVtawOoVdstEmfZS0Xww3 4igQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695222778; x=1695827578; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=HmVAbxrBShJuHLQR5gEo6Ne5AQru2jPNp+4AXEeW/u0=; b=HQ/r+4sRM944GHZk2wPbxFu35msN+I/OEj9WZFQttWqVAwf8TDyrXyU1vgsy80cH35 k1RbTg1zMeBQWT2xwWHoMaz+bHUNkRUik41Ytct3jWJz1LTpawoRrbbN+8iw5O5PWfcV VKGJgex1puH/tuPiIKeH/06cAVnYAk+Eh+c73U6952/88HGQFn3SY53aBRCNsgwHKMcP iStMYNiIO0zDTkDvQ2LOqFIRUqx8m+I5CYOWK71GX8aeV0Ebmk3brwL73atRG7336uG8 kILjkIAK5pKoRwddDaCAHNX0kY1tMaAM/sGvybDIZqBjVgXmUl1GAXzkok0a6iwlPP6a xqpw== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOJu0Yze/MB9exzEx+gQcwpXTDCKydLoYt1F29RCVIQ4QNxmdeJRnJo7 TDolXYDxBXkZZoQo9n9xPl8= X-Google-Smtp-Source: AGHT+IF+nxskWg6IkroVAU9Y0Dl5WCzpyVhrUmzzc7Y/bdVcoLNalrKK0xGlB+667qktzH4pAw61ag== X-Received: by 2002:a25:e054:0:b0:d80:9ef:928e with SMTP id x81-20020a25e054000000b00d8009ef928emr3088582ybg.33.1695222777941; Wed, 20 Sep 2023 08:12:57 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:6902:72f:b0:d7a:e0a5:9256 with SMTP id l15-20020a056902072f00b00d7ae0a59256ls674683ybt.2.-pod-prod-03-us; Wed, 20 Sep 2023 08:12:56 -0700 (PDT) X-Received: by 2002:a0d:d54e:0:b0:589:f4ec:4d51 with SMTP id x75-20020a0dd54e000000b00589f4ec4d51mr2633833ywd.3.1695222776831; Wed, 20 Sep 2023 08:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695222776; cv=none; d=google.com; s=arc-20160816; b=cFIsncEJomdU35+ht13kAIANGHWNRZss0XsyiUkW0Uguk3aZd1GFQbUpLTeKXIcaI2 SmUSPPd6t8q7V8OqYNns8qo3obCJn6V6/fLdpD13R8E3hCeD0OgizpggAXomsz3c5MgF Cb85uMoKRIj42t1lmQLm6rUUAxlXksYOM3EyMFjtlHPfQWgwUmint7fO5fhcfpWqNAQB GfxyG/mc+LUpfHwX4ennaGcZJbkq6Demdaw20a+br4dMkI6AR175hW/XfdmDeBAz6t/x byca8VkniuUQ0VIu+Qcveb4NlHNZnJXYR105HBZT1MKbG2i3Oz/BbudCrE5Vnu67xf9/ f0nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=4W57ANNtqmtQWACu78tnDT1P/v33weu7K/D0DP2PvRs=; fh=KPrAw848PoyEggiIX82ubXk7sJG2UD396EeWf1FQVUo=; b=myFRF60FGR8H7iQP2x3nBysxhLBecaZ/5nk4fb1DTDyvk9bWcOpX/h6gFcDWheD96N aYn+6gxxJhPR0fLgBFOhYcH+EleudHyxEnUztpP4IAO3ew+UFoDkFnwM1wjHSRvM7fI+ ZvlGqBxJmizIAWK+zW7zv+lsKeC0SU4IwdkSalyIE/6SyCAJDf+M5q7nsf91d84nC/28 jqKKyuKweAeNWn+QLmyVtWtj5pdHFNvAsdZnJNXNwdkE/2967STAZzKhDV4liCWPuzmT +Bl9xwaRpeQhORJXhDrvBRB0cUEIg7JMuqqLcf3miPUBaxWIgbO45alovTXuu9dL0CUe f7xA== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="d/X5nxQB"; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d2a as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com. [2607:f8b0:4864:20::d2a]) by gmr-mx.google.com with ESMTPS id u199-20020a8179d0000000b0059b59abd82csi2072272ywc.3.2023.09.20.08.12.56 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Sep 2023 08:12:56 -0700 (PDT) Received-SPF: pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d2a as permitted sender) client-ip=2607:f8b0:4864:20::d2a; Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-79565370aa3so263739939f.0 for ; Wed, 20 Sep 2023 08:12:56 -0700 (PDT) X-Received: by 2002:a05:6602:2583:b0:790:fc73:6e3c with SMTP id p3-20020a056602258300b00790fc736e3cmr3396479ioo.8.1695222775864; Wed, 20 Sep 2023 08:12:55 -0700 (PDT) Received: from james-x399.localdomain (71-33-152-19.hlrn.qwest.net. [71.33.152.19]) by smtp.gmail.com with ESMTPSA id a20-20020a02ac14000000b0042b48d372aasm4177301jao.100.2023.09.20.08.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:12:55 -0700 (PDT) From: James Hilliard To: swupdate@googlegroups.com Cc: James Hilliard Subject: [swupdate] [PATCH 1/1] bootloader/uboot: support environment in ubi Date: Wed, 20 Sep 2023 09:12:45 -0600 Message-Id: <20230920151245.2786420-1-james.hilliard1@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Original-Sender: james.hilliard1@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="d/X5nxQB"; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::d2a as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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: , When using uboot env in UBI in combination with CONFIG_UBIATTACH we may fail to interface with the environment as scan_mtd_devices would not be run until actually running an update. To handle this case safely add an erase flag to scan_mtd_devices so that we can attempt to attach UBI partitions in the event that our call to libuboot_read_config fails with a -EINVAL return without performing potentially problematic erase operations prior to running a swu update. Signed-off-by: James Hilliard --- bootloader/uboot.c | 23 +++++++++++++++++++---- core/stream_interface.c | 2 +- corelib/mtd-interface.c | 8 +++++--- include/flash.h | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/bootloader/uboot.c b/bootloader/uboot.c index a2f0794..3456132 100644 --- a/bootloader/uboot.c +++ b/bootloader/uboot.c @@ -18,6 +18,9 @@ #include "generated/autoconf.h" #include "util.h" #include "dlfcn.h" +#ifdef CONFIG_UBIATTACH +#include "flash.h" +#endif #include "bootloader.h" #include @@ -39,17 +42,29 @@ static struct { static int bootloader_initialize(struct uboot_ctx **ctx) { - if (libuboot.initialize(ctx, NULL) < 0) { + int ret; + + ret = libuboot.initialize(ctx, NULL); + if (ret < 0) { ERROR("Error: environment not initialized"); return -ENODEV; } - if (libuboot.read_config(*ctx, CONFIG_UBOOT_FWENV) < 0) { + ret = libuboot.read_config(*ctx, CONFIG_UBOOT_FWENV); +#ifdef CONFIG_UBIATTACH + if (ret == -EINVAL) { + scan_mtd_devices(false); + ret = libuboot.read_config(*ctx, CONFIG_UBOOT_FWENV); + } +#endif + if (ret < 0) { ERROR("Configuration file %s wrong or corrupted", CONFIG_UBOOT_FWENV); return -EINVAL; } - if (libuboot.open(*ctx) < 0) { + ret = libuboot.open(*ctx); + if (ret < 0) { WARN("Cannot read environment, using default"); - if (libuboot.load_file(*ctx, CONFIG_UBOOT_DEFAULTENV) < 0) { + ret = libuboot.load_file(*ctx, CONFIG_UBOOT_DEFAULTENV); + if (ret < 0) { ERROR("Error: Cannot read default environment from file"); return -ENODATA; } diff --git a/core/stream_interface.c b/core/stream_interface.c index 3f0b952..823ed54 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -604,7 +604,7 @@ void *network_initializer(void *data) if (!ret) { #ifdef CONFIG_MTD mtd_cleanup(); - scan_mtd_devices(); + scan_mtd_devices(true); #endif /* * extract the meta data and relevant parts diff --git a/corelib/mtd-interface.c b/corelib/mtd-interface.c index 22e86bd..a394de1 100644 --- a/corelib/mtd-interface.c +++ b/corelib/mtd-interface.c @@ -328,7 +328,7 @@ static void scan_for_ubi_devices(void) } #if defined(CONFIG_UBIATTACH) -static void scan_ubi_partitions(int mtd) +static void scan_ubi_partitions(int mtd, bool erase) { struct flash_description *flash = get_flash_info(); libubi_t libubi = flash->libubi; @@ -365,6 +365,8 @@ static void scan_ubi_partitions(int mtd) do { err = ubi_attach(libubi, DEFAULT_CTRL_DEV, &mtd_info->req); if (err) { + if (!erase) + return; if (mtd_info->has_ubi && !tryattach) { TRACE("cannot attach mtd%d ..try erasing", mtd); if (flash_erase(mtd)) { @@ -390,7 +392,7 @@ static void scan_ubi_partitions(int mtd) #endif #endif -int scan_mtd_devices (void) +int scan_mtd_devices (bool erase) { int err; struct flash_description *flash = get_flash_info(); @@ -493,7 +495,7 @@ int scan_mtd_devices (void) if (flash->libubi && !flash->mtd_info[i].skipubi && !flash->mtd_info[i].scanned && flash->mtd_info[i].mtd.type != MTD_UBIVOLUME) - scan_ubi_partitions(i); + scan_ubi_partitions(i, erase); } #endif #endif diff --git a/include/flash.h b/include/flash.h index 3f73079..e549770 100644 --- a/include/flash.h +++ b/include/flash.h @@ -47,7 +47,7 @@ void ubi_umount(const char *mntpoint); void mtd_init(void); void mtd_set_ubiblacklist(char *mtdlist); void ubi_init(void); -int scan_mtd_devices (void); +int scan_mtd_devices (bool erase); void mtd_cleanup (void); int get_mtd_from_device(char *s); int get_mtd_from_name(const char *s);