]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - cmd/io.c
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012 The Chromium OS Authors.
7 * IO space access commands.
12 #include <display_options.h>
15 /* Display values from last command */
16 static ulong last_addr
, last_size
;
17 static ulong last_length
= 0x40;
18 static ulong base_address
;
20 #define DISP_LINE_LEN 16
26 * iod{.b, .w, .l} {addr}
28 int do_io_iod(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
30 ulong addr
, length
, bytes
;
31 u8 buf
[DISP_LINE_LEN
];
35 * We use the last specified parameters, unless new ones are
45 if ((flag
& CMD_FLAG_REPEAT
) == 0) {
47 * New command specified. Check for a size specification.
48 * Defaults to long if no or incorrect specification.
50 size
= cmd_get_data_size(argv
[0], 4);
54 /* Address is specified since argc > 1 */
55 addr
= hextoul(argv
[1], NULL
);
59 * If another parameter, it is the length to display.
60 * Length is the number of objects, not number of bytes.
63 length
= hextoul(argv
[2], NULL
);
66 bytes
= size
* length
;
69 for (; bytes
> 0; addr
+= todo
) {
73 todo
= min(bytes
, (ulong
)DISP_LINE_LEN
);
74 for (i
= 0; i
< todo
; i
+= size
, ptr
+= size
) {
76 *(u32
*)ptr
= inl(addr
+ i
);
78 *(u16
*)ptr
= inw(addr
+ i
);
82 print_buffer(addr
, buf
, size
, todo
/ size
,
83 DISP_LINE_LEN
/ size
);
94 int do_io_iow(struct cmd_tbl
*cmdtp
, int flag
, int argc
, char *const argv
[])
100 return CMD_RET_USAGE
;
102 size
= cmd_get_data_size(argv
[0], 4);
106 addr
= hextoul(argv
[1], NULL
);
107 val
= hextoul(argv
[2], NULL
);
110 outl((u32
) val
, addr
);
112 outw((u16
) val
, addr
);
114 outb((u8
) val
, addr
);
119 /**************************************************/
120 U_BOOT_CMD(iod
, 3, 1, do_io_iod
,
121 "IO space display", "[.b, .w, .l] address");
123 U_BOOT_CMD(iow
, 3, 0, do_io_iow
,
125 "[.b, .w, .l] address value");