Re: [PATCH 1/5] cdev: make file operations const

2017-05-31 Thread Sascha Hauer
On Tue, May 30, 2017 at 04:09:43PM +0200, Philipp Zabel wrote:
> scripts/checkpatch.pl warns that struct file_operations should be const,
> but cdev->ops is not const, so without this patch we can choose between
> a warning from checkpatch and a warning from the compiler about
> discarding the const attribute when assigning the struct file_operations
> cdev->ops.
> 
> Since there is no reason to modify the contents of cdev->ops after
> probing, make it const.

Applied this one and the second patch.

Sascha

> 
> Signed-off-by: Philipp Zabel 
> ---
>  include/driver.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/driver.h b/include/driver.h
> index 52e06f7d62..086e44636b 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -440,7 +440,7 @@ struct file_operations {
>  #define MAX_PARTUUID_STR sizeof("00112233-4455-6677-8899-AABBCCDDEEFF")
>  
>  struct cdev {
> - struct file_operations *ops;
> + const struct file_operations *ops;
>   void *priv;
>   struct device_d *dev;
>   struct device_node *device_node;
> -- 
> 2.11.0
> 
> 
> ___
> 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 4/5] fs: add cdev_create_from_file for loop mount option

2017-05-31 Thread Sascha Hauer
Hi Philipp,

On Tue, May 30, 2017 at 04:09:46PM +0200, Philipp Zabel wrote:
> Allow to create a loopback cdev from a file.
> 
> Signed-off-by: Philipp Zabel 
> ---
>  fs/devfs-core.c  | 81 
> 
>  fs/fs.c  | 21 ---
>  include/driver.h |  1 +
>  3 files changed, 99 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/devfs-core.c b/fs/devfs-core.c
> +static ssize_t loop_write(struct cdev *cdev, const void *buf, size_t count,
> + loff_t offset, ulong flags)
> +{
> + struct loop_priv *priv = cdev->priv;
> + loff_t ofs;
> +
> + ofs = lseek(priv->fd, offset, SEEK_SET);
> + if (ofs < 0)
> + return ofs;
> +
> + return write(priv->fd, buf, count);
> +}
> +
> +static const struct file_operations loop_ops = {
> + .read = loop_read,
> + .write = loop_write,
> + .memmap = generic_memmap_rw,
> + .lseek = dev_lseek_default,
> +};
> +
> +struct cdev *cdev_create_from_file(const char *path, ulong flags)

Looks good, but I'm missing the counterpart of this function and its
usage in umount().

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/2] ARM: imx6: gw54xx: add function to retrieve board revision from GSC

2017-05-31 Thread Sascha Hauer
On Mon, May 29, 2017 at 10:02:41PM +0200, Lucas Stach wrote:
> This parses the board revision from the GSC EEPROm model string.
> 
> Signed-off-by: Lucas Stach 
> ---
>  arch/arm/boards/gateworks-ventana/gsc.c | 14 ++
>  arch/arm/boards/gateworks-ventana/gsc.h |  2 ++
>  2 files changed, 16 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/boards/gateworks-ventana/gsc.c 
> b/arch/arm/boards/gateworks-ventana/gsc.c
> index 3614230..92244d1 100644
> --- a/arch/arm/boards/gateworks-ventana/gsc.c
> +++ b/arch/arm/boards/gateworks-ventana/gsc.c
> @@ -65,3 +65,17 @@ int gsc_i2c_write(struct i2c_client *client, u32 addr, 
> const u8 *buf, u16 count)
>  
>   return ret;
>  }
> +
> +char gsc_get_rev(struct i2c_client *client)
> +{
> + int i;
> + u8 model[16];
> +
> + gsc_i2c_read(client, 0x30, model, 16);
> + for (i = sizeof(model) - 1; i > 0; i--) {
> + if (model[i] >= 'A')
> + return model[i];
> + }
> +
> + return 'A';
> +}
> diff --git a/arch/arm/boards/gateworks-ventana/gsc.h 
> b/arch/arm/boards/gateworks-ventana/gsc.h
> index a6e7e22..13f2262 100644
> --- a/arch/arm/boards/gateworks-ventana/gsc.h
> +++ b/arch/arm/boards/gateworks-ventana/gsc.h
> @@ -56,3 +56,5 @@
>   */
>  int gsc_i2c_read(struct i2c_client *client, u32 addr, u8 *buf, u16 count);
>  int gsc_i2c_write(struct i2c_client *client, u32 addr, const u8 *buf, u16 
> count);
> +
> +char gsc_get_rev(struct i2c_client *client);
> -- 
> 2.9.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


[PATCH 2/2] sandbox: --stdin and --stdout allow max one bidirectional console

