[PATCH] imd: Make all pointers into image const

2018-01-29 Thread Sascha Hauer
The IMD code should be readonly and never modify any pointers. Make
all pointers const so that const pointers can be passed in to IMD.

Signed-off-by: Sascha Hauer 
---
 common/bbu.c |  4 ++--
 common/imd.c | 27 ++-
 include/bbu.h|  2 +-
 include/image-metadata.h | 21 +++--
 4 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/common/bbu.c b/common/bbu.c
index 3b372263b1..11e44f4a7d 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -159,7 +159,7 @@ static int bbu_check_of_compat(struct bbu_data *data)
struct device_node *root_node;
const char *machine, *str;
int ret;
-   struct imd_header *of_compat;
+   const struct imd_header *of_compat;
 
if (!IS_ENABLED(CONFIG_OFDEVICE) || !IS_ENABLED(CONFIG_IMD))
return 0;
@@ -191,7 +191,7 @@ static int bbu_check_of_compat(struct bbu_data *data)
 
 static int bbu_check_metadata(struct bbu_data *data)
 {
-   struct imd_header *imd;
+   const struct imd_header *imd;
int ret;
char *str;
 
diff --git a/common/imd.c b/common/imd.c
index a8a10fc9bb..05e118e773 100644
--- a/common/imd.c
+++ b/common/imd.c
@@ -35,7 +35,7 @@ int imd_command_setenv(const char *variable_name, const char 
*value)
  * imd_next - return a pointer to the next metadata field.
  * @imdThe current metadata field
  */
-struct imd_header *imd_next(struct imd_header *imd)
+const struct imd_header *imd_next(const struct imd_header *imd)
 {
int length;
 
@@ -43,10 +43,11 @@ struct imd_header *imd_next(struct imd_header *imd)
length = ALIGN(length, 4);
length += 8;
 
-   return (void *)imd + length;
+   return (const void *)imd + length;
 }
 
-struct imd_header *imd_find_type(struct imd_header *imd, uint32_t type)
+const struct imd_header *imd_find_type(const struct imd_header *imd,
+  uint32_t type)
 {
imd_for_each(imd, imd)
if (imd_read_type(imd) == type)
@@ -55,10 +56,10 @@ struct imd_header *imd_find_type(struct imd_header *imd, 
uint32_t type)
return NULL;
 }
 
-static int imd_next_validate(void *buf, int bufsize, int start_ofs)
+static int imd_next_validate(const void *buf, int bufsize, int start_ofs)
 {
int length, size;
-   struct imd_header *imd = buf + start_ofs;
+   const struct imd_header *imd = buf + start_ofs;
 
size = bufsize - start_ofs;
 
@@ -82,10 +83,10 @@ static int imd_next_validate(void *buf, int bufsize, int 
start_ofs)
return length;
 }
 
-static int imd_validate_tags(void *buf, int bufsize, int start_ofs)
+static int imd_validate_tags(const void *buf, int bufsize, int start_ofs)
 {
int ret;
-   struct imd_header *imd = buf + start_ofs;
+   const struct imd_header *imd = buf + start_ofs;
 
while (1) {
uint32_t type;
@@ -122,7 +123,7 @@ static int imd_validate_tags(void *buf, int bufsize, int 
start_ofs)
  *
  * Return: a pointer to the image metadata or a ERR_PTR
  */
-struct imd_header *imd_get(void *buf, int size)
+const struct imd_header *imd_get(const void *buf, int size)
 {
int start_ofs = 0;
int i, ret;
@@ -206,7 +207,7 @@ static uint32_t imd_name_to_type(const char *name)
  *
  * Return: A pointer to the string or NULL if the string is not found
  */
-const char *imd_string_data(struct imd_header *imd, int index)
+const char *imd_string_data(const struct imd_header *imd, int index)
 {
int i, total = 0, l = 0;
int len = imd_read_length(imd);
@@ -233,7 +234,7 @@ const char *imd_string_data(struct imd_header *imd, int 
index)
  *
  * Return: A pointer to the string or NULL if the string is not found
  */
-char *imd_concat_strings(struct imd_header *imd)
+char *imd_concat_strings(const struct imd_header *imd)
 {
int i, len = imd_read_length(imd);
char *str;
@@ -266,9 +267,9 @@ char *imd_concat_strings(struct imd_header *imd)
  *
  * Return: A pointer to the value or NULL if the string is not found
  */
-const char *imd_get_param(struct imd_header *imd, const char *name)
+const char *imd_get_param(const struct imd_header *imd, const char *name)
 {
-   struct imd_header *cur;
+   const struct imd_header *cur;
int namelen = strlen(name);
 
imd_for_each(imd, cur) {
@@ -294,7 +295,7 @@ int imd_command(int argc, char *argv[])
void *buf;
size_t size;
uint32_t type = IMD_TYPE_INVALID;
-   struct imd_header *imd_start, *imd;
+   const struct imd_header *imd_start, *imd;
const char *filename;
const char *variable_name = NULL;
char *str;
diff --git a/include/bbu.h b/include/bbu.h
index 54434b03e0..a3824e11cf 100644
--- a/include/bbu.h
+++ b/include/bbu.h
@@ -16,7 +16,7 @@ struct bbu_data {
const char *devicefile;
size_t len;
const char *handler_name;
-   struct 

Re: [PATCH] ratp: remove unused context fields

2018-01-29 Thread Sascha Hauer
On Mon, Jan 29, 2018 at 05:28:15PM +0100, Aleksander Morgado wrote:
> Signed-off-by: Aleksander Morgado 
> ---
>  common/ratp.c | 6 --
>  1 file changed, 6 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/ratp.c b/common/ratp.c
> index 6db4df870..80863f81f 100644
> --- a/common/ratp.c
> +++ b/common/ratp.c
> @@ -54,14 +54,8 @@ struct ratp_bb_command_return {
>  struct ratp_ctx {
>   struct console_device *cdev;
>   struct ratp ratp;
> - int ratp_status;
>   struct console_device ratp_console;
>   int have_synch;
> - int in_ratp_console;
> -
> - u8 sendbuf[256];
> - u8 sendbuf_len;
> -
>   int old_active;
>  
>   struct kfifo *console_recv_fifo;
> -- 
> 2.15.1
> 
> 

-- 
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 1/3] commands: ubi: ubiupdatevol: Reduce error code to 0 or 1

2018-01-29 Thread Sascha Hauer
On Tue, Jan 30, 2018 at 08:05:09AM +0100, Sascha Hauer wrote:
> On Mon, Jan 29, 2018 at 02:04:09PM +0100, Daniel Schultz wrote:
> > do_ubiupdatevol can either return 0 or the ioctl return value. This is
> > not in conformity with the other ubi comannds return values.
> > 
> > Signed-off-by: Daniel Schultz 
> > ---
> >  commands/ubi.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Applied, thanks

I meant I Applied 1 & 2.

Sascha

> 
> Sascha
> 
> > 
> > diff --git a/commands/ubi.c b/commands/ubi.c
> > index 5e27584..de5633c 100644
> > --- a/commands/ubi.c
> > +++ b/commands/ubi.c
> > @@ -82,7 +82,7 @@ error:
> > close(fd_vol);
> >  error_img:
> > close(fd_img);
> > -   return ret;
> > +   return ret ? 1 : 0;
> >  }
> >  
> >  
> > -- 
> > 2.7.4
> > 
> > 
> > ___
> > barebox mailing list
> > barebox@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/barebox
> > 
> 
> -- 
> 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
> 

-- 
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 3/3] drivers: mtd: nand: omap: Return stat value

2018-01-29 Thread Sascha Hauer
On Mon, Jan 29, 2018 at 02:04:11PM +0100, Daniel Schultz wrote:
> The read page function should return the total count of flipped bits,
> otherwise the caller always thinks no bitflip occured.
> 
> Signed-off-by: Daniel Schultz 
> ---
>  drivers/mtd/nand/nand_omap_gpmc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
> b/drivers/mtd/nand/nand_omap_gpmc.c
> index e18ce63..38f4960 100644
> --- a/drivers/mtd/nand/nand_omap_gpmc.c
> +++ b/drivers/mtd/nand/nand_omap_gpmc.c
> @@ -712,7 +712,7 @@ static int omap_gpmc_read_page_bch_rom_mode(struct 
> mtd_info *mtd,
>   else
>   mtd->ecc_stats.corrected += stat;
>  
> - return 0;
> + return stat;
>  }

I'm afraid this is not enough. read_page should return the maximum
number of bitflips in any ECC step. You first have to change
omap_correct_bch() so that it returns this number.

Sascha


-- 
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 1/3] commands: ubi: ubiupdatevol: Reduce error code to 0 or 1

2018-01-29 Thread Sascha Hauer
On Mon, Jan 29, 2018 at 02:04:09PM +0100, Daniel Schultz wrote:
> do_ubiupdatevol can either return 0 or the ioctl return value. This is
> not in conformity with the other ubi comannds return values.
> 
> Signed-off-by: Daniel Schultz 
> ---
>  commands/ubi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks

Sascha

> 
> diff --git a/commands/ubi.c b/commands/ubi.c
> index 5e27584..de5633c 100644
> --- a/commands/ubi.c
> +++ b/commands/ubi.c
> @@ -82,7 +82,7 @@ error:
>   close(fd_vol);
>  error_img:
>   close(fd_img);
> - return ret;
> + return ret ? 1 : 0;
>  }
>  
>  
> -- 
> 2.7.4
> 
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
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] ratp: remove unused list pointer from ratp_bb_pkt

2018-01-29 Thread Sascha Hauer
On Sun, Jan 28, 2018 at 10:30:48PM +0100, Aleksander Morgado wrote:
> This struct type is used in the RATP FS implementation, but was never
> used as a list element anywhere.
> 
> Signed-off-by: Aleksander Morgado 
> ---
>  include/ratp_bb.h | 2 --
>  1 file changed, 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/include/ratp_bb.h b/include/ratp_bb.h
> index 70fd58a67..f485f7d8a 100644
> --- a/include/ratp_bb.h
> +++ b/include/ratp_bb.h
> @@ -2,8 +2,6 @@
>  #define __RATP_BB_H
>  
>  struct ratp_bb_pkt {
> - struct list_head list;
> -
>   unsigned int len;
>   uint8_t data[];
>  };
> -- 
> 2.15.1
> 
> 

-- 
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] ratp: move barebox-specific command to ratp_bb.h

2018-01-29 Thread Sascha Hauer
On Sun, Jan 28, 2018 at 10:30:23PM +0100, Aleksander Morgado wrote:
> The ratp_run_command() is really an implementation detail of the
> barebox ratp 'command' operation support. Move it to the barebox
> specific header and rename it with the correct prefix.
> 
> Signed-off-by: Aleksander Morgado 
> ---
>  common/ratp.c | 2 +-
>  include/ratp.h| 2 --
>  include/ratp_bb.h | 7 ---
>  lib/readline.c| 4 ++--
>  4 files changed, 7 insertions(+), 8 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/ratp.c b/common/ratp.c
> index c5eae2e2c..6db4df870 100644
> --- a/common/ratp.c
> +++ b/common/ratp.c
> @@ -323,7 +323,7 @@ static int ratp_console_register(struct ratp_ctx *ctx)
>   return 0;
>  }
>  
> -void ratp_run_command(void)
> +void barebox_ratp_command_run(void)
>  {
>   int ret;
>  
> diff --git a/include/ratp.h b/include/ratp.h
> index 94fd004f4..6f4cf8a6f 100644
> --- a/include/ratp.h
> +++ b/include/ratp.h
> @@ -17,6 +17,4 @@ int ratp_poll(struct ratp *ratp);
>  bool ratp_closed(struct ratp *ratp);
>  bool ratp_busy(struct ratp *ratp);
>  
> -void ratp_run_command(void);
> -
>  #endif /* __RATP_H */
> \ No newline at end of file
> diff --git a/include/ratp_bb.h b/include/ratp_bb.h
> index 52ecaff37..70fd58a67 100644
> --- a/include/ratp_bb.h
> +++ b/include/ratp_bb.h
> @@ -8,8 +8,9 @@ struct ratp_bb_pkt {
>   uint8_t data[];
>  };
>  
> -int barebox_ratp(struct console_device *cdev);
> -int barebox_ratp_fs_call(struct ratp_bb_pkt *tx, struct ratp_bb_pkt **rx);
> -int barebox_ratp_fs_mount(const char *path);
> +int  barebox_ratp(struct console_device *cdev);
> +void barebox_ratp_command_run(void);
> +int  barebox_ratp_fs_call(struct ratp_bb_pkt *tx, struct ratp_bb_pkt **rx);
> +int  barebox_ratp_fs_mount(const char *path);
>  
>  #endif /* __RATP_BB_H */
> diff --git a/lib/readline.c b/lib/readline.c
> index b5d99ca18..1e380abec 100644
> --- a/lib/readline.c
> +++ b/lib/readline.c
> @@ -3,7 +3,7 @@
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -203,7 +203,7 @@ int readline(const char *prompt, char *buf, int len)
>   while (!tstc()) {
>   poller_call();
>   if (IS_ENABLED(CONFIG_RATP))
> - ratp_run_command();
> + barebox_ratp_command_run();
>   }
>  
>   ichar = read_key();
> -- 
> 2.15.1
> 
> 

-- 
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] ratp: rename global context variable

2018-01-29 Thread Sascha Hauer
On Sun, Jan 28, 2018 at 10:29:59PM +0100, Aleksander Morgado wrote:
> The 'ratp_command_ctx' seems to specify that this variable is only
> used to process command operations, but it really is used in every
> async operation (e.g. also in FS), so just rename it to a more generic
> name for clarity.
> 
> Signed-off-by: Aleksander Morgado 
> ---
>  common/ratp.c | 18 +-
>  1 file changed, 9 insertions(+), 9 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/ratp.c b/common/ratp.c
> index 7be86d49a..c5eae2e2c 100644
> --- a/common/ratp.c
> +++ b/common/ratp.c
> @@ -204,7 +204,7 @@ static int ratp_bb_send_getenv_return(struct ratp_ctx 
> *ctx, const char *val)
>  }
>  
>  static char *ratp_command;
> -static struct ratp_ctx *ratp_command_ctx;
> +static struct ratp_ctx *ratp_ctx;
>  
>  static int ratp_bb_dispatch(struct ratp_ctx *ctx, const void *buf, int len)
>  {
> @@ -220,7 +220,7 @@ static int ratp_bb_dispatch(struct ratp_ctx *ctx, const 
> void *buf, int len)
>   return 0;
>  
>   ratp_command = xmemdup_add_zero(>data, dlen);
> - ratp_command_ctx = ctx;
> + ratp_ctx = ctx;
>   pr_debug("got command: %s\n", ratp_command);
>  
>   break;
> @@ -337,7 +337,7 @@ void ratp_run_command(void)
>   free(ratp_command);
>   ratp_command = NULL;
>  
> - ratp_bb_send_command_return(ratp_command_ctx, ret);
> + ratp_bb_send_command_return(ratp_ctx, ret);
>  }
>  
>  static const char *ratpfs_mount_path;
> @@ -400,7 +400,7 @@ out:
>  
>  int barebox_ratp_fs_call(struct ratp_bb_pkt *tx, struct ratp_bb_pkt **rx)
>  {
> - struct ratp_ctx *ctx = ratp_command_ctx;
> + struct ratp_ctx *ctx = ratp_ctx;
>   struct ratp_bb *rbb;
>   int len;
>   u64 start;
> @@ -446,11 +446,11 @@ int barebox_ratp(struct console_device *cdev)
>   if (!cdev->getc || !cdev->putc)
>   return -EINVAL;
>  
> - if (ratp_command_ctx) {
> - ctx = ratp_command_ctx;
> + if (ratp_ctx) {
> + ctx = ratp_ctx;
>   } else {
>   ctx = xzalloc(sizeof(*ctx));
> - ratp_command_ctx = ctx;
> + ratp_ctx = ctx;
>   ctx->ratp.send = console_send;
>   ctx->ratp.recv = console_recv;
>   ctx->console_recv_fifo = kfifo_alloc(512);
> @@ -494,7 +494,7 @@ out:
>  
>  static void barebox_ratp_close(void)
>  {
> - if (ratp_command_ctx && ratp_command_ctx->cdev)
> - ratp_console_unregister(ratp_command_ctx);
> + if (ratp_ctx && ratp_ctx->cdev)
> + ratp_console_unregister(ratp_ctx);
>  }
>  predevshutdown_exitcall(barebox_ratp_close);
> -- 
> 2.15.1
> 
> 

-- 
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] bbremote: rename command subparser variables

2018-01-29 Thread Sascha Hauer
On Sun, Jan 28, 2018 at 11:33:26AM +0100, Aleksander Morgado wrote:
> Don't reuse unrelated subparser variables for new command subparsers,
> make each subparser have its own variable.
> 
> Just for consistency really, not a bugfix.
> 
> Signed-off-by: Aleksander Morgado 
> ---
>  scripts/remote/main.py | 14 +++---
>  1 file changed, 7 insertions(+), 7 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/scripts/remote/main.py b/scripts/remote/main.py
> index bd304723b..79203df05 100644
> --- a/scripts/remote/main.py
> +++ b/scripts/remote/main.py
> @@ -139,15 +139,15 @@ parser_run.set_defaults(func=handle_run)
>  parser_ping = subparsers.add_parser('ping', help="test connection")
>  parser_ping.set_defaults(func=handle_ping)
>  
> -parser_ping = subparsers.add_parser('getenv', help="get a barebox 
> environment variable")
> -parser_ping.add_argument('arg', nargs='+', help="variable name")
> -parser_ping.set_defaults(func=handle_getenv)
> +parser_getenv = subparsers.add_parser('getenv', help="get a barebox 
> environment variable")
> +parser_getenv.add_argument('arg', nargs='+', help="variable name")
> +parser_getenv.set_defaults(func=handle_getenv)
>  
> -parser_run = subparsers.add_parser('listen', help="listen for an incoming 
> connection")
> -parser_run.set_defaults(func=handle_listen)
> +parser_listen = subparsers.add_parser('listen', help="listen for an incoming 
> connection")
> +parser_listen.set_defaults(func=handle_listen)
>  
> -parser_run = subparsers.add_parser('console', help="connect to the console")
> -parser_run.set_defaults(func=handle_console)
> +parser_console = subparsers.add_parser('console', help="connect to the 
> console")
> +parser_console.set_defaults(func=handle_console)
>  
>  args = parser.parse_args()
>  logging.basicConfig(level=VERBOSITY[args.verbose],
> -- 
> 2.15.1
> 
> 

-- 
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 v3 1/5] net/e1000: remove one level of indentation

2018-01-29 Thread Sascha Hauer
On Fri, Jan 26, 2018 at 02:32:28PM +0100, Lucas Stach wrote:
> By returning early if the MAC type isn't e1000_igb.
> 
> Signed-off-by: Lucas Stach 
> ---
>  drivers/net/e1000/eeprom.c | 121 
> +++--
>  1 file changed, 61 insertions(+), 60 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/net/e1000/eeprom.c b/drivers/net/e1000/eeprom.c
> index 748d8afe7922..ddac7de8a0e9 100644
> --- a/drivers/net/e1000/eeprom.c
> +++ b/drivers/net/e1000/eeprom.c
> @@ -1551,79 +1551,80 @@ int e1000_eeprom_valid(struct e1000_hw *hw)
>   */
>  int e1000_register_eeprom(struct e1000_hw *hw)
>  {
> - int ret = E1000_SUCCESS;
> -
>   struct e1000_eeprom_info *eeprom = >eeprom;
> + uint32_t eecd;
> + int ret;
>  
> - if (hw->mac_type == e1000_igb) {
> - uint32_t eecd = e1000_read_reg(hw, E1000_EECD);
> + if (hw->mac_type != e1000_igb)
> + return E1000_SUCCESS;
>  
> - hw->eepromcdev.dev = hw->dev;
> - hw->eepromcdev.ops = _eeprom_ops;
> - hw->eepromcdev.name = xasprintf("e1000-eeprom%d", hw->dev->id);
> - hw->eepromcdev.size = 0x1000;
> + eecd = e1000_read_reg(hw, E1000_EECD);
>  
> - ret = devfs_create(>eepromcdev);
> - if (ret < 0)
> - return ret;
> + hw->eepromcdev.dev = hw->dev;
> + hw->eepromcdev.ops = _eeprom_ops;
> + hw->eepromcdev.name = xasprintf("e1000-eeprom%d", hw->dev->id);
> + hw->eepromcdev.size = 0x1000;
> +
> + ret = devfs_create(>eepromcdev);
> + if (ret < 0)
> + return ret;
>  
> - if (eecd & E1000_EECD_AUTO_RD) {
> - if (eecd & E1000_EECD_EE_PRES) {
> - if (eecd & E1000_EECD_FLASH_IN_USE) {
> - uint32_t fla = e1000_read_reg(hw, 
> E1000_FLA);
> - dev_info(hw->dev,
> -  "Hardware programmed from 
> flash (%ssecure)\n",
> -  fla & E1000_FLA_LOCKED ? "" : 
> "un");
> - } else {
> - dev_info(hw->dev, "Hardware programmed 
> from iNVM\n");
> - }
> + if (eecd & E1000_EECD_AUTO_RD) {
> + if (eecd & E1000_EECD_EE_PRES) {
> + if (eecd & E1000_EECD_FLASH_IN_USE) {
> + uint32_t fla = e1000_read_reg(hw, E1000_FLA);
> + dev_info(hw->dev,
> +  "Hardware programmed from flash 
> (%ssecure)\n",
> +  fla & E1000_FLA_LOCKED ? "" : "un");
>   } else {
> - dev_warn(hw->dev, "Shadow RAM invalid\n");
> + dev_info(hw->dev, "Hardware programmed from 
> iNVM\n");
>   }
>   } else {
> - /*
> -  * I never saw this case in practise and I'm unsure how
> -  * to handle that. Maybe just wait until the hardware is
> -  * up enough that this bit is set?
> -  */
> - dev_err(hw->dev, "Flash Auto-Read not done\n");
> - }
> -
> - if (eecd & E1000_EECD_I210_FLASH_DETECTED) {
> - hw->mtd.parent = hw->dev;
> - hw->mtd.read = e1000_mtd_read;
> - hw->mtd.write = e1000_mtd_write;
> - hw->mtd.erase = e1000_mtd_erase;
> - hw->mtd.lock = e1000_mtd_lock;
> - hw->mtd.unlock = e1000_mtd_unlock;
> - hw->mtd.size = eeprom->word_size * 2;
> - hw->mtd.writesize = 1;
> - hw->mtd.subpage_sft = 0;
> -
> - hw->mtd.eraseregions = xzalloc(sizeof(struct 
> mtd_erase_region_info));
> - hw->mtd.erasesize = SZ_4K;
> - hw->mtd.eraseregions[0].erasesize = SZ_4K;
> - hw->mtd.eraseregions[0].numblocks = hw->mtd.size / 
> SZ_4K;
> - hw->mtd.numeraseregions = 1;
> -
> - hw->mtd.flags = MTD_CAP_NORFLASH;
> - hw->mtd.type = MTD_NORFLASH;
> -
> - ret = add_mtd_device(>mtd, "e1000-nor",
> -  DEVICE_ID_DYNAMIC);
> - if (ret) {
> - devfs_remove(>eepromcdev);
> - return ret;
> - }
> + dev_warn(hw->dev, "Shadow RAM invalid\n");
>   }
> + } else {
> + /*
> +  * I never saw this case in practise and I'm unsure how
> +  * to handle that. Maybe just wait until the hardware is
> +  

Re: [PATCH] fs: Fix memory leak in mount()

2018-01-29 Thread Sam Ravnborg
Hi Sasha.

...
> > No check for PTR_ERR after calling canonalize_path()
> > 
> > unlink()
> > No check for PTR_ERR after call to canonalize_dir()
> > 
> > readlink()
> > No check for PTR_ERR after call to canonalize_dir()
> 
> Yes, the result should be checked.
> 
> > 
> > I can create patch for these - but I cannot do any thrustworthy testing.
> > And for the canonalize() I am uncertain if the check is requied.
> > Let me know your preference and I will take care.
> 
> Patches would be very welcomed. Thanks Sam.

Thanks for the confirmation. Will get back to this in a few weeks.
Heading for vacation in a few days, so not time right now.

Sam

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


[PATCH 07/10] ARM: install HYP vectors at PBL and Barebox entry

2018-01-29 Thread Lucas Stach
If the CPU was already in HYP mode when entering the PBL, install a
simple trap handler to allow to get back from SVC to HYP before
switching to HYP mode.

As the vectors are part of the currently running binary, we need to
do the same setup when starting the real Barebox binary, as the PBL
setup vectors might get overwritten. To do this we trap into HYP mode
just before jumping to Barebox and then re-do the vector setup and
SVC switch as the first thing in Barebox proper.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/lowlevel.S   | 3 +++
 arch/arm/cpu/start-pbl.c  | 3 +++
 arch/arm/cpu/start.c  | 3 +++
 arch/arm/cpu/uncompress.c | 4 
 4 files changed, 13 insertions(+)

diff --git a/arch/arm/cpu/lowlevel.S b/arch/arm/cpu/lowlevel.S
index 194ce0e7c274..28ad8508726f 100644
--- a/arch/arm/cpu/lowlevel.S
+++ b/arch/arm/cpu/lowlevel.S
@@ -8,6 +8,9 @@ ENTRY(arm_cpu_lowlevel_init)
/* save lr, since it may be banked away with a processor mode change */
mov r2, lr
 
+   /* careful: the hyp install corrupts r0 and r1 */
+   bl  __hyp_install
+
/* set the cpu to SVC32 mode, mask irq and fiq */
mrs r12 , cpsr
eor r12, r12, #HYP_MODE
diff --git a/arch/arm/cpu/start-pbl.c b/arch/arm/cpu/start-pbl.c
index e851b4a2da5e..cea1cb200b6f 100644
--- a/arch/arm/cpu/start-pbl.c
+++ b/arch/arm/cpu/start-pbl.c
@@ -100,5 +100,8 @@ __noreturn void barebox_single_pbl_start(unsigned long 
membase,
else
barebox = (void *)barebox_base;
 
+   if (__boot_cpu_mode == HYP_MODE)
+   armv7_switch_to_hyp();
+
barebox(membase, memsize, boarddata);
 }
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 171e6ad0eb7a..a0db6436f387 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -145,6 +146,8 @@ __noreturn void barebox_non_pbl_start(unsigned long membase,
unsigned long malloc_start, malloc_end;
unsigned long barebox_size = barebox_image_size + MAX_BSS_SIZE;
 
+   armv7_hyp_install();
+
if (IS_ENABLED(CONFIG_RELOCATABLE)) {
unsigned long barebox_base = arm_mem_barebox_image(membase,
   endmem,
diff --git a/arch/arm/cpu/uncompress.c b/arch/arm/cpu/uncompress.c
index 9d7fe0e921a9..28636aa8101f 100644
--- a/arch/arm/cpu/uncompress.c
+++ b/arch/arm/cpu/uncompress.c
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -109,5 +110,8 @@ void __noreturn barebox_multi_pbl_start(unsigned long 
membase,
 
pr_debug("jumping to uncompressed image at 0x%p\n", barebox);
 
+   if (__boot_cpu_mode == HYP_MODE)
+   armv7_switch_to_hyp();
+
barebox(membase, memsize, boarddata);
 }
-- 
2.15.1


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


[PATCH 05/10] ARM: don't try to install secure monitor when entered in HYP mode

2018-01-29 Thread Lucas Stach
When Barebox has been entered in HYP mode, the CPU is already switched
to the non-secure world and it's not possible for Barebox to install
it's own secure monitor.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/sm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/cpu/sm.c b/arch/arm/cpu/sm.c
index 5808dfd92bdc..71bb394c8540 100644
--- a/arch/arm/cpu/sm.c
+++ b/arch/arm/cpu/sm.c
@@ -184,6 +184,9 @@ int armv7_secure_monitor_install(void)
return -EINVAL;
}
 
+   if (__boot_cpu_mode == HYP_MODE)
+   return 0;
+
mmuon = get_cr() & CR_M;
 
vbar = get_vbar();
-- 
2.15.1


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


[PATCH 08/10] ARM: rpi: add revision IDs for Pi 3 Model B and Pi Zero

2018-01-29 Thread Lucas Stach
From: Enrico Joerns 

Signed-off-by: Enrico Joerns 
---
 arch/arm/boards/raspberry-pi/rpi-common.c | 2 ++
 arch/arm/mach-bcm283x/include/mach/mbox.h | 4 
 2 files changed, 6 insertions(+)

diff --git a/arch/arm/boards/raspberry-pi/rpi-common.c 
b/arch/arm/boards/raspberry-pi/rpi-common.c
index 6e375bc984de..aec8cb27ed40 100644
--- a/arch/arm/boards/raspberry-pi/rpi-common.c
+++ b/arch/arm/boards/raspberry-pi/rpi-common.c
@@ -174,6 +174,8 @@ const struct rpi_model rpi_models_old_scheme[] = {
 const struct rpi_model rpi_models_new_scheme[] = {
RPI_MODEL(0, "Unknown model", NULL),
RPI_MODEL(BCM2836_BOARD_REV_2_B, "2 Model B", rpi_b_plus_init),
+   RPI_MODEL(BCM2837_BOARD_REV_3_B, "3 Model B", rpi_b_plus_init),
+   RPI_MODEL(BCM2837_BOARD_REV_ZERO, "Zero", rpi_b_plus_init),
 };
 
 static int rpi_board_rev = 0;
diff --git a/arch/arm/mach-bcm283x/include/mach/mbox.h 
b/arch/arm/mach-bcm283x/include/mach/mbox.h
index 2b5aea88ee0a..4cddf99a8429 100644
--- a/arch/arm/mach-bcm283x/include/mach/mbox.h
+++ b/arch/arm/mach-bcm283x/include/mach/mbox.h
@@ -129,6 +129,10 @@ struct bcm2835_mbox_tag_hdr {
 
 /* RPi 2 */
 #define BCM2836_BOARD_REV_2_B  0x4
+/* RPi 3 */
+#define BCM2837_BOARD_REV_3_B  0x8
+/* Zero */
+#define BCM2837_BOARD_REV_ZERO 0x9
 
 /*
  * 0x2..0xf from:
-- 
2.15.1


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


[PATCH 01/10] ARM: import opcode helpers from Linux kernel

2018-01-29 Thread Lucas Stach
Those are needed to generate some of the ARM SEC and VIRT
opcodes in a portable way.

Signed-off-by: Lucas Stach 
---
 arch/arm/include/asm/opcodes-virt.h |  39 ++
 arch/arm/include/asm/opcodes.h  | 231 
 2 files changed, 270 insertions(+)
 create mode 100644 arch/arm/include/asm/opcodes-virt.h
 create mode 100644 arch/arm/include/asm/opcodes.h

diff --git a/arch/arm/include/asm/opcodes-virt.h 
b/arch/arm/include/asm/opcodes-virt.h
new file mode 100644
index ..efcfdf92d9d5
--- /dev/null
+++ b/arch/arm/include/asm/opcodes-virt.h
@@ -0,0 +1,39 @@
+/*
+ * opcodes-virt.h: Opcode definitions for the ARM virtualization extensions
+ * Copyright (C) 2012  Linaro Limited
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifndef __ASM_ARM_OPCODES_VIRT_H
+#define __ASM_ARM_OPCODES_VIRT_H
+
+#include 
+
+#define __HVC(imm16) __inst_arm_thumb32(   \
+   0xE1400070 | (((imm16) & 0xFFF0) << 4) | ((imm16) & 0x000F),\
+   0xF7E08000 | (((imm16) & 0xF000) << 4) | ((imm16) & 0x0FFF) \
+)
+
+#define __ERET __inst_arm_thumb32( \
+   0xE160006E, \
+   0xF3DE8F00  \
+)
+
+#define __MSR_ELR_HYP(regnum)  __inst_arm_thumb32( \
+   0xE12EF300 | regnum,\
+   0xF3808E30 | (regnum << 16) \
+)
+
+#endif /* ! __ASM_ARM_OPCODES_VIRT_H */
diff --git a/arch/arm/include/asm/opcodes.h b/arch/arm/include/asm/opcodes.h
new file mode 100644
index ..a78bf5d2c518
--- /dev/null
+++ b/arch/arm/include/asm/opcodes.h
@@ -0,0 +1,231 @@
+/*
+ *  arch/arm/include/asm/opcodes.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_ARM_OPCODES_H
+#define __ASM_ARM_OPCODES_H
+
+#ifndef __ASSEMBLY__
+#include 
+extern asmlinkage unsigned int arm_check_condition(u32 opcode, u32 psr);
+#endif
+
+#define ARM_OPCODE_CONDTEST_FAIL   0
+#define ARM_OPCODE_CONDTEST_PASS   1
+#define ARM_OPCODE_CONDTEST_UNCOND 2
+
+
+/*
+ * Assembler opcode byteswap helpers.
+ * These are only intended for use by this header: don't use them directly,
+ * because they will be suboptimal in most cases.
+ */
+#define ___asm_opcode_swab32(x) (  \
+ (((x) << 24) & 0xFF00)\
+   | (((x) <<  8) & 0x00FF)\
+   | (((x) >>  8) & 0xFF00)\
+   | (((x) >> 24) & 0x00FF)\
+)
+#define ___asm_opcode_swab16(x) (  \
+ (((x) << 8) & 0xFF00) \
+   | (((x) >> 8) & 0x00FF) \
+)
+#define ___asm_opcode_swahb32(x) ( \
+ (((x) << 8) & 0xFF00FF00) \
+   | (((x) >> 8) & 0x00FF00FF) \
+)
+#define ___asm_opcode_swahw32(x) ( \
+ (((x) << 16) & 0x)\
+   | (((x) >> 16) & 0x)\
+)
+#define ___asm_opcode_identity32(x) ((x) & 0x)
+#define ___asm_opcode_identity16(x) ((x) & 0x)
+
+
+/*
+ * Opcode byteswap helpers
+ *
+ * These macros help with converting instructions between a canonical integer
+ * format and in-memory representation, in an endianness-agnostic manner.
+ *
+ * __mem_to_opcode_*() convert from in-memory representation to canonical form.
+ * __opcode_to_mem_*() convert from canonical form to in-memory representation.
+ *
+ *
+ * Canonical instruction representation:
+ *
+ * ARM:0xKKLLMMNN
+ * Thumb 16-bit:   0xKKLL, where KK < 0xE8
+ * Thumb 32-bit:   0xKKLLMMNN, where KK >= 0xE8
+ *
+ * There is no way to distinguish an ARM instruction in canonical 
representation
+ * from a Thumb instruction (just as these cannot be distinguished in memory).
+ * Where this distinction is important, it needs to be tracked separately.
+ *
+ * Note that values in the range 0xE800..0xE7FF intentionally do not
+ * represent any valid Thumb-2 instruction.  For this range,
+ * __opcode_is_thumb32() and __opcode_is_thumb16() will both be false.
+ *
+ * The ___asm variants are intended only for use by this header, 

[PATCH 06/10] ARM: default to starting kernel in HYP mode when entered in HYP

2018-01-29 Thread Lucas Stach
When Barebox has been entered in HYP mode, there is a high chance that
the kernel is  intended to be started in HYP mode also. Get this
default into place.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/sm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/arm/cpu/sm.c b/arch/arm/cpu/sm.c
index 71bb394c8540..3369fbb5ff1a 100644
--- a/arch/arm/cpu/sm.c
+++ b/arch/arm/cpu/sm.c
@@ -264,6 +264,9 @@ static int sm_init(void)
  bootm_secure_state_names,
  ARRAY_SIZE(bootm_secure_state_names));
 
+   if (__boot_cpu_mode == HYP_MODE)
+   bootm_secure_state = ARM_STATE_HYP;
+
return 0;
 }
 device_initcall(sm_init);
\ No newline at end of file
-- 
2.15.1


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


[PATCH 02/10] ARM: safely switch from HYP to SVC mode if required

2018-01-29 Thread Lucas Stach
This is a port of the Linux safe_svcmode_maskall macro to
the Barebox lowlevel init.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/lowlevel.S   | 20 
 arch/arm/include/asm/system.h | 26 ++
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/lowlevel.S b/arch/arm/cpu/lowlevel.S
index 7696a198e764..194ce0e7c274 100644
--- a/arch/arm/cpu/lowlevel.S
+++ b/arch/arm/cpu/lowlevel.S
@@ -1,16 +1,28 @@
 #include 
 #include 
 #include 
+#include 
 
 .section ".text_bare_init_","ax"
 ENTRY(arm_cpu_lowlevel_init)
/* save lr, since it may be banked away with a processor mode change */
mov r2, lr
+
/* set the cpu to SVC32 mode, mask irq and fiq */
-   mrs r12, cpsr
-   bic r12, r12, #0x1f
-   orr r12, r12, #0xd3
-   msr cpsr, r12
+   mrs r12 , cpsr
+   eor r12, r12, #HYP_MODE
+   tst r12, #MODE_MASK
+   bic r12 , r12 , #MODE_MASK
+   orr r12 , r12 , #(PSR_I_BIT | PSR_F_BIT | SVC_MODE)
+THUMB( orr r12 , r12 , #PSR_T_BIT  )
+   bne 1f
+   orr r12, r12, #PSR_A_BIT
+   adr lr, 2f
+   msr spsr_cxsf, r12
+   __MSR_ELR_HYP(14)
+   __ERET
+1: msr cpsr_c, r12
+2:
 
 #if __LINUX_ARM_ARCH__ >= 6
/*
diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
index 57c76186b499..55e0f4090295 100644
--- a/arch/arm/include/asm/system.h
+++ b/arch/arm/include/asm/system.h
@@ -60,6 +60,32 @@
 #define CR_AFE  (1 << 29)  /* Access flag enable   */
 #define CR_TE   (1 << 30)  /* Thumb exception enable   */
 
+/*
+ * PSR bits
+ */
+#define USR_MODE   0x0010
+#define FIQ_MODE   0x0011
+#define IRQ_MODE   0x0012
+#define SVC_MODE   0x0013
+#define ABT_MODE   0x0017
+#define HYP_MODE   0x001a
+#define UND_MODE   0x001b
+#define SYSTEM_MODE0x001f
+#define MODE32_BIT 0x0010
+#define MODE_MASK  0x001f
+
+#define PSR_T_BIT  0x0020
+#define PSR_F_BIT  0x0040
+#define PSR_I_BIT  0x0080
+#define PSR_A_BIT  0x0100
+#define PSR_E_BIT  0x0200
+#define PSR_J_BIT  0x0100
+#define PSR_Q_BIT  0x0800
+#define PSR_V_BIT  0x1000
+#define PSR_C_BIT  0x2000
+#define PSR_Z_BIT  0x4000
+#define PSR_N_BIT  0x8000
+
 #ifndef __ASSEMBLY__
 #if __LINUX_ARM_ARCH__ >= 7
 static inline unsigned int current_el(void)
-- 
2.15.1


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


[PATCH 04/10] ARM: add file for HYP mode related setup

2018-01-29 Thread Lucas Stach
This adds routines to add hyp mode vectors and switch back to HYP
mode from SVC. This is needed in both the PBL and Barebox proper.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/Makefile |   4 ++
 arch/arm/cpu/hyp.S| 115 ++
 arch/arm/cpu/sm_as.S  |  11 
 arch/arm/include/asm/secure.h |   2 +
 4 files changed, 121 insertions(+), 11 deletions(-)
 create mode 100644 arch/arm/cpu/hyp.S

diff --git a/arch/arm/cpu/Makefile b/arch/arm/cpu/Makefile
index 13fe12c31f6f..537fe5b9bb8d 100644
--- a/arch/arm/cpu/Makefile
+++ b/arch/arm/cpu/Makefile
@@ -9,6 +9,10 @@ obj-$(CONFIG_ARM_EXCEPTIONS) += exceptions.o
 obj-$(CONFIG_MMU) += mmu.o mmu-early.o
 pbl-$(CONFIG_MMU) += mmu-early.o
 lwl-y += lowlevel.o
+obj-y += hyp.o
+AFLAGS_hyp.o :=-Wa,-march=armv7-a
+pbl-y += hyp.o
+AFLAGS_pbl-hyp.o :=-Wa,-march=armv7-a
 endif
 
 obj-$(CONFIG_ARM_EXCEPTIONS) += interrupts.o
diff --git a/arch/arm/cpu/hyp.S b/arch/arm/cpu/hyp.S
new file mode 100644
index ..435d416f980a
--- /dev/null
+++ b/arch/arm/cpu/hyp.S
@@ -0,0 +1,115 @@
+#include 
+#include 
+#include 
+
+.arch_extension sec
+.arch_extension virt
+
+.section ".text_bare_init_","ax"
+
+.data
+   .align  2
+ENTRY(__boot_cpu_mode)
+   .long   0
+.text
+
+ENTRY(__hyp_install)
+   mrs r12, cpsr
+   and r12, r12, #MODE_MASK
+
+   @ Save the initial CPU state
+   adr r0, .L__boot_cpu_mode_offset
+   ldr r1, [r0]
+   str r12, [r0, r1]
+
+   cmp r12, #HYP_MODE
+   movne   pc, lr  @ give up if the CPU is not in HYP mode
+
+   @ Now install the hypervisor stub:
+   adr r12, __hyp_vectors
+   mcr p15, 4, r12, c12, c0, 0 @ set hypervisor vector base (HVBAR)
+
+   @ Disable all traps, so we don't get any nasty surprise
+   mov r12, #0
+   mcr p15, 4, r12, c1, c1, 0  @ HCR
+   mcr p15, 4, r12, c1, c1, 2  @ HCPTR
+   mcr p15, 4, r12, c1, c1, 3  @ HSTR
+
+THUMB( orr r12, #(1 << 30) )   @ HSCTLR.TE
+   mcr p15, 4, r12, c1, c0, 0  @ HSCTLR
+
+   mrc p15, 4, r12, c1, c1, 1  @ HDCR
+   and r12, #0x1f  @ Preserve HPMN
+   mcr p15, 4, r12, c1, c1, 1  @ HDCR
+
+   @ Make sure NS-SVC is initialised appropriately
+   mrc p15, 0, r12, c1, c0, 0  @ SCTLR
+   orr r12, #(1 << 5)  @ CP15 barriers enabled
+   bic r12, #(3 << 7)  @ Clear SED/ITD for v8 (RES0 for v7)
+   bic r12, #(3 << 19) @ WXN and UWXN disabled
+   mcr p15, 0, r12, c1, c0, 0  @ SCTLR
+
+   mrc p15, 0, r12, c0, c0, 0  @ MIDR
+   mcr p15, 4, r12, c0, c0, 0  @ VPIDR
+
+   mrc p15, 0, r12, c0, c0, 5  @ MPIDR
+   mcr p15, 4, r12, c0, c0, 5  @ VMPIDR
+   bx  lr
+ENDPROC(__hyp_install)
+
+ENTRY(armv7_hyp_install)
+   mov r2, lr
+
+   bl  __hyp_install
+
+   /* set the cpu to SVC32 mode, mask irq and fiq */
+   mrs r12 , cpsr
+   eor r12, r12, #HYP_MODE
+   tst r12, #MODE_MASK
+   bic r12 , r12 , #MODE_MASK
+   orr r12 , r12 , #(PSR_I_BIT | PSR_F_BIT | SVC_MODE)
+THUMB( orr r12 , r12 , #PSR_T_BIT  )
+   bne 1f
+   orr r12, r12, #PSR_A_BIT
+   adr lr, 2f
+   msr spsr_cxsf, r12
+   __MSR_ELR_HYP(14)
+   __ERET
+1: msr cpsr_c, r12
+2:
+   mov pc, r2
+ENDPROC(armv7_hyp_install)
+
+ENTRY(armv7_switch_to_hyp)
+   mov r0, lr
+   mov r1, sp  @ save SVC copy of LR and SP
+   isb
+   hvc #0  @ for older asm: .byte 0x70, 0x00, 0x40, 0xe1
+   mov sp, r1
+   mov lr, r0  @ restore SVC copy of LR and SP
+
+   bx  lr
+ENDPROC(armv7_switch_to_hyp)
+
+.align 2
+.L__boot_cpu_mode_offset:
+   .long   __boot_cpu_mode - .
+
+/* The HYP trap is crafted to match armv7_switch_to_hyp() */
+__hyp_do_trap:
+   mov lr, r0
+   mov sp, r1
+   bx  lr
+ENDPROC(__hyp_do_trap)
+
+.align 5
+__hyp_vectors:
+__hyp_reset:   W(b).
+__hyp_und: W(b).
+__hyp_svc: W(b).
+__hyp_pabort:  W(b).
+__hyp_dabort:  W(b).
+__hyp_trap:W(b)__hyp_do_trap
+__hyp_irq: W(b).
+__hyp_fiq: W(b).
+ENDPROC(__hyp_vectors)
diff --git a/arch/arm/cpu/sm_as.S b/arch/arm/cpu/sm_as.S
index 0d01e1bf2435..de6cd0406f4f 100644
--- a/arch/arm/cpu/sm_as.S
+++ b/arch/arm/cpu/sm_as.S
@@ -148,17 +148,6 @@ hyp_trap:
 mov pc, lr  @ do no switch modes, but
 @ return to caller
 
-ENTRY(armv7_switch_to_hyp)
-   mov r0, lr
-   mov r1, sp  @ save SVC copy of LR and SP
-   isb
-   hvc #0  @ for older asm: .byte 0x70, 0x00, 0x40, 0xe1
-   mov sp, r1
-   mov lr, r0  @ restore SVC copy of LR and SP
-
-   bx  lr

[PATCH 03/10] ARM: allow secure monitor code to be built without PSCI

2018-01-29 Thread Lucas Stach
The hyp mode handling added in the secure monitor code is also useful
when Barebox doesn't have PSCI control. Allow to build without PSCI.

Signed-off-by: Lucas Stach 
---
 arch/arm/cpu/sm_as.S | 4 
 1 file changed, 4 insertions(+)

diff --git a/arch/arm/cpu/sm_as.S b/arch/arm/cpu/sm_as.S
index 09580e75de5f..0d01e1bf2435 100644
--- a/arch/arm/cpu/sm_as.S
+++ b/arch/arm/cpu/sm_as.S
@@ -129,7 +129,9 @@ secure_monitor:
sub sp, sp, #4*4@ allocate result structure on 
stack
mov r12, sp
push{r4-r6, r12}
+#ifdef CONFIG_ARM_PSCI
bl  psci_entry
+#endif
pop {r4-r6, r12}
ldm r12, {r0-r3}
add sp, sp, #4*4
@@ -163,6 +165,8 @@ ENTRY(psci_cpu_entry)
mcr p15, 0, r0, c1, c0, 1   @ ACTLR
 
bl  secure_monitor_stack_setup
+#ifdef CONFIG_ARM_PSCI
bl  psci_cpu_entry_c
+#endif
 
 ENDPROC(psci_cpu_entry)
-- 
2.15.1


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


[PATCH 09/10] ARM: rpi: add raspberry pi 3 support

2018-01-29 Thread Lucas Stach
This adds basic support at the same feature level as the other
supported raspberry pi boards.

Signed-off-by: Lucas Stach 
---
 arch/arm/boards/raspberry-pi/lowlevel.c | 14 --
 arch/arm/configs/rpi_defconfig  |  2 ++
 arch/arm/dts/Makefile   |  1 +
 arch/arm/dts/bcm2837-rpi-3.dts  | 15 +++
 arch/arm/mach-bcm283x/Kconfig   |  6 ++
 arch/arm/mach-bcm283x/core.c|  1 +
 images/Makefile.bcm283x |  4 
 7 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/dts/bcm2837-rpi-3.dts

diff --git a/arch/arm/boards/raspberry-pi/lowlevel.c 
b/arch/arm/boards/raspberry-pi/lowlevel.c
index 4e71e29e0c0b..5ca0d3877069 100644
--- a/arch/arm/boards/raspberry-pi/lowlevel.c
+++ b/arch/arm/boards/raspberry-pi/lowlevel.c
@@ -1,7 +1,7 @@
+#include 
+#include 
 #include 
 #include 
-#include 
-#include 
 #include 
 
 extern char __dtb_bcm2835_rpi_start[];
@@ -23,3 +23,13 @@ ENTRY_FUNCTION(start_raspberry_pi2, r0, r1, r2)
 
barebox_arm_entry(BCM2835_SDRAM_BASE, SZ_512M, fdt);
 }
+
+extern char __dtb_bcm2837_rpi_3_start[];
+ENTRY_FUNCTION(start_raspberry_pi3, r0, r1, r2)
+{
+   void *fdt = __dtb_bcm2837_rpi_3_start - get_runtime_offset();
+
+   arm_cpu_lowlevel_init();
+
+   barebox_arm_entry(BCM2835_SDRAM_BASE, SZ_512M, fdt);
+}
diff --git a/arch/arm/configs/rpi_defconfig b/arch/arm/configs/rpi_defconfig
index 6dc90c59b36d..34070a05abe7 100644
--- a/arch/arm/configs/rpi_defconfig
+++ b/arch/arm/configs/rpi_defconfig
@@ -1,9 +1,11 @@
 CONFIG_ARCH_BCM283X=y
 CONFIG_MACH_RPI=y
 CONFIG_MACH_RPI2=y
+CONFIG_MACH_RPI3=y
 CONFIG_AEABI=y
 CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
+CONFIG_IMAGE_COMPRESSION_NONE=y
 CONFIG_MMU=y
 CONFIG_MALLOC_TLSF=y
 CONFIG_KALLSYMS=y
diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 0526a6f40724..0eab313c5011 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -66,6 +66,7 @@ pbl-dtb-$(CONFIG_MACH_PHYTEC_SOM_RK3288) += 
rk3288-phycore-som.dtb.o
 pbl-dtb-$(CONFIG_MACH_REALQ7) += imx6q-dmo-edmqmx6.dtb.o
 pbl-dtb-$(CONFIG_MACH_RPI) += bcm2835-rpi.dtb.o
 pbl-dtb-$(CONFIG_MACH_RPI2) += bcm2836-rpi-2.dtb.o
+pbl-dtb-$(CONFIG_MACH_RPI3) += bcm2837-rpi-3.dtb.o
 pbl-dtb-$(CONFIG_MACH_SABRELITE) += imx6q-sabrelite.dtb.o 
imx6dl-sabrelite.dtb.o
 pbl-dtb-$(CONFIG_MACH_SABRESD) += imx6q-sabresd.dtb.o
 pbl-dtb-$(CONFIG_MACH_FREESCALE_IMX6SX_SABRESDB) += imx6sx-sdb.dtb.o
diff --git a/arch/arm/dts/bcm2837-rpi-3.dts b/arch/arm/dts/bcm2837-rpi-3.dts
new file mode 100644
index ..f8c58c570137
--- /dev/null
+++ b/arch/arm/dts/bcm2837-rpi-3.dts
@@ -0,0 +1,15 @@
+#include 
+
+/ {
+   chosen {
+   stdout-path = 
+   };
+
+   memory {
+   reg = <0x0 0x0>;
+   };
+};
+
+ {
+   status = "okay";
+};
diff --git a/arch/arm/mach-bcm283x/Kconfig b/arch/arm/mach-bcm283x/Kconfig
index 1457f114ccaa..af2f88c47acb 100644
--- a/arch/arm/mach-bcm283x/Kconfig
+++ b/arch/arm/mach-bcm283x/Kconfig
@@ -19,6 +19,12 @@ config MACH_RPI2
select CPU_V7
select MACH_RPI_COMMON
 
+config MACH_RPI3
+   bool "RaspberryPi 3 (BCM2837/CORTEX-A53)"
+   select CPU_V7
+   select MACH_RPI_COMMON
+   select ARM_SECURE_MONITOR
+
 endmenu
 
 config MACH_RPI_DEBUG_UART_BASE
diff --git a/arch/arm/mach-bcm283x/core.c b/arch/arm/mach-bcm283x/core.c
index fddcb0d1a1d4..26f0996b1cb8 100644
--- a/arch/arm/mach-bcm283x/core.c
+++ b/arch/arm/mach-bcm283x/core.c
@@ -41,6 +41,7 @@ static int bcm2835_clk_init(void)
clk = clk_fixed("uart0-pl0110", 3 * 1000 * 1000);
clk_register_clkdev(clk, NULL, "uart0-pl0110");
clk_register_clkdev(clk, NULL, "20201000.serial");
+   clk_register_clkdev(clk, NULL, "3f201000.serial");
 
clk = clk_fixed("bcm2835-cs", 1 * 1000 * 1000);
clk_register_clkdev(clk, NULL, "bcm2835-cs");
diff --git a/images/Makefile.bcm283x b/images/Makefile.bcm283x
index d59ef043f05c..d14e648926ac 100644
--- a/images/Makefile.bcm283x
+++ b/images/Makefile.bcm283x
@@ -9,3 +9,7 @@ image-$(CONFIG_MACH_RPI) += barebox-raspberry-pi-1.img
 pblx-$(CONFIG_MACH_RPI2) += start_raspberry_pi2
 FILE_barebox-raspberry-pi-2.img = start_raspberry_pi2.pblx
 image-$(CONFIG_MACH_RPI2) += barebox-raspberry-pi-2.img
+
+pblx-$(CONFIG_MACH_RPI3) += start_raspberry_pi3
+FILE_barebox-raspberry-pi-3.img = start_raspberry_pi3.pblx
+image-$(CONFIG_MACH_RPI3) += barebox-raspberry-pi-3.img
\ No newline at end of file
-- 
2.15.1


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


[PATCH 10/10] ARM: rpi: autosize malloc area

2018-01-29 Thread Lucas Stach
Autosize the malloc area according to the available RAM size.

Signed-off-by: Lucas Stach 
---
 arch/arm/configs/rpi_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/configs/rpi_defconfig b/arch/arm/configs/rpi_defconfig
index 34070a05abe7..ddd1a5970f9e 100644
--- a/arch/arm/configs/rpi_defconfig
+++ b/arch/arm/configs/rpi_defconfig
@@ -7,6 +7,7 @@ CONFIG_ARM_OPTIMZED_STRING_FUNCTIONS=y
 CONFIG_ARM_UNWIND=y
 CONFIG_IMAGE_COMPRESSION_NONE=y
 CONFIG_MMU=y
+CONFIG_MALLOC_SIZE=0x0
 CONFIG_MALLOC_TLSF=y
 CONFIG_KALLSYMS=y
 CONFIG_PROMPT="R-Pi> "
-- 
2.15.1


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


[PATCH] ratp: remove unused context fields

2018-01-29 Thread Aleksander Morgado
Signed-off-by: Aleksander Morgado 
---
 common/ratp.c | 6 --
 1 file changed, 6 deletions(-)

diff --git a/common/ratp.c b/common/ratp.c
index 6db4df870..80863f81f 100644
--- a/common/ratp.c
+++ b/common/ratp.c
@@ -54,14 +54,8 @@ struct ratp_bb_command_return {
 struct ratp_ctx {
struct console_device *cdev;
struct ratp ratp;
-   int ratp_status;
struct console_device ratp_console;
int have_synch;
-   int in_ratp_console;
-
-   u8 sendbuf[256];
-   u8 sendbuf_len;
-
int old_active;
 
struct kfifo *console_recv_fifo;
-- 
2.15.1


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


[PATCH 3/3] drivers: mtd: nand: omap: Return stat value

2018-01-29 Thread Daniel Schultz
The read page function should return the total count of flipped bits,
otherwise the caller always thinks no bitflip occured.

Signed-off-by: Daniel Schultz 
---
 drivers/mtd/nand/nand_omap_gpmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/nand_omap_gpmc.c 
b/drivers/mtd/nand/nand_omap_gpmc.c
index e18ce63..38f4960 100644
--- a/drivers/mtd/nand/nand_omap_gpmc.c
+++ b/drivers/mtd/nand/nand_omap_gpmc.c
@@ -712,7 +712,7 @@ static int omap_gpmc_read_page_bch_rom_mode(struct mtd_info 
*mtd,
else
mtd->ecc_stats.corrected += stat;
 
-   return 0;
+   return stat;
 }
 
 static int omap_gpmc_eccmode(struct gpmc_nand_info *oinfo,
-- 
2.7.4


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


[PATCH 2/3] ARM: configs: am335x_defconfig: Reorder configs

2018-01-29 Thread Daniel Schultz
These configs were added directly in the config file and not with
menuconfig. Reorder these like menuconfig would place them.

Signed-off-by: Daniel Schultz 
---
 arch/arm/configs/am335x_defconfig | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm/configs/am335x_defconfig 
b/arch/arm/configs/am335x_defconfig
index 5a236fb..09dde90 100644
--- a/arch/arm/configs/am335x_defconfig
+++ b/arch/arm/configs/am335x_defconfig
@@ -29,12 +29,14 @@ CONFIG_BOOTM_OFTREE=y
 CONFIG_BLSPEC=y
 CONFIG_CONSOLE_ACTIVATE_NONE=y
 CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW=y
+CONFIG_STATE=y
 CONFIG_RESET_SOURCE=y
 CONFIG_DEBUG_INFO=y
 CONFIG_LONGHELP=y
 CONFIG_CMD_IOMEM=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_ARM_MMUINFO=y
+CONFIG_CMD_MMC_EXTCSD=y
 # CONFIG_CMD_BOOTU is not set
 CONFIG_CMD_BOOTZ=y
 CONFIG_CMD_GO=y
@@ -87,7 +89,6 @@ CONFIG_CMD_OF_DISPLAY_TIMINGS=y
 CONFIG_CMD_OF_FIXUP_STATUS=y
 CONFIG_CMD_OFTREE=y
 CONFIG_CMD_TIME=y
-CONFIG_CMD_MMC_EXTCSD=y
 CONFIG_CMD_STATE=y
 CONFIG_NET=y
 CONFIG_NET_NFS=y
@@ -124,6 +125,7 @@ CONFIG_USB_MUSB_GADGET=y
 CONFIG_MCI=y
 CONFIG_MCI_STARTUP=y
 CONFIG_MCI_OMAP_HSMMC=y
+CONFIG_STATE_DRV=y
 CONFIG_LED=y
 CONFIG_LED_GPIO=y
 CONFIG_LED_GPIO_OF=y
@@ -143,5 +145,3 @@ CONFIG_FS_FAT_LFN=y
 CONFIG_FS_UBIFS=y
 CONFIG_FS_UBIFS_COMPRESSION_LZO=y
 CONFIG_FS_UBIFS_COMPRESSION_ZLIB=y
-CONFIG_STATE=y
-CONFIG_STATE_DRV=y
-- 
2.7.4


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


[PATCH 1/3] commands: ubi: ubiupdatevol: Reduce error code to 0 or 1

2018-01-29 Thread Daniel Schultz
do_ubiupdatevol can either return 0 or the ioctl return value. This is
not in conformity with the other ubi comannds return values.

Signed-off-by: Daniel Schultz 
---
 commands/ubi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/ubi.c b/commands/ubi.c
index 5e27584..de5633c 100644
--- a/commands/ubi.c
+++ b/commands/ubi.c
@@ -82,7 +82,7 @@ error:
close(fd_vol);
 error_img:
close(fd_img);
-   return ret;
+   return ret ? 1 : 0;
 }
 
 
-- 
2.7.4


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