bdinfo.c 11 KB

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