bdinfo.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #include <asm/global_data.h>
  18. DECLARE_GLOBAL_DATA_PTR;
  19. void bdinfo_print_num_l(const char *name, ulong value)
  20. {
  21. printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
  22. }
  23. void bdinfo_print_num_ll(const char *name, unsigned long long value)
  24. {
  25. printf("%-12s= 0x%.*llx\n", name, 2 * (int)sizeof(ulong), value);
  26. }
  27. static void print_eth(int idx)
  28. {
  29. char name[10], *val;
  30. if (idx)
  31. sprintf(name, "eth%iaddr", idx);
  32. else
  33. strcpy(name, "ethaddr");
  34. val = env_get(name);
  35. if (!val)
  36. val = "(not set)";
  37. printf("%-12s= %s\n", name, val);
  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_l("DRAM bank", i);
  50. bdinfo_print_num_ll("-> start", bd->bi_dram[i].start);
  51. bdinfo_print_num_ll("-> 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. bdinfo_print_num_ll("FB base", (ulong)upriv->fb);
  68. if (upriv->copy_fb)
  69. bdinfo_print_num_ll("FB copy",
  70. (ulong)upriv->copy_fb);
  71. printf("%-12s= %dx%dx%d\n", "FB size", upriv->xsize,
  72. upriv->ysize, 1 << upriv->bpix);
  73. }
  74. }
  75. }
  76. int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  77. {
  78. struct bd_info *bd = gd->bd;
  79. #ifdef DEBUG
  80. bdinfo_print_num_l("bd address", (ulong)bd);
  81. #endif
  82. bdinfo_print_num_l("boot_params", (ulong)bd->bi_boot_params);
  83. print_bi_dram(bd);
  84. if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
  85. bdinfo_print_num_l("sramstart", (ulong)bd->bi_sramstart);
  86. bdinfo_print_num_l("sramsize", (ulong)bd->bi_sramsize);
  87. }
  88. bdinfo_print_num_l("flashstart", (ulong)bd->bi_flashstart);
  89. bdinfo_print_num_l("flashsize", (ulong)bd->bi_flashsize);
  90. bdinfo_print_num_l("flashoffset", (ulong)bd->bi_flashoffset);
  91. printf("baudrate = %u bps\n", gd->baudrate);
  92. bdinfo_print_num_l("relocaddr", gd->relocaddr);
  93. bdinfo_print_num_l("reloc off", gd->reloc_off);
  94. printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
  95. if (IS_ENABLED(CONFIG_CMD_NET)) {
  96. printf("current eth = %s\n", eth_get_name());
  97. print_eth(0);
  98. printf("IP addr = %s\n", env_get("ipaddr"));
  99. }
  100. bdinfo_print_num_l("fdt_blob", (ulong)gd->fdt_blob);
  101. bdinfo_print_num_l("new_fdt", (ulong)gd->new_fdt);
  102. bdinfo_print_num_l("fdt_size", (ulong)gd->fdt_size);
  103. if (IS_ENABLED(CONFIG_DM_VIDEO))
  104. show_video_info();
  105. #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
  106. bdinfo_print_num_l("FB base ", gd->fb_base);
  107. #endif
  108. #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  109. bdinfo_print_num_l("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
  110. #endif
  111. if (gd->fdt_blob) {
  112. struct lmb lmb;
  113. lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
  114. lmb_dump_all_force(&lmb);
  115. }
  116. arch_print_bdinfo();
  117. return 0;
  118. }
  119. U_BOOT_CMD(
  120. bdinfo, 1, 1, do_bdinfo,
  121. "print Board Info structure",
  122. ""
  123. );