[PATCH v2 2/7] filetype: Allow specifying cdev's filetype explicitly

2019-06-03 Thread Andrey Smirnov
Allow specifying cdev's filetype explicitly to support the cases where
the type of a cdev is known apriori, yet cannot be determined by
reading the cdev's content.

Signed-off-by: Andrey Smirnov 
---
 common/filetype.c | 6 ++
 include/driver.h  | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 429911533..e4c8005b5 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -425,6 +425,11 @@ enum filetype cdev_detect_type(const char *name)
if (!cdev)
return type;
 
+   if (cdev->filetype != filetype_unknown) {
+   type = cdev->filetype;
+   goto cdev_close;
+   }
+
buf = xzalloc(FILE_TYPE_SAFE_BUFSIZE);
ret = cdev_read(cdev, buf, FILE_TYPE_SAFE_BUFSIZE, 0, 0);
if (ret < 0)
@@ -434,6 +439,7 @@ enum filetype cdev_detect_type(const char *name)
 
 err_out:
free(buf);
+cdev_close:
cdev_close(cdev);
return type;
 }
diff --git a/include/driver.h b/include/driver.h
index 26ec413bd..fe2d30ab5 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define FORMAT_DRIVER_NAME_ID  "%s%d"
 
@@ -464,6 +465,7 @@ struct cdev {
struct list_head link_entry, links;
struct list_head partition_entry, partitions;
struct cdev *master;
+   enum filetype filetype;
 };
 
 int devfs_create(struct cdev *);
-- 
2.21.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 3/7] drivers: Introduce late_platform_driver()

2019-06-03 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 include/driver.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/driver.h b/include/driver.h
index fe2d30ab5..300603fa3 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -420,6 +420,8 @@ int platform_driver_register(struct driver_d *drv);
register_driver_macro(device,platform,drv)
 #define console_platform_driver(drv)   \
register_driver_macro(console,platform,drv)
+#define late_platform_driver(drv)  \
+   register_driver_macro(late,platform,drv)
 
 int platform_device_register(struct device_d *new_device);
 
-- 
2.21.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 7/7] ARM: rdu1: Add U-Boot environment partition

2019-06-03 Thread Andrey Smirnov
From: Cory Tusar 

Signed-off-by: Cory Tusar 
---
 arch/arm/dts/imx51-zii-rdu1.dts | 21 +
 1 file changed, 21 insertions(+)

diff --git a/arch/arm/dts/imx51-zii-rdu1.dts b/arch/arm/dts/imx51-zii-rdu1.dts
index 01e46baf2..66d1e0144 100644
--- a/arch/arm/dts/imx51-zii-rdu1.dts
+++ b/arch/arm/dts/imx51-zii-rdu1.dts
@@ -23,6 +23,11 @@
compatible = "barebox,environment";
device-path = , "partname:barebox-environment";
};
+
+   ubootenv {
+   compatible = "barebox,uboot-environment";
+   device-path = _env;
+   };
};
 
aliases {
@@ -61,6 +66,22 @@
};
 };
 
+ {
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   /*
+* Layout info is taken from /etc/fw_env.config
+*/
+   uboot_env: partition@c {
+   label = "uboot-environment";
+   reg = <0xc 0x2>;
+   };
+   };
+};
+
 _gpio {
switch: switch@0 {};
 };
-- 
2.21.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 0/7] U-Boot environment data as a filesystem

2019-06-03 Thread Andrey Smirnov
Everyone:

This series adds code needed to expose U-Boot environemnt variable
data partition as a regular filesystem in Barebox. It currently only
supports the use-case where environment is stored on SD/MMC device,
since that is the only use-case I have access to for testing, however
adding support for other cases should be relatively
straightforward.

Feedback is welcome!

Changes since [v1]:

- ubootvar changed to not rely on struct resource
*/mem_write/mem_read etc. and use a private pointer instead

- ubootvar changed to handle the case of no valid environment data
  by allocation parition 0 as empty/new
  
- Added documentation for ubootvarfs as well as ubootvar DT
  bindings

Thanks,
Andrey Smirnov

[v1] http://lists.infradead.org/pipermail/barebox/2019-May/038223.html

Andrey Smirnov (6):
  filetype: Add "U-Boot environmemnt variable data" filetype
  filetype: Allow specifying cdev's filetype explicitly
  drivers: Introduce late_platform_driver()
  misc: Add a driver to expose U-Boot environment variable data
  fs: Add a driver to access U-Boot environment variables
  ARM: rdu2: Add U-Boot environment partitions

Cory Tusar (1):
  ARM: rdu1: Add U-Boot environment partition

 .../barebox/barebox,uboot-environment.rst |  43 ++
 Documentation/filesystems/ubootvarfs.rst  |  28 +
 arch/arm/dts/imx51-zii-rdu1.dts   |  21 +
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi|  27 +
 common/filetype.c |   8 +
 drivers/misc/Kconfig  |  12 +
 drivers/misc/Makefile |   1 +
 drivers/misc/ubootvar.c   | 360 +
 fs/Kconfig|   8 +
 fs/Makefile   |   1 +
 fs/ubootvarfs.c   | 499 ++
 include/driver.h  |   4 +
 include/filetype.h|   1 +
 13 files changed, 1013 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst
 create mode 100644 Documentation/filesystems/ubootvarfs.rst
 create mode 100644 drivers/misc/ubootvar.c
 create mode 100644 fs/ubootvarfs.c

-- 
2.21.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 1/7] filetype: Add "U-Boot environmemnt variable data" filetype

2019-06-03 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 common/filetype.c  | 2 ++
 include/filetype.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index e2d707b15..429911533 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -77,6 +77,8 @@ static const struct filetype_str filetype_str[] = {
[filetype_imx_image_v2] = { "i.MX image (v2)", "imx-image-v2" },
[filetype_layerscape_image] = { "Layerscape image", "layerscape-PBL" },
[filetype_layerscape_qspi_image] = { "Layerscape QSPI image", 
"layerscape-qspi-PBL" },
+   [filetype_ubootvar] = { "U-Boot environmemnt variable data",
+   "ubootvar" },
 };
 
 const char *file_type_to_string(enum filetype f)
diff --git a/include/filetype.h b/include/filetype.h
index dcb331a6c..f1be04e81 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -47,6 +47,7 @@ enum filetype {
filetype_imx_image_v2,
filetype_layerscape_image,
filetype_layerscape_qspi_image,
+   filetype_ubootvar,
filetype_max,
 };
 
-- 
2.21.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 6/7] ARM: rdu2: Add U-Boot environment partitions

2019-06-03 Thread Andrey Smirnov
Signed-off-by: Andrey Smirnov 
---
 arch/arm/dts/imx6qdl-zii-rdu2.dtsi | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi 
