From patchwork Mon Apr 8 12:56:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ernestas Kulik X-Patchwork-Id: 1920825 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=u2qvOn37; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::23a; helo=mail-lj1-x23a.google.com; envelope-from=swupdate+bncbaabbsotz6yamgqeinrofli@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-lj1-x23a.google.com (mail-lj1-x23a.google.com [IPv6:2a00:1450:4864:20::23a]) (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 4VCpzQ4cR4z1yYT for ; Mon, 8 Apr 2024 22:57:53 +1000 (AEST) Received: by mail-lj1-x23a.google.com with SMTP id 38308e7fff4ca-2d87b880861sf16840981fa.1 for ; Mon, 08 Apr 2024 05:57:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712581067; cv=pass; d=google.com; s=arc-20160816; b=wTN/tTvPh5hcyJZ9SVoZ56LL77RS8RRC+uXtTbV9K5RYXBQS/NqPj+4ADhItlCsjBE PWmlVEQ7hpypJzLUtVMkt6pcYHxwMPu+Rqf3rjciZ0fOFOXAed2JtRGpbLdhC9/m0WrO epLxAsdTf6+xjRM21y6SavRlPLwNMzhIf0mfyxHeirFq0FTRd9PdchEHCualQXoMMzvA FzOm0Fmct/eHtycjNa19oSN4jWimkiMhUGn4xVSNqsCADwznsHP6LCFcVTQmYjlo0EhG qP095olGF1DX78FPpf676ll1WvKdnSQIG3q75jtlA4a/c3YrliDTWCZRsHecTDsliuqi cA3w== 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:reply-to:mime-version:message-id :date:subject:cc:to:from:dkim-signature; bh=KJNyVZGVjfz9mR2R9H/ZdZU6bEMYun3KuqopXBS9U8E=; fh=OHmty0tFmCDkeoav8ky8gIPJnRnu59JnvcktYGb3Y8A=; b=OZEkyCqeGA5sl8mdBknfJ8QfiVGRdLCc/a6uhL8Pd1kwtJGrqc0Ta3ty9VDSYYFBXe Vgqxe7aUBYaqTERA/tgcRWi+GkuwERgM7mMmcN2GYDP7IUwZvKq4M7PC1hbnIqWse22L yNCffEWj1XwkEZtB1u69RrV/War2yEKBhbnUaEde0fQ+mAuJe3m6TELhKVBQyMO+DBpK 1p3xwHmAf2eiuWdpTfkeproj7U/r3OuCJQh31owtPNX3FxOWoNTX1/Hjqmp92AXUwJ08 AAE3vPpxYrNxMtb5G5tRV380113tRScxf371oca5s7mQZWyrQHUgOUplW0GQmpUKYqRt 5j3A==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@wilibox.com header.s=default header.b="fqt/pi96"; spf=pass (google.com: domain of ernestas.k@wilibox.com designates 62.77.155.212 as permitted sender) smtp.mailfrom=ernestas.k@wilibox.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wilibox.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1712581067; x=1713185867; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :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=KJNyVZGVjfz9mR2R9H/ZdZU6bEMYun3KuqopXBS9U8E=; b=u2qvOn37G3wBf0pJ8p3V+QKtuhdbMEjALvs1wGW4faFKW+lz14Rq+mO5nlrW5dY9tb Ikl147AMwx7CnpAAVkdC77BMq4wbC0ACHZv8lOptqJPaFVuyZcC70Rx0rQTnbJu4SdCP 0UOiypFJuD5vn5hNogIjR5BZwqPeqdVrDHrutpxbe6Ws6K9F+x2v4V95M4LaY5eVZO/l NSQzWZ56ZTWDXEVYh8CNG3+dGcBr8yitGqzzo7Gu4K0/mCJZZf9WfRDgH9Q+479ouLm/ AV7M/wou/M4WvTSia0v8NyDhW+HSssbczEjkmoyLHdJlV31vK3FG8SeexmShrsT3tSJA r1EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712581067; x=1713185867; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:mime-version :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=KJNyVZGVjfz9mR2R9H/ZdZU6bEMYun3KuqopXBS9U8E=; b=IW2BM+mcEwvlpPIgsLqFwh0t5Crm3VTiwAVFq9k95hxGX+1XjlTNtYCykdTPz7IzdY pUWmW8FFbu/8GBoDDBAJqkxNo3UNxdRDrSGhFhhJI62mt1MRWAha1b1Y3YTDSdxQzX+7 mFKAR5XJZ8Zzr8ItzmvZ9BXW1GyUjnRbkFzBsgEisLQMWjdNlzNTlzTkjIjUlr03Eksg KV2nHazTIqwh+AugQLKlaUFABBP8PEflaJnRlCD/KQmScq/PvwQg6hCKuFn0LzJmCg0e GaU4hMnVKoVtWmzMay7d81F/d6RHAMs11eoElN3zauGyVq7V3Kv7HzG0MggKJ3Wr9Pwv 2AqQ== X-Forwarded-Encrypted: i=2; AJvYcCVy377lwQXAgM+DXW+ayyKOIcousul5/usc/o0xAZ/UHtmXUsWPsfyXdu8AwyDRZ5/UXSG+JlQhuGMEgvjmov49dye87hp2FtoCQGWB7Q== X-Gm-Message-State: AOJu0Yyt3FWfKrP0lAdqwzbYM7QN7P35Mjevs+ZxrA+u7H7WF5XPhXOq +NaogcHr7NNbbas6lo5/hjPdo0bJqLOGbd/IYRLawr3Fi18dp2dY X-Google-Smtp-Source: AGHT+IFkVXP1HLWucQnzDEtI/ql/3nX4vYGZCg3rSBOV3HuHwSSNc/2TqIDmYu98p4lfob9M4V/fSA== X-Received: by 2002:a2e:8ecd:0:b0:2d8:4af7:1235 with SMTP id e13-20020a2e8ecd000000b002d84af71235mr5375279ljl.44.1712581066678; Mon, 08 Apr 2024 05:57:46 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:9013:0:b0:2d3:3a2f:99a0 with SMTP id h19-20020a2e9013000000b002d33a2f99a0ls26102ljg.0.-pod-prod-09-eu; Mon, 08 Apr 2024 05:57:44 -0700 (PDT) X-Received: by 2002:a05:651c:1693:b0:2d6:cb82:24e6 with SMTP id bd19-20020a05651c169300b002d6cb8224e6mr5217730ljb.37.1712581064475; Mon, 08 Apr 2024 05:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712581064; cv=none; d=google.com; s=arc-20160816; b=fqQqlqo6YKv457d90RqtwsSkI3NKJg6oh6KgQglclMIKRthyYMZcTWi1tnmCm0tEJS 9KbbQPRSEuJJBZAIfCO/nKFU5mN6XjjpyFhFBeYFjO5xPpeji0J09EgyUBEFI+u1Wg1W o0vftxsBRAfVpQxN/Q/JOYuwMj5b286ZcCRPmqX8BRmsrAqLakmAv7qetcz8U5wAwnKu wOrVocGMSA5y5rc4FZa1rRW1Hi+NKLNnxKmiOtg5t320B7lGrsmjjU0Griq8MEc5G0oy n2ekRvmvT0jjUEY9vbx19zmjMDLhh0FjuwyLUOaB/SkkT9ibf+FE19pIf4s9sg0jaLvV 0VVA== 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=JGz2VE+TGZ59Yb4U8RpjKtFCJSAcQYUxy7fLzTKWCH4=; fh=Dc3A/FkoMh70uYzOCCTQTgVTS+Ckl+RvIIBgKZzWlfA=; b=OQliP4OjMbypdaXMFLUb7tvCuhHvd3LYFblhIDCqL44LMfxvoSWpjAASMqXZMdNAKn E63IXBE7BCJgcfD0h6xE7cb4SQcE9/sZlgURbg+tg2/wb/kQQX1ZYuzUhIrBVr4euaYS 78QWalZfTmgSE9aAxKabcW+TVMpeyXvybAFVHyeceXX8eermcMklUnHeIlRL5r+PQw2s XgfnCL14uqYZmxIsMQf3f+ZZ5Nusz43t6wkNk1krTNqaduaisWZmEAU1Sa53+KzW3iC/ dIBNuubABQTINZ6qkNg8tlj9K90Qg5Nv6OuEEdSXd3jaXOwRUJtXQOycgzSjFUDWGdsa BGKQ==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@wilibox.com header.s=default header.b="fqt/pi96"; spf=pass (google.com: domain of ernestas.k@wilibox.com designates 62.77.155.212 as permitted sender) smtp.mailfrom=ernestas.k@wilibox.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wilibox.com Received: from zebra.wilibox.com (zebra.wilibox.com. [62.77.155.212]) by gmr-mx.google.com with ESMTPS id l14-20020a05600c1d0e00b00416488ec4d9si96521wms.0.2024.04.08.05.57.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 05:57:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ernestas.k@wilibox.com designates 62.77.155.212 as permitted sender) client-ip=62.77.155.212; Received: from localhost.localdomain (81-7-79-211.static.zebra.lt [81.7.79.211]) (Authenticated sender: ernestas.k@wilibox.com) by zebra.wilibox.com (Postfix) with ESMTPSA id C4528161CEE; Mon, 8 Apr 2024 15:57:42 +0300 (EEST) X-Patchwork-Original-From: "'Ernestas Kulik' via swupdate" From: Ernestas Kulik To: swupdate@googlegroups.com Cc: Ernestas Kulik Subject: [swupdate] [PATCH] handlers: ubivol: Allow specifying MTD device Date: Mon, 8 Apr 2024 15:56:20 +0300 Message-Id: <20240408125620.2510328-1-ernestas.k@wilibox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Original-Sender: ernestas.k@wilibox.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@wilibox.com header.s=default header.b="fqt/pi96"; spf=pass (google.com: domain of ernestas.k@wilibox.com designates 62.77.155.212 as permitted sender) smtp.mailfrom=ernestas.k@wilibox.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wilibox.com X-Original-From: Ernestas Kulik Reply-To: Ernestas Kulik 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: , Updates will typically fail in devices that use multiple MTD partitions for failsafe upgrades and identical UBI volume names, since only the first partition will match. Allowing to specify the device as well as volume name in images allows such cases to work. Signed-off-by: Ernestas Kulik Reviewed-by: Stefano Babic --- handlers/ubivol_handler.c | 45 +++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c index 251f917..9db6472 100644 --- a/handlers/ubivol_handler.c +++ b/handlers/ubivol_handler.c @@ -51,6 +51,26 @@ static struct ubi_part *search_volume_global(const char *str) return NULL; } +/* search for a UBI volume by name on a specified MTD partition */ +static struct ubi_part *search_volume_local(char *device, const char *volname) +{ + struct flash_description *flash = get_flash_info(); + int mtdnum; + struct mtd_ubi_info *mtd_ubi_info; + + mtdnum = get_mtd_from_device(device); + if (mtdnum < 0) { + mtdnum = get_mtd_from_name(device); + } + if (mtdnum < 0 || !mtd_dev_present(flash->libmtd, mtdnum)) { + ERROR("%s does not exist", device); + return NULL; + } + mtd_ubi_info = &flash->mtd_info[mtdnum]; + + return search_volume(volname, &mtd_ubi_info->ubi_partitions); +} + /** * check_replace - check for and validate replace property * @img: image information @@ -77,7 +97,10 @@ static int check_replace(struct img_type *img, if (tmpvol_name == NULL) return 0; - tmpvol = search_volume_global(tmpvol_name); + if (strlen(img->device)) + tmpvol = search_volume_local(img->device, tmpvol_name); + else + tmpvol = search_volume_global(tmpvol_name); if (!tmpvol) { INFO("replace: unable to find a volume %s, will rename", tmpvol_name); @@ -400,7 +423,11 @@ static int wait_volume(struct img_type *img) struct stat buf; char node[64]; - ubivol = search_volume_global(img->volname); + if (strlen(img->device)) + ubivol = search_volume_local(img->device, img->volname); + else + ubivol = search_volume_global(img->volname); + if (!ubivol) { ERROR("can't found volume %s", img->volname); return -1; @@ -451,7 +478,10 @@ static int install_ubivol_image(struct img_type *img, } /* find the volume to be updated */ - ubivol = search_volume_global(img->volname); + if (strlen(img->device)) + ubivol = search_volume_local(img->device, img->volname); + else + ubivol = search_volume_global(img->volname); if (!ubivol) { ERROR("Image %s should be stored in volume " @@ -472,11 +502,14 @@ static int adjust_volume(struct img_type *cfg, return resize_volume(cfg, cfg->partsize); } -static int ubi_volume_get_info(char *name, int *dev_num, int *vol_id) +static int ubi_volume_get_info(char *device, char *name, int *dev_num, int *vol_id) { struct ubi_part *ubi_part; - ubi_part = search_volume_global(name); + if (device) + ubi_part = search_volume_local(device, name); + else + ubi_part = search_volume_global(name); if (!ubi_part) { ERROR("could not found UBI volume %s", name); return -1; @@ -533,7 +566,7 @@ static int swap_volume(struct img_type *img, void *data) } name[num] = volume->value; - if (ubi_volume_get_info(volume->value, + if (ubi_volume_get_info(img->device, volume->value, &dev_num[num], &vol_id[num]) < 0) goto out;