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_MIPS) 342 343 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 344 { 345 print_std_bdinfo(gd->bd); 346 print_num("relocaddr", gd->relocaddr); 347 print_num("reloc off", gd->reloc_off); 348 349 return 0; 350 } 351 352 #elif defined(CONFIG_AVR32) 353 354 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 355 { 356 print_std_bdinfo(gd->bd); 357 return 0; 358 } 359 360 #elif defined(CONFIG_ARM) 361 362 static int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, 363 char * const argv[]) 364 { 365 bd_t *bd = gd->bd; 366 367 print_num("arch_number", bd->bi_arch_number); 368 print_bi_boot_params(bd); 369 print_bi_dram(bd); 370 371 #ifdef CONFIG_SYS_MEM_RESERVE_SECURE 372 if (gd->arch.secure_ram & MEM_RESERVE_SECURE_SECURED) { 373 print_num("Secure ram", 374 gd->arch.secure_ram & MEM_RESERVE_SECURE_ADDR_MASK); 375 } 376 #endif 377 #ifdef CONFIG_RESV_RAM 378 if (gd->arch.resv_ram) 379 print_num("Reserved ram", gd->arch.resv_ram); 380 #endif 381 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH) 382 print_eths(); 383 #endif 384 print_baudrate(); 385 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF)) 386 print_num("TLB addr", gd->arch.tlb_addr); 387 #endif 388 print_num("relocaddr", gd->relocaddr); 389 print_num("reloc off", gd->reloc_off); 390 print_num("irq_sp", gd->irq_sp); /* irq stack pointer */ 391 print_num("sp start ", gd->start_addr_sp); 392 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) 393 print_num("FB base ", gd->fb_base); 394 #endif 395 /* 396 * TODO: Currently only support for davinci SOC's is added. 397 * Remove this check once all the board implement this. 398 */ 399 #ifdef CONFIG_CLOCKS 400 printf("ARM frequency = %ld MHz\n", gd->bd->bi_arm_freq); 401 printf("DSP frequency = %ld MHz\n", gd->bd->bi_dsp_freq); 402 printf("DDR frequency = %ld MHz\n", gd->bd->bi_ddr_freq); 403 #endif 404 #ifdef CONFIG_BOARD_TYPES 405 printf("Board Type = %ld\n", gd->board_type); 406 #endif 407 #ifdef CONFIG_SYS_MALLOC_F 408 printf("Early malloc usage: %lx / %x\n", gd->malloc_ptr, 409 CONFIG_SYS_MALLOC_F_LEN); 410 #endif 411 412 return 0; 413 } 414 415 #elif defined(CONFIG_SH) 416 417 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 418 { 419 bd_t *bd = gd->bd; 420 421 print_bi_mem(bd); 422 print_bi_flash(bd); 423 print_eth_ip_addr(); 424 print_baudrate(); 425 return 0; 426 } 427 428 #elif defined(CONFIG_X86) 429 430 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 431 { 432 bd_t *bd = gd->bd; 433 434 print_bi_boot_params(bd); 435 436 print_bi_dram(bd); 437 438 #if defined(CONFIG_CMD_NET) 439 print_eth_ip_addr(); 440 print_mhz("ethspeed", bd->bi_ethspeed); 441 #endif 442 print_baudrate(); 443 444 return 0; 445 } 446 447 #elif defined(CONFIG_SANDBOX) 448 449 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 450 { 451 bd_t *bd = gd->bd; 452 453 print_bi_boot_params(bd); 454 print_bi_dram(bd); 455 print_eth_ip_addr(); 456 457 #if defined(CONFIG_LCD) || defined(CONFIG_VIDEO) 458 print_num("FB base ", gd->fb_base); 459 #endif 460 return 0; 461 } 462 463 #elif defined(CONFIG_NDS32) 464 465 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 466 { 467 bd_t *bd = gd->bd; 468 469 print_num("arch_number", bd->bi_arch_number); 470 print_bi_boot_params(bd); 471 print_bi_dram(bd); 472 print_eth_ip_addr(); 473 print_baudrate(); 474 475 return 0; 476 } 477 478 #elif defined(CONFIG_OPENRISC) 479 480 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 481 { 482 bd_t *bd = gd->bd; 483 484 print_bi_mem(bd); 485 print_bi_flash(bd); 486 print_eth_ip_addr(); 487 print_baudrate(); 488 489 return 0; 490 } 491 492 #elif defined(CONFIG_ARC) 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_eth_ip_addr(); 500 print_baudrate(); 501 502 return 0; 503 } 504 505 #elif defined(CONFIG_XTENSA) 506 507 int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) 508 { 509 print_std_bdinfo(gd->bd); 510 return 0; 511 } 512 513 #else 514 #error "a case for this architecture does not exist!" 515 #endif 516 517 /* -------------------------------------------------------------------- */ 518 519 U_BOOT_CMD( 520 bdinfo, 1, 1, do_bdinfo, 521 "print Board Info structure", 522 "" 523 ); 524