From patchwork Tue Oct 22 10:25:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Schocher X-Patchwork-Id: 285395 X-Patchwork-Delegate: trini@ti.com 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 57DFA2C0092 for ; Tue, 22 Oct 2013 21:26:59 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EA1744A2B3; Tue, 22 Oct 2013 12:26:45 +0200 (CEST) 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 vDV9cw8HIbge; Tue, 22 Oct 2013 12:26:45 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AAEE74A2BB; Tue, 22 Oct 2013 12:26:17 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3F61D4A29E for ; Tue, 22 Oct 2013 12:26:00 +0200 (CEST) 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 vejASa-F1hVm for ; Tue, 22 Oct 2013 12:25:59 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 BL_NJABL=ERR(-1.5) (only DNSBL check requested) Received: from pollux.denx.de (host-82-135-33-74.customer.m-online.net [82.135.33.74]) by theia.denx.de (Postfix) with ESMTP id B93174A28A for ; Tue, 22 Oct 2013 12:25:47 +0200 (CEST) Received: by pollux.denx.de (Postfix, from userid 515) id 35B9AFBD; Tue, 22 Oct 2013 12:25:47 +0200 (CEST) From: Heiko Schocher To: u-boot@lists.denx.de Date: Tue, 22 Oct 2013 12:25:41 +0200 Message-Id: <1382437545-23720-2-git-send-email-hs@denx.de> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1382437545-23720-1-git-send-email-hs@denx.de> References: <1382437545-23720-1-git-send-email-hs@denx.de> Subject: [U-Boot] [PATCH v1 1/5] bootcount: store bootcount var in environment 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: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de If no softreset save registers are found on the hardware "bootcount" is stored in the environment. To prevent a saveenv on all reboots, the environment variable "upgrade_available" is introduced. If "upgrade_available" is 0, "bootcount" is always 0 therefore no need to save the environment on u-boot boot, if "upgrade_available" is 1 "bootcount" is incremented in the environment and environment gets written on u-boot start. So the Userspace Applikation must set the "upgrade_available" and "bootcount" variable to 0 (for example with fw_setenv), if a boot was successfully. Signed-off-by: Heiko Schocher --- README | 16 ++++++++++++++++ drivers/bootcount/Makefile | 1 + drivers/bootcount/bootcount_env.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 drivers/bootcount/bootcount_env.c diff --git a/README b/README index 232c96a..2558e42 100644 --- a/README +++ b/README @@ -784,6 +784,22 @@ The following options need to be configured: as a convenience, when switching between booting from RAM and NFS. +- Bootcount: + CONFIG_BOOTCOUNT_LIMIT + Implements a mechanism for detecting a repeating reboot + cycle, see: + http://www.denx.de/wiki/view/DULG/UBootBootCountLimit + + CONFIG_BOOTCOUNT_ENV + If no softreset save registers are found on the hardware + "bootcount" is stored in the environment. To prevent a + saveenv on all reboots, the environment variable + "upgrade_available" is used. If "upgrade_available" is + 0, "bootcount" is always 0, if "upgrade_available" is + 1 "bootcount" is incremented in the environment. + So the Userspace Applikation must set the "upgrade_available" + and "bootcount" variable to 0, if a boot was successfully. + - Pre-Boot Commands: CONFIG_PREBOOT diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile index 2b517b6..8ec0423 100644 --- a/drivers/bootcount/Makefile +++ b/drivers/bootcount/Makefile @@ -11,6 +11,7 @@ COBJS-$(CONFIG_AT91SAM9XE) += bootcount_at91.o COBJS-$(CONFIG_BLACKFIN) += bootcount_blackfin.o COBJS-$(CONFIG_SOC_DA8XX) += bootcount_davinci.o COBJS-$(CONFIG_BOOTCOUNT_RAM) += bootcount_ram.o +COBJS-$(CONFIG_BOOTCOUNT_ENV) += bootcount_env.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c) diff --git a/drivers/bootcount/bootcount_env.c b/drivers/bootcount/bootcount_env.c new file mode 100644 index 0000000..2d6e8db --- /dev/null +++ b/drivers/bootcount/bootcount_env.c @@ -0,0 +1,29 @@ +/* + * (C) Copyright 2013 + * Heiko Schocher, DENX Software Engineering, hs@denx.de. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include + +void bootcount_store(ulong a) +{ + int upgrade_available = getenv_ulong("upgrade_available", 10, 0); + + if (upgrade_available) { + setenv_ulong("bootcount", a); + saveenv(); + } +} + +ulong bootcount_load(void) +{ + int upgrade_available = getenv_ulong("upgrade_available", 10, 0); + ulong val = 0; + + if (upgrade_available) + val = getenv_ulong("bootcount", 10, 0); + + return val; +}