hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
 * SPDX-License-Identifier:     GPL-2.0+
 *
 * (C) Copyright 2018 Rockchip Electronics Co., Ltd
 *
 */
 
#include <asm/io.h>
#include <common.h>
#include <dm.h>
#include <fdtdec.h>
 
enum ops {
   SEARCH_NAME,
   SEARCH_COMP,
};
 
void iomem_show(const char *label, unsigned long base, size_t start, size_t end)
{
   unsigned long val, offset = start, nr = 0;
 
   if (label)
       printf("%s:\n", label);
 
   printf("%08lx:  ", base + offset);
   for (offset = start; offset <= end; offset += 0x04) {
       if (nr >= 4) {
           printf("\n%08lx:  ", base + offset);
           nr = 0;
       }
       val = readl((void __iomem *)base + offset);
       printf("%08lx ", val);
       nr++;
   }
   printf("\n");
}
 
static int iomem_show_by_match(enum ops op, const char *search,
                  size_t start, size_t end)
{
   const void *fdt = gd->fdt_blob;
   const char *name;
   fdt_addr_t addr;
   int found = 0;
   int offset;
 
   for (offset = fdt_next_node(fdt, 0, NULL);
        offset >= 0;
        offset = fdt_next_node(fdt, offset, NULL)) {
       if (op == SEARCH_COMP)
           name = fdt_getprop(fdt, offset, "compatible", NULL);
       else if (op == SEARCH_NAME)
           name = fdt_get_name(fdt, offset, NULL);
       else
           goto out;
 
       if (!name)
           continue;
 
       if (strstr(name, search)) {
           addr = fdtdec_get_addr_size_auto_noparent(fdt, offset,
                           "reg", 0, NULL, false);
           if (addr == FDT_ADDR_T_NONE)
               goto out;
 
           iomem_show(name, addr, start, end);
           found = 1;
           break;
       }
   }
   printf("\n");
 
out:
   return found;
}
 
void iomem_show_by_compatible(const char *compat, size_t start, size_t end)
{
   iomem_show_by_match(SEARCH_COMP, compat, start, end);
}
 
static int do_iomem_by_match(cmd_tbl_t *cmdtp, int flag,
                int argc, char *const argv[])
{
   size_t start, end;
   const char *search;
 
   if (argc != 4)
       return CMD_RET_USAGE;
 
   search = argv[1];
   start = simple_strtoul(argv[2], NULL, 0);
   end = simple_strtoul(argv[3], NULL, 0);
   if (start > end) {
       printf("Invalid: 0x%lx > 0x%lx\n", (ulong)start, (ulong)end);
       return CMD_RET_FAILURE;
   }
 
   if (!iomem_show_by_match(SEARCH_COMP, search, start, end))
       iomem_show_by_match(SEARCH_NAME, search, start, end);
 
   return 0;
}
 
U_BOOT_CMD(
   iomem, 4, 1, do_iomem_by_match,
   "Show iomem data by device compatible(high priority) or node name",
   "iomem <compatible or node name> <start offset>  <end offset>\n"
   "  eg: iomem -grf  0x0 0x200"
   "  eg: iomem gpio3 0x0 0x200"
);