2017-05-31 Thread Aleksander Morgado
Allow up to one bidirectional FIFO/file based console in addition to
the default stdin/stdout console that is always registered.

We avoid opening the FIFO files while parsing the options because the
whole logic may block if e.g. trying to open the --stdout FIFO and
there is no reader in the other end. So instead, we store the --stdout
and --stdin file paths given, and we open both sequentially once all
the options have been parsed. This also allows us to validate that at
most a single pair of --stdin and --stdout paths has been given.
e.g.:
term1 $ mkfifo /tmp/bbstdin
term1 $ mkfifo /tmp/bbstdout
term1 $ ./barebox -I /tmp/bbstdin -O /tmp/bbstdout
   (blocks until a reader is available in the stdout FIFO)

term2 $ cat /tmp/bbstdout & cat > /tmp/bbstdin
   (starts reader and writer, which triggers barebox to continue)

If only one console is activated (CONFIG_CONSOLE_ACTIVATE_ALL=n), the
default stdin/stdout console will be preferred instead of the new
FIFO/file based, which would need to be activated explicitly later on.
e.g.:
barebox@barebox sandbox:/ cs1.active=ioe

Signed-off-by: Aleksander Morgado 
---
 arch/sandbox/os/common.c | 48 +---
 1 file changed, 37 insertions(+), 11 deletions(-)

diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 192917ac2..0461abaac 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -39,6 +39,7 @@
 #include 
 #include 
 #include 
+#include 
 /*
  * ...except the ones needed to connect with barebox
  */
@@ -329,9 +330,11 @@ static const char optstring[] = "hm:i:e:d:O:I:x:y:";
 int main(int argc, char *argv[])
 {
void *ram;
-   int opt, ret, fd;
+   int opt, ret;
int malloc_size = CONFIG_MALLOC_SIZE;
int fdno = 0, envno = 0, option_index = 0;
+   char path_stdout[PATH_MAX + 1] = { 0 };
+   char path_stdin[PATH_MAX + 1] = { 0 };
 
while (1) {
option_index = 0;
@@ -360,22 +363,18 @@ int main(int argc, char *argv[])
}
break;
case 'O':
-   fd = open(optarg, O_WRONLY);
-   if (fd < 0) {
-   perror("open");
+   if (path_stdout[0]) {
+   printf("error: cannot specify -O,--stdout 
multiple times\n");
exit(1);
}
-
-   barebox_register_console(-1, fd);
+   strncpy(path_stdout, optarg, PATH_MAX);
break;
case 'I':
-   fd = open(optarg, O_RDWR);
-   if (fd < 0) {
-   perror("open");
+   if (path_stdin[0]) {
+   printf("error: cannot specify -I,--stdin 
multiple times\n");
exit(1);
}
-
-   barebox_register_console(fd, -1);
+   strncpy(path_stdin, optarg, PATH_MAX);
break;
case 'x':
sdl_xres = strtoul(optarg, NULL, 0);
@@ -426,6 +425,33 @@ int main(int argc, char *argv[])
}
}
 
+   /* Register additional FIFO console */
+   if (path_stdout[0] || path_stdin[0]) {
+   int fdout, fdin;
+
+   /* Both must be given to build a FIFO console */
+   if (!path_stdin[0] || !path_stdout[0]) {
+   printf("error: both -I,--stdin and -O,--stdout must be"
+  "specified to enable the FIFO console\n");
+   exit(1);
+   }
+
+   fdout = open(path_stdout, O_WRONLY);
+   if (fdout < 0) {
+   perror("open stdout");
+   exit(1);
+   }
+
+   fdin = open(path_stdin, O_RDWR);
+   if (fdin < 0) {
+   perror("open stdin");
+   exit(1);
+   }
+
+   barebox_register_console(fdin, fdout);
+   }
+
+   /* Register default stdin/stdout console */
barebox_register_console(fileno(stdin), fileno(stdout));
 
rawmode();
-- 
2.13.0


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


[PATCH 1/2] sandbox: fix registering multiple consoles

2017-05-31 Thread Aleksander Morgado
Consoles need to be registered with the "console" device name so that
they are probed by the correct driver. The barebox_register_console()
was already forcing this as it was overwriting the name that was being
passed as argument, but it was failing to provide a unique id for
each new console, so the underlying register_device() would just
return an error when wanting to re-register a device with device name
"console" and id 0.

We remove the unused name parameter from barebox_register_console() as
it is really nowhere used, and also specify DEVICE_ID_DYNAMIC as id,
so that a new unique device id is given to each newly registered
console device.

Signed-off-by: Aleksander Morgado 
---
 arch/sandbox/board/console.c   | 5 ++---
 arch/sandbox/mach-sandbox/include/mach/linux.h | 2 +-
 arch/sandbox/os/common.c   | 6 +++---
 drivers/serial/linux_console.c | 3 +++
 4 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/arch/sandbox/board/console.c b/arch/sandbox/board/console.c
index cd5ad5723..cf1781d15 100644
--- a/arch/sandbox/board/console.c
+++ b/arch/sandbox/board/console.c
@@ -22,7 +22,7 @@
 #include 
 #include 
 
-int barebox_register_console(char *name, int stdinfd, int stdoutfd)
+int barebox_register_console(int stdinfd, int stdoutfd)
 {
struct device_d *dev;
struct linux_console_data *data;
@@ -32,9 +32,8 @@ int barebox_register_console(char *name, int stdinfd, int 
stdoutfd)
data = (struct linux_console_data *)(dev + 1);
 
dev->platform_data = data;
-   strcpy(dev->name, name);
-
strcpy(dev->name, "console");
+   dev->id = DEVICE_ID_DYNAMIC;
 
data->stdoutfd = stdoutfd;
data->stdinfd  = stdinfd;
diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h 
b/arch/sandbox/mach-sandbox/include/mach/linux.h
index 1f11ed449..1327a56ca 100644
--- a/arch/sandbox/mach-sandbox/include/mach/linux.h
+++ b/arch/sandbox/mach-sandbox/include/mach/linux.h
@@ -19,7 +19,7 @@ void __attribute__((noreturn)) linux_exit(void);
 
 int linux_execve(const char * filename, char *const argv[], char *const 
envp[]);
 
-int barebox_register_console(char *name_template, int stdinfd, int stdoutfd);
+int barebox_register_console(int stdinfd, int stdoutfd);
 
 int barebox_register_dtb(const void *dtb);
 
diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c
index 67667d40d..192917ac2 100644
--- a/arch/sandbox/os/common.c
+++ b/arch/sandbox/os/common.c
@@ -366,7 +366,7 @@ int main(int argc, char *argv[])
exit(1);
}
 
-   barebox_register_console("cout", -1, fd);
+   barebox_register_console(-1, fd);
break;
case 'I':
fd = open(optarg, O_RDWR);
@@ -375,7 +375,7 @@ int main(int argc, char *argv[])
exit(1);
}
 
-   barebox_register_console("cin", fd, -1);
+   barebox_register_console(fd, -1);
break;
case 'x':
sdl_xres = strtoul(optarg, NULL, 0);
@@ -426,7 +426,7 @@ int main(int argc, char *argv[])
}
}
 
