bdinfo.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. */
  6. /*
  7. * Boot support
  8. */
  9. #include <common.h>
  10. #include <command.h>
  11. #include <env.h>
  12. #include <vsprintf.h>
  13. #include <linux/compiler.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. __maybe_unused
  16. static void print_num(const char *name, ulong value)
  17. {
  18. printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
  19. }
  20. __maybe_unused
  21. static void print_eth(int idx)
  22. {
  23. char name[10], *val;
  24. if (idx)
  25. sprintf(name, "eth%iaddr", idx);
  26. else
  27. strcpy(name, "ethaddr");
  28. val = env_get(name);
  29. if (!val)
  30. val = "(not set)";
  31. printf("%-12s= %s\n", name, val);
  32. }
  33. #ifndef CONFIG_DM_ETH
  34. __maybe_unused
  35. static void print_eths(void)
  36. {
  37. struct eth_device *dev;
  38. int i = 0;
  39. do {
  40. dev = eth_get_dev_by_index(i);
  41. if (dev) {
  42. printf("eth%dname = %s\n", i, dev->name);
  43. print_eth(i);
  44. i++;
  45. }
  46. } while (dev);
  47. printf("current eth = %s\n", eth_get_name());
  48. printf("ip_addr = %s\n", env_get("ipaddr"));
  49. }
  50. #endif
  51. __maybe_unused
  52. static void print_lnum(const char *name, unsigned long long value)
  53. {
  54. printf("%-12s= 0x%.8llX\n", name, value);
  55. }
  56. __maybe_unused
  57. static void 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 inline void print_bi_boot_params(const bd_t *bd)
  63. {
  64. print_num("boot_params", (ulong)bd->bi_boot_params);
  65. }
  66. static inline void print_bi_mem(const bd_t *bd)
  67. {
  68. #if defined(CONFIG_SH)
  69. print_num("mem start ", (ulong)bd->bi_memstart);
  70. print_lnum("mem size ", (u64)bd->bi_memsize);
  71. #elif defined(CONFIG_ARC)
  72. print_num("mem start", (ulong)bd->bi_memstart);
  73. print_lnum("mem size", (u64)bd->bi_memsize);
  74. #else
  75. print_num("memstart", (ulong)bd->bi_memstart);
  76. print_lnum("memsize", (u64)bd->bi_memsize);
  77. #endif
  78. }
  79. static inline void print_bi_dram(const bd_t *bd)
  80. {
  81. #ifdef CONFIG_NR_DRAM_BANKS
  82. int i;
  83. for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
  84. if (bd->bi_dram[i].size) {
  85. print_num("DRAM bank", i);
  86. print_num("-> start", bd->bi_dram[i].start);
  87. print_num("-> size", bd->bi_dram[i].size);
  88. }
  89. }
  90. #endif
  91. }
  92. static inline void print_bi_flash(const bd_t *bd)
  93. {
  94. #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_SH)
  95. print_num("flash start ", (ulong)bd->bi_flashstart);
  96. print_num("flash size ", (ulong)bd->bi_flashsize);
  97. print_num("flash offset ", (ulong)bd->bi_flashoffset);
  98. #elif defined(CONFIG_NIOS2)
  99. print_num("flash start", (ulong)bd->bi_flashstart);
  100. print_num("flash size", (ulong)bd->bi_flashsize);
  101. print_num("flash offset", (ulong)bd->bi_flashoffset);
  102. #else
  103. print_num("flashstart", (ulong)bd->bi_flashstart);
  104. print_num("flashsize", (ulong)bd->bi_flashsize);
  105. print_num("flashoffset", (ulong)bd->bi_flashoffset);
  106. #endif
  107. }
  108. static inline void print_eth_ip_addr(void)
  109. {
  110. #if defined(CONFIG_CMD_NET)
  111. print_eth(0);
  112. #if defined(CONFIG_HAS_ETH1)
  113. print_eth(1);
  114. #endif
  115. #if defined(CONFIG_HAS_ETH2)
  116. print_eth(2);
  117. #endif
  118. #if defined(CONFIG_HAS_ETH3)
  119. print_eth(3);
  120. #endif
  121. #if defined(CONFIG_HAS_ETH4)
  122. print_eth(4);
  123. #endif
  124. #if defined(CONFIG_HAS_ETH5)
  125. print_eth(5);
  126. #endif
  127. printf("IP addr = %s\n", env_get("ipaddr"));
  128. #endif
  129. }
  130. static inline void print_baudrate(void)
  131. {
  132. #if defined(CONFIG_PPC)
  133. printf("baudrate = %6u bps\n", gd->baudrate);
  134. #else
  135. printf("baudrate = %u bps\n", gd->baudrate);
  136. #endif
  137. }
  138. static inline void __maybe_unused print_std_bdinfo(const bd_t *bd)
  139. {
  140. print_bi_boot_params(bd);
  141. print_bi_mem(bd);
  142. print_bi_flash(bd);
  143. print_eth_ip_addr();
  144. print_baudrate();
  145. }
  146. #if defined(CONFIG_PPC)
  147. void __weak board_detail(void)
  148. {
  149. /* Please define board_detail() for your platform */
  150. }
  151. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  152. {
  153. bd_t *bd = gd->bd;
  154. #ifdef DEBUG
  155. print_num("bd address", (ulong)bd);
  156. #endif
  157. print_bi_mem(bd);
  158. print_bi_flash(bd);
  159. print_num("sramstart", bd->bi_sramstart);
  160. print_num("sramsize", bd->bi_sramsize);
  161. #if defined(CONFIG_MPC8xx) || defined(CONFIG_E500)
  162. print_num("immr_base", bd->bi_immr_base);
  163. #endif
  164. print_num("bootflags", bd->bi_bootflags);
  165. #if defined(CONFIG_CPM2)
  166. print_mhz("vco", bd->bi_vco);
  167. print_mhz("sccfreq", bd->bi_sccfreq);
  168. print_mhz("brgfreq", bd->bi_brgfreq);
  169. #endif
  170. print_mhz("intfreq", bd->bi_intfreq);
  171. #if defined(CONFIG_CPM2)
  172. print_mhz("cpmfreq", bd->bi_cpmfreq);
  173. #endif
  174. print_mhz("busfreq", bd->bi_busfreq);
  175. #ifdef CONFIG_ENABLE_36BIT_PHYS
  176. #ifdef CONFIG_PHYS_64BIT
  177. puts("addressing = 36-bit\n");
  178. #else
  179. puts("addressing = 32-bit\n");
  180. #endif
  181. #endif
  182. print_eth_ip_addr();
  183. print_baudrate();
  184. print_num("relocaddr", gd->relocaddr);
  185. board_detail();
  186. return 0;
  187. }
  188. #elif defined(CONFIG_NIOS2)
  189. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  190. {
  191. bd_t *bd = gd->bd;
  192. print_bi_dram(bd);
  193. print_bi_flash(bd);
  194. #if defined(CONFIG_SYS_SRAM_BASE)
  195. print_num ("sram start", (ulong)bd->bi_sramstart);
  196. print_num ("sram size", (ulong)bd->bi_sramsize);
  197. #endif
  198. print_eth_ip_addr();
  199. print_baudrate();
  200. return 0;
  201. }
  202. #elif defined(CONFIG_MICROBLAZE)
  203. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  204. {
  205. bd_t *bd = gd->bd;
  206. print_bi_dram(bd);
  207. print_bi_flash(bd);
  208. #if defined(CONFIG_SYS_SRAM_BASE)
  209. print_num("sram start ", (ulong)bd->bi_sramstart);
  210. print_num("sram size ", (ulong)bd->bi_sramsize);
  211. #endif
  212. #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
  213. print_eths();
  214. #endif
  215. print_baudrate();
  216. print_num("relocaddr", gd->relocaddr);
  217. print_num("reloc off", gd->reloc_off);
  218. print_num("fdt_blob", (ulong)gd->fdt_blob);
  219. print_num("new_fdt", (ulong)gd->new_fdt);
  220. print_num("fdt_size", (ulong)gd->fdt_size);
  221. return 0;
  222. }
  223. #elif defined(CONFIG_M68K)
  224. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  225. {
  226. bd_t *bd = gd->bd;
  227. print_bi_mem(bd);
  228. print_bi_flash(bd);
  229. #if defined(CONFIG_SYS_INIT_RAM_ADDR)
  230. print_num("sramstart", (ulong)bd->bi_sramstart);
  231. print_num("sramsize", (ulong)bd->bi_sramsize);
  232. #endif
  233. #if defined(CONFIG_SYS_MBAR)
  234. print_num("mbar", bd->bi_mbar_base);
  235. #endif
  236. print_mhz("cpufreq", bd->bi_intfreq);
  237. print_mhz("busfreq", bd->bi_busfreq);
  238. #ifdef CONFIG_PCI
  239. print_mhz("pcifreq", bd->bi_pcifreq);
  240. #endif
  241. #ifdef CONFIG_EXTRA_CLOCK
  242. print_mhz("flbfreq", bd->bi_flbfreq);
  243. print_mhz("inpfreq", bd->bi_inpfreq);
  244. print_mhz("vcofreq", bd->bi_vcofreq);
  245. #endif
  246. print_eth_ip_addr();
  247. print_baudrate();
  248. return 0;
  249. }
  250. #elif defined(CONFIG_MIPS)
  251. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  252. {
  253. print_std_bdinfo(gd->bd);
  254. print_num("relocaddr", gd->relocaddr);
  255. print_num("reloc off", gd->reloc_off);
  256. return 0;
  257. }
  258. #elif defined(CONFIG_ARM)
  259. static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc,
  260. char * const argv[])
  261. {
  262. bd_t *bd = gd->bd;
  263. print_num("arch_number", bd->bi_arch_number);
  264. print_bi_boot_params(bd);
  265. print_bi_dram(bd);
  266. #ifdef CONFIG_SYS_MEM_RESERVE_SECURE
  267. if (gd->arch.secure_ram & MEM_RESERVE_SECURE_SECURED) {
  268. print_num("Secure ram",
  269. gd->arch.secure_ram & MEM_RESERVE_SECURE_ADDR_MASK);
  270. }
  271. #endif
  272. #ifdef CONFIG_RESV_RAM
  273. if (gd->arch.resv_ram)
  274. print_num("Reserved ram", gd->arch.resv_ram);
  275. #endif
  276. #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
  277. print_eths();
  278. #endif
  279. print_baudrate();
  280. #if !(CONFIG_IS_ENABLED(SYS_ICACHE_OFF) && CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
  281. print_num("TLB addr", gd->arch.tlb_addr);
  282. #endif
  283. print_num("relocaddr", gd->relocaddr);
  284. print_num("reloc off", gd->reloc_off);
  285. print_num("irq_sp", gd->irq_sp); /* irq stack pointer */
  286. print_num("sp start ", gd->start_addr_sp);
  287. #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) || defined(CONFIG_DM_VIDEO)
  288. print_num("FB base ", gd->fb_base);
  289. #endif
  290. /*
  291. * TODO: Currently only support for davinci SOC's is added.
  292. * Remove this check once all the board implement this.
  293. */
  294. #ifdef CONFIG_CLOCKS
  295. printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq);
  296. printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq);
  297. printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq);
  298. #endif
  299. #ifdef CONFIG_BOARD_TYPES
  300. printf("Board Type = %ld\n", gd->board_type);
  301. #endif
  302. #if CONFIG_VAL(SYS_MALLOC_F_LEN)
  303. printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr,
  304. CONFIG_VAL(SYS_MALLOC_F_LEN));
  305. #endif
  306. if (gd->fdt_blob)
  307. print_num("fdt_blob", (ulong)gd->fdt_blob);
  308. return 0;
  309. }
  310. #elif defined(CONFIG_SH)
  311. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  312. {
  313. bd_t *bd = gd->bd;
  314. print_bi_mem(bd);
  315. print_bi_flash(bd);
  316. print_eth_ip_addr();
  317. print_baudrate();
  318. return 0;
  319. }
  320. #elif defined(CONFIG_X86)
  321. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  322. {
  323. bd_t *bd = gd->bd;
  324. print_bi_boot_params(bd);
  325. print_bi_dram(bd);
  326. print_num("relocaddr", gd->relocaddr);
  327. print_num("reloc off", gd->reloc_off);
  328. #if defined(CONFIG_CMD_NET)
  329. print_eth_ip_addr();
  330. print_mhz("ethspeed", bd->bi_ethspeed);
  331. #endif
  332. print_baudrate();
  333. return 0;
  334. }
  335. #elif defined(CONFIG_SANDBOX)
  336. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  337. {
  338. bd_t *bd = gd->bd;
  339. print_bi_boot_params(bd);
  340. print_bi_dram(bd);
  341. print_eth_ip_addr();
  342. #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO)
  343. print_num("FB base ", gd->fb_base);
  344. #endif
  345. return 0;
  346. }
  347. #elif defined(CONFIG_NDS32)
  348. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  349. {
  350. bd_t *bd = gd->bd;
  351. print_num("arch_number", bd->bi_arch_number);
  352. print_bi_boot_params(bd);
  353. print_bi_dram(bd);
  354. print_eth_ip_addr();
  355. print_baudrate();
  356. return 0;
  357. }
  358. #elif defined(CONFIG_RISCV)
  359. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  360. {
  361. bd_t *bd = gd->bd;
  362. print_bi_boot_params(bd);
  363. print_bi_dram(bd);
  364. print_num("relocaddr", gd->relocaddr);
  365. print_num("reloc off", gd->reloc_off);
  366. print_eth_ip_addr();
  367. print_baudrate();
  368. return 0;
  369. }
  370. #elif defined(CONFIG_ARC)
  371. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  372. {
  373. bd_t *bd = gd->bd;
  374. print_bi_mem(bd);
  375. print_eth_ip_addr();
  376. print_baudrate();
  377. return 0;
  378. }
  379. #elif defined(CONFIG_XTENSA)
  380. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  381. {
  382. print_std_bdinfo(gd->bd);
  383. return 0;
  384. }
  385. #elif defined(CONFIG_CSKY)
  386. int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  387. {
  388. print_std_bdinfo(gd->bd);
  389. return 0;
  390. }
  391. #else
  392. #error "a case for this architecture does not exist!"
  393. #endif
  394. /* -------------------------------------------------------------------- */
  395. U_BOOT_CMD(
  396. bdinfo, 1, 1, do_bdinfo,
  397. "print Board Info structure",
  398. ""
  399. );