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
16 int do_read(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
19 struct blk_desc *dev_desc = NULL;
22 struct disk_partition part_info;
34 dev = (int)hextoul(argv[2], &ep);
37 printf("Invalid block device %s\n", argv[2]);
40 part = (int)hextoul(++ep, NULL);
43 dev_desc = blk_get_dev(argv[1], dev);
44 if (dev_desc == NULL) {
45 printf("Block device %s %d not supported\n", argv[1], dev);
49 addr = map_sysmem(hextoul(argv[3], NULL), 0);
50 blk = hextoul(argv[4], NULL);
51 cnt = hextoul(argv[5], NULL);
54 if (part_get_info(dev_desc, part, &part_info)) {
55 printf("Cannot find partition %d\n", part);
58 offset = part_info.start;
59 limit = part_info.size;
61 /* Largest address not available in struct blk_desc. */
65 if (cnt + blk > limit) {
66 printf("Read out of range\n");
70 if (blk_dread(dev_desc, offset + blk, cnt, addr) != cnt) {
71 printf("Error reading blocks\n");
80 "Load binary data from a partition",
81 "<interface> <dev[:part]> addr blk# cnt"