1 /* 2 * (C) Copyright 2003 3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 /* 9 * Boot support 10 */ 11 #include <common.h> 12 #include <command.h> 13 #include <linux/compiler.h> 14 15 DECLARE_GLOBAL_DATA_PTR; 16 17 __maybe_unused 18 static void print_num(const char *name, ulong value) 19 { 20 printf("%-12s= 0x%08lX\n", name, value); 21 } 22 23 __maybe_unused 24 static void print_eth(int idx) 25 { 26 char name[10], *val; 27 if (idx) 28 sprintf(name, "eth%iaddr", idx); 29 else 30 strcpy(name, "ethaddr"); 31 val = getenv(name); 32 if (!val) 33 val = "(not set)"; 34 printf("%-12s= %s\n", name, val); 35 } 36 37 #ifndef CONFIG_DM_ETH 38 __maybe_unused 39 static void print_eths(void) 40 { 41 struct eth_device *dev; 42 int i = 0; 43 44 do { 45 dev = eth_get_dev_by_index(i); 46 if (dev) { 47 printf("eth%dname = %s\n", i, dev->name); 48 print_eth(i); 49 i++; 50 } 51 } while (dev); 52 53 printf("current eth = %s\n", eth_get_name()); 54 printf("ip_addr = %s\n", getenv("ipaddr")); 55 } 56 #endif 57 58 __maybe_unused 59 static void print_lnum(const char *name, unsigned long long value) 60 { 61 printf("%-12s= 0x%.8llX\n", name, value); 62 } 63 64 __maybe_unused 65 static void print_mhz(const char *name, unsigned long hz) 66 { 67 char buf[32]; 68 69 printf("%-12s= %6s MHz\n", name, strmhz(buf, hz)); 70 } 71 72 73 static inline void print_bi_boot_params(const bd_t *bd) 74 { 75 print_num("boot_params", (ulong)bd->bi_boot_params); 76 } 77 78 static inline void print_bi_mem(const bd_t *bd) 79 { 80 #if defined(CONFIG_SH) 81 print_num("mem start ", (ulong)bd->bi_memstart); 82 print_lnum("mem size ", (u64)bd->bi_memsize); 83 #elif defined(CONFIG_ARC) 84 print_num("mem start", (ulong)bd->bi_memstart); 85 print_lnum("mem size", (u64)bd->bi_memsize); 86 #elif defined(CONFIG_AVR32) 87 print_num("memstart", (ulong)bd->bi_dram[0].start); 88 print_lnum("memsize", (u64)bd->bi_dram[0].size); 89 #else 90 print_num("memstart", (ulong)bd->bi_memstart); 91 print_lnum("memsize", (u64)bd->bi_memsize); 92 #endif 93 } 94 95 static inline void print_bi_dram(const bd_t *bd) 96 { 97 #ifdef CONFIG_NR_DRAM_BANKS 98 int i; 99 100 for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { 101 if (bd->bi_dram[i].size) { 102 print_num("DRAM bank", i); 103 print_num("-> start", bd->bi_dram[i].start); 104 print_num("-> size", bd->bi_dram[i].size); 105 } 106 } 107 #endif 108 } 109 110 static inline void print_bi_flash(const bd_t *bd) 111 { 112 #if defined(CONFIG_MICROBLAZE) || defined(CONFIG_SH) 113 print_num("flash start ", (ulong)bd->bi_flashstart); 114 print_num("flash size ", (ulong)bd->bi_flashsize); 115 print_num("flash offset ", (ulong)bd->bi_flashoffset); 116 117 #elif defined(CONFIG_NIOS2) || defined(CONFIG_OPENRISC) 118 print_num("flash start", (ulong)bd->bi_flashstart); 119 print_num("flash size", (ulong)bd->bi_flashsize); 120 print_num("flash offset", (ulong)bd->bi_flashoffset); 121 #else 122 print_num("flashstart", (ulong)bd->bi_flashstart); 123 print_num("flashsize", (ulong)bd->bi_flashsize); 124 print_num("flashoffset", (ulong)bd->bi_flashoffset); 125 #endif 126 } 127 128 static inline void print_eth_ip_addr(void) 129 { 130 #if defined(CONFIG_CMD_NET) 131 print_eth(0); 132 #if defined(CONFIG_HAS_ETH1) 133 print_eth(1); 134 #endif 135 #if defined(CONFIG_HAS_ETH2) 136 print_eth(2); 137 #endif 138 #if defined(CONFIG_HAS_ETH3) 139 print_eth(3); 140 #endif 141 #if defined(CONFIG_HAS_ETH4) 142 print_eth(4); 143 #endif 144 #if defined(CONFIG_HAS_ETH5) 145 print_eth(5); 146 #endif 147 printf("IP addr = %s\n", getenv("ipaddr")); 148 #endif 149 } 150 151 static inline void print_baudrate(void) 152 { 153 #if defined(CONFIG_PPC) 154 printf("baudrate = %6u bps\n", gd->baudrate); 155 #elif defined(CONFIG_SPARC) 156 printf("baudrate = %6u bps\n", gd->baudrate); 157 #else 158 printf("baudrate = %u bps\n", gd->baudrate); 159 #endif 160 } 161 162 static inline void print_std_bdinfo(const bd_t *bd) 163 { 164 print_bi_boot_params(bd); 165 print_bi_mem(bd); 166 print_bi_flash(bd); 167 print_eth_ip_addr(); 168 print_baudrate(); 169 } 170 171 #if defined(CONFIG_PPC) 172 void __weak board_detail(void) 173 { 174 /* Please define boot_detail() for your platform */ 175 } 176 177 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 178 { 179 bd_t *bd = gd->bd; 180 181 #ifdef DEBUG 182 print_num("bd address", (ulong)bd); 183 #endif 184 print_bi_mem(bd); 185 print_bi_flash(bd); 186 print_num("sramstart", bd->bi_sramstart); 187 print_num("sramsize", bd->bi_sramsize); 188 #if defined(CONFIG_5xx) || defined(CONFIG_8xx) || \ 189 defined(CONFIG_MPC8260) || defined(CONFIG_E500) 190 print_num("immr_base", bd->bi_immr_base); 191 #endif 192 print_num("bootflags", bd->bi_bootflags); 193 #if defined(CONFIG_405EP) || \ 194 defined(CONFIG_405GP) || \ 195 defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \ 196 defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \ 197 defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \ 198 defined(CONFIG_XILINX_405) 199 print_mhz("procfreq", bd->bi_procfreq); 200 print_mhz("plb_busfreq", bd->bi_plb_busfreq); 201 #if defined(CONFIG_405EP) || defined(CONFIG_405GP) || \ 202 defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \ 203 defined(CONFIG_440GR) || defined(CONFIG_440GRX) || \ 204 defined(CONFIG_440SPE) || defined(CONFIG_XILINX_405) 205 print_mhz("pci_busfreq", bd->bi_pci_busfreq); 206 #endif 207 #else /* ! CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */ 208 #if defined(CONFIG_CPM2) 209 print_mhz("vco", bd->bi_vco); 210 print_mhz("sccfreq", bd->bi_sccfreq); 211 print_mhz("brgfreq", bd->bi_brgfreq); 212 #endif 213 print_mhz("intfreq", bd->bi_intfreq); 214 #if defined(CONFIG_CPM2) 215 print_mhz("cpmfreq", bd->bi_cpmfreq); 216 #endif 217 print_mhz("busfreq", bd->bi_busfreq); 218 #endif /* CONFIG_405GP, CONFIG_405EP, CONFIG_XILINX_405, CONFIG_440EP CONFIG_440GR */ 219 220 #ifdef CONFIG_ENABLE_36BIT_PHYS 221 #ifdef CONFIG_PHYS_64BIT 222 puts("addressing = 36-bit\n"); 223 #else 224 puts("addressing = 32-bit\n"); 225 #endif 226 #endif 227 228 print_eth_ip_addr(); 229 print_baudrate(); 230 print_num("relocaddr", gd->relocaddr); 231 board_detail(); 232 return 0; 233 } 234 235 #elif defined(CONFIG_NIOS2) 236 237 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 238 { 239 bd_t *bd = gd->bd; 240 241 print_bi_dram(bd); 242 print_bi_flash(bd); 243 244 #if defined(CONFIG_SYS_SRAM_BASE) 245 print_num ("sram start", (ulong)bd->bi_sramstart); 246 print_num ("sram size", (ulong)bd->bi_sramsize); 247 #endif 248 249 print_eth_ip_addr(); 250 print_baudrate(); 251 252 return 0; 253 } 254 255 #elif defined(CONFIG_MICROBLAZE) 256 257 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 258 { 259 bd_t *bd = gd->bd; 260 261 print_bi_dram(bd); 262 print_bi_flash(bd); 263 #if defined(CONFIG_SYS_SRAM_BASE) 264 print_num("sram start ", (ulong)bd->bi_sramstart); 265 print_num("sram size ", (ulong)bd->bi_sramsize); 266 #endif 267 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH) 268 print_eths(); 269 #endif 270 print_baudrate(); 271 print_num("relocaddr", gd->relocaddr); 272 print_num("reloc off", gd->reloc_off); 273 print_num("fdt_blob", (ulong)gd->fdt_blob); 274 print_num("new_fdt", (ulong)gd->new_fdt); 275 print_num("fdt_size", (ulong)gd->fdt_size); 276 277 return 0; 278 } 279 280 #elif defined(CONFIG_SPARC) 281 282 int do_bdinfo(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) 283 { 284 bd_t *bd = gd->bd; 285 286 #ifdef DEBUG 287 print_num("bd address ", (ulong) bd); 288 #endif 289 print_num("memstart ", bd->bi_memstart); 290 print_lnum("memsize ", bd->bi_memsize); 291 print_num("flashstart ", bd->bi_flashstart); 292 print_num("CONFIG_SYS_MONITOR_BASE ", CONFIG_SYS_MONITOR_BASE); 293 print_num("CONFIG_ENV_ADDR ", CONFIG_ENV_ADDR); 294 printf("CONFIG_SYS_RELOC_MONITOR_BASE = 0x%x (%d)\n", CONFIG_SYS_RELOC_MONITOR_BASE, 295 CONFIG_SYS_MONITOR_LEN); 296 printf("CONFIG_SYS_MALLOC_BASE = 0x%x (%d)\n", CONFIG_SYS_MALLOC_BASE, 297 CONFIG_SYS_MALLOC_LEN); 298 printf("CONFIG_SYS_INIT_SP_OFFSET = 0x%x (%d)\n", CONFIG_SYS_INIT_SP_OFFSET, 299 CONFIG_SYS_STACK_SIZE); 300 printf("CONFIG_SYS_PROM_OFFSET = 0x%x (%d)\n", CONFIG_SYS_PROM_OFFSET, 301 CONFIG_SYS_PROM_SIZE); 302 printf("CONFIG_SYS_GBL_DATA_OFFSET = 0x%x (%d)\n", CONFIG_SYS_GBL_DATA_OFFSET, 303 GENERATED_GBL_DATA_SIZE); 304 305 print_eth_ip_addr(); 306 print_baudrate(); 307 return 0; 308 } 309 310 #elif defined(CONFIG_M68K) 311 312 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 313 { 314 bd_t *bd = gd->bd; 315 316 print_bi_mem(bd); 317 print_bi_flash(bd); 318 #if defined(CONFIG_SYS_INIT_RAM_ADDR) 319 print_num("sramstart", (ulong)bd->bi_sramstart); 320 print_num("sramsize", (ulong)bd->bi_sramsize); 321 #endif 322 #if defined(CONFIG_SYS_MBAR) 323 print_num("mbar", bd->bi_mbar_base); 324 #endif 325 print_mhz("cpufreq", bd->bi_intfreq); 326 print_mhz("busfreq", bd->bi_busfreq); 327 #ifdef CONFIG_PCI 328 print_mhz("pcifreq", bd->bi_pcifreq); 329 #endif 330 #ifdef CONFIG_EXTRA_CLOCK 331 print_mhz("flbfreq", bd->bi_flbfreq); 332 print_mhz("inpfreq", bd->bi_inpfreq); 333 print_mhz("vcofreq", bd->bi_vcofreq); 334 #endif 335 print_eth_ip_addr(); 336 print_baudrate(); 337 338 return 0; 339 } 340 341 #elif defined(CONFIG_BLACKFIN) 342 343 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 344 { 345 bd_t *bd = gd->bd; 346 347 printf("U-Boot = %s\n", bd->bi_r_version); 348 printf("CPU = %s\n", bd->bi_cpu); 349 printf("Board = %s\n", bd->bi_board_name); 350 print_mhz("VCO", bd->bi_vco); 351 print_mhz("CCLK", bd->bi_cclk); 352 print_mhz("SCLK", bd->bi_sclk); 353 354 print_std_bdinfo(bd); 355 356 return 0; 357 } 358 359 #elif defined(CONFIG_MIPS) 360 361 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 362 { 363 print_std_bdinfo(gd->bd); 364 print_num("relocaddr", gd->relocaddr); 365 print_num("reloc off", gd->reloc_off); 366 367 return 0; 368 } 369 370 #elif defined(CONFIG_AVR32) 371 372 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 373 { 374 print_std_bdinfo(gd->bd); 375 return 0; 376 } 377 378 #elif defined(CONFIG_ARM) 379 380 static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, 381 char * const argv[]) 382 { 383 bd_t *bd = gd->bd; 384 385 print_num("arch_number", bd->bi_arch_number); 386 print_bi_boot_params(bd); 387 print_bi_dram(bd); 388 389 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE 390 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_SECURED) { 391 print_num("Secure ram", 392 gd->arch.secure_ram & MEM_RESERVE_SECURE_ADDR_MASK); 393 } 394 #endif 395 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH) 396 print_eths(); 397 #endif 398 print_baudrate(); 399 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) 400 print_num("TLB addr", gd->arch.tlb_addr); 401 #endif 402 print_num("relocaddr", gd->relocaddr); 403 print_num("reloc off", gd->reloc_off); 404 print_num("irq_sp", gd->irq_sp); /* irq stack pointer */ 405 print_num("sp start ", gd->start_addr_sp); 406 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) 407 print_num("FB base ", gd->fb_base); 408 #endif 409 /* 410 * TODO: Currently only support for davinci SOC's is added. 411 * Remove this check once all the board implement this. 412 */ 413 #ifdef CONFIG_CLOCKS 414 printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq); 415 printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq); 416 printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq); 417 #endif 418 #ifdef CONFIG_BOARD_TYPES 419 printf("Board Type = %ld\n", gd->board_type); 420 #endif 421 #ifdef CONFIG_SYS_MALLOC_F 422 printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr, 423 CONFIG_SYS_MALLOC_F_LEN); 424 #endif 425 426 return 0; 427 } 428 429 #elif defined(CONFIG_SH) 430 431 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 432 { 433 bd_t *bd = gd->bd; 434 435 print_bi_mem(bd); 436 print_bi_flash(bd); 437 print_eth_ip_addr(); 438 print_baudrate(); 439 return 0; 440 } 441 442 #elif defined(CONFIG_X86) 443 444 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 445 { 446 bd_t *bd = gd->bd; 447 448 print_bi_boot_params(bd); 449 450 print_bi_dram(bd); 451 452 #if defined(CONFIG_CMD_NET) 453 print_eth_ip_addr(); 454 print_mhz("ethspeed", bd->bi_ethspeed); 455 #endif 456 print_baudrate(); 457 458 return 0; 459 } 460 461 #elif defined(CONFIG_SANDBOX) 462 463 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 464 { 465 bd_t *bd = gd->bd; 466 467 print_bi_boot_params(bd); 468 print_bi_dram(bd); 469 print_eth_ip_addr(); 470 471 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) 472 print_num("FB base ", gd->fb_base); 473 #endif 474 return 0; 475 } 476 477 #elif defined(CONFIG_NDS32) 478 479 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 480 { 481 bd_t *bd = gd->bd; 482 483 print_num("arch_number", bd->bi_arch_number); 484 print_bi_boot_params(bd); 485 print_bi_dram(bd); 486 print_eth_ip_addr(); 487 print_baudrate(); 488 489 return 0; 490 } 491 492 #elif defined(CONFIG_OPENRISC) 493 494 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 495 { 496 bd_t *bd = gd->bd; 497 498 print_bi_mem(bd); 499 print_bi_flash(bd); 500 print_eth_ip_addr(); 501 print_baudrate(); 502 503 return 0; 504 } 505 506 #elif defined(CONFIG_ARC) 507 508 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 509 { 510 bd_t *bd = gd->bd; 511 512 print_bi_mem(bd); 513 print_eth_ip_addr(); 514 print_baudrate(); 515 516 return 0; 517 } 518 519 #elif defined(CONFIG_XTENSA) 520 521 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 522 { 523 print_std_bdinfo(gd->bd); 524 return 0; 525 } 526 527 #else 528 #error "a case for this architecture does not exist!" 529 #endif 530 531 /* -------------------------------------------------------------------- */ 532 533 U_BOOT_CMD( 534 bdinfo, 1, 1, do_bdinfo, 535 "print Board Info structure", 536 "" 537 ); 538