b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
index bfc75ba60..c9a243c22 100644
--- a/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
+++ b/arch/arm/dts/imx6qdl-zii-rdu2.dtsi
@@ -47,6 +47,12 @@
compatible = "barebox,environment";
device-path = _flash, 
"partname:barebox-environment";
};
+
+   ubootenv {
+   compatible = "barebox,uboot-environment";
+   device-path-0 = _env_0;
+   device-path-1 = _env_1;
+   };
};
 
device-info {
@@ -249,6 +255,27 @@
dr_mode = "otg";
 };
 
+ {
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   /*
+* Layout info is taken from /etc/fw_env.config
+*/
+   uboot_env_0: partition@c {
+   label = "uboot-environment-0";
+   reg = <0xc 0x4000>;
+   };
+
+   uboot_env_1: partition@cc800 {
+   label = "uboot-environment-1";
+   reg = <0xcc800 0x4000>;
+   };
+   };
+};
+
  {
pinctrl-names = "default";
pinctrl-0 = <_gpio3_hog>;
-- 
2.21.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH v2 5/7] fs: Add a driver to access U-Boot environment variables

2019-06-03 Thread Andrey Smirnov
Add a driver working on top of ubootvar device and exposing U-Boot
environment variable data as files.

Signed-off-by: Andrey Smirnov 
Signed-off-by: Cory Tusar 
---
 Documentation/filesystems/ubootvarfs.rst |  28 ++
 fs/Kconfig   |   8 +
 fs/Makefile  |   1 +
 fs/ubootvarfs.c  | 499 +++
 4 files changed, 536 insertions(+)
 create mode 100644 Documentation/filesystems/ubootvarfs.rst
 create mode 100644 fs/ubootvarfs.c

diff --git a/Documentation/filesystems/ubootvarfs.rst 
b/Documentation/filesystems/ubootvarfs.rst
new file mode 100644
index 0..0433b1294
--- /dev/null
+++ b/Documentation/filesystems/ubootvarfs.rst
@@ -0,0 +1,28 @@
+.. index:: ubootvarfs (filesystem)
+
+.. _filesystems_ubootvarfs:
+
+U-Boot environment filesystem
+=
+
+barebox supports accessing U-Boot environment contents as a regular
+filesystems in both read and write modes.  U-Boot environment data
+(ubootvar) device supports automount, so no explicit mount command
+should be necessary and accessing the environment should be as easy
+as:
+
+.. code-block:: console
+
+  barebox:/ ls -l /mnt/ubootvar0
+
+However the filesystem can be explicitly mounted with the following
+command:
+
+.. code-block:: console
+
+  barebox:/ mount -t ubootvarfs /dev/device /mnt/path
+
+**NOTE** Current implementation of the filesystem driver uses lazy
+synchronization, any changes made to the environment will not be
+written to the medium until the filesystem is unmounted (will happen
+automatically on Barebox shutdown)
diff --git a/fs/Kconfig b/fs/Kconfig
index e3a95321c..adf281a5b 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -118,4 +118,12 @@ config FS_RATP
  This enables support for transferring files over RATP. A host can
  export a directory which can then be mounted under barebox.
 
+config FS_UBOOTVARFS
+   bool
+   depends on UBOOTVAR
+   prompt "U-Boot environment variable filesystem support"
+   help
+ This filesystem driver provides access to U-Boot environment
+ variables.
+
 endmenu
diff --git a/fs/Makefile b/fs/Makefile
index ac3e6a03a..9889a6507 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -18,3 +18,4 @@ obj-$(CONFIG_FS_SMHFS) += smhfs.o
 obj-$(CONFIG_FS_PSTORE) += pstore/
 obj-$(CONFIG_FS_SQUASHFS) += squashfs/
 obj-$(CONFIG_FS_RATP)  += ratpfs.o
+obj-$(CONFIG_FS_UBOOTVARFS) += ubootvarfs.o
diff --git a/fs/ubootvarfs.c b/fs/ubootvarfs.c
new file mode 100644
index 0..81ec05d5e
--- /dev/null
+++ b/fs/ubootvarfs.c
@@ -0,0 +1,499 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ */
+
+#define pr_fmt(fmt) "ubootvarfs: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * Some theory of operation:
+ *
+ * U-Boot environment variable data is expected to be presented as a
+ * single blob containing an arbitrary number "=\0" pairs
+ * without any other auxiliary information (accomplished by ubootvar
+ * driver)
+ *
+ * Filesystem driver code in this file parses above data an creates a
+ * linked list of all of the "variables" found (see @ubootvarfs_var to
+ * what information is recorded).
+ *
+ * With that in place reading or writing file data becomes as trivial
+ * as looking up a variable in the linked list by name and then
+ * memcpy()-ing bytes from its value region.
+ *
+ * The only moderately tricky part is re-sizing a given file/variable
+ * since, given the underlying data format, it requires us to move all
+ * of the key/value data that comes after the given file/variable as
+ * well as to adjust all of the cached offsets stored in variable
+ * linked list. See ubootvarfs_adjust() for the implementation
+ * details.
+ */
+
+/**
+ * struct ubootvarfs_var - U-Boot environment key-value pair
+ *
+ * @list:  Linked list head
+ * @name:  Pointer to memory containing key string (variable name)
+ * @name_len:  Variable name's (above) length
+ * @start: Start of value in memory
+ * @end:   End of value in memory
+ */
+struct ubootvarfs_var {
+   struct list_head list;
+   char *name;
+   size_t name_len;
+   char *start;
+   char *end;
+};
+
+/**
+ * struct ubootvarfs_data - U-Boot environment data
+ *
+ * @var_list:  Linked list of all of the parsed variables
+ * @fd:File descriptor of underlying ubootvar device
+ * @end:   End of U-boot environment
+ * @limit: U-boot environment limit (can't grow to go past the limit)
+ */
+struct ubootvarfs_data {
+   struct list_head var_list;
+   int fd;
+   char *end;
+   const char *limit;
+};
+
+struct ubootvarfs_inode {
+   struct inode inode;
+   struct ubootvarfs_var *var;
+   struct ubootvarfs_data *data;
+};
+
+static struct ubootvarfs_inode *inode_to_node(struct 

[PATCH v2 4/7] misc: Add a driver to expose U-Boot environment variable data

2019-06-03 Thread Andrey Smirnov
Add a driver to expose U-Boot environment variable data as a single
mmap-able device, hiding various low-level details such as:

* Preamble format differences
* Read/write logic in presence of redundant partition

Not very useful on its own, it is a crucial low-level plumbing needed
by filesystem driver introduced in the following commit.

Signed-off-by: Andrey Smirnov 
Signed-off-by: Cory Tusar 
---
 .../barebox/barebox,uboot-environment.rst |  43 +++
 drivers/misc/Kconfig  |  12 +
 drivers/misc/Makefile |   1 +
 drivers/misc/ubootvar.c   | 360 ++
 4 files changed, 416 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst
 create mode 100644 drivers/misc/ubootvar.c

diff --git 
a/Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst 
b/Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst
new file mode 100644
index 0..da0ccd2c2
--- /dev/null
+++ b/Documentation/devicetree/bindings/barebox/barebox,uboot-environment.rst
@@ -0,0 +1,43 @@
+U-Boot environment device
+=
+
+This driver provides a unified device exposing U-Boot environment
+varaible data, sans the low-level parts. Resulting device is intended
+to be used with corresponding filesystem driver to expose environment
+data as a filesystem.
+
+Required properties:
+
+* ``compatible``: should be ``barebox,uboot-environment``
+* ``device-path``: phandle of the partition the device environment is
+  on (single partiton configuration)
+* ``device-path-0`` and ``device-path-1``: phandle of the partition
+  the environment is on (redundant configuration)
+
+Example:
+
+.. code-block:: none
+
+  environment {
+   compatible = "barebox,uboot-environment";
+   device-path-0 = _env_0;
+   device-path-1 = _env_1;
+  };
+  
+   {
+   partitions {
+   compatible = "fixed-partitions";
+   #address-cells = <1>;
+   #size-cells = <1>;
+
+   uboot_env_0: partition@c {
+   label = "uboot-environment-0";
+   reg = <0xc 0x4000>;
+   };
+
+   uboot_env_1: partition@cc800 {
+   label = "uboot-environment-1";
+   reg = <0xcc800 0x4000>;
+   };
+   };
+  };
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4c8a769c4..0f736f8bd 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -23,4 +23,16 @@ config STATE_DRV
 config DEV_MEM
 bool "Generic memory I/O device (/dev/mem)"
 
+config UBOOTVAR
+   bool "U-Boot environment storage"
+   help
+ This driver exposes U-Boot environment variable storage as a
+ single mmap-able device, hiding various low-level details
+ such as:
+ - Preamble format differences
+ - Read/write logic in presence of redundant partition
+
+ While it can be used standalone, it is best when coupled
+ with corresponding filesystem driver.
+
 endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index d4e616d51..bc1c01ea4 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_JTAG)  += jtag.o
 obj-$(CONFIG_SRAM) += sram.o
 obj-$(CONFIG_STATE_DRV)+= state.o
 obj-$(CONFIG_DEV_MEM)  += mem.o
