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.
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
15 int do_read(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
18 struct blk_desc
*dev_desc
= NULL
;
21 disk_partition_t part_info
;
33 dev
= (int)simple_strtoul(argv
[2], &ep
, 16);
36 printf("Invalid block device %s\n", argv
[2]);
39 part
= (int)simple_strtoul(++ep
, NULL
, 16);
42 dev_desc
= blk_get_dev(argv
[1], dev
);
43 if (dev_desc
== NULL
) {
44 printf("Block device %s %d not supported\n", argv
[1], dev
);
48 addr
= (void *)simple_strtoul(argv
[3], NULL
, 16);
49 blk
= simple_strtoul(argv
[4], NULL
, 16);
50 cnt
= simple_strtoul(argv
[5], NULL
, 16);
53 if (part_get_info(dev_desc
, part
, &part_info
)) {
54 printf("Cannot find partition %d\n", part
);
57 offset
= part_info
.start
;
58 limit
= part_info
.size
;
60 /* Largest address not available in struct blk_desc. */
64 if (cnt
+ blk
> limit
) {
65 printf("Read out of range\n");
69 if (blk_dread(dev_desc
, offset
+ blk
, cnt
, addr
) != cnt
) {
70 printf("Error reading blocks\n");
79 "Load binary data from a partition",
80 "<interface> <dev[:part]> addr blk# cnt"