3 * Afzal Mohammed <afzal.mohd.ma@gmail.com>
6 * Copyright (C) 2012 Samsung Electronics
7 * author: Lukasz Majewski <l.majewski@samsung.com>
9 * SPDX-License-Identifier: GPL-2.0+
17 static int dfu_transfer_medium_ram(enum dfu_op op, struct dfu_entity *dfu,
18 u64 offset, void *buf, long *len)
20 if (dfu->layout != DFU_RAM_ADDR) {
21 error("unsupported layout: %s\n", dfu_get_layout(dfu->layout));
25 if (offset > dfu->data.ram.size) {
26 error("request exceeds allowed area\n");
30 if (op == DFU_OP_WRITE)
31 memcpy(dfu->data.ram.start + offset, buf, *len);
33 memcpy(buf, dfu->data.ram.start + offset, *len);
38 static int dfu_write_medium_ram(struct dfu_entity *dfu, u64 offset,
41 return dfu_transfer_medium_ram(DFU_OP_WRITE, dfu, offset, buf, len);
44 long dfu_get_medium_size_ram(struct dfu_entity *dfu)
46 return dfu->data.ram.size;
49 static int dfu_read_medium_ram(struct dfu_entity *dfu, u64 offset,
52 return dfu_transfer_medium_ram(DFU_OP_READ, dfu, offset, buf, len);
55 int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char *s)
59 dfu->dev_type = DFU_DEV_RAM;
61 if (strcmp(st, "ram")) {
62 error("unsupported device: %s\n", st);
66 dfu->layout = DFU_RAM_ADDR;
67 dfu->data.ram.start = (void *)simple_strtoul(s, &s, 16);
69 dfu->data.ram.size = simple_strtoul(s, &s, 16);
71 dfu->write_medium = dfu_write_medium_ram;
72 dfu->get_medium_size = dfu_get_medium_size_ram;
73 dfu->read_medium = dfu_read_medium_ram;