+obj-$(CONFIG_UBOOTVAR) += ubootvar.o
diff --git a/drivers/misc/ubootvar.c b/drivers/misc/ubootvar.c
new file mode 100644
index 0..27f2515e7
--- /dev/null
+++ b/drivers/misc/ubootvar.c
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * U-Boot environment vriable blob driver
+ *
+ * Copyright (C) 2019 Zodiac Inflight Innovations
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+enum ubootvar_flag_scheme {
+   FLAG_NONE,
+   FLAG_BOOLEAN,
+   FLAG_INCREMENTAL,
+};
+
+struct ubootvar_data {
+   struct cdev cdev;
+   char *path[2];
+   bool current;
+   uint8_t flag;
+   int count;
+   void *data;
+   size_t size;
+};
+
+static int ubootvar_flush(struct cdev *cdev)
+{
+   struct device_d *dev = cdev->dev;
+   struct ubootvar_data *ubdata = dev->priv;
+   const char *path = ubdata->path[!ubdata->current];
+   uint32_t crc = 0x;
+   resource_size_t size;
+   const void *data;
+   int fd, ret = 0;
+
+   fd = open(path, O_WRONLY);
+   if (fd < 0) {
+   dev_err(dev, "Failed to open %s\n", path);
+   return -errno;
+   }
+   /*
+* FIXME: This code needs to do a proper protect/unprotect and
+* erase calls to work on MTD devices
+*/
+
+   /*
+* Write a dummy CRC first as a way of invalidating the
+* environment in case we 

Re: [PATCH 4/7] ARM: stm32mp1: enable watchdog in oftree and defconfig

2019-06-03 Thread Ahmad Fatoum
Hello Sam,

On 3/6/19 21:34, Sam Ravnborg wrote:
> Hi Ahmad.
> 
> Subject: [PATCH 4/7] ARM: stm32mp1: enable watchdog in oftree and defconfig
>  ^
> 
> Someone just renamed this arch to stm32mp...

Ye, the script that I use to generate the prefixes didn't account for that.. :D


> 
>   Sam
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH 4/7] ARM: stm32mp1: enable watchdog in oftree and defconfig

2019-06-03 Thread Sam Ravnborg
Hi Ahmad.

Subject: [PATCH 4/7] ARM: stm32mp1: enable watchdog in oftree and defconfig
 ^

Someone just renamed this arch to stm32mp...

Sam

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] ARM: rdu2: Initialize DEBUG_LL in entry function

2019-06-03 Thread Andrey Smirnov
When bootstrapping Barebox via JTAG rdu2_sram_setup() won't be
executed resulting in non functional DEBUG_LL API. Move low-level UART
initialization code to be a part of start_imx6_zii_rdu2() to avoid
that problem.

Signed-off-by: Andrey Smirnov 
---
 arch/arm/boards/zii-imx6q-rdu2/lowlevel.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c 
b/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
index a5ac6f64c..9672a69bf 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
@@ -271,11 +271,6 @@ static noinline void rdu2_sram_setup(void)
enum bootsource bootsrc;
int instance;
 
-   imx6_ungate_all_peripherals();
-
-   if (IS_ENABLED(CONFIG_DEBUG_LL))
-   setup_uart();
-
arm_setup_stack(0x0092 - 8);
relocate_to_current_adr();
setup_c();
@@ -296,6 +291,11 @@ ENTRY_FUNCTION(start_imx6_zii_rdu2, r0, r1, r2)
 {
imx6_cpu_lowlevel_init();
 
+   imx6_ungate_all_peripherals();
+
+   if (IS_ENABLED(CONFIG_DEBUG_LL))
+   setup_uart();
+
/*
 * When still running in SRAM, we need to setup the DRAM now and load
 * the remaining image.
-- 
2.21.0


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] commands: don't use stale errno when calling fb_open

2019-06-03 Thread Andrey Smirnov
On Mon, Jun 3, 2019 at 12:05 PM Ahmad Fatoum  wrote:
>
> fb_open returns a pointer and doesn't populate errno, which will
> results in a stale errno being evaluated by perror() on failure.
> Fix this by populating errno manually at call sites.
>

Why not just convert the code to use strerror() instead? Seems a bit
more straightforward plus changing errno outside of our "POSIX/C"
layer seems a bit out of place. Not a big deal though.

Thanks,
Andrey Smirnov

> While at it, correct the typo in the prefix passed to perror().
>
> Signed-off-by: Ahmad Fatoum 
> ---
>  commands/fbtest.c | 5 +++--
>  commands/splash.c | 5 +++--
>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/commands/fbtest.c b/commands/fbtest.c
> index e5dd8ba7fabf..2c589f77d3b8 100644
> --- a/commands/fbtest.c
> +++ b/commands/fbtest.c
> @@ -271,8 +271,9 @@ static int do_fbtest(int argc, char *argv[])
>
> sc = fb_open(fbdev);
> if (IS_ERR(sc)) {
> -   perror("fd_open");
> -   return PTR_ERR(sc);
> +   errno = PTR_ERR(sc);
> +   perror("fb_open");
> +   return errno;
> }
>
> if (!pattern_name) {
> diff --git a/commands/splash.c b/commands/splash.c
> index 2b70b296837e..75b3ee3fadaf 100644
> --- a/commands/splash.c
> +++ b/commands/splash.c
> @@ -54,8 +54,9 @@ static int do_splash(int argc, char *argv[])
>
> sc = fb_open(fbdev);
> if (IS_ERR(sc)) {
> -   perror("fd_open");
> -   return PTR_ERR(sc);
> +   errno = PTR_ERR(sc);
> +   perror("fb_open");
> +   return errno;
> }
>
> buf = gui_screen_render_buffer(sc);
> --
> 2.20.1
>
>
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 3/7] watchdog: add stm32 watchdog and reset driver

2019-06-03 Thread Ahmad Fatoum
The driver supports setting watchdog timeout, system reset
and querying reset reason. Disabling watchdog isn't possible
in hardware, thus users should either enable it before boot
or have the poller take care of feeding it.

Signed-off-by: Ahmad Fatoum 
---
 .../mach-stm32mp/include/mach/reset-reason.h  |  28 ++
 drivers/watchdog/Kconfig  |   8 +
 drivers/watchdog/Makefile |   1 +
 drivers/watchdog/stm32_wdt.c  | 288 ++
 4 files changed, 325 insertions(+)
 create mode 100644 arch/arm/mach-stm32mp/include/mach/reset-reason.h
 create mode 100644 drivers/watchdog/stm32_wdt.c

diff --git a/arch/arm/mach-stm32mp/include/mach/reset-reason.h 
b/arch/arm/mach-stm32mp/include/mach/reset-reason.h
new file mode 100644
index ..1165b347c31f
--- /dev/null
+++ b/arch/arm/mach-stm32mp/include/mach/reset-reason.h
@@ -0,0 +1,28 @@
+#ifndef __MACH_RESET_REASON_H__
+#define __MACH_RESET_REASON_H__
+
+#include 
+
+#define RCC_RSTF_POR   BIT(0)
+#define RCC_RSTF_BOR   BIT(1)
+#define RCC_RSTF_PAD   BIT(2)
+#define RCC_RSTF_HCSS  BIT(3)
+#define RCC_RSTF_VCORE BIT(4)
+
+#define RCC_RSTF_MPSYS BIT(6)
+#define RCC_RSTF_MCSYS BIT(7)
+#define RCC_RSTF_IWDG1 BIT(8)
+#define RCC_RSTF_IWDG2 BIT(9)
+
+#define RCC_RSTF_STDBY BIT(11)
+#define RCC_RSTF_CSTDBYBIT(12)
+#define RCC_RSTF_MPUP0 BIT(13)
+#define RCC_RSTF_MPUP1 BIT(14)
+
+struct stm32_reset_reason {
+   uint32_t mask;
+   enum reset_src_type type;
+   int instance;
+};
+
+#endif
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 04efb1a3c866..5a28b530099d 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -81,4 +81,12 @@ config RAVE_SP_WATCHDOG
depends on RAVE_SP_CORE
help
  Support for the watchdog on RAVE SP device.
+
+config STM32_IWDG_WATCHDOG
+bool "Enable IWDG watchdog driver for STM32 processors"
+   depends on ARCH_STM32MP
+   select MFD_SYSCON
+help
+Enable the STM32 watchdog (IWDG) driver. Enable support to
+configure STM32's on-SoC watchdog.
 endif
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 6c8d36c8b805..b2f39fa3719e 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_WATCHDOG_IMX) += imxwd.o
 obj-$(CONFIG_WATCHDOG_ORION) += orion_wdt.o
 obj-$(CONFIG_ARCH_BCM283X) += bcm2835_wdt.o
 obj-$(CONFIG_RAVE_SP_WATCHDOG) += rave-sp-wdt.o
+obj-$(CONFIG_STM32_IWDG_WATCHDOG) += stm32_wdt.o
diff --git a/drivers/watchdog/stm32_wdt.c b/drivers/watchdog/stm32_wdt.c
new file mode 100644
index ..a972aade5900
--- /dev/null
+++ b/drivers/watchdog/stm32_wdt.c
@@ -0,0 +1,288 @@
+// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
+/*
+ * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* IWDG registers */
+#define IWDG_KR0x00/* Key register */
+#define IWDG_PR0x04/* Prescaler Register */
+#define IWDG_RLR   0x08/* ReLoad Register */
+#define IWDG_SR0x0C/* Status Register */
+
+/* IWDG_KR register bit mask */
+#define KR_KEY_RELOAD  0x  /* Reload counter enable */
+#define KR_KEY_ENABLE  0x  /* Peripheral enable */
+#define KR_KEY_EWA 0x  /* Write access enable */
+
+/* IWDG_PR register bit values */
+#define PR_SHIFT   2
+
+/* IWDG_RLR register values */
+#define RLR_MAXGENMASK(11, 0)
+
+/* IWDG_SR register bit mask */
+#define SR_PVU BIT(0) /* Watchdog prescaler value update */
+#define SR_RVU BIT(1) /* Watchdog counter reload value update */
+
+#define RCC_MP_GRSTCSETR   0x404
+#define RCC_MP_RSTSCLRR0x408
+#define RCC_MP_GRSTCSETR_MPSYSRST  BIT(0)
+
+/* set timeout to 100 ms */
+#define TIMEOUT_US 10
+
+struct stm32_iwdg {
+   struct watchdog wdd;
+   struct restart_handler restart;
+   void __iomem *iwdg_base;
+   struct regmap *rcc_regmap;
+   unsigned int timeout;
+   unsigned int rate;
+};
+
+static inline struct stm32_iwdg *to_stm32_iwdg(struct watchdog *wdd)
+{
+   return container_of(wdd, struct stm32_iwdg, wdd);
+}
+
+static void __noreturn stm32_iwdg_restart_handler(struct restart_handler *rst)
+{
+   struct stm32_iwdg *wd = container_of(rst, struct stm32_iwdg, restart);
+
+   regmap_update_bits(wd->rcc_regmap, RCC_MP_GRSTCSETR,
+  RCC_MP_GRSTCSETR_MPSYSRST, 
RCC_MP_GRSTCSETR_MPSYSRST);
+
+   mdelay(1000);
+   hang();
+}
+
+static void stm32_iwdg_ping(struct stm32_iwdg *wd)
+{
+   writel(KR_KEY_RELOAD, wd->iwdg_base + IWDG_KR);
+}
+
+static int stm32_iwdg_start(struct stm32_iwdg *wd, unsigned int 

[PATCH 4/7] ARM: stm32mp1: enable watchdog in oftree and defconfig

2019-06-03 Thread Ahmad Fatoum
With the IWDG driver implemented in barebox, have it be part of the
default configuration.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/configs/stm32mp_defconfig | 5 -
 arch/arm/dts/stm32mp157c-dk2.dts   | 4 
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/arch/arm/configs/stm32mp_defconfig 
b/arch/arm/configs/stm32mp_defconfig
index 657b2edf57f2..99523a78650e 100644
--- a/arch/arm/configs/stm32mp_defconfig
+++ b/arch/arm/configs/stm32mp_defconfig
@@ -25,7 +25,6 @@ CONFIG_CONSOLE_ALLOW_COLOR=y
 CONFIG_PBL_CONSOLE=y
 CONFIG_PARTITION=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
-CONFIG_POLLER=y
 CONFIG_RESET_SOURCE=y
 CONFIG_DEBUG_INITCALLS=y
 CONFIG_CMD_DMESG=y
@@ -71,6 +70,7 @@ CONFIG_CMD_MM=y
 CONFIG_CMD_CLK=y
 CONFIG_CMD_DETECT=y
 CONFIG_CMD_FLASH=y
+CONFIG_CMD_WD=y
 CONFIG_CMD_BAREBOX_UPDATE=y
 CONFIG_CMD_OF_NODE=y
 CONFIG_CMD_OF_PROPERTY=y
@@ -86,6 +86,9 @@ CONFIG_DRIVER_NET_DESIGNWARE_GENERIC=y
 CONFIG_AT803X_PHY=y
 CONFIG_MICREL_PHY=y
 # CONFIG_SPI is not set
+CONFIG_WATCHDOG=y
+CONFIG_WATCHDOG_POLLER=y
+CONFIG_STM32_IWDG_WATCHDOG=y
 # CONFIG_PINCTRL is not set
 CONFIG_FS_EXT4=y
 CONFIG_FS_TFTP=y
diff --git a/arch/arm/dts/stm32mp157c-dk2.dts b/arch/arm/dts/stm32mp157c-dk2.dts
index 7565cabc3d92..5c39a1a4f5a8 100644
--- a/arch/arm/dts/stm32mp157c-dk2.dts
+++ b/arch/arm/dts/stm32mp157c-dk2.dts
@@ -12,3 +12,7 @@
model = "STMicroelectronics STM32MP157C-DK2 Discovery Board";
compatible = "st,stm32mp157c-dk2", "st,stm32mp157";
 };
+
+ {
+   status = "okay";
+};
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 5/7] ARM: stm32mp: stm32mp157c-dk2: configure debug_ll UART

