Purchase Inquiry

2018-09-12 Thread Purchases
Good morning,

We have a client who is interested in some of your services. I 
will provide further details should we get a response from you. 

Regards,

Joseph Hamilton
Accounts Payable
c\o Hamtons Merchants Trading Co. Int'l
10722 - 32nd Street SE, Calgary AB T2C 5B2 Canada

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


[PATCH] checkpatch: don't check TODO file presence

2018-09-12 Thread Antony Pavlov
The commit b3baf2d86149 ("TODO: remove unused file") drops
the TODO file. Alas scripts/checkpatch.pl checks TODO file
presence in top_of_kernel_tree(). Without TODO checkpatch.pl
exits with 'Must be run from the top-level dir. of a kernel tree'.

Signed-off-by: Antony Pavlov 
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 48ad4938d9..9a6f6e2298 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -330,7 +330,7 @@ sub top_of_kernel_tree {
my @tree_check = (
"arch", "commands", "common", "COPYING", "defaultenv",
"Documentation", "drivers", "fs", "include", "lib",
-   "MAKEALL", "Makefile", "net", "README", "scripts", "TODO"
+   "MAKEALL", "Makefile", "net", "README", "scripts"
);
 
foreach my $check (@tree_check) {
-- 
2.18.0


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


[PATCH for master 0/2] MIPS and PCI-related fixes

2018-09-12 Thread Antony Pavlov
Antony Pavlov (2):
  MIPS: fix PCI quirk infrastructure build
  pci_of_match_device: don't crash on MIPS Malta

 arch/mips/lib/barebox.lds.S | 11 +++
 drivers/pci/pci.c   |  2 +-
 2 files changed, 12 insertions(+), 1 deletion(-)

-- 
2.18.0


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


[PATCH for master 1/2] MIPS: fix PCI quirk infrastructure build

2018-09-12 Thread Antony Pavlov
The commit fc2c618c2038 ("pci: add quirk infrastructure")
adds necessary ld-script changes only for ARM architecture.
As a result, qemu-malta build fails:

 LD  barebox
drivers/built-in.o: In function `pci_fixup_device':
(.text.pci_fixup_device+0x30): undefined reference to 
`__end_pci_fixups_enable'
(.text.pci_fixup_device+0x38): undefined reference to 
`__end_pci_fixups_enable'
(.text.pci_fixup_device+0x34): undefined reference to 
`__start_pci_fixups_enable'
(.text.pci_fixup_device+0x3c): undefined reference to 
`__start_pci_fixups_enable'
(.text.pci_fixup_device+0x70): undefined reference to 
`__end_pci_fixups_header'
(.text.pci_fixup_device+0x78): undefined reference to 
`__end_pci_fixups_header'
(.text.pci_fixup_device+0x74): undefined reference to 
`__start_pci_fixups_header'
(.text.pci_fixup_device+0x80): undefined reference to 
`__start_pci_fixups_header'
(.text.pci_fixup_device+0x2c): undefined reference to 
`__end_pci_fixups_early'
(.text.pci_fixup_device+0x88): undefined reference to 
`__end_pci_fixups_early'
(.text.pci_fixup_device+0x84): undefined reference to 
`__start_pci_fixups_early'
(.text.pci_fixup_device+0x90): undefined reference to 
`__start_pci_fixups_early'
make: *** [Makefile:767: barebox] Error 1

Signed-off-by: Antony Pavlov 
---
 arch/mips/lib/barebox.lds.S | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/mips/lib/barebox.lds.S b/arch/mips/lib/barebox.lds.S
index 660d4be85e..c4026bb7f1 100644
--- a/arch/mips/lib/barebox.lds.S
+++ b/arch/mips/lib/barebox.lds.S
@@ -75,6 +75,17 @@ SECTIONS
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;
 
+#ifdef CONFIG_PCI
+   __start_pci_fixups_early = .;
+   .pci_fixup_early : { KEEP(*(.pci_fixup_early)) }
+   __end_pci_fixups_early = .;
+   __start_pci_fixups_header = .;
+   .pci_fixup_header : { KEEP(*(.pci_fixup_header)) }
+   __end_pci_fixups_header = .;
+   __start_pci_fixups_enable = .;
+   .pci_fixup_enable : { KEEP(*(.pci_fixup_enable)) }
+   __end_pci_fixups_enable = .;
+#endif
.oftables : { BAREBOX_CLK_TABLE() }
 
.dtb : { BAREBOX_DTB() }
-- 
2.18.0


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


[PATCH for master 2/2] pci_of_match_device: don't crash on MIPS Malta

2018-09-12 Thread Antony Pavlov
In arch/mips/mach-malta/pci.c PCI controller is instantiated
without dt and struct pci_controller parent field is NULL.

Signed-off-by: Antony Pavlov 
---
 drivers/pci/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d206c53848..7abc7a3439 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -339,7 +339,7 @@ pci_of_match_device(struct device_d *parent, unsigned int 
devfn)
struct device_node *np;
u32 reg;
 
-   if (!IS_ENABLED(CONFIG_OFTREE) || !parent->device_node)
+   if (!IS_ENABLED(CONFIG_OFTREE) || !parent || !parent->device_node)
return NULL;
 
for_each_child_of_node(parent->device_node, np) {
-- 
2.18.0


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


[PATCH v2 7/7] ratp: fix incorrect whitespaces in method calls

2018-09-12 Thread Aleksander Morgado
This is a simple coding style fix to avoid the whitespace before the
open-parenthesis in method calls.

Signed-off-by: Aleksander Morgado 
---
 common/ratp/getenv.c | 12 ++--
 common/ratp/md.c |  8 
 common/ratp/mw.c |  6 +++---
 common/ratp/reset.c  |  4 ++--
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/common/ratp/getenv.c b/common/ratp/getenv.c
index b40963488..fdb4b0b28 100644
--- a/common/ratp/getenv.c
+++ b/common/ratp/getenv.c
@@ -27,20 +27,20 @@
 static int ratp_cmd_getenv(const struct ratp_bb *req, int req_len,
   struct ratp_bb **rsp, int *rsp_len)
 {
-   int dlen = req_len - sizeof (struct ratp_bb);
+   int dlen = req_len - sizeof(struct ratp_bb);
char *varname;
const char *value;
 
-   varname = xstrndup ((const char *)req->data, dlen);
-   value = getenv (varname);
-   free (varname);
+   varname = xstrndup((const char *)req->data, dlen);
+   value = getenv(varname);
+   free(varname);
 
-   dlen = strlen (value);
+   dlen = strlen(value);
 
*rsp_len = sizeof(struct ratp_bb) + dlen;
*rsp = xzalloc(*rsp_len);
(*rsp)->type = cpu_to_be16(BB_RATP_TYPE_GETENV_RETURN);
-   memcpy ((*rsp)->data, value, dlen);
+   memcpy((*rsp)->data, value, dlen);
return 0;
 }
 
diff --git a/common/ratp/md.c b/common/ratp/md.c
index 2e5a956cb..9ce7e99df 100644
--- a/common/ratp/md.c
+++ b/common/ratp/md.c
@@ -124,7 +124,7 @@ static int ratp_cmd_md(const struct ratp_bb *req, int 
req_len,
/* At least message header should be valid */
if (req_len < sizeof(*md_req)) {
pr_err("ignored: size mismatch (%d < %zu)\n",
-  req_len, sizeof (*md_req));
+  req_len, sizeof(*md_req));
ret = -EINVAL;
goto out;
}
@@ -162,8 +162,8 @@ static int ratp_cmd_md(const struct ratp_bb *req, int 
req_len,
goto out;
}
 
-   addr = be16_to_cpu (md_req->addr);
-   size = be16_to_cpu (md_req->size);
+   addr = be16_to_cpu(md_req->addr);
+   size = be16_to_cpu(md_req->size);
path = xstrndup((const char *)[path_offset], path_size);
 
 out:
@@ -193,7 +193,7 @@ out:
*rsp = (struct ratp_bb *)md_rsp;
*rsp_len = md_rsp_len;
 
-   free (path);
+   free(path);
return ret;
 }
 
diff --git a/common/ratp/mw.c b/common/ratp/mw.c
index 0579da3c1..55e79bbaf 100644
--- a/common/ratp/mw.c
+++ b/common/ratp/mw.c
@@ -80,7 +80,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int req_len,
/* At least message header should be valid */
if (req_len < sizeof(*mw_req)) {
pr_err("ignored: size mismatch (%d < %zu)\n",
-  req_len, sizeof (*mw_req));
+  req_len, sizeof(*mw_req));
ret = -EINVAL;
goto out;
}
@@ -131,7 +131,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int 
req_len,
goto out;
}
 
-   addr = be16_to_cpu (mw_req->addr);
+   addr = be16_to_cpu(mw_req->addr);
path = xstrndup((const char *)[path_offset], path_size);
 
fd = open_and_lseek(path, O_RWSIZE_1 | O_WRONLY, addr);
@@ -164,7 +164,7 @@ out:
*rsp = (struct ratp_bb *)mw_rsp;
*rsp_len = sizeof(*mw_rsp);
 
-   free (path);
+   free(path);
return ret;
 }
 
diff --git a/common/ratp/reset.c b/common/ratp/reset.c
index 5439f344f..d0229d5d6 100644
--- a/common/ratp/reset.c
+++ b/common/ratp/reset.c
@@ -36,8 +36,8 @@ static int ratp_cmd_reset(const struct ratp_bb *req, int 
req_len,
 {
struct ratp_bb_reset *reset_req = (struct ratp_bb_reset *)req;
 
-   if (req_len < sizeof (*reset_req)) {
-   pr_err("ignored: size mismatch (%d < %zu)\n", req_len, sizeof 
(*reset_req));
+   if (req_len < sizeof(*reset_req)) {
+   pr_err("ignored: size mismatch (%d < %zu)\n", req_len, 
sizeof(*reset_req));
return 2;
}
 
-- 
2.19.0


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


[PATCH v2 6/7] ratp: use pr_ macros to print messages

2018-09-12 Thread Aleksander Morgado
Following suggestions in other patch reviews, the RAPT commands are
updated to use pr_err() instead of plain printf() to report errors
to the user.

Signed-off-by: Aleksander Morgado 
---
 common/ratp/md.c| 12 +++-
 common/ratp/mw.c| 14 --
 common/ratp/reset.c |  6 --
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/common/ratp/md.c b/common/ratp/md.c
index 5b877947c..2e5a956cb 100644
--- a/common/ratp/md.c
+++ b/common/ratp/md.c
@@ -15,6 +15,8 @@
  *
  */
 
+#define pr_fmt(fmt) "barebox-ratp: md: " fmt
+
 #include 
 #include 
 #include 
@@ -121,7 +123,7 @@ static int ratp_cmd_md(const struct ratp_bb *req, int 
req_len,
 
/* At least message header should be valid */
if (req_len < sizeof(*md_req)) {
-   printf("ratp md ignored: size mismatch (%d < %zu)\n",
+   pr_err("ignored: size mismatch (%d < %zu)\n",
   req_len, sizeof (*md_req));
ret = -EINVAL;
goto out;
@@ -130,7 +132,7 @@ static int ratp_cmd_md(const struct ratp_bb *req, int 
req_len,
/* Validate buffer position and size */
buffer_offset = be16_to_cpu(md_req->buffer_offset);
if (req_len < buffer_offset) {
-   printf("ratp md ignored: invalid buffer offset (%d < %hu)\n",
+   pr_err("ignored: invalid buffer offset (%d < %hu)\n",
   req_len, buffer_offset);
ret = -EINVAL;
goto out;
@@ -141,20 +143,20 @@ static int ratp_cmd_md(const struct ratp_bb *req, int 
req_len,
/* Validate path position and size */
path_offset = be16_to_cpu(md_req->path_offset);
if (path_offset != 0) {
-   printf("ratp md ignored: invalid path offset\n");
+   pr_err("ignored: invalid path offset\n");
ret = -EINVAL;
goto out;
}
path_size = be16_to_cpu(md_req->path_size);
if (!path_size) {
-   printf("ratp md ignored: no filepath given\n");
+   pr_err("ignored: no filepath given\n");
ret = -EINVAL;
goto out;
}
 
/* Validate buffer size */
if (buffer_size < path_size) {
-   printf("ratp mw ignored: size mismatch (%d < %hu): path may not 
be fully given\n",
+   pr_err("ignored: size mismatch (%d < %hu): path may not be 
fully given\n",
   req_len, path_size);
ret = -EINVAL;
goto out;
diff --git a/common/ratp/mw.c b/common/ratp/mw.c
index 3234d7dac..0579da3c1 100644
--- a/common/ratp/mw.c
+++ b/common/ratp/mw.c
@@ -16,6 +16,8 @@
  *
  */
 
+#define pr_fmt(fmt) "barebox-ratp: mw: " fmt
+
 #include 
 #include 
 #include 
@@ -77,7 +79,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int req_len,
 
/* At least message header should be valid */
if (req_len < sizeof(*mw_req)) {
-   printf("ratp mw ignored: size mismatch (%d < %zu)\n",
+   pr_err("ignored: size mismatch (%d < %zu)\n",
   req_len, sizeof (*mw_req));
ret = -EINVAL;
goto out;
@@ -86,7 +88,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int req_len,
/* Validate buffer position and size */
buffer_offset = be16_to_cpu(mw_req->buffer_offset);
if (req_len < buffer_offset) {
-   printf("ratp mw ignored: invalid buffer offset (%d < %hu)\n",
+   pr_err("ignored: invalid buffer offset (%d < %hu)\n",
   req_len, buffer_offset);
ret = -EINVAL;
goto out;
@@ -97,13 +99,13 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int 
req_len,
/* Validate path position and size */
path_offset = be16_to_cpu(mw_req->path_offset);
if (path_offset != 0) {
-   printf("ratp mw ignored: invalid path offset\n");
+   pr_err("ignored: invalid path offset\n");
ret = -EINVAL;
goto out;
}
path_size = be16_to_cpu(mw_req->path_size);
if (!path_size) {
-   printf("ratp mw ignored: no filepath given\n");
+   pr_err("ignored: no filepath given\n");
ret = -EINVAL;
goto out;
}
@@ -111,7 +113,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int 
req_len,
/* Validate data position and size */
data_offset = be16_to_cpu(mw_req->data_offset);
if (data_offset != (path_offset + path_size)) {
-   printf("ratp mw ignored: invalid path offset\n");
+   pr_err("ignored: invalid path offset\n");
ret = -EINVAL;
goto out;
}
@@ -123,7 +125,7 @@ static int ratp_cmd_mw(const struct ratp_bb *req, int 
req_len,
 
/* Validate buffer size */
if (buffer_size < (path_size + data_size)) {
-   printf("ratp mw 

[PATCH v2 5/7] ratp: use __packed instead of the full form

2018-09-12 Thread Aleksander Morgado
Just a minor coding style change to follow the suggestions given in
patch reviews for other RATP commands.

Signed-off-by: Aleksander Morgado 
---
 common/ratp/md.c| 4 ++--
 common/ratp/mw.c| 4 ++--
 common/ratp/reset.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/common/ratp/md.c b/common/ratp/md.c
index 9b8fc2bc5..5b877947c 100644
--- a/common/ratp/md.c
+++ b/common/ratp/md.c
@@ -46,7 +46,7 @@ struct ratp_bb_md_request {
uint16_t path_size;
uint16_t path_offset;
uint8_t  buffer[];
-} __attribute__((packed));
+} __packed;
 
 struct ratp_bb_md_response {
struct ratp_bb header;
@@ -55,7 +55,7 @@ struct ratp_bb_md_response {
uint16_t data_size;
uint16_t data_offset;
uint8_t  buffer[];
-} __attribute__((packed));
+} __packed;
 
 extern char *mem_rw_buf;
 
diff --git a/common/ratp/mw.c b/common/ratp/mw.c
index 7d6df3d0a..3234d7dac 100644
--- a/common/ratp/mw.c
+++ b/common/ratp/mw.c
@@ -47,7 +47,7 @@ struct ratp_bb_mw_request {
uint16_t data_size;
uint16_t data_offset;
uint8_t  buffer[];
-} __attribute__((packed));
+} __packed;
 
 struct ratp_bb_mw_response {
struct ratp_bb header;
@@ -55,7 +55,7 @@ struct ratp_bb_mw_response {
uint32_t errno;
uint16_t written;
uint8_t  buffer[];
-} __attribute__((packed));
+} __packed;
 
 static int ratp_cmd_mw(const struct ratp_bb *req, int req_len,
   struct ratp_bb **rsp, int *rsp_len)
diff --git a/common/ratp/reset.c b/common/ratp/reset.c
index ca8be4e62..60b6ff536 100644
--- a/common/ratp/reset.c
+++ b/common/ratp/reset.c
@@ -27,7 +27,7 @@
 struct ratp_bb_reset {
struct ratp_bb header;
uint8_tforce;
-} __attribute__((packed));
+} __packed;
 
 static int ratp_cmd_reset(const struct ratp_bb *req, int req_len,
  struct ratp_bb **rsp, int *rsp_len)
-- 
2.19.0


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


[PATCH v2 2/7] bbremote: implement i2c read/write support

2018-09-12 Thread Aleksander Morgado
Extend the bbremote script with operations to perform binary i2c
read/write operations.

E.g.:

barebox:/ i2c_read -b 0 -a 0x68 -r 0x06A0 -c 4 -w
0x8f 0x30 0x00 0x00

barebox:/ i2c_write -b 0 -a 0x68 -r 0x06A0 -w 0x87 0x30 0x00 0x00

barebox:/ i2c_read -b 0 -a 0x68 -r 0x06A0 -c 4 -w
0x87 0x30 0x00 0x00

barebox:/ i2c_write -b 0 -a 0x68 -r 0x06A0 -w 0x8f 0x30 0x00 0x00

barebox:/ i2c_read -b 0 -a 0x68 -r 0x06A0 -c 4 -w
0x8f 0x30 0x00 0x00

===

$ ./scripts/bbremote --port /dev/ttyUSB2 i2c-read 0x00 0x68 0x06A0 0x01 4
8f30

$ ./scripts/bbremote --port /dev/ttyUSB2 i2c-write 0x00 0x68 0x06A0 0x01 
"8730"
4 bytes written

$ ./scripts/bbremote --port /dev/ttyUSB2 i2c-read 0x00 0x68 0x06A0 0x01 4
8730

$ ./scripts/bbremote --port /dev/ttyUSB2 i2c-write 0x00 0x68 0x06A0 0x01 
"8f30"
4 bytes written

$ ./scripts/bbremote --port /dev/ttyUSB2 i2c-read 0x00 0x68 0x06A0 0x01 4
8f30

Signed-off-by: Aleksander Morgado 
---
 scripts/remote/controller.py | 24 ++
 scripts/remote/main.py   | 37 
 scripts/remote/messages.py   | 86 
 3 files changed, 147 insertions(+)

diff --git a/scripts/remote/controller.py b/scripts/remote/controller.py
index 1a8390904..10037b890 100644
--- a/scripts/remote/controller.py
+++ b/scripts/remote/controller.py
@@ -61,6 +61,18 @@ def unpack(data):
 elif p_type == BBType.reset:
 logging.debug("received: reset")
 return BBPacketReset(raw=data)
+elif p_type == BBType.i2c_read:
+logging.debug("received: i2c_read")
+return BBPacketI2cRead(raw=data)
+elif p_type == BBType.i2c_read_return:
+logging.debug("received: i2c_read_return")
+return BBPacketI2cReadReturn(raw=data)
+elif p_type == BBType.i2c_write:
+logging.debug("received: i2c_write")
+return BBPacketI2cWrite(raw=data)
+elif p_type == BBType.i2c_write_return:
+logging.debug("received: i2c_write_return")
+return BBPacketI2cWriteReturn(raw=data)
 else:
 logging.debug("received: UNKNOWN")
 return BBPacket(raw=data)
@@ -139,6 +151,18 @@ class Controller(Thread):
 logging.info("Mw return: %r", r)
 return (r.exit_code,r.written)
 
+def i2c_read(self, bus, addr, reg, flags, size):
+self._send(BBPacketI2cRead(bus=bus, addr=addr, reg=reg, flags=flags, 
size=size))
+r = self._expect(BBPacketI2cReadReturn)
+logging.info("i2c read return: %r", r)
+return (r.exit_code,r.data)
+
+def i2c_write(self, bus, addr, reg, flags, data):
+self._send(BBPacketI2cWrite(bus=bus, addr=addr, reg=reg, flags=flags, 
data=data))
+r = self._expect(BBPacketI2cWriteReturn)
+logging.info("i2c write return: %r", r)
+return (r.exit_code,r.written)
+
 def reset(self, force):
 self._send(BBPacketReset(force=force))
 
diff --git a/scripts/remote/main.py b/scripts/remote/main.py
index 38d280bfe..0f7783927 100644
--- a/scripts/remote/main.py
+++ b/scripts/remote/main.py
@@ -98,6 +98,27 @@ def handle_mw(args):
 return res
 
 
+def handle_i2c_read(args):
+ctrl = get_controller(args)
+(res,data) = ctrl.i2c_read(args.bus, args.address, args.reg, args.flags, 
args.size)
+if res == 0:
+print(binascii.hexlify(data))
+ctrl.close()
+return res
+
+
+def handle_i2c_write(args):
+ctrl = get_controller(args)
+data=args.data
+if ((len(data) % 2) != 0):
+data="0"+data
+(res,written) = ctrl.i2c_write(args.bus, args.address, args.reg, 
args.flags, binascii.unhexlify(data))
+if res == 0:
+print("%i bytes written" % written)
+ctrl.close()
+return res
+
+
 def handle_reset(args):
 ctrl = get_controller(args)
 ctrl.reset(args.force)
@@ -188,6 +209,22 @@ parser_mw.add_argument('address', type=auto_int, 
help="address")
 parser_mw.add_argument('data', help="data")
 parser_mw.set_defaults(func=handle_mw)
 
+parser_i2c_read = subparsers.add_parser('i2c-read', help="run i2c read 
command")
+parser_i2c_read.add_argument('bus', type=auto_int, help="bus")
+parser_i2c_read.add_argument('address', type=auto_int, help="address")
+parser_i2c_read.add_argument('reg', type=auto_int, help="reg")
+parser_i2c_read.add_argument('flags', type=auto_int, help="flags")
+parser_i2c_read.add_argument('size', type=auto_int, help="size")
+parser_i2c_read.set_defaults(func=handle_i2c_read)
+
+parser_i2c_write = subparsers.add_parser('i2c-write', help="run i2c write 
command")
+parser_i2c_write.add_argument('bus', type=auto_int, help="bus")
+parser_i2c_write.add_argument('address', type=auto_int, help="address")
+parser_i2c_write.add_argument('reg', type=auto_int, help="reg")
+parser_i2c_write.add_argument('flags', type=auto_int, help="flags")
+parser_i2c_write.add_argument('data', help="data")

[PATCH v2 4/7] bbremote: implement support for GPIO operations

2018-09-12 Thread Aleksander Morgado
Signed-off-by: Aleksander Morgado 
---
 scripts/remote/controller.py | 36 ++
 scripts/remote/main.py   | 37 ++
 scripts/remote/messages.py   | 93 
 3 files changed, 166 insertions(+)

diff --git a/scripts/remote/controller.py b/scripts/remote/controller.py
index 10037b890..b4493591d 100644
--- a/scripts/remote/controller.py
+++ b/scripts/remote/controller.py
@@ -73,6 +73,24 @@ def unpack(data):
 elif p_type == BBType.i2c_write_return:
 logging.debug("received: i2c_write_return")
 return BBPacketI2cWriteReturn(raw=data)
+elif p_type == BBType.gpio_get_value:
+logging.debug("received: gpio_get_value")
+return BBPacketGpioGetValue(raw=data)
+elif p_type == BBType.gpio_get_value_return:
+logging.debug("received: gpio_get_value_return")
+return BBPacketGpioGetValueReturn(raw=data)
+elif p_type == BBType.gpio_set_value:
+logging.debug("received: gpio_set_value")
+return BBPacketGpioSetValue(raw=data)
+elif p_type == BBType.gpio_set_value_return:
+logging.debug("received: gpio_set_value_return")
+return BBPacketGpioSetValueReturn(raw=data)
+elif p_type == BBType.gpio_set_direction:
+logging.debug("received: gpio_set_direction")
+return BBPacketGpioSetDirection(raw=data)
+elif p_type == BBType.gpio_set_direction_return:
+logging.debug("received: gpio_set_direction_return")
+return BBPacketGpioSetDirectionReturn(raw=data)
 else:
 logging.debug("received: UNKNOWN")
 return BBPacket(raw=data)
@@ -163,6 +181,24 @@ class Controller(Thread):
 logging.info("i2c write return: %r", r)
 return (r.exit_code,r.written)
 
+def gpio_get_value(self, gpio):
+self._send(BBPacketGpioGetValue(gpio=gpio))
+r = self._expect(BBPacketGpioGetValueReturn)
+logging.info("gpio get value return: %r", r)
+return r.value
+
+def gpio_set_value(self, gpio, value):
+self._send(BBPacketGpioSetValue(gpio=gpio, value=value))
+r = self._expect(BBPacketGpioSetValueReturn)
+logging.info("gpio set value return: %r", r)
+return 0
+
+def gpio_set_direction(self, gpio, direction, value):
+self._send(BBPacketGpioSetDirection(gpio=gpio, direction=direction, 
value=value))
+r = self._expect(BBPacketGpioSetDirectionReturn)
+logging.info("gpio set direction return: %r", r)
+return r.exit_code
+
 def reset(self, force):
 self._send(BBPacketReset(force=force))
 
diff --git a/scripts/remote/main.py b/scripts/remote/main.py
index 0f7783927..cef5d92ee 100644
--- a/scripts/remote/main.py
+++ b/scripts/remote/main.py
@@ -119,6 +119,28 @@ def handle_i2c_write(args):
 return res
 
 
+def handle_gpio_get_value(args):
+ctrl = get_controller(args)
+value = ctrl.gpio_get_value(args.gpio)
+print ("%u" % value);
+ctrl.close()
+return 0
+
+
+def handle_gpio_set_value(args):
+ctrl = get_controller(args)
+ctrl.gpio_set_value(args.gpio, args.value)
+ctrl.close()
+return 0
+
+
+def handle_gpio_set_direction(args):
+ctrl = get_controller(args)
+res = ctrl.gpio_set_direction(args.gpio, args.direction, args.value)
+ctrl.close()
+return res
+
+
 def handle_reset(args):
 ctrl = get_controller(args)
 ctrl.reset(args.force)
@@ -225,6 +247,21 @@ parser_i2c_write.add_argument('flags', type=auto_int, 
help="flags")
 parser_i2c_write.add_argument('data', help="data")
 parser_i2c_write.set_defaults(func=handle_i2c_write)
 
+parser_gpio_get_value = subparsers.add_parser('gpio-get-value', help="run gpio 
get value command")
+parser_gpio_get_value.add_argument('gpio', type=auto_int, help="gpio")
+parser_gpio_get_value.set_defaults(func=handle_gpio_get_value)
+
+parser_gpio_set_value = subparsers.add_parser('gpio-set-value', help="run gpio 
set value command")
+parser_gpio_set_value.add_argument('gpio', type=auto_int, help="gpio")
+parser_gpio_set_value.add_argument('value', type=auto_int, help="value")
+parser_gpio_set_value.set_defaults(func=handle_gpio_set_value)
+
+parser_gpio_set_direction = subparsers.add_parser('gpio-set-direction', 
help="run gpio set direction command")
+parser_gpio_set_direction.add_argument('gpio', type=auto_int, help="gpio")
+parser_gpio_set_direction.add_argument('direction', type=auto_int, 
help="direction (0: input, 1: output)")
+parser_gpio_set_direction.add_argument('value', type=auto_int, help="value (if 
output)")
+parser_gpio_set_direction.set_defaults(func=handle_gpio_set_direction)
+
 parser_reset = subparsers.add_parser('reset', help="run reset command")
 parser_reset_force = parser_reset.add_mutually_exclusive_group(required=False)
 parser_reset_force.add_argument('--force', dest='force', action='store_true')
diff --git a/scripts/remote/messages.py b/scripts/remote/messages.py
index bc40cbcc3..abd331c8b 100644
--- 

[PATCH v2 1/7] ratp: implement i2c read/write support

2018-09-12 Thread Aleksander Morgado
Introduce two new RATP commands that allow running i2c read/write
operations, very similar in format to the already existing md/mw
RATP commands.

The messages are defined with a fixed 16-bit long register field, but
it will only be treated as a 16-bit address if I2C_FLAG_WIDE_ADDRESS
is set in the message flags field. If this flag is unset, the start
register address is assumed 8-bit long.

If the message includes the I2C_FLAG_MASTER_MODE flag, the start
register field is ignored and a i2c master send/receive operation is
performed.

Signed-off-by: Aleksander Morgado 
---
 common/ratp/Kconfig  |   7 ++
 common/ratp/Makefile |   1 +
 common/ratp/i2c.c| 284 +++
 include/ratp_bb.h|   4 +
 4 files changed, 296 insertions(+)
 create mode 100644 common/ratp/i2c.c

diff --git a/common/ratp/Kconfig b/common/ratp/Kconfig
index 93ff75d64..4b28d5f9f 100644
--- a/common/ratp/Kconfig
+++ b/common/ratp/Kconfig
@@ -12,3 +12,10 @@ config CONSOLE_RATP
  this option adds a machine readable interface for controlling barebox.
  Say yes here if you want to control barebox from a remote host.
 
+config RATP_CMD_I2C
+   bool
+   depends on RATP
+   depends on I2C
+   prompt "RATP i2c support"
+   help
+ This option adds support for i2c read/write commands via RATP.
\ No newline at end of file
diff --git a/common/ratp/Makefile b/common/ratp/Makefile
index 2c6d674f6..b83c48327 100644
--- a/common/ratp/Makefile
+++ b/common/ratp/Makefile
@@ -4,3 +4,4 @@ obj-y += getenv.o
 obj-y += md.o
 obj-y += mw.o
 obj-y += reset.o
+obj-$(CONFIG_RATP_CMD_I2C) += i2c.o
diff --git a/common/ratp/i2c.c b/common/ratp/i2c.c
new file mode 100644
index 0..07097c7f4
--- /dev/null
+++ b/common/ratp/i2c.c
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2018 Sascha Hauer , Pengutronix
+ * Copyright (c) 2018 Zodiac Inflight Innovations
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ */
+
+#define pr_fmt(fmt) "barebox-ratp: i2c: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* NOTE:
+ *  - Fixed-size fields (e.g. integers) are given just after the header.
+ *  - Variable-length fields are stored inside the buffer[] and their position
+ *within the buffer[] and their size are given as fixed-sized fields after
+ *the header.
+ *  The message may be extended at any time keeping backwards compatibility,
+ *  as the position of the buffer[] is given by the buffer_offset field. i.e.
+ *  increasing the buffer_offset field we can extend the fixed-sized section
+ *  to add more fields.
+ */
+
+#define I2C_FLAG_WIDE_ADDRESS BIT(0)
+#define I2C_FLAG_MASTER_MODE  BIT(1)
+
+struct ratp_bb_i2c_read_request {
+   struct ratp_bb header;
+   uint16_t buffer_offset;
+   uint8_t  bus;
+   uint8_t  addr;
+   uint16_t reg;
+   uint8_t  flags;
+   uint16_t size;
+   uint8_t  buffer[];
+} __packed;
+
+struct ratp_bb_i2c_read_response {
+   struct ratp_bb header;
+   uint16_t buffer_offset;
+   uint32_t errno;
+   uint16_t data_size;
+   uint16_t data_offset;
+   uint8_t  buffer[];
+} __packed;
+
+struct ratp_bb_i2c_write_request {
+   struct ratp_bb header;
+   uint16_t buffer_offset;
+   uint8_t  bus;
+   uint8_t  addr;
+   uint16_t reg;
+   uint8_t  flags;
+   uint16_t data_size;
+   uint16_t data_offset;
+   uint8_t  buffer[];
+} __packed;
+
+struct ratp_bb_i2c_write_response {
+   struct ratp_bb header;
+   uint16_t buffer_offset;
+   uint32_t errno;
+   uint16_t written;
+   uint8_t  buffer[];
+} __packed;
+
+static int ratp_cmd_i2c_read(const struct ratp_bb *req, int req_len,
+struct ratp_bb **rsp, int *rsp_len)
+{
+   struct ratp_bb_i2c_read_request *i2c_read_req = (struct 
ratp_bb_i2c_read_request *)req;
+   struct ratp_bb_i2c_read_response *i2c_read_rsp;
+   struct i2c_adapter *adapter;
+   struct i2c_client client;
+   uint16_t buffer_offset;
+   int i2c_read_rsp_len;
+   uint16_t reg;
+   uint16_t size;
+   uint32_t wide = 0;
+   int ret = 0;
+
+   /* At least message header should be valid */
+   if (req_len < sizeof(*i2c_read_req)) {
+   pr_err("read ignored: size mismatch (%d < %zu)\n",
+  req_len, sizeof(*i2c_read_req));
+   ret = -EINVAL;
+   goto out_rsp;
+   }
+
+   /* We don't require any buffer 

[PATCH v2 3/7] ratp: implement support for GPIO commands

2018-09-12 Thread Aleksander Morgado
Introduce three new RATP commands that allow getting and setting GPIO
values as well as configuring the direction of the GPIO pins.

Signed-off-by: Aleksander Morgado 
---
 common/ratp/Kconfig  |  10 ++-
 common/ratp/Makefile |   1 +
 common/ratp/gpio.c   | 144 +++
 include/ratp_bb.h|   6 ++
 4 files changed, 160 insertions(+), 1 deletion(-)
 create mode 100644 common/ratp/gpio.c

diff --git a/common/ratp/Kconfig b/common/ratp/Kconfig
index 4b28d5f9f..ddbbd955c 100644
--- a/common/ratp/Kconfig
+++ b/common/ratp/Kconfig
@@ -18,4 +18,12 @@ config RATP_CMD_I2C
depends on I2C
prompt "RATP i2c support"
help
- This option adds support for i2c read/write commands via RATP.
\ No newline at end of file
+ This option adds support for i2c read/write commands via RATP.
+
+config RATP_CMD_GPIO
+   bool
+   depends on RATP
+   depends on GENERIC_GPIO
+   prompt "RATP GPIO support"
+   help
+ This option adds support for GPIO get/set/direction commands via RATP.
\ No newline at end of file
diff --git a/common/ratp/Makefile b/common/ratp/Makefile
index b83c48327..71288bcb8 100644
--- a/common/ratp/Makefile
+++ b/common/ratp/Makefile
@@ -5,3 +5,4 @@ obj-y += md.o
 obj-y += mw.o
 obj-y += reset.o
 obj-$(CONFIG_RATP_CMD_I2C) += i2c.o
+obj-$(CONFIG_RATP_CMD_GPIO) += gpio.o
diff --git a/common/ratp/gpio.c b/common/ratp/gpio.c
new file mode 100644
index 0..d2c527a40
--- /dev/null
+++ b/common/ratp/gpio.c
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2018 Sascha Hauer , Pengutronix
+ * Copyright (c) 2018 Zodiac Inflight Innovations
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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.
+ *
+ * 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.
+ *
+ */
+
+#define pr_fmt(fmt) "barebox-ratp: gpio: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct ratp_bb_gpio_get_value_request {
+   struct ratp_bb header;
+   uint32_t   gpio;
+} __packed;
+
+struct ratp_bb_gpio_get_value_response {
+   struct ratp_bb header;
+   uint8_tvalue;
+} __packed;
+
+static int ratp_cmd_gpio_get_value(const struct ratp_bb *req, int req_len,
+  struct ratp_bb **rsp, int *rsp_len)
+{
+   struct ratp_bb_gpio_get_value_request *gpio_req = (struct 
ratp_bb_gpio_get_value_request *)req;
+   struct ratp_bb_gpio_get_value_response *gpio_rsp;
+   int gpio_rsp_len;
+
+   if (req_len < sizeof(*gpio_req)) {
+   pr_err("get value request ignored: size mismatch (%d < %zu)\n", 
req_len, sizeof(*gpio_req));
+   return 2;
+   }
+
+   gpio_rsp_len = sizeof(struct ratp_bb_gpio_get_value_response);
+   gpio_rsp = xzalloc(gpio_rsp_len);
+   gpio_rsp->header.type = cpu_to_be16(BB_RATP_TYPE_GPIO_GET_VALUE_RETURN);
+   gpio_rsp->value = !!gpio_get_value(be32_to_cpu(gpio_req->gpio));
+
+   *rsp_len = gpio_rsp_len;
+   *rsp = (struct ratp_bb *)gpio_rsp;
+   return 0;
+}
+
+BAREBOX_RATP_CMD_START(GPIO_GET_VALUE)
+   .request_id = BB_RATP_TYPE_GPIO_GET_VALUE,
+   .response_id = BB_RATP_TYPE_GPIO_GET_VALUE_RETURN,
+   .cmd = ratp_cmd_gpio_get_value
+BAREBOX_RATP_CMD_END
+
+
+struct ratp_bb_gpio_set_value_request {
+   struct ratp_bb header;
+   uint32_t   gpio;
+   uint8_tvalue;
+} __packed;
+
+static int ratp_cmd_gpio_set_value(const struct ratp_bb *req, int req_len,
+  struct ratp_bb **rsp, int *rsp_len)
+{
+   struct ratp_bb_gpio_set_value_request *gpio_req = (struct 
ratp_bb_gpio_set_value_request *)req;
+
+   if (req_len < sizeof(*gpio_req)) {
+   pr_err("set value request ignored: size mismatch (%d < %zu)\n", 
req_len, sizeof(*gpio_req));
+   return 2;
+   }
+
+   gpio_set_value(be32_to_cpu(gpio_req->gpio), gpio_req->value);
+
+   *rsp_len = sizeof(struct ratp_bb);
+   *rsp = xzalloc(*rsp_len);
+   (*rsp)->type = cpu_to_be16(BB_RATP_TYPE_GPIO_SET_VALUE_RETURN);
+   return 0;
+}
+
+BAREBOX_RATP_CMD_START(GPIO_SET_VALUE)
+   .request_id = BB_RATP_TYPE_GPIO_SET_VALUE,
+   .response_id = BB_RATP_TYPE_GPIO_SET_VALUE_RETURN,
+   .cmd = ratp_cmd_gpio_set_value
+BAREBOX_RATP_CMD_END
+
+
+struct ratp_bb_gpio_set_direction_request {
+   struct ratp_bb header;
+   uint32_t   gpio;
+   uint8_tdirection; /* 0: input, 1: output */
+   uint8_tvalue; /* applicable only if direction output */
+} __packed;
+
+struct 

[PATCH v2 0/7] RATP i2c and GPIO support

2018-09-12 Thread Aleksander Morgado
This series of patches implements support for i2c and GPIO operations via RATP. 

It addresses most of the comments from the first series review, except for 
Sascha's suggestion to implement name resolving for the i2c buses and Andrey's 
suggestion to prepare a new helper method to initialize the i2c_client 
structure. I already have a patch for the latter, but will send it for review 
once these have been accepted and merged, as it's really a bit orthogonal to 
the whole RATP logic.

Another different w.r.t. v1 apart from addressing the comments is the review is 
that I made the RATP i2c support depend on CONFIG_I2C and the RATP GPIO support 
on CONFIG_GENERIC_GPIO. That was missing, and was breaking build if RATP was 
selected but no i2c or GPIO support was included in the build.

Comments welcome!

Aleksander Morgado (7):
  ratp: implement i2c read/write support
  bbremote: implement i2c read/write support
  ratp: implement support for GPIO commands
  bbremote: implement support for GPIO operations
  ratp: use __packed instead of the full form
  ratp: use pr_ macros to print messages
  ratp: fix incorrect whitespaces in method calls

 common/ratp/Kconfig  |  15 ++
 common/ratp/Makefile |   2 +
 common/ratp/getenv.c |  12 +-
 common/ratp/gpio.c   | 144 ++
 common/ratp/i2c.c| 284 +++
 common/ratp/md.c |  24 +--
 common/ratp/mw.c |  24 +--
 common/ratp/reset.c  |  10 +-
 include/ratp_bb.h|  10 ++
 scripts/remote/controller.py |  60 
 scripts/remote/main.py   |  74 +
 scripts/remote/messages.py   | 179 ++
 12 files changed, 806 insertions(+), 32 deletions(-)
 create mode 100644 common/ratp/gpio.c
 create mode 100644 common/ratp/i2c.c

-- 
2.19.0


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


Re: [PATCH 1/4] ratp: implement i2c read/write support

2018-09-12 Thread Aleksander Morgado
Hey Andrey,

Thanks for the review :) see some comments below.

>> +   /* Don't read anything on error or if 0 bytes were requested */
>> +   if (size > 0) {
>> +   adapter = i2c_get_adapter(i2c_read_req->bus);
>> +   if (!adapter) {
>> +   printf("ratp i2c read ignored: i2c bus %u not 
>> found\n", i2c_read_req->bus);
>> +   ret = -ENODEV;
>> +   goto out;
>> +   }
>> +
>> +   client.adapter = adapter;
>> +   client.addr = i2c_read_req->addr;
>> +
>> +   if (i2c_read_req->flags & I2C_FLAG_MASTER_MODE) {
>> +   ret = i2c_master_recv(, i2c_read_rsp->buffer, 
>> size);
>> +   } else {
>> +   ret = i2c_read_reg(, reg | wide, 
>> i2c_read_rsp->buffer, size);
>> +   }
>> +   if (ret != size) {
>> +   printf("ratp i2c read ignored: not all bytes read 
>> (%u < %u)\n", ret, size);
>> +   ret = -EIO;
>> +   goto out;
>> +   }
>> +   ret = 0;
>> +   }
>> +
>> +out:
>> +   if (ret != 0) {
>> +   i2c_read_rsp->data_size = 0;
>> +   i2c_read_rsp->errno = cpu_to_be32(ret);
>> +   i2c_read_rsp_len = sizeof(*i2c_read_rsp);
>> +   } else {
>> +   i2c_read_rsp->data_size = cpu_to_be16(size);
>> +   i2c_read_rsp->errno = 0;
>> +   }
>> +
>
> It looks like you can move:
>
> i2c_read_rsp->data_size = cpu_to_be16(size);
> i2c_read_rsp->errno = cpu_to_be32(ret);
>
> outside of if since it should work as intended for both cases (size is
> 0 if ret != 0).
>

Don't think I can do that. In the if (size > 0) {} just a bit above,
size is not modified but ret may become an error. We do want to make
sure 0 is returned as size when there is an error, so cannot move it
outside the if() as you suggest here.

-- 
Aleksander
https://aleksander.es

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


Re: problems writing an fs image to a disk partition

2018-09-12 Thread Giorgio Dal Molin


> On September 12, 2018 at 9:12 AM Sascha Hauer  wrote:
> 
> 
> Hi Giorgio,
> 
> On Tue, Sep 11, 2018 at 10:33:52PM +0200, Giorgio Dal Molin wrote:
> > Hi,
> > 
> > today I've tried barebox v2018.09.0 on an EFI system.
> > It basically runs but I have problems when writing an fs image file
> > to a disk partition:
> > 
> >  > cp rootfs.img /dev/disk1.userland
> > 
> > barebox v2018.09.0 returns a 'no space left on device' error.
> > 
> > First of all I must ask if this is still the proper way to
> > write a content to a disk partition.
> 
> Yes, it is. You found a bug.
> 
> > 
> > In case this should still work as expected here is a pseudo
> > backtrace of how the error happens on my system:
> > 
> > commands/cp.c:do_cp() ret = copy_file(argv[i], argv[argc - 1], verbose);
> > lib/libfile.c:copy_file() dstfd = open(dst, mode);
> > fs/fs.c:open() error = fsdrv->truncate(>dev, f, 0);
> > fs/devfs.c: devfs_truncate()
> > 
> > in the call to devfs_truncate() I see cdev->ops->truncate == NULL
> > and f->fsdev->dev.num_resources == 0 and this makes the function
> > return -ENOSPC.
> > 
> > Hope the report helps identify a problem.
> 
> Yes, indeed, thanks. The problem was that with the switch to dentry
> cache implementation the files in /dev/ no longer appear as character
> devices but as regular files. the copy_file function then does a
> truncate on the files which fails. I just sent out a patch addressing
> this issue, please test. I would also recommend to take the second patch
> although this fixes another issue.
> 
> Sascha
> 
Hi,

I've seen the two patches, thank you.

I've seen the dentry 'big patch' and I knew it was the problem
but it was too complex for me to understand exactly where the proper
fix should go.

I'll try them out today,

giorgio

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


Re: problems writing an fs image to a disk partition

2018-09-12 Thread Sascha Hauer
Hi Giorgio,

On Tue, Sep 11, 2018 at 10:33:52PM +0200, Giorgio Dal Molin wrote:
> Hi,
> 
> today I've tried barebox v2018.09.0 on an EFI system.
> It basically runs but I have problems when writing an fs image file
> to a disk partition:
> 
>  > cp rootfs.img /dev/disk1.userland
> 
> barebox v2018.09.0 returns a 'no space left on device' error.
> 
> First of all I must ask if this is still the proper way to
> write a content to a disk partition.

Yes, it is. You found a bug.

> 
> In case this should still work as expected here is a pseudo
> backtrace of how the error happens on my system:
> 
> commands/cp.c:do_cp() ret = copy_file(argv[i], argv[argc - 1], verbose);
> lib/libfile.c:copy_file() dstfd = open(dst, mode);
> fs/fs.c:open() error = fsdrv->truncate(>dev, f, 0);
> fs/devfs.c: devfs_truncate()
> 
> in the call to devfs_truncate() I see cdev->ops->truncate == NULL
> and f->fsdev->dev.num_resources == 0 and this makes the function
> return -ENOSPC.
> 
> Hope the report helps identify a problem.

Yes, indeed, thanks. The problem was that with the switch to dentry
cache implementation the files in /dev/ no longer appear as character
devices but as regular files. the copy_file function then does a
truncate on the files which fails. I just sent out a patch addressing
this issue, please test. I would also recommend to take the second patch
although this fixes another issue.

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


[PATCH 1/2] fs: devfs: Create device files as character devices

2018-09-12 Thread Sascha Hauer
Without this files in /dev/ appear as regular files. copy_file()
stumbles upon this as it tries a truncate() on that files which
then fails. Create the files as character devices so that copy_file()
works as expected.

Fixes: 9137c41915 ("fs: devfs: Switch to dentry cache implementation")

Signed-off-by: Sascha Hauer 
---
 fs/devfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/devfs.c b/fs/devfs.c
index 5d0bb2c674..84c619f1ed 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -226,7 +226,7 @@ static struct inode *devfs_get_inode(struct super_block 
*sb, const struct inode
switch (mode & S_IFMT) {
default:
return NULL;
-   case S_IFREG:
+   case S_IFCHR:
inode->i_op = _file_inode_operations;
inode->i_fop = _file_operations;
break;
@@ -251,7 +251,7 @@ static struct dentry *devfs_lookup(struct inode *dir, 
struct dentry *dentry,
if (!cdev)
return ERR_PTR(-ENOENT);
 
-   inode = devfs_get_inode(dir->i_sb, dir, S_IFREG | S_IRWXUGO);
+   inode = devfs_get_inode(dir->i_sb, dir, S_IFCHR | S_IRWXUGO);
if (!inode)
return ERR_PTR(-ENOMEM);
 
-- 
2.18.0


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


[PATCH 2/2] fs: devfs: fix r/w permissions

2018-09-12 Thread Sascha Hauer
The real r/w flags were lost in the switch to dentry cache
implementation. Restore them.

Fixes: 9137c41915 ("fs: devfs: Switch to dentry cache implementation")

Signed-off-by: Sascha Hauer 
---
 fs/devfs.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/devfs.c b/fs/devfs.c
index 84c619f1ed..d2b801036e 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -251,10 +251,15 @@ static struct dentry *devfs_lookup(struct inode *dir, 
struct dentry *dentry,
if (!cdev)
return ERR_PTR(-ENOENT);
 
-   inode = devfs_get_inode(dir->i_sb, dir, S_IFCHR | S_IRWXUGO);
+   inode = devfs_get_inode(dir->i_sb, dir, S_IFCHR);
if (!inode)
return ERR_PTR(-ENOMEM);
 
+   if (cdev->ops->write)
+   inode->i_mode |= S_IWUSR;
+   if (cdev->ops->read)
+   inode->i_mode |= S_IRUSR;
+
dinode = container_of(inode, struct devfs_inode, inode);
 
inode->i_size = cdev->size;
-- 
2.18.0


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