diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2018-10-09 12:00:43 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2018-10-09 12:00:43 +0200 |
commit | 7f071269ddb8f3786f6c5ec1d4b91ae928833c96 (patch) | |
tree | 06e1586a503baad326e381e93b2d8cc6b6e57d9f /common | |
parent | fee477f487b246490e7167acc3331e43fbeff901 (diff) | |
parent | fb6fd3128c11653b7990b16887b37ddab6d1bae3 (diff) | |
download | barebox-7f071269ddb8f3786f6c5ec1d4b91ae928833c96.tar.gz barebox-7f071269ddb8f3786f6c5ec1d4b91ae928833c96.tar.xz |
Merge branch 'for-next/ratp'
Diffstat (limited to 'common')
-rw-r--r-- | common/ratp/Kconfig | 15 | ||||
-rw-r--r-- | common/ratp/Makefile | 2 | ||||
-rw-r--r-- | common/ratp/getenv.c | 12 | ||||
-rw-r--r-- | common/ratp/gpio.c | 144 | ||||
-rw-r--r-- | common/ratp/i2c.c | 284 | ||||
-rw-r--r-- | common/ratp/md.c | 24 | ||||
-rw-r--r-- | common/ratp/mw.c | 24 | ||||
-rw-r--r-- | common/ratp/reset.c | 10 |
8 files changed, 483 insertions, 32 deletions
diff --git a/common/ratp/Kconfig b/common/ratp/Kconfig index 07d1f53da7..25c931b978 100644 --- a/common/ratp/Kconfig +++ b/common/ratp/Kconfig @@ -13,3 +13,18 @@ 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. + +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 2c6d674f61..71288bcb8c 100644 --- a/common/ratp/Makefile +++ b/common/ratp/Makefile @@ -4,3 +4,5 @@ obj-y += getenv.o 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/getenv.c b/common/ratp/getenv.c index b409634886..fdb4b0b282 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/gpio.c b/common/ratp/gpio.c new file mode 100644 index 0000000000..d2c527a40c --- /dev/null +++ b/common/ratp/gpio.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2018 Sascha Hauer <s.hauer@pengutronix.de>, 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 <common.h> +#include <ratp_bb.h> +#include <malloc.h> +#include <environment.h> +#include <gpio.h> +#include <errno.h> + +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_t value; +} __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_t value; +} __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_t direction; /* 0: input, 1: output */ + uint8_t value; /* applicable only if direction output */ +} __packed; + +struct ratp_bb_gpio_set_direction_response { + struct ratp_bb header; + uint32_t errno; +} __packed; + +static int ratp_cmd_gpio_set_direction(const struct ratp_bb *req, int req_len, + struct ratp_bb **rsp, int *rsp_len) +{ + struct ratp_bb_gpio_set_direction_request *gpio_req = (struct ratp_bb_gpio_set_direction_request *)req; + struct ratp_bb_gpio_set_direction_response *gpio_rsp; + int gpio_rsp_len; + uint32_t gpio; + int ret; + + if (req_len < sizeof(*gpio_req)) { + pr_err("set direction request ignored: size mismatch (%d < %zu)\n", req_len, sizeof(*gpio_req)); + return 2; + } + + gpio = be32_to_cpu(gpio_req->gpio); + if (gpio_req->direction) + ret = gpio_direction_output(gpio, gpio_req->value); + else + ret = gpio_direction_input(gpio); + + gpio_rsp_len = sizeof(struct ratp_bb_gpio_set_direction_response); + gpio_rsp = xzalloc(gpio_rsp_len); + gpio_rsp->header.type = cpu_to_be16(BB_RATP_TYPE_GPIO_SET_DIRECTION_RETURN); + gpio_rsp->errno = (ret == 0 ? 0 : EIO); + + *rsp_len = gpio_rsp_len; + *rsp = (struct ratp_bb *)gpio_rsp; + return 0; +} + +BAREBOX_RATP_CMD_START(GPIO_SET_DIRECTION) + .request_id = BB_RATP_TYPE_GPIO_SET_DIRECTION, + .response_id = BB_RATP_TYPE_GPIO_SET_DIRECTION_RETURN, + .cmd = ratp_cmd_gpio_set_direction +BAREBOX_RATP_CMD_END diff --git a/common/ratp/i2c.c b/common/ratp/i2c.c new file mode 100644 index 0000000000..07097c7f4b --- /dev/null +++ b/common/ratp/i2c.c @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2018 Sascha Hauer <s.hauer@pengutronix.de>, 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 <common.h> +#include <ratp_bb.h> +#include <init.h> +#include <driver.h> +#include <malloc.h> +#include <errno.h> +#include <i2c/i2c.h> + +/* 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 here, but just validate buffer position and size */ + buffer_offset = be16_to_cpu(i2c_read_req->buffer_offset); + if (buffer_offset != req_len) { + pr_err("read ignored: invalid buffer offset (%hu != %d)\n", + buffer_offset, req_len); + ret = -EINVAL; + goto out_rsp; + } + + reg = be16_to_cpu(i2c_read_req->reg); + size = be16_to_cpu(i2c_read_req->size); + if (i2c_read_req->flags & I2C_FLAG_WIDE_ADDRESS) + wide = I2C_ADDR_16_BIT; + +out_rsp: + /* Avoid reading anything on error */ + if (ret != 0) + size = 0; + + i2c_read_rsp_len = sizeof(*i2c_read_rsp) + size; + i2c_read_rsp = xzalloc(i2c_read_rsp_len); + i2c_read_rsp->header.type = cpu_to_be16(BB_RATP_TYPE_I2C_READ_RETURN); + i2c_read_rsp->buffer_offset = cpu_to_be16(sizeof(*i2c_read_rsp)); + i2c_read_rsp->data_offset = 0; + + /* 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) { + pr_err("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(&client, i2c_read_rsp->buffer, size); + } else { + ret = i2c_read_reg(&client, reg | wide, i2c_read_rsp->buffer, size); + } + if (ret != size) { + pr_err("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; + } + + *rsp = (struct ratp_bb *)i2c_read_rsp; + *rsp_len = i2c_read_rsp_len; + + return ret; +} + +BAREBOX_RATP_CMD_START(I2C_READ) + .request_id = BB_RATP_TYPE_I2C_READ, + .response_id = BB_RATP_TYPE_I2C_READ_RETURN, + .cmd = ratp_cmd_i2c_read +BAREBOX_RATP_CMD_END + + +static int ratp_cmd_i2c_write(const struct ratp_bb *req, int req_len, + struct ratp_bb **rsp, int *rsp_len) +{ + struct ratp_bb_i2c_write_request *i2c_write_req = (struct ratp_bb_i2c_write_request *)req; + struct ratp_bb_i2c_write_response *i2c_write_rsp; + struct i2c_adapter *adapter; + struct i2c_client client; + uint8_t *buffer; + uint16_t buffer_offset; + uint16_t buffer_size; + uint16_t reg; + uint16_t data_offset; + uint16_t data_size; + uint32_t wide = 0; + int ret = 0; + int written = 0; + + /* At least message header should be valid */ + if (req_len < sizeof(*i2c_write_req)) { + pr_err("write ignored: size mismatch (%d < %zu)\n", + req_len, sizeof(*i2c_write_req)); + ret = -EINVAL; + goto out; + } + + /* Validate buffer position and size */ + buffer_offset = be16_to_cpu(i2c_write_req->buffer_offset); + if (req_len < buffer_offset) { + pr_err("write ignored: invalid buffer offset (%d < %hu)\n", + req_len, buffer_offset); + ret = -EINVAL; + goto out; + } + buffer_size = req_len - buffer_offset; + buffer = ((uint8_t *)i2c_write_req) + buffer_offset; + + /* Validate data position and size */ + data_offset = be16_to_cpu(i2c_write_req->data_offset); + if (data_offset != 0) { + pr_err("write ignored: invalid data offset\n"); + ret = -EINVAL; + goto out; + } + data_size = be16_to_cpu(i2c_write_req->data_size); + if (!data_size) { + /* Success */ + goto out; + } + + /* Validate buffer size */ + if (buffer_size < data_size) { + pr_err("write ignored: size mismatch (%d < %hu): data not fully given\n", + buffer_size, data_size); + ret = -EINVAL; + goto out; + } + + reg = be16_to_cpu(i2c_write_req->reg); + if (i2c_write_req->flags & I2C_FLAG_WIDE_ADDRESS) + wide = I2C_ADDR_16_BIT; + + adapter = i2c_get_adapter(i2c_write_req->bus); + if (!adapter) { + pr_err("write ignored: i2c bus %u not found\n", i2c_write_req->bus); + ret = -ENODEV; + goto out; + } + + client.adapter = adapter; + client.addr = i2c_write_req->addr; + + if (i2c_write_req->flags & I2C_FLAG_MASTER_MODE) { + written = i2c_master_send(&client, &buffer[data_offset], data_size); + } else { + written = i2c_write_reg(&client, reg | wide, &buffer[data_offset], data_size); + } + + if (written != data_size) { + pr_err("write ignored: not all bytes written (%u < %u)\n", ret, data_size); + ret = -EIO; + goto out; + } + +out: + i2c_write_rsp = xzalloc(sizeof(*i2c_write_rsp)); + i2c_write_rsp->header.type = cpu_to_be16(BB_RATP_TYPE_I2C_WRITE_RETURN); + i2c_write_rsp->buffer_offset = cpu_to_be16(sizeof(*i2c_write_rsp)); /* n/a */ + + if (ret != 0) { + i2c_write_rsp->written = 0; + i2c_write_rsp->errno = cpu_to_be32(ret); + } else { + i2c_write_rsp->written = cpu_to_be16((uint16_t)written); + i2c_write_rsp->errno = 0; + } + + *rsp = (struct ratp_bb *)i2c_write_rsp; + *rsp_len = sizeof(*i2c_write_rsp); + + return ret; +} + +BAREBOX_RATP_CMD_START(I2C_WRITE) + .request_id = BB_RATP_TYPE_I2C_WRITE, + .response_id = BB_RATP_TYPE_I2C_WRITE_RETURN, + .cmd = ratp_cmd_i2c_write +BAREBOX_RATP_CMD_END diff --git a/common/ratp/md.c b/common/ratp/md.c index 9b8fc2bc50..9ce7e99dfd 100644 --- a/common/ratp/md.c +++ b/common/ratp/md.c @@ -15,6 +15,8 @@ * */ +#define pr_fmt(fmt) "barebox-ratp: md: " fmt + #include <common.h> #include <ratp_bb.h> #include <init.h> @@ -46,7 +48,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 +57,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; @@ -121,8 +123,8 @@ 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", - req_len, sizeof (*md_req)); + 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,27 +143,27 @@ 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; } - 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 *)&buffer[path_offset], path_size); out: @@ -191,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 7d6df3d0a0..55e79bbaf0 100644 --- a/common/ratp/mw.c +++ b/common/ratp/mw.c @@ -16,6 +16,8 @@ * */ +#define pr_fmt(fmt) "barebox-ratp: mw: " fmt + #include <common.h> #include <ratp_bb.h> #include <init.h> @@ -47,7 +49,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 +57,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) @@ -77,8 +79,8 @@ 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", - req_len, sizeof (*mw_req)); + 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,13 +125,13 @@ 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 ignored: size mismatch (%d < %hu): path or data not be fully given\n", + pr_err("ignored: size mismatch (%d < %hu): path or data not be fully given\n", req_len, path_size + data_size); ret = -EINVAL; goto out; } - addr = be16_to_cpu (mw_req->addr); + addr = be16_to_cpu(mw_req->addr); path = xstrndup((const char *)&buffer[path_offset], path_size); fd = open_and_lseek(path, O_RWSIZE_1 | O_WRONLY, addr); @@ -162,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 ca8be4e62f..d0229d5d6c 100644 --- a/common/ratp/reset.c +++ b/common/ratp/reset.c @@ -17,6 +17,8 @@ * */ +#define pr_fmt(fmt) "barebox-ratp: reset: " fmt + #include <common.h> #include <command.h> #include <ratp_bb.h> @@ -27,19 +29,19 @@ struct ratp_bb_reset { struct ratp_bb header; uint8_t force; -} __attribute__((packed)); +} __packed; static int ratp_cmd_reset(const struct ratp_bb *req, int req_len, struct ratp_bb **rsp, int *rsp_len) { struct ratp_bb_reset *reset_req = (struct ratp_bb_reset *)req; - if (req_len < sizeof (*reset_req)) { - printf ("ratp reset 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; } - debug("running reset %s\n", reset_req->force ? "(forced)" : ""); + pr_debug("running %s\n", reset_req->force ? "(forced)" : ""); if (!reset_req->force) shutdown_barebox(); |