2019-06-03 Thread Ahmad Fatoum
This configures UART4 for use as the debug_ll UART,
whenever CONFIG_DEBUG_LL is defined.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/boards/stm32mp157c-dk2/lowlevel.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/arch/arm/boards/stm32mp157c-dk2/lowlevel.c 
b/arch/arm/boards/stm32mp157c-dk2/lowlevel.c
index b8e5959bef83..7f66cbfa1224 100644
--- a/arch/arm/boards/stm32mp157c-dk2/lowlevel.c
+++ b/arch/arm/boards/stm32mp157c-dk2/lowlevel.c
@@ -5,6 +5,24 @@
 #include 
 #include 
 
+#define RCC_MP_APB1ENSETR (STM32_RCC_BASE + 0x0A00)
+#define RCC_MP_AHB4ENSETR (STM32_RCC_BASE + 0x0A28)
+#define GPIOG_BASE 0x50008000
+
+static inline void setup_uart(void)
+{
+   /* UART4 clock enable */
+   setbits_le32(RCC_MP_APB1ENSETR, BIT(16));
+
+   /* GPIOG clock enable */
+   writel(BIT(6), RCC_MP_AHB4ENSETR);
+   /* GPIO configuration for EVAL board => UART4 TX = G11 */
+   writel(0xffbf, GPIOG_BASE + 0x00);
+   writel(0x6000, GPIOG_BASE + 0x24);
+
+   putc_ll('>');
+}
+
 extern char __dtb_stm32mp157c_dk2_start[];
 
 ENTRY_FUNCTION(start_stm32mp157c_dk2, r0, r1, r2)