-   barebox_register_console("console", fileno(stdin), fileno(stdout));
+   barebox_register_console(fileno(stdin), fileno(stdout));
 
rawmode();
start_barebox();
diff --git a/drivers/serial/linux_console.c b/drivers/serial/linux_console.c
index 760b3b81f..0d5da9d1b 100644
--- a/drivers/serial/linux_console.c
+++ b/drivers/serial/linux_console.c
@@ -73,6 +73,9 @@ static int linux_console_probe(struct device_d *dev)
 
console_register(cdev);
 
+   pr_info("%s: registered as %s%d\n", dev->name, cdev->class_dev.name,
+   cdev->class_dev.id);
+
return 0;
 }
 
-- 
2.13.0


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


[PATCH 0/2] Enabling support for the FIFO based console in sandbox

2017-05-31 Thread Aleksander Morgado
Hey,

I've been trying to make the FIFO based extra sandbox console work for some 
time now, and ended up preparing a couple of patches that seem to serve the 
purpose. I'm not totally sure whether this hasn't been working for a long time 
or if I was doing somethin wrong myself (possibly!).

The first one is a fix to allow registering multiple sandbox consoles; looks 
like this was not possible with the current codebase as the additional consoles 
were all being registered as devices with the same name and id.

The second patch is open for discussion. I wasn't able to make the setup work 
with separate console devices registered for input and output, the only way I 
could make it work was registering a console that did both input and output, so 
I ended up modifying it so that the logic of the application allows only that, 
an extra bidirectional console using two separate FIFO files. If either --stdin 
or --stdout is not given, or if either of them gets given multiple times, an 
error is issued. With this setup it works for me, I can run barebox and use 
either the default stdin/stdout console or the FIFO based one, but maybe we're 
losing other useful usecases.

What do you think?

Aleksander Morgado (2):
  sandbox: fix registering multiple consoles
  sandbox: --stdin and --stdout allow max one bidirectional console

 arch/sandbox/board/console.c   |  5 ++-
 arch/sandbox/mach-sandbox/include/mach/linux.h |  2 +-
 arch/sandbox/os/common.c   | 50 +++---
 drivers/serial/linux_console.c |  3 ++
 4 files changed, 44 insertions(+), 16 deletions(-)

--
2.13.0

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