From patchwork Fri Nov 3 10:10:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martyn Welch X-Patchwork-Id: 833749 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jr8CxrY+"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3ySySd6sWkz9s8J for ; Fri, 3 Nov 2017 21:12:48 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4DC0BC21E35; Fri, 3 Nov 2017 10:12:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id BA17AC21C45; Fri, 3 Nov 2017 10:11:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 63DD4C21C59; Fri, 3 Nov 2017 10:11:03 +0000 (UTC) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by lists.denx.de (Postfix) with ESMTPS id ECA3EC21C59 for ; Fri, 3 Nov 2017 10:11:00 +0000 (UTC) Received: by mail-wr0-f195.google.com with SMTP id u40so2014534wrf.10 for ; Fri, 03 Nov 2017 03:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=srycvGSGgVw6pz+xaYzwXIwFX0RU4jOMBfT1h2PgtL0=; b=jr8CxrY+HluG5SkBFaM9cwVnn3Jtpt0Vq3LLicwkiaXVvsaYW+WwosKIwvNpBT8mv+ JKnUfYzy6itEK+aE1PfP4l44ZwCnnZC4Ogi7HrpdqqUqJWLJkxaqUXwwNnKtzKb5qYHP ZMU0kp/ub+LiigdhUYXFxsS3/Vsh6wEm0GoOPyJoA1W3vW2r6JanDQjjdzDdCHBllorb lXU3cG6jpwngd2hyQmdnYNK3AGP46ZVfcw7AsNz03Wsi35sdsbyYBLzMRkoBzEqot7xN HGnHtXShYQ0S9GkOH6aEF7NxV5F19GsGaJtf9blc9S7bCMQ9a9SneUgRt/NoSBOcxwTU wckA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=srycvGSGgVw6pz+xaYzwXIwFX0RU4jOMBfT1h2PgtL0=; b=gUWon7baCfy9snEEUHOCbkrWuPtCFZ7vPzY7GD61H4ke9Alm4LOX/1ccOx3/RTQiJL imZqX16Y3sPQb9NgiNiQu/QSijYUSXHCZ3uULm/PAuL95KiMy5wGWDASCaOlP5A2u75z ViLRz2Ie2B27WnahG/0qJ7FEQUn/uR6ktTKy+hEuKW/1jpBQ2cxLbP98p9tFW4MRCtk3 iKzNzfuqdLTBZUKTOEYfT1c0k/m8aWQbvY8poPE3WqvbWrzzKiitgGhhOwcqn106hUzP r416sddjwp8Aw96zFEuDIY5pLgdzk3l42SASt6yiHzMjjLAe+MQVUogQgQEE0aZvBcbc KGFA== X-Gm-Message-State: AMCzsaXyXlqi+jQX0YECMRo0+wwgpy1NNbp0ABoh206V5z2Zi6g7Z1P9 caQmP9IOG8GrocDIcn+MdxBdAQ== X-Google-Smtp-Source: ABhQp+SrVPN7rRHwIWSrGzuSkJH8WZEYeWBQ3DwMYekMmdtvUGSp0+fhrF9pNeQ7myoL32g9j/DV+A== X-Received: by 10.223.193.70 with SMTP id w6mr5732266wre.158.1509703860263; Fri, 03 Nov 2017 03:11:00 -0700 (PDT) Received: from hades (host86-156-77-147.range86-156.btcentralplus.com. [86.156.77.147]) by smtp.gmail.com with ESMTPSA id u4sm3451942wre.1.2017.11.03.03.10.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 03:10:59 -0700 (PDT) From: Martyn Welch X-Google-Original-From: Martyn Welch Received: from martyn by hades with local (Exim 4.84_2) (envelope-from ) id 1eAYwD-0002bX-Ra; Fri, 03 Nov 2017 10:10:57 +0000 To: u-boot@lists.denx.de Date: Fri, 3 Nov 2017 10:10:52 +0000 Message-Id: <1509703855-9948-6-git-send-email-martyn.welch@collabora.co.uk> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1509703855-9948-1-git-send-email-martyn.welch@collabora.co.uk> References: <1509703855-9948-1-git-send-email-martyn.welch@collabora.co.uk> Cc: Ian Ray Subject: [U-Boot] [PATCH v4 5/8] bootcount: add support for bootcounter on EXT filesystem X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" From: Ian Ray Add support for bootcounter on an EXT filesystem. Sync configuration whitelist. Signed-off-by: Ian Ray Signed-off-by: Martyn Welch --- Changes for v2: - Adding Kconfig for EXT bootcount. Changes for v3: - Add over-arching BOOTCOUNT Kconfig entry. README | 7 +++++ drivers/Kconfig | 2 ++ drivers/bootcount/Kconfig | 57 +++++++++++++++++++++++++++++++++++++ drivers/bootcount/Makefile | 1 + drivers/bootcount/bootcount_ext.c | 59 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 drivers/bootcount/Kconfig create mode 100644 drivers/bootcount/bootcount_ext.c diff --git a/README b/README index f288176..6336c5c 100644 --- a/README +++ b/README @@ -2362,6 +2362,13 @@ The following options need to be configured: CONFIG_SYS_BOOTCOUNT_ADDR = i2c addr which is used for the bootcounter. CONFIG_BOOTCOUNT_ALEN = address len + CONFIG_BOOTCOUNT_EXT + enable support for the bootcounter in EXT filesystem + CONFIG_SYS_BOOTCOUNT_ADDR = RAM address used for read + and write. + CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE = interface + CONFIG_SYS_BOOTCOUNT_EXT_DEVPART = device and part + CONFIG_SYS_BOOTCOUNT_EXT_NAME = filename - Show boot progress: CONFIG_SHOW_BOOT_PROGRESS diff --git a/drivers/Kconfig b/drivers/Kconfig index 613e602..c2e813f 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -10,6 +10,8 @@ source "drivers/ata/Kconfig" source "drivers/block/Kconfig" +source "drivers/bootcount/Kconfig" + source "drivers/clk/Kconfig" source "drivers/cpu/Kconfig" diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig new file mode 100644 index 0000000..acffbcf --- /dev/null +++ b/drivers/bootcount/Kconfig @@ -0,0 +1,57 @@ +# +# Boot count configuration +# + +menu "Boot count support" + +config BOOTCOUNT + bool "Enable Boot count support" + help + Enable boot count support, which provides the ability to store the + number of times the board has booted on a number of different + persistent storage mediums. + +if BOOTCOUNT + +config BOOTCOUNT_EXT + bool "Boot counter on EXT filesystem" + help + Add support for bootcounter on an EXT filesystem. + +if BOOTCOUNT_EXT + +config SYS_BOOTCOUNT_EXT_INTERFACE + string "Interface on which to find boot counter EXT filesystem" + default "mmc" + depends on BOOTCOUNT_EXT + help + Set the interface to use when locating the filesystem to use for the + boot counter. + +config SYS_BOOTCOUNT_EXT_DEVPART + string "Partition of the boot counter EXT filesystem" + default "0:1" + depends on BOOTCOUNT_EXT + help + Set the partition to use when locating the filesystem to use for the + boot counter. + +config SYS_BOOTCOUNT_EXT_NAME + string "Path and filename of the EXT filesystem based boot counter" + default "/boot/failures" + depends on BOOTCOUNT_EXT + help + Set the filename and path of the file used to store the boot counter. + +config SYS_BOOTCOUNT_ADDR + hex "RAM address used for reading and writing the boot counter" + default 0x7000A000 + depends on BOOTCOUNT_EXT + help + Set the address used for reading and writing the boot counter. + +endif + +endif + +endmenu diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile index ed9659a..45445d2 100644 --- a/drivers/bootcount/Makefile +++ b/drivers/bootcount/Makefile @@ -9,3 +9,4 @@ obj-$(CONFIG_BOOTCOUNT_AM33XX) += bootcount_davinci.o obj-$(CONFIG_BOOTCOUNT_RAM) += bootcount_ram.o obj-$(CONFIG_BOOTCOUNT_ENV) += bootcount_env.o obj-$(CONFIG_BOOTCOUNT_I2C) += bootcount_i2c.o +obj-$(CONFIG_BOOTCOUNT_EXT) += bootcount_ext.o diff --git a/drivers/bootcount/bootcount_ext.c b/drivers/bootcount/bootcount_ext.c new file mode 100644 index 0000000..d36bb0e --- /dev/null +++ b/drivers/bootcount/bootcount_ext.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 General Electric Company. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +#define BC_MAGIC 0xbc + +void bootcount_store(ulong a) +{ + uint8_t *buf; + loff_t len; + int ret; + + if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE, CONFIG_SYS_BOOTCOUNT_EXT_DEVPART, FS_TYPE_EXT)) { + puts("Error selecting device\n"); + return; + } + + buf = map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR, 2); + buf[0] = BC_MAGIC; + buf[1] = (a & 0xff); + unmap_sysmem(buf); + + ret = fs_write(CONFIG_SYS_BOOTCOUNT_EXT_NAME, CONFIG_SYS_BOOTCOUNT_ADDR, 0, 2, &len); + if (ret != 0) { + puts("Error storing bootcount\n"); + } +} + +ulong bootcount_load(void) +{ + uint8_t *buf; + loff_t len_read; + int ret; + + if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE, CONFIG_SYS_BOOTCOUNT_EXT_DEVPART, FS_TYPE_EXT)) { + puts("Error selecting device\n"); + return 0; + } + + ret = fs_read(CONFIG_SYS_BOOTCOUNT_EXT_NAME, CONFIG_SYS_BOOTCOUNT_ADDR, 0, 2, &len_read); + if (ret != 0 || len_read != 2) { + puts("Error loading bootcount\n"); + return 0; + } + + buf = map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR, 2); + if (buf[0] == BC_MAGIC) { + ret = buf[1]; + } + unmap_sysmem(buf); + + return ret; +}