@@ -13,6 +31,9 @@ ENTRY_FUNCTION(start_stm32mp157c_dk2, r0, r1, r2)
 
arm_cpu_lowlevel_init();
 
+   if (IS_ENABLED(CONFIG_DEBUG_LL))
+   setup_uart();
+
fdt = __dtb_stm32mp157c_dk2_start + get_runtime_offset();
 
barebox_arm_entry(STM32_DDR_BASE, SZ_512M, fdt);
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 1/7] ARM: stm32mp1: rename to stm32mp

2019-06-03 Thread Ahmad Fatoum
Serial and clk driver both depend on CONFIG_ARCH_STM32MP1,
so either the Kconfig symbol or their depend needs to change.

Patches posted by the vendor to Linux, U-Boot and their BSP
Yocto-Layer speak of a STM32MP-Family of which the STM32MP1
is the first series, thus rename the arch by dropping the 1.

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/Kconfig  | 4 ++--
 arch/arm/Makefile | 2 +-
 arch/arm/configs/{stm32mp1_defconfig => stm32mp_defconfig}| 2 +-
 arch/arm/{mach-stm32mp1 => mach-stm32mp}/Kconfig  | 2 +-
 arch/arm/{mach-stm32mp1 => mach-stm32mp}/Makefile | 0
 .../{mach-stm32mp1 => mach-stm32mp}/include/mach/debug_ll.h   | 0
 arch/arm/{mach-stm32mp1 => mach-stm32mp}/include/mach/stm32.h | 0
 images/Makefile   | 2 +-
 images/{Makefile.stm32mp1 => Makefile.stm32mp}| 0
 9 files changed, 6 insertions(+), 6 deletions(-)
 rename arch/arm/configs/{stm32mp1_defconfig => stm32mp_defconfig} (98%)
 rename arch/arm/{mach-stm32mp1 => mach-stm32mp}/Kconfig (87%)
 rename arch/arm/{mach-stm32mp1 => mach-stm32mp}/Makefile (100%)
 rename arch/arm/{mach-stm32mp1 => mach-stm32mp}/include/mach/debug_ll.h (100%)
 rename arch/arm/{mach-stm32mp1 => mach-stm32mp}/include/mach/stm32.h (100%)
 rename images/{Makefile.stm32mp1 => Makefile.stm32mp} (100%)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 480c6f011797..1d4b6e09ce79 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -207,7 +207,7 @@ config ARCH_S3C64xx
select CPU_V6
select GENERIC_GPIO
 
