bdinfo.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Implements the 'bd' command to show board information
  4. *
  5. * (C) Copyright 2003
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <dm.h>
  11. #include <env.h>
  12. #include <lmb.h>
  13. #include <net.h>
  14. #include <video.h>
  15. #include <vsprintf.h>
  16. #include <asm/cache.h>
  17. DECLARE_GLOBAL_DATA_PTR;
  18. void bdinfo_print_num(const char *name, ulong value)
  19. {
  20. printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
  21. }
  22. static void print_eth(int idx)
  23. {
  24. char name[10], *val;
  25. if (idx)
  26. sprintf(name, "eth%iaddr", idx);
  27. else
  28. strcpy(name, "ethaddr");
  29. val = env_get(name);
  30. if (!val)
  31. val = "(not set)";
  32. printf("%-12s= %s\n", name, val);
  33. }
  34. static void print_phys_addr(const char *name, phys_addr_t value)
  35. {
  36. printf("%-12s= 0x%.*llx\n", name, 2 * (int)sizeof(ulong),
  37. (unsigned long long)value);
  38. }
  39. void bdinfo_print_mhz(const char *name, unsigned long hz)
  40. {
  41. char buf[32];
  42. printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
  43. }
  44. static void print_bi_dram(const struct bd_info *bd)
  45. {
  46. int i;
  47. for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
  48. if (bd->bi_dram[i].size) {
  49. bdinfo_print_num("DRAM bank", i);
  50. bdinfo_print_num("-> start", bd->bi_dram[i].start);
  51. bdinfo_print_num("-> size", bd->bi_dram[i].size);
  52. }
  53. }
  54. }
  55. __weak void arch_print_bdinfo(void)
  56. {
  57. }
  58. static void show_video_info(void)
  59. {
  60. const struct udevice *dev;
  61. struct uclass *uc;
  62. uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) {
  63. printf("%-12s= %s %sactive\n", "Video", dev->name,
  64. device_active(dev) ? "" : "in");
  65. if (device_active(dev)) {
  66. struct video_priv *upriv = dev_get_uclass_priv(dev);
  67. print_phys_addr("FB base", (ulong)upriv->fb);
  68. if (upriv->copy_fb)
  69. print_phys_addr("FB copy", (ulong)upriv->copy_fb);
  70. printf("%-12s= %dx%dx%d\n", "FB size", upriv->xsize,
  71. upriv->ysize, 1 << upriv->bpix);
  72. }
  73. }
  74. }
  75. int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  76. {
  77. struct bd_info *bd = gd->bd;
  78. #ifdef DEBUG
  79. bdinfo_print_num("bd address", (ulong)bd);
  80. #endif
  81. bdinfo_print_num("boot_params", (ulong)bd->bi_boot_params);
  82. print_bi_dram(bd);
  83. if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
  84. bdinfo_print_num("sramstart", (ulong)bd->bi_sramstart);
  85. bdinfo_print_num("sramsize", (ulong)bd->bi_sramsize);
  86. }
  87. bdinfo_print_num("flashstart", (ulong)bd->bi_flashstart);
  88. bdinfo_print_num("flashsize", (ulong)bd->bi_flashsize);
  89. bdinfo_print_num("flashoffset", (ulong)bd->bi_flashoffset);
  90. printf("baudrate = %u bps\n", gd->baudrate);
  91. bdinfo_print_num("relocaddr", gd->relocaddr);
  92. bdinfo_print_num("reloc off", gd->reloc_off);
  93. printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
  94. if (IS_ENABLED(CONFIG_CMD_NET)) {
  95. printf("current eth = %s\n", eth_get_name());
  96. print_eth(0);
  97. printf("IP addr = %s\n", env_get("ipaddr"));
  98. }
  99. bdinfo_print_num("fdt_blob", (ulong)gd->fdt_blob);
  100. bdinfo_print_num("new_fdt", (ulong)gd->new_fdt);
  101. bdinfo_print_num("fdt_size", (ulong)gd->fdt_size);
  102. if (IS_ENABLED(CONFIG_DM_VIDEO))
  103. show_video_info();
  104. #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
  105. bdinfo_print_num("FB base ", gd->fb_base);
  106. #endif
  107. #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  108. bdinfo_print_num("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
  109. #endif
  110. if (gd->fdt_blob) {
  111. struct lmb lmb;
  112. lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
  113. lmb_dump_all_force(&lmb);
  114. }
  115. arch_print_bdinfo();
  116. return 0;
  117. }
  118. U_BOOT_CMD(
  119. bdinfo, 1, 1, do_bdinfo,
  120. "print Board Info structure",
  121. ""
  122. );