From patchwork Sat Jan 16 21:14:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Maier X-Patchwork-Id: 1427579 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=rockwellcollins.com header.i=@rockwellcollins.com header.a=rsa-sha256 header.s=hrcrc2020 header.b=dKF1kaa/; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DJ9nF4M5Xz9sVs for ; Sun, 17 Jan 2021 08:15:20 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9CED88297C; Sat, 16 Jan 2021 22:15:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=rockwellcollins.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=rockwellcollins.com header.i=@rockwellcollins.com header.b="dKF1kaa/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6BD1982986; Sat, 16 Jan 2021 22:15:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from da1vs04.rockwellcollins.com (da1vs04.rockwellcollins.com [205.175.227.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9BF6A82979 for ; Sat, 16 Jan 2021 22:15:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=rockwellcollins.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=brandon.maier@rockwellcollins.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rockwellcollins.com; s=hrcrc2020; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Oh6oEJ9qhYeFGiIwxhNhRykmS5HTbbMwiE77kojlkqA=; b=dKF1kaa/acrl1oHCIJC3xEwdY4BKIdyNZUnxC8YANiQdIdfMYskXGokU H8LlWhVP6OV3kIJZy8UAEv32bL7aijQBm0PTrLMDnOkhmPJCdBGM3Sz6B JtdH7X9PUMj6kDcjgwa/ctgXMdLO32NXHD47tfP+orVOEEAE81ng9HaEn JLojgeOfat+WxB4HU7RGlgPFxdTqEIYltY/OdFS+W2OrKq3xCuZ8qnwNu lpYmhabffovaE3PTtTUbHBI2VUEeXDLdLEm2MKv1qMea63D19Df7AWJZU jf0AMwe4AFC1xdWPvX4bw436xB4gueJOd0cv+bO5VlDvLZ/XM4piGA6oH w==; IronPort-SDR: 2/eSdB0Z8rQzPntiRi9tEqqrJZy5ITedV2vdIfbauCkgjy3RqAy3wm/TtQVrejHalgXRiJINsx l+C8SACCBnq2VgrJ6nIZtPAWnosKuS1DfLdP4XLbKva8t/XzZxkA8GSh271jGnexVEJo8Sh1tt ZFUXwiTHGdOcJR84Fal7gI4d7+U/Jo/UN2ym77X3lzGG++zloOJgYX7qm/Dgu0XmPxi4hqfdTS KAjeswRYUMTM9PaMo4uEhdei1dSCw4rZVMN5RRyCbqZ0B85AuBOw7c8DfAUWuCNA2NDELEfRfi ctY= Received: from ofwda1n02.rockwellcollins.com (HELO ciulimr02.rockwellcollins.com) ([205.175.227.14]) by da1vs04.rockwellcollins.com with ESMTP; 16 Jan 2021 15:15:03 -0600 X-Received: from righttwix.rockwellcollins.com (righttwix.rockwellcollins.com [192.168.141.218]) by ciulimr02.rockwellcollins.com (Postfix) with ESMTP id 75C7820051; Sat, 16 Jan 2021 15:15:03 -0600 (CST) From: Brandon Maier To: u-boot@lists.denx.de Cc: Brandon Maier , Joe Hershberger , Wolfgang Denk Subject: [PATCH] env/fat.c: support redund environment Date: Sat, 16 Jan 2021 15:14:43 -0600 Message-Id: <20210116211443.138744-1-brandon.maier@rockwellcollins.com> X-Mailer: git-send-email 2.29.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Signed-off-by: Brandon Maier CC: Joe Hershberger CC: Wolfgang Denk --- env/Kconfig | 13 +++++++++++-- env/fat.c | 41 +++++++++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/env/Kconfig b/env/Kconfig index 67ce93061b..a940ddce95 100644 --- a/env/Kconfig +++ b/env/Kconfig @@ -411,8 +411,9 @@ config ENV_IS_IN_UBI config SYS_REDUNDAND_ENVIRONMENT bool "Enable redundant environment support" - depends on ENV_IS_IN_EEPROM || ENV_IS_IN_FLASH || ENV_IS_IN_MMC || \ - ENV_IS_IN_NAND || ENV_IS_IN_SPI_FLASH || ENV_IS_IN_UBI + depends on ENV_IS_IN_EEPROM || ENV_IS_IN_FAT || ENV_IS_IN_FLASH || \ + ENV_IS_IN_MMC || ENV_IS_IN_NAND || ENV_IS_IN_SPI_FLASH || \ + ENV_IS_IN_UBI help Normally, the environemt is stored in a single location. By selecting this option, you can then define where to hold a redundant @@ -461,6 +462,14 @@ config ENV_FAT_FILE It's a string of the FAT file name. This file use to store the environment. +config ENV_FAT_FILE_REDUND + string "Name of the FAT file to use for the environment" + depends on ENV_IS_IN_FAT && SYS_REDUNDAND_ENVIRONMENT + default "uboot-redund.env" + help + It's a string of the FAT file name. This file use to store the + redundant environment. + config ENV_EXT4_INTERFACE string "Name of the block device for the environment" depends on ENV_IS_IN_EXT4 diff --git a/env/fat.c b/env/fat.c index 653a38fd93..e4cd5970b4 100644 --- a/env/fat.c +++ b/env/fat.c @@ -29,6 +29,10 @@ # define LOADENV #endif +#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT +DECLARE_GLOBAL_DATA_PTR; +#endif + static char *env_fat_device_and_part(void) { #ifdef CONFIG_MMC @@ -53,6 +57,7 @@ static int env_fat_save(void) env_t __aligned(ARCH_DMA_MINALIGN) env_new; struct blk_desc *dev_desc = NULL; struct disk_partition info; + const char *file = CONFIG_ENV_FAT_FILE; int dev, part; int err; loff_t size; @@ -78,29 +83,41 @@ static int env_fat_save(void) return 1; } - err = file_fat_write(CONFIG_ENV_FAT_FILE, (void *)&env_new, 0, sizeof(env_t), - &size); +#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT + if (gd->env_valid == ENV_VALID) + file = CONFIG_ENV_FAT_FILE_REDUND; +#endif + + err = file_fat_write(file, (void *)&env_new, 0, sizeof(env_t), &size); if (err == -1) { /* * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. */ printf("Unable to write \"%s\" from %s%d:%d... ", - CONFIG_ENV_FAT_FILE, CONFIG_ENV_FAT_INTERFACE, dev, part); + file, CONFIG_ENV_FAT_INTERFACE, dev, part); return 1; } +#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT + gd->env_valid = (gd->env_valid == ENV_REDUND) ? ENV_VALID : ENV_REDUND; +#endif + return 0; } #ifdef LOADENV static int env_fat_load(void) { - ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); + ALLOC_CACHE_ALIGN_BUFFER(char, buf1, CONFIG_ENV_SIZE); +#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT + ALLOC_CACHE_ALIGN_BUFFER(char, buf2, CONFIG_ENV_SIZE); + int err2; +#endif struct blk_desc *dev_desc = NULL; struct disk_partition info; int dev, part; - int err; + int err1; #ifdef CONFIG_MMC if (!strcmp(CONFIG_ENV_FAT_INTERFACE, "mmc")) @@ -124,8 +141,15 @@ static int env_fat_load(void) goto err_env_relocate; } - err = file_fat_read(CONFIG_ENV_FAT_FILE, buf, CONFIG_ENV_SIZE); - if (err == -1) { + err1 = file_fat_read(CONFIG_ENV_FAT_FILE, buf1, CONFIG_ENV_SIZE); +#ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT + err2 = file_fat_read(CONFIG_ENV_FAT_FILE_REDUND, buf2, CONFIG_ENV_SIZE); + + err1 = (err1 >= 0) ? 0 : -1; + err2 = (err2 >= 0) ? 0 : -1; + return env_import_redund(buf1, err1, buf2, err2, H_EXTERNAL); +#else + if (err1 < 0) { /* * This printf is embedded in the messages from env_save that * will calling it. The missing \n is intentional. @@ -135,7 +159,8 @@ static int env_fat_load(void) goto err_env_relocate; } - return env_import(buf, 1, H_EXTERNAL); + return env_import(buf1, 1, H_EXTERNAL); +#endif err_env_relocate: env_set_default(NULL, 0);