bdinfo.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 <mapmem.h>
  14. #include <net.h>
  15. #include <serial.h>
  16. #include <video.h>
  17. #include <vsprintf.h>
  18. #include <asm/cache.h>
  19. #include <asm/global_data.h>
  20. #include <display_options.h>
  21. DECLARE_GLOBAL_DATA_PTR;
  22. void bdinfo_print_size(const char *name, uint64_t size)
  23. {
  24. printf("%-12s= ", name);
  25. print_size(size, "\n");
  26. }
  27. void bdinfo_print_str(const char *name, const char *str)
  28. {
  29. printf("%-12s= %s\n", name, str);
  30. }
  31. void bdinfo_print_num_l(const char *name, ulong value)
  32. {
  33. printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
  34. }
  35. void bdinfo_print_num_ll(const char *name, unsigned long long value)
  36. {
  37. printf("%-12s= 0x%.*llx\n", name, 2 * (int)sizeof(ulong), value);
  38. }
  39. static void print_eth(void)
  40. {
  41. const int idx = eth_get_dev_index();
  42. uchar enetaddr[6];
  43. char name[10];
  44. int ret;
  45. if (idx)
  46. sprintf(name, "eth%iaddr", idx);
  47. else
  48. strcpy(name, "ethaddr");
  49. ret = eth_env_get_enetaddr_by_index("eth", idx, enetaddr);
  50. printf("current eth = %s\n", eth_get_name());
  51. if (!ret)
  52. printf("%-12s= (not set)\n", name);
  53. else
  54. printf("%-12s= %pM\n", name, enetaddr);
  55. printf("IP addr = %s\n", env_get("ipaddr"));
  56. }
  57. void bdinfo_print_mhz(const char *name, unsigned long hz)
  58. {
  59. char buf[32];
  60. printf("%-12s= %6s MHz\n", name, strmhz(buf, hz));
  61. }
  62. static void print_bi_dram(const struct bd_info *bd)
  63. {
  64. int i;
  65. for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
  66. if (bd->bi_dram[i].size) {
  67. bdinfo_print_num_l("DRAM bank", i);
  68. bdinfo_print_num_ll("-> start", bd->bi_dram[i].start);
  69. bdinfo_print_num_ll("-> size", bd->bi_dram[i].size);
  70. }
  71. }
  72. }
  73. __weak void arch_print_bdinfo(void)
  74. {
  75. }
  76. static void show_video_info(void)
  77. {
  78. const struct udevice *dev;
  79. struct uclass *uc;
  80. uclass_id_foreach_dev(UCLASS_VIDEO, dev, uc) {
  81. printf("%-12s= %s %sactive\n", "Video", dev->name,
  82. device_active(dev) ? "" : "in");
  83. if (device_active(dev)) {
  84. struct video_priv *upriv = dev_get_uclass_priv(dev);
  85. struct video_uc_plat *plat = dev_get_uclass_plat(dev);
  86. bdinfo_print_num_ll("FB base", (ulong)upriv->fb);
  87. if (upriv->copy_fb) {
  88. bdinfo_print_num_ll("FB copy",
  89. (ulong)upriv->copy_fb);
  90. bdinfo_print_num_l(" copy size",
  91. plat->copy_size);
  92. }
  93. printf("%-12s= %dx%dx%d\n", "FB size", upriv->xsize,
  94. upriv->ysize, 1 << upriv->bpix);
  95. }
  96. }
  97. }
  98. static void print_serial(struct udevice *dev)
  99. {
  100. struct serial_device_info info;
  101. int ret;
  102. if (!dev || !IS_ENABLED(CONFIG_DM_SERIAL))
  103. return;
  104. ret = serial_getinfo(dev, &info);
  105. if (ret)
  106. return;
  107. bdinfo_print_num_l("serial addr", info.addr);
  108. bdinfo_print_num_l(" width", info.reg_width);
  109. bdinfo_print_num_l(" shift", info.reg_shift);
  110. bdinfo_print_num_l(" offset", info.reg_offset);
  111. bdinfo_print_num_l(" clock", info.clock);
  112. }
  113. int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  114. {
  115. struct bd_info *bd = gd->bd;
  116. #ifdef DEBUG
  117. bdinfo_print_num_l("bd address", (ulong)bd);
  118. #endif
  119. bdinfo_print_num_l("boot_params", (ulong)bd->bi_boot_params);
  120. print_bi_dram(bd);
  121. if (IS_ENABLED(CONFIG_SYS_HAS_SRAM)) {
  122. bdinfo_print_num_l("sramstart", (ulong)bd->bi_sramstart);
  123. bdinfo_print_num_l("sramsize", (ulong)bd->bi_sramsize);
  124. }
  125. bdinfo_print_num_l("flashstart", (ulong)bd->bi_flashstart);
  126. bdinfo_print_num_l("flashsize", (ulong)bd->bi_flashsize);
  127. bdinfo_print_num_l("flashoffset", (ulong)bd->bi_flashoffset);
  128. printf("baudrate = %u bps\n", gd->baudrate);
  129. bdinfo_print_num_l("relocaddr", gd->relocaddr);
  130. bdinfo_print_num_l("reloc off", gd->reloc_off);
  131. printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8);
  132. if (IS_ENABLED(CONFIG_CMD_NET))
  133. print_eth();
  134. bdinfo_print_num_l("fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob));
  135. bdinfo_print_num_l("new_fdt", (ulong)map_to_sysmem(gd->new_fdt));
  136. bdinfo_print_num_l("fdt_size", (ulong)gd->fdt_size);
  137. if (IS_ENABLED(CONFIG_VIDEO))
  138. show_video_info();
  139. #if CONFIG_IS_ENABLED(MULTI_DTB_FIT)
  140. bdinfo_print_num_l("multi_dtb_fit", (ulong)gd->multi_dtb_fit);
  141. #endif
  142. if (IS_ENABLED(CONFIG_LMB) && gd->fdt_blob) {
  143. struct lmb lmb;
  144. lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
  145. lmb_dump_all_force(&lmb);
  146. if (IS_ENABLED(CONFIG_OF_REAL))
  147. printf("devicetree = %s\n", fdtdec_get_srcname());
  148. }
  149. print_serial(gd->cur_serial_dev);
  150. if (IS_ENABLED(CONFIG_CMD_BDINFO_EXTRA)) {
  151. bdinfo_print_num_ll("stack ptr", (ulong)&bd);
  152. bdinfo_print_num_ll("ram_top ptr", (ulong)gd->ram_top);
  153. bdinfo_print_num_l("malloc base", gd_malloc_start());
  154. }
  155. arch_print_bdinfo();
  156. return 0;
  157. }
  158. U_BOOT_CMD(
  159. bdinfo, 1, 1, do_bdinfo,
  160. "print Board Info structure",
  161. ""
  162. );