From patchwork Tue Feb 26 12:45:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Waibel Georg X-Patchwork-Id: 223215 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 37E6F2C02F5 for ; Tue, 26 Feb 2013 23:46:20 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1ABF64A046; Tue, 26 Feb 2013 13:46:17 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 ZKq6Q3eKBBeH; Tue, 26 Feb 2013 13:46:16 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DF7FD4A047; Tue, 26 Feb 2013 13:46:15 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 308454A047 for ; Tue, 26 Feb 2013 13:46:07 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 6vLX3umI7tVM for ; Tue, 26 Feb 2013 13:46:01 +0100 (CET) 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 mail.sensor-technik.de (mail.sensor-technik.de [80.150.181.156]) by theia.denx.de (Postfix) with ESMTP id AFC0A4A046 for ; Tue, 26 Feb 2013 13:45:58 +0100 (CET) X-IronPort-AV: E=Sophos;i="4.84,741,1355094000"; d="scan'208";a="101027" Received: from unknown (HELO stwkeys.sensor-technik.de) ([172.25.208.3]) by mail.sensor-technik.de with ESMTP; 26 Feb 2013 13:45:58 +0100 Received: from stwkeys.sensor-technik.de (localhost [127.0.0.1]) by stwkeys.sensor-technik.de (Postfix) with ESMTP id 22D5218C073 for ; Tue, 26 Feb 2013 13:45:58 +0100 (CET) Received: from mail.sensor-technik.de (unknown [172.25.2.15]) by stwkeys.sensor-technik.de (Postfix) with ESMTP id ED49E18C054 for ; Tue, 26 Feb 2013 13:45:57 +0100 (CET) Received: from STWEXDB.stww2k.local ([172.25.2.16]) by stwexca.stww2k.local ([172.25.2.15]) with mapi id 14.02.0318.004; Tue, 26 Feb 2013 13:45:52 +0100 From: Waibel Georg To: "u-boot@lists.denx.de" Thread-Topic: [U-Boot] Flash protection and fw_setenv tool Thread-Index: Ac4UHrwOQWy2RHPTTu+UHy+vN8qXAA== Date: Tue, 26 Feb 2013 12:45:51 +0000 Message-ID: Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.4.201] MIME-Version: 1.0 X-TBoneOriginalFrom: Waibel Georg X-TBoneOriginalTo: "u-boot@lists.denx.de" X-TBoneDomainSigned: false Subject: Re: [U-Boot] Flash protection and fw_setenv tool X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Hi again, the previous patch missed some places to apply the unprotect switch. Here's an improved version: Index: common/env_flash.c =================================================================== --- common/env_flash.c (revision 4065) +++ common/env_flash.c (working copy) @@ -218,9 +218,12 @@ done: if (saved_data) free(saved_data); + +#ifndef CONFIG_ENV_UNPROTECTED /* try to re-protect */ flash_sect_protect(1, (ulong)flash_addr, end_addr); flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new); +#endif return rc; } @@ -310,7 +313,9 @@ if (saved_data) free(saved_data); /* try to re-protect */ +#ifndef CONFIG_ENV_UNPROTECTED flash_sect_protect(1, (long)flash_addr, end_addr); +#endif return rc; } #endif /* CMD_SAVEENV */ @@ -340,7 +345,9 @@ flash_write(&flag, (ulong)&(flash_addr_new->flags), sizeof(flash_addr_new->flags)); +#ifndef CONFIG_ENV_UNPROTECTED flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new); +#endif } if (flash_addr->flags != ACTIVE_FLAG && @@ -352,7 +359,9 @@ flash_write(&flag, (ulong)&(flash_addr->flags), sizeof(flash_addr->flags)); +#ifndef CONFIG_ENV_UNPROTECTED flash_sect_protect(1, (ulong)flash_addr, end_addr); +#endif } if (gd->env_valid == 2) Index: drivers/mtd/cfi_flash.c =================================================================== --- drivers/mtd/cfi_flash.c (revision 4065) +++ drivers/mtd/cfi_flash.c (working copy) @@ -2294,7 +2294,7 @@ #endif /* Environment protection ON by default */ -#ifdef CONFIG_ENV_IS_IN_FLASH +#if defined(CONFIG_ENV_IS_IN_FLASH) && !defined(CONFIG_ENV_UNPROTECTED) flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR, CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1, @@ -2302,7 +2302,7 @@ #endif /* Redundant environment protection ON by default */ -#ifdef CONFIG_ENV_ADDR_REDUND +#if defined(CONFIG_ENV_ADDR_REDUND) && !defined(CONFIG_ENV_UNPROTECTED) flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND, CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1, Regards Georg -----Ursprüngliche Nachricht----- Von: u-boot-bounces@lists.denx.de [mailto:u-boot-bounces@lists.denx.de] Im Auftrag von Waibel Georg Gesendet: Dienstag, 26. Februar 2013 12:05 An: 'u-boot@lists.denx.de' Betreff: [U-Boot] Flash protection and fw_setenv tool Hi, I activated flash sector protection for our CFI NOR flash chip (CONFIG_SYS_FLASH_PROTECTION). Protection bits for U-Boot code sectors and environment sector are set by default during U-Boot startup. Thus from Linux, I cannot write to this sectors, which is generally a correct behavior. BUT, with this, changing the environment from user space with the fw_setenv tool does not work anymore. And here's the question: How to deal with this issue correctly? Two approaches came in my mind: a) Unprotecting the flash sectors by the Linux kernel (in CFI driver). This seems not to be implemented yet, at least for AMD CFI command set (0x0002). However, when unprotecting flash sectors from Linux side, does a sector protection actually makes sense? b) Introduce a config option in U-Boot which allows to leave the environment unprotected. See patch below. I called this option CONFIG_ENV_UNPROTECTED When defined, U-Boot does not protect the environment. For compatibility with boards in which the environment sector is already protected, I left the unprotect part in the saveenv function untouched. Any comments about this issue? Thanks and regards Georg Index: common/env_flash.c =================================================================== --- common/env_flash.c (revision 3966) +++ common/env_flash.c (working copy) @@ -218,9 +218,12 @@ done: if (saved_data) free(saved_data); + +#ifndef CONFIG_ENV_UNPROTECTED /* try to re-protect */ flash_sect_protect(1, (ulong)flash_addr, end_addr); flash_sect_protect(1, (ulong)flash_addr_new, end_addr_new); +#endif return rc; } Index: drivers/mtd/cfi_flash.c =================================================================== --- drivers/mtd/cfi_flash.c (revision 3966) +++ drivers/mtd/cfi_flash.c (working copy) @@ -2294,7 +2294,7 @@ #endif /* Environment protection ON by default */ -#ifdef CONFIG_ENV_IS_IN_FLASH +#if defined(CONFIG_ENV_IS_IN_FLASH) && !defined(CONFIG_ENV_UNPROTECTED) flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR, CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,