Re: [U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-29 Thread Simon Glass
Hi Philipp,

On 23 August 2018 at 07:48, Dr. Philipp Tomsich
 wrote:
> Simon,
>
>> On 23 Aug 2018, at 12:45, Simon Glass  wrote:
>>
>> Hi Philipp,
>>
>> On 17 August 2018 at 06:56, Dr. Philipp Tomsich
>>  wrote:
>>> Simon,
>>>
>>> On 17 Aug 2018, at 14:49, Simon Glass  wrote:
>>>
>>> Hi Philipp,
>>>
>>> On 14 August 2018 at 05:39, Dr. Philipp Tomsich
>>>  wrote:
>>>
>>> Lukasz,
>>>
>>> On 14 Aug 2018, at 13:10, Lukasz Majewski  wrote:
>>>
>>> Hi Philipp,
>>>
>>> The original bootcount methods do not provide an interface to DM and
>>> rely on a static configuration for I2C devices (e.g. bus, chip-addr,
>>> etc. are configured through defines statically).  On a modern system
>>> that exposes multiple devices in a DTS-configurable way, this is less
>>> than optimal and a interface to DM-based devices will be desirable.
>>>
>>> This adds a simple driver that is DM-aware and configurable via DTS:
>>> the /chosen/u-boot,bootcount-device property is used to detect the DM
>>> device storing the bootcount and deviceclass-specific commands are
>>> used to read/write the bootcount.
>>>
>>> Initially, this provides support for the following DM devices:
>>> * RTC devices implementing the read8/write8 ops
>>>
>>> Signed-off-by: Philipp Tomsich 
>>> Tested-by: Klaus Goger 
>>> ---
>>>
>>> doc/device-tree-bindings/chosen.txt | 27 +++
>>> drivers/bootcount/Kconfig   | 12 +
>>> drivers/bootcount/Makefile  |  1 +
>>> drivers/bootcount/bootcount_dm.c| 93
>>> + 4 files changed, 133
>>> insertions(+) create mode 100644 drivers/bootcount/bootcount_dm.c
>>>
>>> diff --git a/doc/device-tree-bindings/chosen.txt
>>> b/doc/device-tree-bindings/chosen.txt index da7b4e6..734fd15 100644
>>> --- a/doc/device-tree-bindings/chosen.txt
>>> +++ b/doc/device-tree-bindings/chosen.txt
>>> @@ -42,6 +42,33 @@ Example
>>>};
>>> };
>>>
>>> +u-boot,bootcount-device property
>>> +
>>> +In a DM-based system, the bootcount may be stored in a device known
>>> to +the DM framework (e.g. in a battery-backed SRAM area within a RTC
>>> +device).  To identify the device to be used for the bootcount, the
>>> +u-boot,bootcount-device property needs to point to the target device.
>>> +
>>> +Further configuration in the target device's node may be required
>>> +(e.g. an offset into an I2C RTC's address space), depending on the
>>> +UCLASS of the target device.
>>> +
>>> +Example
>>> +---
>>> +/ {
>>> +chosen {
>>> +u-boot,bootcount-device = 
>>> +};
>>> +
>>> +i2c2 {
>>> +rv3029: rtc@56 {
>>> +compatible = "mc,rv3029";
>>> +reg = <0x56>;
>>> +u-boot,bootcount-offset = <0x38>;
>>> +};
>>> +};
>>> +};
>>> +
>>> u-boot,spl-boot-order property
>>> --
>>>
>>> diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
>>> index d335ed1..cdde7b5 100644
>>> --- a/drivers/bootcount/Kconfig
>>> +++ b/drivers/bootcount/Kconfig
>>> @@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
>>>bool "Boot counter for Atmel AT91SAM9XE"
>>>depends on AT91SAM9XE
>>>
>>> +config BOOTCOUNT_DM
>>> +bool "Boot counter in a device-model device"
>>> +help
>>> +  Enables reading/writing the bootcount in a device-model
>>> +  device referenced from the /chosen node.  The type of the
>>> +  device is detected from DM and any additional configuration
>>> +  information (e.g. the offset into a RTC device that
>>> supports
>>> +  read32/write32) is read from the device's node.
>>> +
>>> +  At this time the following DM device classes are supported:
>>> +   * RTC (using read32/write32)
>>> +
>>> endchoice
>>>
>>> config BOOTCOUNT_ALEN
>>> diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
>>> index 68bc006..e8ed729 100644
>>> --- a/drivers/bootcount/Makefile
>>> +++ b/drivers/bootcount/Makefile
>>> @@ -7,3 +7,4 @@ 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
>>> +obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
>>> diff --git a/drivers/bootcount/bootcount_dm.c
>>> b/drivers/bootcount/bootcount_dm.c new file mode 100644
>>> index 000..99bdb88
>>> --- /dev/null
>>> +++ b/drivers/bootcount/bootcount_dm.c
>>> @@ -0,0 +1,93 @@
>>> +// SPDX-License-Identifier: GPL-2.0+
>>> +/*
>>> + * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +const u8 bootcount_magic = 0xbc;
>>> +
>>> +static void bootcount_store_rtc(struct udevice *dev, ulong a)
>>> +{
>>> +#if CONFIG_IS_ENABLED(DM_RTC)
>>> +u32 offset;
>>> +const char *offset_propname = "u-boot,bootcount-offset";
>>> +const u16 val = bootcount_magic << 8 | (a & 

Re: [U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-23 Thread Dr. Philipp Tomsich
Simon,

> On 23 Aug 2018, at 12:45, Simon Glass  wrote:
> 
> Hi Philipp,
> 
> On 17 August 2018 at 06:56, Dr. Philipp Tomsich
>  wrote:
>> Simon,
>> 
>> On 17 Aug 2018, at 14:49, Simon Glass  wrote:
>> 
>> Hi Philipp,
>> 
>> On 14 August 2018 at 05:39, Dr. Philipp Tomsich
>>  wrote:
>> 
>> Lukasz,
>> 
>> On 14 Aug 2018, at 13:10, Lukasz Majewski  wrote:
>> 
>> Hi Philipp,
>> 
>> The original bootcount methods do not provide an interface to DM and
>> rely on a static configuration for I2C devices (e.g. bus, chip-addr,
>> etc. are configured through defines statically).  On a modern system
>> that exposes multiple devices in a DTS-configurable way, this is less
>> than optimal and a interface to DM-based devices will be desirable.
>> 
>> This adds a simple driver that is DM-aware and configurable via DTS:
>> the /chosen/u-boot,bootcount-device property is used to detect the DM
>> device storing the bootcount and deviceclass-specific commands are
>> used to read/write the bootcount.
>> 
>> Initially, this provides support for the following DM devices:
>> * RTC devices implementing the read8/write8 ops
>> 
>> Signed-off-by: Philipp Tomsich 
>> Tested-by: Klaus Goger 
>> ---
>> 
>> doc/device-tree-bindings/chosen.txt | 27 +++
>> drivers/bootcount/Kconfig   | 12 +
>> drivers/bootcount/Makefile  |  1 +
>> drivers/bootcount/bootcount_dm.c| 93
>> + 4 files changed, 133
>> insertions(+) create mode 100644 drivers/bootcount/bootcount_dm.c
>> 
>> diff --git a/doc/device-tree-bindings/chosen.txt
>> b/doc/device-tree-bindings/chosen.txt index da7b4e6..734fd15 100644
>> --- a/doc/device-tree-bindings/chosen.txt
>> +++ b/doc/device-tree-bindings/chosen.txt
>> @@ -42,6 +42,33 @@ Example
>>};
>> };
>> 
>> +u-boot,bootcount-device property
>> +
>> +In a DM-based system, the bootcount may be stored in a device known
>> to +the DM framework (e.g. in a battery-backed SRAM area within a RTC
>> +device).  To identify the device to be used for the bootcount, the
>> +u-boot,bootcount-device property needs to point to the target device.
>> +
>> +Further configuration in the target device's node may be required
>> +(e.g. an offset into an I2C RTC's address space), depending on the
>> +UCLASS of the target device.
>> +
>> +Example
>> +---
>> +/ {
>> +chosen {
>> +u-boot,bootcount-device = 
>> +};
>> +
>> +i2c2 {
>> +rv3029: rtc@56 {
>> +compatible = "mc,rv3029";
>> +reg = <0x56>;
>> +u-boot,bootcount-offset = <0x38>;
>> +};
>> +};
>> +};
>> +
>> u-boot,spl-boot-order property
>> --
>> 
>> diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
>> index d335ed1..cdde7b5 100644
>> --- a/drivers/bootcount/Kconfig
>> +++ b/drivers/bootcount/Kconfig
>> @@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
>>bool "Boot counter for Atmel AT91SAM9XE"
>>depends on AT91SAM9XE
>> 
>> +config BOOTCOUNT_DM
>> +bool "Boot counter in a device-model device"
>> +help
>> +  Enables reading/writing the bootcount in a device-model
>> +  device referenced from the /chosen node.  The type of the
>> +  device is detected from DM and any additional configuration
>> +  information (e.g. the offset into a RTC device that
>> supports
>> +  read32/write32) is read from the device's node.
>> +
>> +  At this time the following DM device classes are supported:
>> +   * RTC (using read32/write32)
>> +
>> endchoice
>> 
>> config BOOTCOUNT_ALEN
>> diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
>> index 68bc006..e8ed729 100644
>> --- a/drivers/bootcount/Makefile
>> +++ b/drivers/bootcount/Makefile
>> @@ -7,3 +7,4 @@ 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
>> +obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
>> diff --git a/drivers/bootcount/bootcount_dm.c
>> b/drivers/bootcount/bootcount_dm.c new file mode 100644
>> index 000..99bdb88
>> --- /dev/null
>> +++ b/drivers/bootcount/bootcount_dm.c
>> @@ -0,0 +1,93 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +const u8 bootcount_magic = 0xbc;
>> +
>> +static void bootcount_store_rtc(struct udevice *dev, ulong a)
>> +{
>> +#if CONFIG_IS_ENABLED(DM_RTC)
>> +u32 offset;
>> +const char *offset_propname = "u-boot,bootcount-offset";
>> +const u16 val = bootcount_magic << 8 | (a & 0xff);
>> +
>> +if (dev_read_u32(dev, offset_propname, ) < 0) {
>> +debug("%s: requires %s\n", __func__,
>> offset_propname);
>> +return;
>> +}
>> +
>> +if 

Re: [U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-23 Thread Simon Glass
Hi Philipp,

On 17 August 2018 at 06:56, Dr. Philipp Tomsich
 wrote:
> Simon,
>
> On 17 Aug 2018, at 14:49, Simon Glass  wrote:
>
> Hi Philipp,
>
> On 14 August 2018 at 05:39, Dr. Philipp Tomsich
>  wrote:
>
> Lukasz,
>
> On 14 Aug 2018, at 13:10, Lukasz Majewski  wrote:
>
> Hi Philipp,
>
> The original bootcount methods do not provide an interface to DM and
> rely on a static configuration for I2C devices (e.g. bus, chip-addr,
> etc. are configured through defines statically).  On a modern system
> that exposes multiple devices in a DTS-configurable way, this is less
> than optimal and a interface to DM-based devices will be desirable.
>
> This adds a simple driver that is DM-aware and configurable via DTS:
> the /chosen/u-boot,bootcount-device property is used to detect the DM
> device storing the bootcount and deviceclass-specific commands are
> used to read/write the bootcount.
>
> Initially, this provides support for the following DM devices:
> * RTC devices implementing the read8/write8 ops
>
> Signed-off-by: Philipp Tomsich 
> Tested-by: Klaus Goger 
> ---
>
> doc/device-tree-bindings/chosen.txt | 27 +++
> drivers/bootcount/Kconfig   | 12 +
> drivers/bootcount/Makefile  |  1 +
> drivers/bootcount/bootcount_dm.c| 93
> + 4 files changed, 133
> insertions(+) create mode 100644 drivers/bootcount/bootcount_dm.c
>
> diff --git a/doc/device-tree-bindings/chosen.txt
> b/doc/device-tree-bindings/chosen.txt index da7b4e6..734fd15 100644
> --- a/doc/device-tree-bindings/chosen.txt
> +++ b/doc/device-tree-bindings/chosen.txt
> @@ -42,6 +42,33 @@ Example
> };
> };
>
> +u-boot,bootcount-device property
> +
> +In a DM-based system, the bootcount may be stored in a device known
> to +the DM framework (e.g. in a battery-backed SRAM area within a RTC
> +device).  To identify the device to be used for the bootcount, the
> +u-boot,bootcount-device property needs to point to the target device.
> +
> +Further configuration in the target device's node may be required
> +(e.g. an offset into an I2C RTC's address space), depending on the
> +UCLASS of the target device.
> +
> +Example
> +---
> +/ {
> +chosen {
> +u-boot,bootcount-device = 
> +};
> +
> +i2c2 {
> +rv3029: rtc@56 {
> +compatible = "mc,rv3029";
> +reg = <0x56>;
> +u-boot,bootcount-offset = <0x38>;
> +};
> +};
> +};
> +
> u-boot,spl-boot-order property
> --
>
> diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
> index d335ed1..cdde7b5 100644
> --- a/drivers/bootcount/Kconfig
> +++ b/drivers/bootcount/Kconfig
> @@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
> bool "Boot counter for Atmel AT91SAM9XE"
> depends on AT91SAM9XE
>
> +config BOOTCOUNT_DM
> +bool "Boot counter in a device-model device"
> +help
> +  Enables reading/writing the bootcount in a device-model
> +  device referenced from the /chosen node.  The type of the
> +  device is detected from DM and any additional configuration
> +  information (e.g. the offset into a RTC device that
> supports
> +  read32/write32) is read from the device's node.
> +
> +  At this time the following DM device classes are supported:
> +   * RTC (using read32/write32)
> +
> endchoice
>
> config BOOTCOUNT_ALEN
> diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
> index 68bc006..e8ed729 100644
> --- a/drivers/bootcount/Makefile
> +++ b/drivers/bootcount/Makefile
> @@ -7,3 +7,4 @@ 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
> +obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
> diff --git a/drivers/bootcount/bootcount_dm.c
> b/drivers/bootcount/bootcount_dm.c new file mode 100644
> index 000..99bdb88
> --- /dev/null
> +++ b/drivers/bootcount/bootcount_dm.c
> @@ -0,0 +1,93 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +const u8 bootcount_magic = 0xbc;
> +
> +static void bootcount_store_rtc(struct udevice *dev, ulong a)
> +{
> +#if CONFIG_IS_ENABLED(DM_RTC)
> +u32 offset;
> +const char *offset_propname = "u-boot,bootcount-offset";
> +const u16 val = bootcount_magic << 8 | (a & 0xff);
> +
> +if (dev_read_u32(dev, offset_propname, ) < 0) {
> +debug("%s: requires %s\n", __func__,
> offset_propname);
> +return;
> +}
> +
> +if (rtc_write16(dev, offset, val) < 0) {
> +debug("%s: rtc_write16 failed\n", __func__);
> +return;
> +}
> +#endif
> +}
> +
> +static u32 bootcount_load_rtc(struct udevice *dev)
> +{
> +#if 

Re: [U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-17 Thread Dr. Philipp Tomsich
Simon,

> On 17 Aug 2018, at 14:49, Simon Glass  wrote:
> 
> Hi Philipp,
> 
> On 14 August 2018 at 05:39, Dr. Philipp Tomsich
>  > wrote:
>> Lukasz,
>> 
>>> On 14 Aug 2018, at 13:10, Lukasz Majewski  wrote:
>>> 
>>> Hi Philipp,
>>> 
 The original bootcount methods do not provide an interface to DM and
 rely on a static configuration for I2C devices (e.g. bus, chip-addr,
 etc. are configured through defines statically).  On a modern system
 that exposes multiple devices in a DTS-configurable way, this is less
 than optimal and a interface to DM-based devices will be desirable.
 
 This adds a simple driver that is DM-aware and configurable via DTS:
 the /chosen/u-boot,bootcount-device property is used to detect the DM
 device storing the bootcount and deviceclass-specific commands are
 used to read/write the bootcount.
 
 Initially, this provides support for the following DM devices:
 * RTC devices implementing the read8/write8 ops
 
 Signed-off-by: Philipp Tomsich 
 Tested-by: Klaus Goger 
 ---
 
 doc/device-tree-bindings/chosen.txt | 27 +++
 drivers/bootcount/Kconfig   | 12 +
 drivers/bootcount/Makefile  |  1 +
 drivers/bootcount/bootcount_dm.c| 93
 + 4 files changed, 133
 insertions(+) create mode 100644 drivers/bootcount/bootcount_dm.c
 
 diff --git a/doc/device-tree-bindings/chosen.txt
 b/doc/device-tree-bindings/chosen.txt index da7b4e6..734fd15 100644
 --- a/doc/device-tree-bindings/chosen.txt
 +++ b/doc/device-tree-bindings/chosen.txt
 @@ -42,6 +42,33 @@ Example
 };
 };
 
 +u-boot,bootcount-device property
 +
 +In a DM-based system, the bootcount may be stored in a device known
 to +the DM framework (e.g. in a battery-backed SRAM area within a RTC
 +device).  To identify the device to be used for the bootcount, the
 +u-boot,bootcount-device property needs to point to the target device.
 +
 +Further configuration in the target device's node may be required
 +(e.g. an offset into an I2C RTC's address space), depending on the
 +UCLASS of the target device.
 +
 +Example
 +---
 +/ {
 +chosen {
 +u-boot,bootcount-device = 
 +};
 +
 +i2c2 {
 +rv3029: rtc@56 {
 +compatible = "mc,rv3029";
 +reg = <0x56>;
 +u-boot,bootcount-offset = <0x38>;
 +};
 +};
 +};
 +
 u-boot,spl-boot-order property
 --
 
 diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
 index d335ed1..cdde7b5 100644
 --- a/drivers/bootcount/Kconfig
 +++ b/drivers/bootcount/Kconfig
 @@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
 bool "Boot counter for Atmel AT91SAM9XE"
 depends on AT91SAM9XE
 
 +config BOOTCOUNT_DM
 +bool "Boot counter in a device-model device"
 +help
 +  Enables reading/writing the bootcount in a device-model
 +  device referenced from the /chosen node.  The type of the
 +  device is detected from DM and any additional configuration
 +  information (e.g. the offset into a RTC device that
 supports
 +  read32/write32) is read from the device's node.
 +
 +  At this time the following DM device classes are supported:
 +   * RTC (using read32/write32)
 +
 endchoice
 
 config BOOTCOUNT_ALEN
 diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
 index 68bc006..e8ed729 100644
 --- a/drivers/bootcount/Makefile
 +++ b/drivers/bootcount/Makefile
 @@ -7,3 +7,4 @@ 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
 +obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
 diff --git a/drivers/bootcount/bootcount_dm.c
 b/drivers/bootcount/bootcount_dm.c new file mode 100644
 index 000..99bdb88
 --- /dev/null
 +++ b/drivers/bootcount/bootcount_dm.c
 @@ -0,0 +1,93 @@
 +// SPDX-License-Identifier: GPL-2.0+
 +/*
 + * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
 + */
 +
 +#include 
 +#include 
 +#include 
 +#include 
 +
 +const u8 bootcount_magic = 0xbc;
 +
 +static void bootcount_store_rtc(struct udevice *dev, ulong a)
 +{
 +#if CONFIG_IS_ENABLED(DM_RTC)
 +u32 offset;
 +const char *offset_propname = "u-boot,bootcount-offset";
 +const u16 val = bootcount_magic << 8 | (a & 0xff);
 +
 +if (dev_read_u32(dev, 

Re: [U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-17 Thread Simon Glass
Hi Philipp,

On 14 August 2018 at 05:39, Dr. Philipp Tomsich
 wrote:
> Lukasz,
>
>> On 14 Aug 2018, at 13:10, Lukasz Majewski  wrote:
>>
>> Hi Philipp,
>>
>>> The original bootcount methods do not provide an interface to DM and
>>> rely on a static configuration for I2C devices (e.g. bus, chip-addr,
>>> etc. are configured through defines statically).  On a modern system
>>> that exposes multiple devices in a DTS-configurable way, this is less
>>> than optimal and a interface to DM-based devices will be desirable.
>>>
>>> This adds a simple driver that is DM-aware and configurable via DTS:
>>> the /chosen/u-boot,bootcount-device property is used to detect the DM
>>> device storing the bootcount and deviceclass-specific commands are
>>> used to read/write the bootcount.
>>>
>>> Initially, this provides support for the following DM devices:
>>> * RTC devices implementing the read8/write8 ops
>>>
>>> Signed-off-by: Philipp Tomsich 
>>> Tested-by: Klaus Goger 
>>> ---
>>>
>>> doc/device-tree-bindings/chosen.txt | 27 +++
>>> drivers/bootcount/Kconfig   | 12 +
>>> drivers/bootcount/Makefile  |  1 +
>>> drivers/bootcount/bootcount_dm.c| 93
>>> + 4 files changed, 133
>>> insertions(+) create mode 100644 drivers/bootcount/bootcount_dm.c
>>>
>>> diff --git a/doc/device-tree-bindings/chosen.txt
>>> b/doc/device-tree-bindings/chosen.txt index da7b4e6..734fd15 100644
>>> --- a/doc/device-tree-bindings/chosen.txt
>>> +++ b/doc/device-tree-bindings/chosen.txt
>>> @@ -42,6 +42,33 @@ Example
>>>  };
>>> };
>>>
>>> +u-boot,bootcount-device property
>>> +
>>> +In a DM-based system, the bootcount may be stored in a device known
>>> to +the DM framework (e.g. in a battery-backed SRAM area within a RTC
>>> +device).  To identify the device to be used for the bootcount, the
>>> +u-boot,bootcount-device property needs to point to the target device.
>>> +
>>> +Further configuration in the target device's node may be required
>>> +(e.g. an offset into an I2C RTC's address space), depending on the
>>> +UCLASS of the target device.
>>> +
>>> +Example
>>> +---
>>> +/ {
>>> +chosen {
>>> +u-boot,bootcount-device = 
>>> +};
>>> +
>>> +i2c2 {
>>> +rv3029: rtc@56 {
>>> +compatible = "mc,rv3029";
>>> +reg = <0x56>;
>>> +u-boot,bootcount-offset = <0x38>;
>>> +};
>>> +};
>>> +};
>>> +
>>> u-boot,spl-boot-order property
>>> --
>>>
>>> diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
>>> index d335ed1..cdde7b5 100644
>>> --- a/drivers/bootcount/Kconfig
>>> +++ b/drivers/bootcount/Kconfig
>>> @@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
>>>  bool "Boot counter for Atmel AT91SAM9XE"
>>>  depends on AT91SAM9XE
>>>
>>> +config BOOTCOUNT_DM
>>> +bool "Boot counter in a device-model device"
>>> +help
>>> +  Enables reading/writing the bootcount in a device-model
>>> +  device referenced from the /chosen node.  The type of the
>>> +  device is detected from DM and any additional configuration
>>> +  information (e.g. the offset into a RTC device that
>>> supports
>>> +  read32/write32) is read from the device's node.
>>> +
>>> +  At this time the following DM device classes are supported:
>>> +   * RTC (using read32/write32)
>>> +
>>> endchoice
>>>
>>> config BOOTCOUNT_ALEN
>>> diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
>>> index 68bc006..e8ed729 100644
>>> --- a/drivers/bootcount/Makefile
>>> +++ b/drivers/bootcount/Makefile
>>> @@ -7,3 +7,4 @@ 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
>>> +obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
>>> diff --git a/drivers/bootcount/bootcount_dm.c
>>> b/drivers/bootcount/bootcount_dm.c new file mode 100644
>>> index 000..99bdb88
>>> --- /dev/null
>>> +++ b/drivers/bootcount/bootcount_dm.c
>>> @@ -0,0 +1,93 @@
>>> +// SPDX-License-Identifier: GPL-2.0+
>>> +/*
>>> + * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
>>> + */
>>> +
>>> +#include 
>>> +#include 
>>> +#include 
>>> +#include 
>>> +
>>> +const u8 bootcount_magic = 0xbc;
>>> +
>>> +static void bootcount_store_rtc(struct udevice *dev, ulong a)
>>> +{
>>> +#if CONFIG_IS_ENABLED(DM_RTC)
>>> +u32 offset;
>>> +const char *offset_propname = "u-boot,bootcount-offset";
>>> +const u16 val = bootcount_magic << 8 | (a & 0xff);
>>> +
>>> +if (dev_read_u32(dev, offset_propname, ) < 0) {
>>> +debug("%s: requires %s\n", __func__,
>>> offset_propname);
>>> +return;
>>> +}
>>> +
>>> +if (rtc_write16(dev, offset, val) < 0) {
>>> +debug("%s: rtc_write16 failed\n", __func__);

Re: [U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-14 Thread Dr. Philipp Tomsich
Lukasz,

> On 14 Aug 2018, at 13:10, Lukasz Majewski  wrote:
> 
> Hi Philipp,
> 
>> The original bootcount methods do not provide an interface to DM and
>> rely on a static configuration for I2C devices (e.g. bus, chip-addr,
>> etc. are configured through defines statically).  On a modern system
>> that exposes multiple devices in a DTS-configurable way, this is less
>> than optimal and a interface to DM-based devices will be desirable.
>> 
>> This adds a simple driver that is DM-aware and configurable via DTS:
>> the /chosen/u-boot,bootcount-device property is used to detect the DM
>> device storing the bootcount and deviceclass-specific commands are
>> used to read/write the bootcount.
>> 
>> Initially, this provides support for the following DM devices:
>> * RTC devices implementing the read8/write8 ops
>> 
>> Signed-off-by: Philipp Tomsich 
>> Tested-by: Klaus Goger 
>> ---
>> 
>> doc/device-tree-bindings/chosen.txt | 27 +++
>> drivers/bootcount/Kconfig   | 12 +
>> drivers/bootcount/Makefile  |  1 +
>> drivers/bootcount/bootcount_dm.c| 93
>> + 4 files changed, 133
>> insertions(+) create mode 100644 drivers/bootcount/bootcount_dm.c
>> 
>> diff --git a/doc/device-tree-bindings/chosen.txt
>> b/doc/device-tree-bindings/chosen.txt index da7b4e6..734fd15 100644
>> --- a/doc/device-tree-bindings/chosen.txt
>> +++ b/doc/device-tree-bindings/chosen.txt
>> @@ -42,6 +42,33 @@ Example
>>  };
>> };
>> 
>> +u-boot,bootcount-device property
>> +
>> +In a DM-based system, the bootcount may be stored in a device known
>> to +the DM framework (e.g. in a battery-backed SRAM area within a RTC
>> +device).  To identify the device to be used for the bootcount, the
>> +u-boot,bootcount-device property needs to point to the target device.
>> +
>> +Further configuration in the target device's node may be required
>> +(e.g. an offset into an I2C RTC's address space), depending on the
>> +UCLASS of the target device.
>> +
>> +Example
>> +---
>> +/ {
>> +chosen {
>> +u-boot,bootcount-device = 
>> +};
>> +
>> +i2c2 {
>> +rv3029: rtc@56 {
>> +compatible = "mc,rv3029";
>> +reg = <0x56>;
>> +u-boot,bootcount-offset = <0x38>;
>> +};
>> +};
>> +};
>> +
>> u-boot,spl-boot-order property
>> --
>> 
>> diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
>> index d335ed1..cdde7b5 100644
>> --- a/drivers/bootcount/Kconfig
>> +++ b/drivers/bootcount/Kconfig
>> @@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
>>  bool "Boot counter for Atmel AT91SAM9XE"
>>  depends on AT91SAM9XE
>> 
>> +config BOOTCOUNT_DM
>> +bool "Boot counter in a device-model device"
>> +help
>> +  Enables reading/writing the bootcount in a device-model
>> +  device referenced from the /chosen node.  The type of the
>> +  device is detected from DM and any additional configuration
>> +  information (e.g. the offset into a RTC device that
>> supports
>> +  read32/write32) is read from the device's node.
>> +
>> +  At this time the following DM device classes are supported:
>> +   * RTC (using read32/write32)
>> +
>> endchoice
>> 
>> config BOOTCOUNT_ALEN
>> diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
>> index 68bc006..e8ed729 100644
>> --- a/drivers/bootcount/Makefile
>> +++ b/drivers/bootcount/Makefile
>> @@ -7,3 +7,4 @@ 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
>> +obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
>> diff --git a/drivers/bootcount/bootcount_dm.c
>> b/drivers/bootcount/bootcount_dm.c new file mode 100644
>> index 000..99bdb88
>> --- /dev/null
>> +++ b/drivers/bootcount/bootcount_dm.c
>> @@ -0,0 +1,93 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +const u8 bootcount_magic = 0xbc;
>> +
>> +static void bootcount_store_rtc(struct udevice *dev, ulong a)
>> +{
>> +#if CONFIG_IS_ENABLED(DM_RTC)
>> +u32 offset;
>> +const char *offset_propname = "u-boot,bootcount-offset";
>> +const u16 val = bootcount_magic << 8 | (a & 0xff);
>> +
>> +if (dev_read_u32(dev, offset_propname, ) < 0) {
>> +debug("%s: requires %s\n", __func__,
>> offset_propname);
>> +return;
>> +}
>> +
>> +if (rtc_write16(dev, offset, val) < 0) {
>> +debug("%s: rtc_write16 failed\n", __func__);
>> +return;
>> +}
>> +#endif
>> +}
>> +
>> +static u32 bootcount_load_rtc(struct udevice *dev)
>> +{
>> +#if CONFIG_IS_ENABLED(DM_RTC)
>> +u32 offset;
>> +const char 

Re: [U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-14 Thread Lukasz Majewski
Hi Philipp,

> The original bootcount methods do not provide an interface to DM and
> rely on a static configuration for I2C devices (e.g. bus, chip-addr,
> etc. are configured through defines statically).  On a modern system
> that exposes multiple devices in a DTS-configurable way, this is less
> than optimal and a interface to DM-based devices will be desirable.
> 
> This adds a simple driver that is DM-aware and configurable via DTS:
> the /chosen/u-boot,bootcount-device property is used to detect the DM
> device storing the bootcount and deviceclass-specific commands are
> used to read/write the bootcount.
> 
> Initially, this provides support for the following DM devices:
>  * RTC devices implementing the read8/write8 ops
> 
> Signed-off-by: Philipp Tomsich 
> Tested-by: Klaus Goger 
> ---
> 
>  doc/device-tree-bindings/chosen.txt | 27 +++
>  drivers/bootcount/Kconfig   | 12 +
>  drivers/bootcount/Makefile  |  1 +
>  drivers/bootcount/bootcount_dm.c| 93
> + 4 files changed, 133
> insertions(+) create mode 100644 drivers/bootcount/bootcount_dm.c
> 
> diff --git a/doc/device-tree-bindings/chosen.txt
> b/doc/device-tree-bindings/chosen.txt index da7b4e6..734fd15 100644
> --- a/doc/device-tree-bindings/chosen.txt
> +++ b/doc/device-tree-bindings/chosen.txt
> @@ -42,6 +42,33 @@ Example
>   };
>  };
>  
> +u-boot,bootcount-device property
> +
> +In a DM-based system, the bootcount may be stored in a device known
> to +the DM framework (e.g. in a battery-backed SRAM area within a RTC
> +device).  To identify the device to be used for the bootcount, the
> +u-boot,bootcount-device property needs to point to the target device.
> +
> +Further configuration in the target device's node may be required
> +(e.g. an offset into an I2C RTC's address space), depending on the
> +UCLASS of the target device.
> +
> +Example
> +---
> +/ {
> + chosen {
> + u-boot,bootcount-device = 
> + };
> +
> + i2c2 {
> + rv3029: rtc@56 {
> + compatible = "mc,rv3029";
> + reg = <0x56>;
> + u-boot,bootcount-offset = <0x38>;
> + };
> + };
> +};
> +
>  u-boot,spl-boot-order property
>  --
>  
> diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
> index d335ed1..cdde7b5 100644
> --- a/drivers/bootcount/Kconfig
> +++ b/drivers/bootcount/Kconfig
> @@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
>   bool "Boot counter for Atmel AT91SAM9XE"
>   depends on AT91SAM9XE
>  
> +config BOOTCOUNT_DM
> +bool "Boot counter in a device-model device"
> + help
> +   Enables reading/writing the bootcount in a device-model
> +   device referenced from the /chosen node.  The type of the
> +   device is detected from DM and any additional configuration
> +   information (e.g. the offset into a RTC device that
> supports
> +   read32/write32) is read from the device's node.
> +
> +   At this time the following DM device classes are supported:
> +* RTC (using read32/write32)
> +
>  endchoice
>  
>  config BOOTCOUNT_ALEN
> diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
> index 68bc006..e8ed729 100644
> --- a/drivers/bootcount/Makefile
> +++ b/drivers/bootcount/Makefile
> @@ -7,3 +7,4 @@ 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
> +obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
> diff --git a/drivers/bootcount/bootcount_dm.c
> b/drivers/bootcount/bootcount_dm.c new file mode 100644
> index 000..99bdb88
> --- /dev/null
> +++ b/drivers/bootcount/bootcount_dm.c
> @@ -0,0 +1,93 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +const u8 bootcount_magic = 0xbc;
> +
> +static void bootcount_store_rtc(struct udevice *dev, ulong a)
> +{
> +#if CONFIG_IS_ENABLED(DM_RTC)
> + u32 offset;
> + const char *offset_propname = "u-boot,bootcount-offset";
> + const u16 val = bootcount_magic << 8 | (a & 0xff);
> +
> + if (dev_read_u32(dev, offset_propname, ) < 0) {
> + debug("%s: requires %s\n", __func__,
> offset_propname);
> + return;
> + }
> +
> + if (rtc_write16(dev, offset, val) < 0) {
> + debug("%s: rtc_write16 failed\n", __func__);
> + return;
> + }
> +#endif
> +}
> +
> +static u32 bootcount_load_rtc(struct udevice *dev)
> +{
> +#if CONFIG_IS_ENABLED(DM_RTC)
> + u32 offset;
> + const char *offset_propname = "u-boot,bootcount-offset";
> + u16 val;
> +
> + if (dev_read_u32(dev, offset_propname, ) < 0) {
> + debug("%s: requires 

[U-Boot] [PATCH 3/3] bootcount: add DM-based backing store for bootcount

2018-08-14 Thread Philipp Tomsich
The original bootcount methods do not provide an interface to DM and
rely on a static configuration for I2C devices (e.g. bus, chip-addr,
etc. are configured through defines statically).  On a modern system
that exposes multiple devices in a DTS-configurable way, this is less
than optimal and a interface to DM-based devices will be desirable.

This adds a simple driver that is DM-aware and configurable via DTS:
the /chosen/u-boot,bootcount-device property is used to detect the DM
device storing the bootcount and deviceclass-specific commands are
used to read/write the bootcount.

Initially, this provides support for the following DM devices:
 * RTC devices implementing the read8/write8 ops

Signed-off-by: Philipp Tomsich 
Tested-by: Klaus Goger 
---

 doc/device-tree-bindings/chosen.txt | 27 +++
 drivers/bootcount/Kconfig   | 12 +
 drivers/bootcount/Makefile  |  1 +
 drivers/bootcount/bootcount_dm.c| 93 +
 4 files changed, 133 insertions(+)
 create mode 100644 drivers/bootcount/bootcount_dm.c

diff --git a/doc/device-tree-bindings/chosen.txt 
b/doc/device-tree-bindings/chosen.txt
index da7b4e6..734fd15 100644
--- a/doc/device-tree-bindings/chosen.txt
+++ b/doc/device-tree-bindings/chosen.txt
@@ -42,6 +42,33 @@ Example
};
 };
 
+u-boot,bootcount-device property
+
+In a DM-based system, the bootcount may be stored in a device known to
+the DM framework (e.g. in a battery-backed SRAM area within a RTC
+device).  To identify the device to be used for the bootcount, the
+u-boot,bootcount-device property needs to point to the target device.
+
+Further configuration in the target device's node may be required
+(e.g. an offset into an I2C RTC's address space), depending on the
+UCLASS of the target device.
+
+Example
+---
+/ {
+   chosen {
+   u-boot,bootcount-device = 
+   };
+
+   i2c2 {
+   rv3029: rtc@56 {
+   compatible = "mc,rv3029";
+   reg = <0x56>;
+   u-boot,bootcount-offset = <0x38>;
+   };
+   };
+};
+
 u-boot,spl-boot-order property
 --
 
diff --git a/drivers/bootcount/Kconfig b/drivers/bootcount/Kconfig
index d335ed1..cdde7b5 100644
--- a/drivers/bootcount/Kconfig
+++ b/drivers/bootcount/Kconfig
@@ -70,6 +70,18 @@ config BOOTCOUNT_AT91
bool "Boot counter for Atmel AT91SAM9XE"
depends on AT91SAM9XE
 
+config BOOTCOUNT_DM
+bool "Boot counter in a device-model device"
+   help
+ Enables reading/writing the bootcount in a device-model
+ device referenced from the /chosen node.  The type of the
+ device is detected from DM and any additional configuration
+ information (e.g. the offset into a RTC device that supports
+ read32/write32) is read from the device's node.
+
+ At this time the following DM device classes are supported:
+  * RTC (using read32/write32)
+
 endchoice
 
 config BOOTCOUNT_ALEN
diff --git a/drivers/bootcount/Makefile b/drivers/bootcount/Makefile
index 68bc006..e8ed729 100644
--- a/drivers/bootcount/Makefile
+++ b/drivers/bootcount/Makefile
@@ -7,3 +7,4 @@ 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
+obj-$(CONFIG_BOOTCOUNT_DM)  += bootcount_dm.o
diff --git a/drivers/bootcount/bootcount_dm.c b/drivers/bootcount/bootcount_dm.c
new file mode 100644
index 000..99bdb88
--- /dev/null
+++ b/drivers/bootcount/bootcount_dm.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+const u8 bootcount_magic = 0xbc;
+
+static void bootcount_store_rtc(struct udevice *dev, ulong a)
+{
+#if CONFIG_IS_ENABLED(DM_RTC)
+   u32 offset;
+   const char *offset_propname = "u-boot,bootcount-offset";
+   const u16 val = bootcount_magic << 8 | (a & 0xff);
+
+   if (dev_read_u32(dev, offset_propname, ) < 0) {
+   debug("%s: requires %s\n", __func__, offset_propname);
+   return;
+   }
+
+   if (rtc_write16(dev, offset, val) < 0) {
+   debug("%s: rtc_write16 failed\n", __func__);
+   return;
+   }
+#endif
+}
+
+static u32 bootcount_load_rtc(struct udevice *dev)
+{
+#if CONFIG_IS_ENABLED(DM_RTC)
+   u32 offset;
+   const char *offset_propname = "u-boot,bootcount-offset";
+   u16 val;
+
+   if (dev_read_u32(dev, offset_propname, ) < 0) {
+   debug("%s: requires %s\n", __func__, offset_propname);
+   goto fail;
+   }
+
+   if (rtc_read16(dev, offset, ) < 0) {
+   debug("%s: rtc_write16 failed\n", __func__);
+   goto fail;
+