{"id":2228630,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2228630/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/d7ec0e5d655f8c2f1d159908f74d00927d7a0776.1777272283.git.weijie.gao@mediatek.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/1.1/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<d7ec0e5d655f8c2f1d159908f74d00927d7a0776.1777272283.git.weijie.gao@mediatek.com>","date":"2026-04-27T07:09:39","name":"[v3,10/10] env: ubi: add support to create environment volume if it does not exist","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"55ac9f8a8f234ef7788636cd2bb71c0a65464c7c","submitter":{"id":75269,"url":"http://patchwork.ozlabs.org/api/1.1/people/75269/?format=json","name":"Weijie Gao","email":"weijie.gao@mediatek.com"},"delegate":{"id":1691,"url":"http://patchwork.ozlabs.org/api/1.1/users/1691/?format=json","username":"hs","first_name":"Heiko","last_name":"Schocher","email":"hs@denx.de"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/d7ec0e5d655f8c2f1d159908f74d00927d7a0776.1777272283.git.weijie.gao@mediatek.com/mbox/","series":[{"id":501588,"url":"http://patchwork.ozlabs.org/api/1.1/series/501588/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=501588","date":"2026-04-27T07:09:11","name":"Add support for ubi environment to create volumes (v3)","version":3,"mbox":"http://patchwork.ozlabs.org/series/501588/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2228630/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2228630/checks/","tags":{},"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=mediatek.com header.i=@mediatek.com header.a=rsa-sha256\n header.s=dk header.b=XYe4wejp;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de\n (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de;\n envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org)","phobos.denx.de;\n dmarc=pass (p=quarantine dis=none) header.from=mediatek.com","phobos.denx.de;\n spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de","phobos.denx.de;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=mediatek.com header.i=@mediatek.com\n header.b=\"XYe4wejp\";\n\tdkim-atps=neutral","phobos.denx.de; dmarc=pass (p=quarantine dis=none)\n header.from=mediatek.com","phobos.denx.de;\n spf=pass smtp.mailfrom=weijie.gao@mediatek.com"],"Received":["from phobos.denx.de (phobos.denx.de\n [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g3vqZ20hGz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 27 Apr 2026 17:11:06 +1000 (AEST)","from h2850616.stratoserver.net (localhost [IPv6:::1])\n\tby phobos.denx.de (Postfix) with ESMTP id F36B3842E7;\n\tMon, 27 Apr 2026 09:09:51 +0200 (CEST)","by phobos.denx.de (Postfix, from userid 109)\n id 6D21580433; Mon, 27 Apr 2026 09:09:49 +0200 (CEST)","from mailgw02.mediatek.com (unknown [210.61.82.184])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits))\n (No client certificate requested)\n by phobos.denx.de (Postfix) with ESMTPS id 1E6C783AA9\n for <u-boot@lists.denx.de>; Mon, 27 Apr 2026 09:09:45 +0200 (CEST)","from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by\n mailgw02.mediatek.com (envelope-from <weijie.gao@mediatek.com>)\n (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256)\n with ESMTP id 89929218; Mon, 27 Apr 2026 15:09:42 +0800","from mtkmbs11n2.mediatek.inc (172.21.101.187) by\n mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server\n (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id\n 15.2.2562.29; Mon, 27 Apr 2026 15:09:41 +0800","from mcddlt001.gcn.mediatek.inc (10.19.240.15) by\n mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id\n 15.2.2562.29 via Frontend Transport; Mon, 27 Apr 2026 15:09:40 +0800"],"X-Spam-Checker-Version":"SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-1.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,\n DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED,\n RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,RDNS_NONE,SPF_HELO_PASS,SPF_PASS,\n UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2","X-UUID":["1046706a420811f19a16598d5ca7f8ec-20260427","1046706a420811f19a16598d5ca7f8ec-20260427"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n d=mediatek.com;\n s=dk;\n h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From;\n bh=d19RNAfcB6xvbqPEsT0OpZPgE6rf5NHvqfa22CEZ06s=;\n b=XYe4wejpPkzLceYXzUpJ9U6oLB0LedZ6ugjm2L5WjPkFGGgoDGsQ8LdzdWlq0Wi5oaaKvQevLvDXCHLnaALGa1hwQK4F/MR9g4Ew75cJ5fi2NC+3wOTACYPVNGczGbdVPOJ/dURa48BUra9j5jKGC9tqXSl22jQ20GowN4vML5s=;","X-CID-P-RULE":"Release_Ham","X-CID-O-INFO":"VERSION:1.3.12, REQID:2ae9ae0e-577c-4bad-8e49-764bb7faabfd,\n IP:0,\n U\n RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:\n release,TS:0","X-CID-META":"VersionHash:e7bac3a, CLOUDID:f92a7fbe-65a8-4b41-ac18-3671578a914d,\n B\n ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|836|865|888|898,TC:-5,Cont\n ent:0|15|50,EDM:-3,IP:nil,URL:0,File:130,RT:0,Bulk:nil,QS:nil,BEC:-1,COL:0\n ,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0","X-CID-BVR":"2,SSN|SDN","X-CID-BAS":"2,SSN|SDN,0,_","X-CID-FACTOR":"TF_CID_SPAM_SNR","X-CID-RHF":"D41D8CD98F00B204E9800998ECF8427E","From":"Weijie Gao <weijie.gao@mediatek.com>","To":"<u-boot@lists.denx.de>","CC":"GSS_MTK_Uboot_upstream <GSS_MTK_Uboot_upstream@mediatek.com>, Tom Rini\n <trini@konsulko.com>, Marek Vasut <marek.vasut+renesas@mailbox.org>, Simon\n Glass <sjg@chromium.org>, Weijie Gao <weijie.gao@mediatek.com>","Subject":"[PATCH v3 10/10] env: ubi: add support to create environment volume\n if it does not exist","Date":"Mon, 27 Apr 2026 15:09:39 +0800","Message-ID":"\n <d7ec0e5d655f8c2f1d159908f74d00927d7a0776.1777272283.git.weijie.gao@mediatek.com>","X-Mailer":"git-send-email 2.17.0","In-Reply-To":"<cover.1777272283.git.weijie.gao@mediatek.com>","References":"<cover.1777272283.git.weijie.gao@mediatek.com>","MIME-Version":"1.0","Content-Type":"text/plain","X-MTK":"N","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.39","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<https://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n <mailto:u-boot-request@lists.denx.de?subject=subscribe>","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>","X-Virus-Scanned":"clamav-milter 0.103.8 at phobos.denx.de","X-Virus-Status":"Clean"},"content":"Add an option to allow environment volume being auto created if not\nexist.\n\nSigned-off-by: Weijie Gao <weijie.gao@mediatek.com>\n---\nv2: updated kconfig help text\n    added error output when failed to create volume\nv3: fix error handling and default env setting\n---\n env/Kconfig | 11 +++++++++++\n env/ubi.c   | 35 ++++++++++++++++++++++++++++++++++-\n 2 files changed, 45 insertions(+), 1 deletion(-)","diff":"diff --git a/env/Kconfig b/env/Kconfig\nindex 7abd82ab6f3..8404e0d44eb 100644\n--- a/env/Kconfig\n+++ b/env/Kconfig\n@@ -716,6 +716,17 @@ config ENV_UBI_VOLUME_REDUND\n \thelp\n \t  Name of the redundant volume that you want to store the environment in.\n \n+config ENV_UBI_VOLUME_CREATE\n+\tbool \"Create UBI volume if not exist\"\n+\tdepends on ENV_IS_IN_UBI\n+\thelp\n+\t  This option is useful if u-boot will be booted from a fresh device\n+\t  where environment volume hasn't been created in the UBI partition.\n+\t  This is a common case where factory UBI image contains only volumes\n+\t  with valid data.\n+\t  By enabling this option, environment volume(s) will be created before\n+\t  loading if not exist.\n+\n config ENV_UBI_VID_OFFSET\n \tint \"ubi environment VID offset\"\n \tdepends on ENV_IS_IN_UBI\ndiff --git a/env/ubi.c b/env/ubi.c\nindex 46970ba754f..6b995ce40ac 100644\n--- a/env/ubi.c\n+++ b/env/ubi.c\n@@ -103,12 +103,29 @@ static int env_ubi_save(void)\n }\n #endif /* CONFIG_ENV_REDUNDANT */\n \n+static int env_ubi_volume_create(const char *volume)\n+{\n+\tstruct ubi_volume *vol;\n+\tint ret;\n+\n+\tvol = ubi_find_volume(volume);\n+\tif (vol)\n+\t\treturn 0;\n+\n+\tret = ubi_create_vol(volume, CONFIG_ENV_SIZE, true, UBI_VOL_NUM_AUTO,\n+\t\t\t     false);\n+\tif (ret)\n+\t\tprintf(\"Failed to create environment volume '%s'\\n\", volume);\n+\n+\treturn ret;\n+}\n+\n #ifdef CONFIG_ENV_REDUNDANT\n static int env_ubi_load(void)\n {\n \tALLOC_CACHE_ALIGN_BUFFER(char, env1_buf, CONFIG_ENV_SIZE);\n \tALLOC_CACHE_ALIGN_BUFFER(char, env2_buf, CONFIG_ENV_SIZE);\n-\tint read1_fail, read2_fail;\n+\tint read1_fail, read2_fail, create1_fail, create2_fail;\n \tenv_t *tmp_env1, *tmp_env2;\n \n \t/*\n@@ -132,6 +149,15 @@ static int env_ubi_load(void)\n \t\treturn -EIO;\n \t}\n \n+\tif (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) {\n+\t\tcreate1_fail = env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME);\n+\t\tcreate2_fail = env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME_REDUND);\n+\t\tif (create1_fail && create2_fail) {\n+\t\t\tenv_set_default(NULL, 0);\n+\t\t\treturn -ENODEV;\n+\t\t}\n+\t}\n+\n \tread1_fail = ubi_volume_read(CONFIG_ENV_UBI_VOLUME, tmp_env1, 0,\n \t\t\t\t     CONFIG_ENV_SIZE);\n \tif (read1_fail)\n@@ -169,6 +195,13 @@ static int env_ubi_load(void)\n \t\treturn -EIO;\n \t}\n \n+\tif (IS_ENABLED(CONFIG_ENV_UBI_VOLUME_CREATE)) {\n+\t\tif (env_ubi_volume_create(CONFIG_ENV_UBI_VOLUME)) {\n+\t\t\tenv_set_default(NULL, 0);\n+\t\t\treturn -ENODEV;\n+\t\t}\n+\t}\n+\n \tif (ubi_volume_read(CONFIG_ENV_UBI_VOLUME, buf, 0, CONFIG_ENV_SIZE)) {\n \t\tprintf(\"\\n** Unable to read env from %s:%s **\\n\",\n \t\t       CONFIG_ENV_UBI_PART, CONFIG_ENV_UBI_VOLUME);\n","prefixes":["v3","10/10"]}