Linux kernel: /proc/iomem-like output to kernel log during boot

This post was written by eli on March 5, 2017
Posted Under: ARM,Linux,Linux kernel

In order to have something similar to /proc/iomem printed out to the console (and dmesg), this piece of code can be implanted somewhere in the kernel code (in my case it was arch/arm/mach-zynq/common.c). It may be required to add #include headers, depending on the file it’s added to.

The original code that produces /proc/iomem is at kernel/resource.c.

static struct resource *adhoc_next_resource(struct resource *p, bool sibling_only)
  /* Caller wants to traverse through siblings only */
  if (sibling_only)
    return p->sibling;

  if (p->child)
    return p->child;
  while (!p->sibling && p->parent)
    p = p->parent;
  return p->sibling;

static void print_iomem(void)
  struct resource *r = &iomem_resource;
  int width = r->end < 0x10000 ? 4 : 8;
  pr_info("iomem mapping:\n");
  while (r) {
    pr_info("%0*llx-%0*llx : %s\n",
             width, (unsigned long long) r->start,
	     width, (unsigned long long) r->end,
	     r->name ? r->name : "");
    r = adhoc_next_resource(r, false);

And then call print_iomem(). The output differs only from /proc/iomem in that it lacks the indentations representing the nesting of memory regions.

This was useful for me to get a snapshot during an early stage of Linux’ boot.

Add a Comment

required, use real name
required, will not be published
optional, your blog address