From patchwork Tue May 24 12:59:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcin Niestroj X-Patchwork-Id: 625614 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3rDb9T2G7Qz9s6r for ; Tue, 24 May 2016 23:00:13 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B675CA7607; Tue, 24 May 2016 15:00:11 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jG2RBWZfqdob; Tue, 24 May 2016 15:00:11 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0EE54A7548; Tue, 24 May 2016 15:00:11 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4BF6BA7548 for ; Tue, 24 May 2016 15:00:07 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UQ1RVzSZs9j4 for ; Tue, 24 May 2016 15:00:07 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from vk1046.megiteam.com.pl (2780.rev.megiteam.pl [91.227.39.128]) by theia.denx.de (Postfix) with ESMTP id 1C6FBA74FB for ; Tue, 24 May 2016 15:00:03 +0200 (CEST) Received: from gm.localdomain (unknown [95.143.241.142]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: marcin.niestroj@grinn-global.com) by vk1046.megiteam.com.pl (Postfix) with ESMTP id D3A386233FC9; Tue, 24 May 2016 15:01:19 +0200 (CEST) From: Marcin Niestroj To: u-boot@lists.denx.de Date: Tue, 24 May 2016 14:59:55 +0200 Message-Id: <1464094795-19396-1-git-send-email-m.niestroj@grinn-global.com> X-Mailer: git-send-email 2.8.2 X-Virus-Scanned: by amavisd-new Subject: [U-Boot] [PATCH] common: env_ubi: Clear environment buffer before reading X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In case we have restarted u-boot there is a chance that environment buffer contains old environment (from the previous boot). If UBI volume is zero size, ubi_volume_read() doesn't modify the buffer and exits successfully. We need to clear buffer manually before reading it from UBI, so the invalid CRC will cause setting default environment in case that the UBI volume is zero size. Signed-off-by: Marcin Niestroj --- common/env_ubi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/common/env_ubi.c b/common/env_ubi.c index 77bbfa6..b021395 100644 --- a/common/env_ubi.c +++ b/common/env_ubi.c @@ -114,6 +114,17 @@ void env_relocate_spec(void) int crc1_ok = 0, crc2_ok = 0; env_t *ep, *tmp_env1, *tmp_env2; + /* + * In case we have restarted u-boot there is a chance that buffer + * contains old environment (from the previous boot). + * If UBI volume is zero size, ubi_volume_read() doesn't modify the + * buffer. + * We need to clear buffer manually here, so the invalid CRC will + * cause setting default environment as expected. + */ + memset(env1_buf, 0x0, CONFIG_ENV_SIZE); + memset(env2_buf, 0x0, CONFIG_ENV_SIZE); + tmp_env1 = (env_t *)env1_buf; tmp_env2 = (env_t *)env2_buf; @@ -173,6 +184,16 @@ void env_relocate_spec(void) { ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); + /* + * In case we have restarted u-boot there is a chance that buffer + * contains old environment (from the previous boot). + * If UBI volume is zero size, ubi_volume_read() doesn't modify the + * buffer. + * We need to clear buffer manually here, so the invalid CRC will + * cause setting default environment as expected. + */ + memset(buf, 0x0, CONFIG_ENV_SIZE); + if (ubi_part(CONFIG_ENV_UBI_PART, NULL)) { printf("\n** Cannot find mtd partition \"%s\"\n", CONFIG_ENV_UBI_PART);