-config ARCH_STM32MP1
+config ARCH_STM32MP
bool "ST stm32mp1xx"
select CPU_V7
select HAVE_PBL_MULTI_IMAGES
@@ -304,7 +304,7 @@ source "arch/arm/mach-pxa/Kconfig"
 source "arch/arm/mach-rockchip/Kconfig"
 source "arch/arm/mach-samsung/Kconfig"
 source "arch/arm/mach-socfpga/Kconfig"
-source "arch/arm/mach-stm32mp1/Kconfig"
+source "arch/arm/mach-stm32mp/Kconfig"
 source "arch/arm/mach-versatile/Kconfig"
 source "arch/arm/mach-vexpress/Kconfig"
 source "arch/arm/mach-tegra/Kconfig"
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 4d54f339f15c..5cb46f661335 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -98,7 +98,7 @@ machine-$(CONFIG_ARCH_PXA):= pxa
 machine-$(CONFIG_ARCH_ROCKCHIP):= rockchip
 machine-$(CONFIG_ARCH_SAMSUNG) := samsung
 machine-$(CONFIG_ARCH_SOCFPGA) := socfpga
-machine-$(CONFIG_ARCH_STM32MP1):= stm32mp1
+machine-$(CONFIG_ARCH_STM32MP) := stm32mp
 machine-$(CONFIG_ARCH_VERSATILE)   := versatile
 machine-$(CONFIG_ARCH_VEXPRESS):= vexpress
 machine-$(CONFIG_ARCH_TEGRA)   := tegra
diff --git a/arch/arm/configs/stm32mp1_defconfig 
b/arch/arm/configs/stm32mp_defconfig
similarity index 98%
rename from arch/arm/configs/stm32mp1_defconfig
rename to arch/arm/configs/stm32mp_defconfig
index 2922ce3632e1..657b2edf57f2 100644
--- a/arch/arm/configs/stm32mp1_defconfig
+++ b/arch/arm/configs/stm32mp_defconfig
@@ -1,4 +1,4 @@
-CONFIG_ARCH_STM32MP1=y
+CONFIG_ARCH_STM32MP=y
 CONFIG_MACH_STM32MP157C_DK2=y
 CONFIG_THUMB2_BAREBOX=y
 CONFIG_ARM_BOARD_APPEND_ATAG=y
diff --git a/arch/arm/mach-stm32mp1/Kconfig b/arch/arm/mach-stm32mp/Kconfig
similarity index 87%
rename from arch/arm/mach-stm32mp1/Kconfig
rename to arch/arm/mach-stm32mp/Kconfig
index cc7cf23cfb31..bcf7293c465b 100644
--- a/arch/arm/mach-stm32mp1/Kconfig
+++ b/arch/arm/mach-stm32mp/Kconfig
@@ -1,4 +1,4 @@
-if ARCH_STM32MP1
+if ARCH_STM32MP
 
 config ARCH_STM32MP1157
bool
diff --git a/arch/arm/mach-stm32mp1/Makefile b/arch/arm/mach-stm32mp/Makefile
similarity index 100%
rename from arch/arm/mach-stm32mp1/Makefile
rename to arch/arm/mach-stm32mp/Makefile
diff --git a/arch/arm/mach-stm32mp1/include/mach/debug_ll.h 
b/arch/arm/mach-stm32mp/include/mach/debug_ll.h
similarity index 100%
rename from arch/arm/mach-stm32mp1/include/mach/debug_ll.h
rename to arch/arm/mach-stm32mp/include/mach/debug_ll.h
diff --git a/arch/arm/mach-stm32mp1/include/mach/stm32.h 
b/arch/arm/mach-stm32mp/include/mach/stm32.h
similarity index 100%
rename from arch/arm/mach-stm32mp1/include/mach/stm32.h
rename to arch/arm/mach-stm32mp/include/mach/stm32.h
diff --git a/images/Makefile b/images/Makefile
index 479647a82726..293e644319ea 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -140,7 +140,7 @@ include $(srctree)/images/Makefile.mxs
 include $(srctree)/images/Makefile.omap3
 include $(srctree)/images/Makefile.rockchip
 include $(srctree)/images/Makefile.socfpga
-include $(srctree)/images/Makefile.stm32mp1
+include $(srctree)/images/Makefile.stm32mp
 include $(srctree)/images/Makefile.tegra
 include $(srctree)/images/Makefile.vexpress
 include $(srctree)/images/Makefile.xburst
diff --git a/images/Makefile.stm32mp1 b/images/Makefile.stm32mp
similarity index 100%
rename from images/Makefile.stm32mp1
rename to 

[PATCH 7/7] ARM: stm32mp: add entry point, not point.pblb to pblb-y

2019-06-03 Thread Ahmad Fatoum
Other images/Makefile.${arch}s, e.g. images/Makefile.imx, populate
pblp-* with the entry points to build, not the pbl file that's
generated. Adjust the images/Makefile.stm32mp  to do the same.

Cc: Sascha Hauer 
Signed-off-by: Ahmad Fatoum 
---
 images/Makefile.stm32mp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/images/Makefile.stm32mp b/images/Makefile.stm32mp
index d26231cd92d1..c49b1d72b788 100644
--- a/images/Makefile.stm32mp
+++ b/images/Makefile.stm32mp
@@ -3,6 +3,6 @@
 # barebox image generation Makefile for STMicroelectronics MP1
 #
 
-pblb-$(CONFIG_MACH_STM32MP157C_DK2) += start_stm32mp157c_dk2.pblb
+pblb-$(CONFIG_MACH_STM32MP157C_DK2) += start_stm32mp157c_dk2
 FILE_barebox-stm32mp157c-dk2.img = start_stm32mp157c_dk2.pblb
 image-$(CONFIG_MACH_STM32MP157C_DK2) += barebox-stm32mp157c-dk2.img
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 6/7] ARM: stm32mp: stm32mp157c-dk2: compress the DTB

2019-06-03 Thread Ahmad Fatoum
This reduces saves 20K with my configuration (from 247K to 227K).

Signed-off-by: Ahmad Fatoum 
---
 arch/arm/boards/stm32mp157c-dk2/lowlevel.c | 4 ++--
 arch/arm/mach-stm32mp/Kconfig  | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boards/stm32mp157c-dk2/lowlevel.c 
b/arch/arm/boards/stm32mp157c-dk2/lowlevel.c
index 7f66cbfa1224..73e1fa1cee3d 100644
--- a/arch/arm/boards/stm32mp157c-dk2/lowlevel.c
+++ b/arch/arm/boards/stm32mp157c-dk2/lowlevel.c
@@ -23,7 +23,7 @@ static inline void setup_uart(void)
putc_ll('>');
 }
 
-extern char __dtb_stm32mp157c_dk2_start[];
+extern char __dtb_z_stm32mp157c_dk2_start[];
 
 ENTRY_FUNCTION(start_stm32mp157c_dk2, r0, r1, r2)
 {
@@ -34,7 +34,7 @@ ENTRY_FUNCTION(start_stm32mp157c_dk2, r0, r1, r2)
if (IS_ENABLED(CONFIG_DEBUG_LL))
setup_uart();
 
-   fdt = __dtb_stm32mp157c_dk2_start + get_runtime_offset();
+   fdt = __dtb_z_stm32mp157c_dk2_start + get_runtime_offset();
 
barebox_arm_entry(STM32_DDR_BASE, SZ_512M, fdt);
 }
