blob: 9d10303164e23bd69f76cb992679738ecd97e3f0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Afzal Mohammede3c687a2013-09-18 01:15:24 +05302/*
3 * (C) Copyright 2013
4 * Afzal Mohammed <afzal.mohd.ma@gmail.com>
5 *
6 * Reference: dfu_mmc.c
7 * Copyright (C) 2012 Samsung Electronics
8 * author: Lukasz Majewski <l.majewski@samsung.com>
Afzal Mohammede3c687a2013-09-18 01:15:24 +05309 */
10
11#include <common.h>
12#include <malloc.h>
Heinrich Schuchardt8784b0b2020-07-22 17:46:02 +020013#include <mapmem.h>
Afzal Mohammede3c687a2013-09-18 01:15:24 +053014#include <errno.h>
15#include <dfu.h>
16
17static int dfu_transfer_medium_ram(enum dfu_op op, struct dfu_entity *dfu,
18 u64 offset, void *buf, long *len)
19{
20 if (dfu->layout != DFU_RAM_ADDR) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090021 pr_err("unsupported layout: %s\n", dfu_get_layout(dfu->layout));
Afzal Mohammede3c687a2013-09-18 01:15:24 +053022 return -EINVAL;
23 }
24
25 if (offset > dfu->data.ram.size) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090026 pr_err("request exceeds allowed area\n");
Afzal Mohammede3c687a2013-09-18 01:15:24 +053027 return -EINVAL;
28 }
29
30 if (op == DFU_OP_WRITE)
Heinrich Schuchardt8784b0b2020-07-22 17:46:02 +020031 memcpy(map_sysmem(dfu->data.ram.start + offset, 0), buf, *len);
Afzal Mohammede3c687a2013-09-18 01:15:24 +053032 else
Heinrich Schuchardt8784b0b2020-07-22 17:46:02 +020033 memcpy(buf, map_sysmem(dfu->data.ram.start + offset, 0), *len);
Afzal Mohammede3c687a2013-09-18 01:15:24 +053034
35 return 0;
36}
37
38static int dfu_write_medium_ram(struct dfu_entity *dfu, u64 offset,
39 void *buf, long *len)
40{
41 return dfu_transfer_medium_ram(DFU_OP_WRITE, dfu, offset, buf, len);
42}
43
Patrick Delaunayf4e934f2017-07-19 16:39:23 +020044int dfu_get_medium_size_ram(struct dfu_entity *dfu, u64 *size)
Stephen Warren020e6f32014-06-11 12:47:27 -060045{
Patrick Delaunay5ea9b892017-07-19 16:39:22 +020046 *size = dfu->data.ram.size;
47
48 return 0;
Stephen Warren020e6f32014-06-11 12:47:27 -060049}
50
Afzal Mohammede3c687a2013-09-18 01:15:24 +053051static int dfu_read_medium_ram(struct dfu_entity *dfu, u64 offset,
52 void *buf, long *len)
53{
Afzal Mohammede3c687a2013-09-18 01:15:24 +053054 return dfu_transfer_medium_ram(DFU_OP_READ, dfu, offset, buf, len);
55}
56
Masami Hiramatsufa4282a2022-01-31 11:52:37 +090057int dfu_fill_entity_ram(struct dfu_entity *dfu, char *devstr, char **argv, int argc)
Afzal Mohammede3c687a2013-09-18 01:15:24 +053058{
Masami Hiramatsufa4282a2022-01-31 11:52:37 +090059 char *s;
Mugunthan V N4fb47432016-04-22 14:19:25 +053060
Masami Hiramatsufa4282a2022-01-31 11:52:37 +090061 if (argc != 3) {
62 pr_err("Invalid number of arguments.\n");
63 return -EINVAL;
Mugunthan V N4fb47432016-04-22 14:19:25 +053064 }
Afzal Mohammede3c687a2013-09-18 01:15:24 +053065
66 dfu->dev_type = DFU_DEV_RAM;
Mugunthan V N4fb47432016-04-22 14:19:25 +053067 if (strcmp(argv[0], "ram")) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090068 pr_err("unsupported device: %s\n", argv[0]);
Afzal Mohammede3c687a2013-09-18 01:15:24 +053069 return -ENODEV;
70 }
71
72 dfu->layout = DFU_RAM_ADDR;
Masami Hiramatsufa4282a2022-01-31 11:52:37 +090073 dfu->data.ram.start = hextoul(argv[1], &s);
74 if (*s)
75 return -EINVAL;
76 dfu->data.ram.size = hextoul(argv[2], &s);
77 if (*s)
78 return -EINVAL;
Afzal Mohammede3c687a2013-09-18 01:15:24 +053079
80 dfu->write_medium = dfu_write_medium_ram;
Stephen Warren020e6f32014-06-11 12:47:27 -060081 dfu->get_medium_size = dfu_get_medium_size_ram;
Afzal Mohammede3c687a2013-09-18 01:15:24 +053082 dfu->read_medium = dfu_read_medium_ram;
83
84 dfu->inited = 0;
85
86 return 0;
87}