]>
Commit | Line | Data |
---|---|---|
ff048ea9 KW |
1 | /* |
2 | * Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | |
3 | * Use of this source code is governed by a BSD-style license that can be | |
4 | * found in the LICENSE file. | |
5 | * | |
6 | * Alternatively, this software may be distributed under the terms of the | |
7 | * GNU General Public License ("GPL") version 2 as published by the Free | |
8 | * Software Foundation. | |
9 | */ | |
10 | ||
ff048ea9 | 11 | #include <command.h> |
e141075f | 12 | #include <mapmem.h> |
ff048ea9 | 13 | #include <part.h> |
03de305e | 14 | #include <vsprintf.h> |
ff048ea9 | 15 | |
8311ac5f RV |
16 | static int |
17 | do_rw(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) | |
ff048ea9 | 18 | { |
4101f687 | 19 | struct blk_desc *dev_desc = NULL; |
0528979f | 20 | struct disk_partition part_info; |
fca7db5b | 21 | ulong offset, limit; |
8311ac5f | 22 | uint blk, cnt, res; |
42f5ffb2 | 23 | void *ptr; |
fca7db5b | 24 | int part; |
ff048ea9 KW |
25 | |
26 | if (argc != 6) { | |
27 | cmd_usage(cmdtp); | |
28 | return 1; | |
29 | } | |
30 | ||
fca7db5b RV |
31 | part = part_get_info_by_dev_and_name_or_num(argv[1], argv[2], |
32 | &dev_desc, &part_info, 1); | |
33 | if (part < 0) | |
ff048ea9 | 34 | return 1; |
ff048ea9 | 35 | |
42f5ffb2 | 36 | ptr = map_sysmem(hextoul(argv[3], NULL), 0); |
7e5f460e SG |
37 | blk = hextoul(argv[4], NULL); |
38 | cnt = hextoul(argv[5], NULL); | |
ff048ea9 | 39 | |
fca7db5b | 40 | if (part > 0) { |
ff048ea9 KW |
41 | offset = part_info.start; |
42 | limit = part_info.size; | |
43 | } else { | |
4101f687 | 44 | /* Largest address not available in struct blk_desc. */ |
fca7db5b | 45 | offset = 0; |
ff048ea9 KW |
46 | limit = ~0; |
47 | } | |
48 | ||
49 | if (cnt + blk > limit) { | |
8311ac5f | 50 | printf("%s out of range\n", cmdtp->name); |
42f5ffb2 | 51 | unmap_sysmem(ptr); |
ff048ea9 KW |
52 | return 1; |
53 | } | |
54 | ||
8311ac5f | 55 | if (IS_ENABLED(CONFIG_CMD_WRITE) && !strcmp(cmdtp->name, "write")) |
42f5ffb2 | 56 | res = blk_dwrite(dev_desc, offset + blk, cnt, ptr); |
8311ac5f | 57 | else |
42f5ffb2 SG |
58 | res = blk_dread(dev_desc, offset + blk, cnt, ptr); |
59 | unmap_sysmem(ptr); | |
8311ac5f RV |
60 | |
61 | if (res != cnt) { | |
62 | printf("%s error\n", cmdtp->name); | |
ff048ea9 KW |
63 | return 1; |
64 | } | |
65 | ||
66 | return 0; | |
67 | } | |
68 | ||
8311ac5f | 69 | #ifdef CONFIG_CMD_READ |
ff048ea9 | 70 | U_BOOT_CMD( |
8311ac5f | 71 | read, 6, 0, do_rw, |
ff048ea9 | 72 | "Load binary data from a partition", |
fca7db5b | 73 | "<interface> <dev[:part|#partname]> addr blk# cnt" |
ff048ea9 | 74 | ); |
8311ac5f RV |
75 | #endif |
76 | ||
77 | #ifdef CONFIG_CMD_WRITE | |
78 | U_BOOT_CMD( | |
79 | write, 6, 0, do_rw, | |
80 | "Store binary data to a partition", | |
81 | "<interface> <dev[:part|#partname]> addr blk# cnt" | |
82 | ); | |
83 | #endif |