diff --git a/arch/arm/mach-stm32mp/Kconfig b/arch/arm/mach-stm32mp/Kconfig
index bcf7293c465b..be16294f5ad7 100644
--- a/arch/arm/mach-stm32mp/Kconfig
+++ b/arch/arm/mach-stm32mp/Kconfig
@@ -5,6 +5,7 @@ config ARCH_STM32MP1157
 
 config MACH_STM32MP157C_DK2
select ARCH_STM32MP1157
+   select ARM_USE_COMPRESSED_DTB
bool "STM32MP157C-DK2 board"
 
 endif
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH 2/7] reset_source: add new Brownout reset (BOR) source

2019-06-03 Thread Ahmad Fatoum
The STM32MP1 can report brown out as reason for a reset,
which doesn't fit into existing reasons. Thus add a new
one to the enumeration.

Signed-off-by: Ahmad Fatoum 
---
 common/reset_source.c  | 1 +
 include/reset_source.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/common/reset_source.c b/common/reset_source.c
index 338d7b9acb30..0489724f3e7f 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -28,6 +28,7 @@ static const char * const reset_src_names[] = {
[RESET_JTAG] = "JTAG",
[RESET_THERM] = "THERM",
[RESET_EXT] = "EXT",
+   [RESET_BOR] = "BOR",
 };
 
 static enum reset_src_type reset_source;
diff --git a/include/reset_source.h b/include/reset_source.h
index 86e415abcf84..c124278ec674 100644
--- a/include/reset_source.h
+++ b/include/reset_source.h
@@ -22,6 +22,7 @@ enum reset_src_type {
RESET_JTAG, /* JTAG reset */
RESET_THERM,/* SoC shut down because of overtemperature */
RESET_EXT,  /* External reset through device pin */
+   RESET_BOR,  /* Brownout Reset */
 };
 
 #ifdef CONFIG_RESET_SOURCE
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] commands: don't use stale errno when calling fb_open

2019-06-03 Thread Ahmad Fatoum
fb_open returns a pointer and doesn't populate errno, which will
results in a stale errno being evaluated by perror() on failure.
Fix this by populating errno manually at call sites.

While at it, correct the typo in the prefix passed to perror().

Signed-off-by: Ahmad Fatoum 
---
 commands/fbtest.c | 5 +++--
 commands/splash.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/commands/fbtest.c b/commands/fbtest.c
index e5dd8ba7fabf..2c589f77d3b8 100644
--- a/commands/fbtest.c
+++ b/commands/fbtest.c
@@ -271,8 +271,9 @@ static int do_fbtest(int argc, char *argv[])
 
sc = fb_open(fbdev);
if (IS_ERR(sc)) {
-   perror("fd_open");
-   return PTR_ERR(sc);
+   errno = PTR_ERR(sc);
+   perror("fb_open");
+   return errno;
}
 
