Commit f31dac4e6e71c7c818151cd917d872909119fb99

Authored by Ian Ray
Committed by Stefano Babic
1 parent 54d8d4942f

bootcount: add support for bootcounter on EXT filesystem

Add support for bootcounter on an EXT filesystem.
Sync configuration whitelist.

Signed-off-by: Ian Ray <ian.ray@ge.com>
Signed-off-by: Martyn Welch <martyn.welch@collabora.co.uk>

Showing 5 changed files with 130 additions and 0 deletions Side-by-side Diff

... ... @@ -2362,6 +2362,13 @@
2362 2362 CONFIG_SYS_BOOTCOUNT_ADDR = i2c addr which is used for
2363 2363 the bootcounter.
2364 2364 CONFIG_BOOTCOUNT_ALEN = address len
  2365 + CONFIG_BOOTCOUNT_EXT
  2366 + enable support for the bootcounter in EXT filesystem
  2367 + CONFIG_SYS_BOOTCOUNT_ADDR = RAM address used for read
  2368 + and write.
  2369 + CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE = interface
  2370 + CONFIG_SYS_BOOTCOUNT_EXT_DEVPART = device and part
  2371 + CONFIG_SYS_BOOTCOUNT_EXT_NAME = filename
2365 2372  
2366 2373 - Show boot progress:
2367 2374 CONFIG_SHOW_BOOT_PROGRESS
... ... @@ -10,6 +10,8 @@
10 10  
11 11 source "drivers/block/Kconfig"
12 12  
  13 +source "drivers/bootcount/Kconfig"
  14 +
13 15 source "drivers/clk/Kconfig"
14 16  
15 17 source "drivers/cpu/Kconfig"
drivers/bootcount/Kconfig
  1 +#
  2 +# Boot count configuration
  3 +#
  4 +
  5 +menu "Boot count support"
  6 +
  7 +config BOOTCOUNT
  8 + bool "Enable Boot count support"
  9 + help
  10 + Enable boot count support, which provides the ability to store the
  11 + number of times the board has booted on a number of different
  12 + persistent storage mediums.
  13 +
  14 +if BOOTCOUNT
  15 +
  16 +config BOOTCOUNT_EXT
  17 + bool "Boot counter on EXT filesystem"
  18 + help
  19 + Add support for maintaining boot count in a file on an EXT
  20 + filesystem.
  21 +
  22 +if BOOTCOUNT_EXT
  23 +
  24 +config SYS_BOOTCOUNT_EXT_INTERFACE
  25 + string "Interface on which to find boot counter EXT filesystem"
  26 + default "mmc"
  27 + depends on BOOTCOUNT_EXT
  28 + help
  29 + Set the interface to use when locating the filesystem to use for the
  30 + boot counter.
  31 +
  32 +config SYS_BOOTCOUNT_EXT_DEVPART
  33 + string "Partition of the boot counter EXT filesystem"
  34 + default "0:1"
  35 + depends on BOOTCOUNT_EXT
  36 + help
  37 + Set the partition to use when locating the filesystem to use for the
  38 + boot counter.
  39 +
  40 +config SYS_BOOTCOUNT_EXT_NAME
  41 + string "Path and filename of the EXT filesystem based boot counter"
  42 + default "/boot/failures"
  43 + depends on BOOTCOUNT_EXT
  44 + help
  45 + Set the filename and path of the file used to store the boot counter.
  46 +
  47 +config SYS_BOOTCOUNT_ADDR
  48 + hex "RAM address used for reading and writing the boot counter"
  49 + default 0x7000A000
  50 + depends on BOOTCOUNT_EXT
  51 + help
  52 + Set the address used for reading and writing the boot counter.
  53 +
  54 +endif
  55 +
  56 +endif
  57 +
  58 +endmenu
drivers/bootcount/Makefile
... ... @@ -9,4 +9,5 @@
9 9 obj-$(CONFIG_BOOTCOUNT_RAM) += bootcount_ram.o
10 10 obj-$(CONFIG_BOOTCOUNT_ENV) += bootcount_env.o
11 11 obj-$(CONFIG_BOOTCOUNT_I2C) += bootcount_i2c.o
  12 +obj-$(CONFIG_BOOTCOUNT_EXT) += bootcount_ext.o
drivers/bootcount/bootcount_ext.c
  1 +/*
  2 + * Copyright (c) 2017 General Electric Company. All rights reserved.
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +#include <bootcount.h>
  8 +#include <fs.h>
  9 +#include <mapmem.h>
  10 +
  11 +#define BC_MAGIC 0xbc
  12 +
  13 +void bootcount_store(ulong a)
  14 +{
  15 + u8 *buf;
  16 + loff_t len;
  17 + int ret;
  18 +
  19 + if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE,
  20 + CONFIG_SYS_BOOTCOUNT_EXT_DEVPART, FS_TYPE_EXT)) {
  21 + puts("Error selecting device\n");
  22 + return;
  23 + }
  24 +
  25 + buf = map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR, 2);
  26 + buf[0] = BC_MAGIC;
  27 + buf[1] = (a & 0xff);
  28 + unmap_sysmem(buf);
  29 +
  30 + ret = fs_write(CONFIG_SYS_BOOTCOUNT_EXT_NAME,
  31 + CONFIG_SYS_BOOTCOUNT_ADDR, 0, 2, &len);
  32 + if (ret != 0)
  33 + puts("Error storing bootcount\n");
  34 +}
  35 +
  36 +ulong bootcount_load(void)
  37 +{
  38 + u8 *buf;
  39 + loff_t len_read;
  40 + int ret;
  41 +
  42 + if (fs_set_blk_dev(CONFIG_SYS_BOOTCOUNT_EXT_INTERFACE,
  43 + CONFIG_SYS_BOOTCOUNT_EXT_DEVPART, FS_TYPE_EXT)) {
  44 + puts("Error selecting device\n");
  45 + return 0;
  46 + }
  47 +
  48 + ret = fs_read(CONFIG_SYS_BOOTCOUNT_EXT_NAME, CONFIG_SYS_BOOTCOUNT_ADDR,
  49 + 0, 2, &len_read);
  50 + if (ret != 0 || len_read != 2) {
  51 + puts("Error loading bootcount\n");
  52 + return 0;
  53 + }
  54 +
  55 + buf = map_sysmem(CONFIG_SYS_BOOTCOUNT_ADDR, 2);
  56 + if (buf[0] == BC_MAGIC)
  57 + ret = buf[1];
  58 +
  59 + unmap_sysmem(buf);
  60 +
  61 + return ret;
  62 +}