if (!pattern_name) {
diff --git a/commands/splash.c b/commands/splash.c
index 2b70b296837e..75b3ee3fadaf 100644
--- a/commands/splash.c
+++ b/commands/splash.c
@@ -54,8 +54,9 @@ static int do_splash(int argc, char *argv[])
 
sc = fb_open(fbdev);
if (IS_ERR(sc)) {
-   perror("fd_open");
-   return PTR_ERR(sc);
+   errno = PTR_ERR(sc);
+   perror("fb_open");
+   return errno;
}
 
buf = gui_screen_render_buffer(sc);
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


[PATCH] plathome-openblocks-a6: provide a kwbimage.cfg file

2019-06-03 Thread Uwe Kleine-König
Since support for Openblocks A6 was introduced in 2014 and commit
906afb533186 ("ARM: mvebu: Add Plat'home's Kirkwood Openblocks A6 board
support") there is no kwbimage config. This patch guesses such a file
that at least makes barebox compile again with
CONFIG_MACH_PLATHOME_OPENBLOCKS_A6=y.

Signed-off-by: Uwe Kleine-König 
---
 arch/arm/boards/plathome-openblocks-a6/kwbimage.cfg | 3 +++
 1 file changed, 3 insertions(+)
 create mode 100644 arch/arm/boards/plathome-openblocks-a6/kwbimage.cfg

diff --git a/arch/arm/boards/plathome-openblocks-a6/kwbimage.cfg 
b/arch/arm/boards/plathome-openblocks-a6/kwbimage.cfg
new file mode 100644
index ..ba3011736fb7
--- /dev/null
+++ b/arch/arm/boards/plathome-openblocks-a6/kwbimage.cfg
@@ -0,0 +1,3 @@
+VERSION 1
+BOOT_FROM nand
+BINARY ./binary.0 005b 0068
-- 
2.20.1


___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: [PATCH] ARM: panic with a message when relocation type is unknown

2019-06-03 Thread Ahmad Fatoum
Hello Andrey,

On 31/5/19 20:56, Andrey Smirnov wrote:
> On Fri, May 31, 2019 at 2:02 AM Ahmad Fatoum  wrote:
>>
>> Currently such failures result in a
>>
>> > 
>>
>> ### ERROR ### Please RESET the board ###
>>
>> With this patch this now becomes
>>
>> > 
>> Unknown relocation type
>> ### ERROR ### Please RESET the board ###
>>
>> which improves user experience a little bit.
>>
>> Signed-off-by: Ahmad Fatoum 
>> ---
>>  arch/arm/cpu/common.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
>> index 821cafbf26c2..3668c5977ca9 100644
>> --- a/arch/arm/cpu/common.c
>> +++ b/arch/arm/cpu/common.c
>> @@ -78,7 +78,7 @@ void relocate_to_current_adr(void)
>> putc_ll(' ');
>> puthex_ll(rel->r_addend);
>> putc_ll('\n');
>> -   panic("");
>> +   panic("Unknown relocation type");
>> }
>>
>> dstart += sizeof(*rel);
>> @@ -108,7 +108,7 @@ void relocate_to_current_adr(void)
>> putc_ll(' ');
>> puthex_ll(rel->r_offset);
>> putc_ll('\n');
>> -   panic("");
>> +   panic("Unknown relocation type");
> 
> Looking at this code makes me wonder if calls to panic() are even
> appropriate here. I am not sure there's any guarantee that by the time
> we get to this line relocation for "Unknown relocation type"(or
> original "") string would be processed and panic() would get right
> arguments not to mention all of the functions called as a part of
> panic() and their potential dependencies. Another thing about painc()
> is in PBL it completely ignores passed arguments, so no message will
> be printed there.
> 
> Maybe it'd make sense to go in a different direction and drop calls to
> panic() altogether and replace them with:
> 
> puts_ll(relocation_failed_message());
> hang();
> 
> where relocation_failed_message() on ARM can be something like:
> 
> .section .text.relocation_failed_message
> ENTRY(relocation_failed_message)
> push {lr}
> bl 1f
> .byte 'U, 'n, 'k, 'n, 'o, 'w, 'n, '\ , 'r, 'e, 'l, 'o, 'c, 'a, 't, 'i,
> 'o, 'n, '\ , 't, 'y, 'p, 'e, '\r, '\n, 0x00
> 1:
> mov r0, lr
> /* In case we are in thumb */
> bic r0, r0, #1
> pop {pc}
> ENDPROC(relocation_failed_message)
> 
> to guarantee that it won't depend on relocation? Might be an overkill
> though, so take this with a grain of salt.

In my particular case, the string literal was already being accessed relative
to the program counter. Do you know if GCC can be coerced to always do that?

> 
> Thanks,
> Andrey Smirnov
> 

-- 
Pengutronix e.K.   | |
Industrial Linux Solutions | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


simplefb question

2019-06-03 Thread Robin van der Gracht

Hello Andre, Sascha,

I'm trying to setup simplefb on my imx6 solo board, and ran into some 
issues and I'm hoping you could

clear things up.

I'm running:
 - Barebox 2018.07.0
 - Linux 4.19

I checked with latest versions but the relevant code seems unchanged.

On Barebox console I ran:

barebox@BOARD:/ of_dump /framebuffer
framebuffer {
display = <0x5a>;
};

barebox@BOARD:/ fb0.enable=1
imx-ipuv3-crtc imx-ipuv3-crtc0: ipu_crtc_mode_set: mode->xres: 800
imx-ipuv3-crtc imx-ipuv3-crtc0: ipu_crtc_mode_set: mode->yres: 480
WARNING: imx-ipuv3-crtc imx-ipuv3-crtc0: videomode adapted for IPU 
restriction


barebox@BOARD:/ fb0.register_simplefb=1

barebox@BOARD:/ oftree -s dump.dtb
fb0: created r8g8b8 node(I added that mode)

barebox@BOARD:/ of_dump -f dump.dtb /framebuffer
framebuffer {
display = <0x5a>;
compatible = "simple-framebuffer";
reg = <0x19ca9000 0x177000>;
width = <0x320>;
height = <0x1e0>;
stride = <0xc80>;
format = "r8g8b8";
status = "okay";
};

# Side-note: Kernel doc says this device-tree node has to in the /chosen 
section..?


The framebuffer is allocated in 'drivers/video/imx-ipu-v3/ipufb.c' 
ipufb_activate_var() with dma_alloc_writecombine().


This failed with my Barebox version, and found that Sascha fixed that 
upstream, so I applied these:

 - ARM: MMU: fix arch_remap_range() across section boundaries
 - ARM: mmu: fix cache flushing when replacing a section with a PTE
 - ARM: MMU: fix wrong dma_flush_range in arm_create_pte()

# So far so good.

When I boot Linux I get the following WARN()

[0.071950] [ cut here ]
[0.071974] WARNING: CPU: 0 PID: 1 at arch/arm/mm/ioremap.c:309 
__arm_ioremap_pfn_caller+0x1ec/0x210

[0.071980] Modules linked in:
[0.071998] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 
4.19.0-20190401-1-00290-gd141d156c111f-dirty #1023
[0.072007] Hardware name: Freescale i.MX6 Quad/DualLite (Device 
Tree)
[0.072036] [<8010ffec>] (unwind_backtrace) from [<8010b8dc>] 
(show_stack+0x10/0x14)
[0.072053] [<8010b8dc>] (show_stack) from [<8091d5fc>] 
(dump_stack+0x88/0x9c)
[0.072074] [<8091d5fc>] (dump_stack) from [<8011e5d8>] 
(__warn+0xd4/0xf0)
[0.072092] [<8011e5d8>] (__warn) from [<8011e634>] 
(warn_slowpath_null+0x40/0x48)
[0.072109] [<8011e634>] (warn_slowpath_null) from [<80115230>] 
(__arm_ioremap_pfn_caller+0x1ec/0x210)
[0.072124] [<80115230>] (__arm_ioremap_pfn_caller) from [<80115298>] 
(__arm_ioremap_caller+0x44/0x54)
[0.072141] [<80115298>] (__arm_ioremap_caller) from [<80407900>] 
(simplefb_probe+0x1fc/0x898)
[0.072162] [<80407900>] (simplefb_probe) from [<804ade34>] 
(platform_drv_probe+0x48/0x98)
[0.072179] [<804ade34>] (platform_drv_probe) from [<804ac23c>] 
(really_probe+0x1f4/0x2b8)
[0.072193] [<804ac23c>] (really_probe) from [<804ac464>] 
(driver_probe_device+0x60/0x164)
[0.072207] [<804ac464>] (driver_probe_device) from [<804ac644>] 
(__driver_attach+0xdc/0xe0)
[0.072224] [<804ac644>] (__driver_attach) from [<804aa540>] 
(bus_for_each_dev+0x74/0xb4)
[0.072242] [<804aa540>] (bus_for_each_dev) from [<804ab6cc>] 
(bus_add_driver+0x1bc/0x200)
[0.072258] [<804ab6cc>] (bus_add_driver) from [<804acf50>] 
(driver_register+0x7c/0x114)
[0.072276] [<804acf50>] (driver_register) from [<80e1b1f8>] 
(simplefb_init+0x14/0x8c)
[0.072293] [<80e1b1f8>] (simplefb_init) from [<80102618>] 
(do_one_initcall+0x7c/0x1a8)
[0.072313] [<80102618>] (do_one_initcall) from [<80e00e40>] 
(kernel_init_freeable+0x148/0x1dc)
[0.072334] [<80e00e40>] (kernel_init_freeable) from [<80930c78>] 
(kernel_init+0x8/0x110)
[0.072349] [<80930c78>] (kernel_init) from [<801010d8>] 
(ret_from_fork+0x14/0x3c)

[0.072358] Exception stack(0x8b84bfb0 to 0x8b84bff8)
[0.072369] bfa0:  
  
[0.072381] bfc0:      
  
[0.072391] bfe0:     0013 


[0.072435] ---[ end trace d197b304a56deeb0 ]---
[0.072463] simple-framebuffer: probe of 19ca9000.framebuffer failed 
with error -12


If I understand correctly, this is due to the use of ioremap_wc on a RAM 
region. I was hoping you could tell me what I'm doing wrong here, or if 
I'm looking at a bug.


My mtype = MT_DEVICE_WC. (Due to the in kernel use of ioremap_wc())
My pfn = 0x19ca9

In my kernel .config i have:
CONFIG_HAVE_ARCH_PFN_VALID=y

Kind regards,

Robin van der Gracht

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox