common.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. /*
  2. * (C) Copyright 2000-2009
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __COMMON_H_
  8. #define __COMMON_H_ 1
  9. #ifndef __ASSEMBLY__ /* put C only stuff in this section */
  10. typedef unsigned char uchar;
  11. typedef volatile unsigned long vu_long;
  12. typedef volatile unsigned short vu_short;
  13. typedef volatile unsigned char vu_char;
  14. /* Allow sharing constants with type modifiers between C and assembly. */
  15. #define _AC(X, Y) (X##Y)
  16. #include <config.h>
  17. #include <errno.h>
  18. #include <time.h>
  19. #include <asm-offsets.h>
  20. #include <linux/bitops.h>
  21. #include <linux/delay.h>
  22. #include <linux/types.h>
  23. #include <linux/string.h>
  24. #include <linux/stringify.h>
  25. #include <asm/ptrace.h>
  26. #include <stdarg.h>
  27. #include <linux/kernel.h>
  28. #include <part.h>
  29. #include <flash.h>
  30. #include <image.h>
  31. /* Bring in printf format macros if inttypes.h is included */
  32. #define __STDC_FORMAT_MACROS
  33. #ifdef __LP64__
  34. #define CONFIG_SYS_SUPPORT_64BIT_DATA
  35. #endif
  36. #ifdef DEBUG
  37. #define _DEBUG 1
  38. #else
  39. #define _DEBUG 0
  40. #endif
  41. #ifdef CONFIG_SPL_BUILD
  42. #define _SPL_BUILD 1
  43. #else
  44. #define _SPL_BUILD 0
  45. #endif
  46. /* Define this at the top of a file to add a prefix to debug messages */
  47. #ifndef pr_fmt
  48. #define pr_fmt(fmt) fmt
  49. #endif
  50. /*
  51. * Output a debug text when condition "cond" is met. The "cond" should be
  52. * computed by a preprocessor in the best case, allowing for the best
  53. * optimization.
  54. */
  55. #define debug_cond(cond, fmt, args...) \
  56. do { \
  57. if (cond) \
  58. printf(pr_fmt(fmt), ##args); \
  59. } while (0)
  60. /* Show a message if DEBUG is defined in a file */
  61. #define debug(fmt, args...) \
  62. debug_cond(_DEBUG, fmt, ##args)
  63. /* Show a message if not in SPL */
  64. #define warn_non_spl(fmt, args...) \
  65. debug_cond(!_SPL_BUILD, fmt, ##args)
  66. /*
  67. * An assertion is run-time check done in debug mode only. If DEBUG is not
  68. * defined then it is skipped. If DEBUG is defined and the assertion fails,
  69. * then it calls panic*( which may or may not reset/halt U-Boot (see
  70. * CONFIG_PANIC_HANG), It is hoped that all failing assertions are found
  71. * before release, and after release it is hoped that they don't matter. But
  72. * in any case these failing assertions cannot be fixed with a reset (which
  73. * may just do the same assertion again).
  74. */
  75. void __assert_fail(const char *assertion, const char *file, unsigned line,
  76. const char *function);
  77. #define assert(x) \
  78. ({ if (!(x) && _DEBUG) \
  79. __assert_fail(#x, __FILE__, __LINE__, __func__); })
  80. #define error(fmt, args...) do { \
  81. printf("ERROR: " pr_fmt(fmt) "\nat %s:%d/%s()\n", \
  82. ##args, __FILE__, __LINE__, __func__); \
  83. } while (0)
  84. #ifndef BUG
  85. #define BUG() do { \
  86. printf("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __FUNCTION__); \
  87. panic("BUG!"); \
  88. } while (0)
  89. #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
  90. #endif /* BUG */
  91. typedef void (interrupt_handler_t)(void *);
  92. #include <asm/u-boot.h> /* boot information for Linux kernel */
  93. #include <asm/global_data.h> /* global data used for startup functions */
  94. #if defined(CONFIG_ENV_IS_EMBEDDED)
  95. #define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
  96. #elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
  97. (CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
  98. defined(CONFIG_ENV_IS_IN_NVRAM)
  99. #define TOTAL_MALLOC_LEN (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
  100. #else
  101. #define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
  102. #endif
  103. /*
  104. * Function Prototypes
  105. */
  106. int dram_init(void);
  107. /**
  108. * dram_init_banksize() - Set up DRAM bank sizes
  109. *
  110. * This can be implemented by boards to set up the DRAM bank information in
  111. * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
  112. * is called.
  113. *
  114. * If this is not provided, a default implementation will try to set up a
  115. * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
  116. * CONFIG_SYS_SDRAM_BASE are set. The bank will have a start address of
  117. * CONFIG_SYS_SDRAM_BASE and the size will be determined by a call to
  118. * get_effective_memsize().
  119. *
  120. * @return 0 if OK, -ve on error
  121. */
  122. int dram_init_banksize(void);
  123. void hang (void) __attribute__ ((noreturn));
  124. int timer_init(void);
  125. int cpu_init(void);
  126. #include <display_options.h>
  127. /* common/main.c */
  128. void main_loop (void);
  129. int run_command(const char *cmd, int flag);
  130. int run_command_repeatable(const char *cmd, int flag);
  131. /**
  132. * Run a list of commands separated by ; or even \0
  133. *
  134. * Note that if 'len' is not -1, then the command does not need to be nul
  135. * terminated, Memory will be allocated for the command in that case.
  136. *
  137. * @param cmd List of commands to run, each separated bu semicolon
  138. * @param len Length of commands excluding terminator if known (-1 if not)
  139. * @param flag Execution flags (CMD_FLAG_...)
  140. * @return 0 on success, or != 0 on error.
  141. */
  142. int run_command_list(const char *cmd, int len, int flag);
  143. /* arch/$(ARCH)/lib/board.c */
  144. void board_init_f(ulong);
  145. void board_init_r(gd_t *, ulong) __attribute__ ((noreturn));
  146. /**
  147. * ulong board_init_f_alloc_reserve - allocate reserved area
  148. *
  149. * This function is called by each architecture very early in the start-up
  150. * code to allow the C runtime to reserve space on the stack for writable
  151. * 'globals' such as GD and the malloc arena.
  152. *
  153. * @top: top of the reserve area, growing down.
  154. * @return: bottom of reserved area
  155. */
  156. ulong board_init_f_alloc_reserve(ulong top);
  157. /**
  158. * board_init_f_init_reserve - initialize the reserved area(s)
  159. *
  160. * This function is called once the C runtime has allocated the reserved
  161. * area on the stack. It must initialize the GD at the base of that area.
  162. *
  163. * @base: top from which reservation was done
  164. */
  165. void board_init_f_init_reserve(ulong base);
  166. /**
  167. * arch_setup_gd() - Set up the global_data pointer
  168. *
  169. * This pointer is special in some architectures and cannot easily be assigned
  170. * to. For example on x86 it is implemented by adding a specific record to its
  171. * Global Descriptor Table! So we we provide a function to carry out this task.
  172. * For most architectures this can simply be:
  173. *
  174. * gd = gd_ptr;
  175. *
  176. * @gd_ptr: Pointer to global data
  177. */
  178. void arch_setup_gd(gd_t *gd_ptr);
  179. int checkboard(void);
  180. int show_board_info(void);
  181. int checkflash(void);
  182. int checkdram(void);
  183. int last_stage_init(void);
  184. extern ulong monitor_flash_len;
  185. int mac_read_from_eeprom(void);
  186. extern u8 __dtb_dt_begin[]; /* embedded device tree blob */
  187. int set_cpu_clk_info(void);
  188. int mdm_init(void);
  189. int print_cpuinfo(void);
  190. int update_flash_size(int flash_size);
  191. int arch_early_init_r(void);
  192. /*
  193. * setup_board_extra() - Fill in extra details in the bd_t structure
  194. *
  195. * @return 0 if OK, -ve on error
  196. */
  197. int setup_board_extra(void);
  198. /**
  199. * arch_fsp_init() - perform firmware support package init
  200. *
  201. * Where U-Boot relies on binary blobs to handle part of the system init, this
  202. * function can be used to set up the blobs. This is used on some Intel
  203. * platforms.
  204. */
  205. int arch_fsp_init(void);
  206. /**
  207. * arch_cpu_init_dm() - init CPU after driver model is available
  208. *
  209. * This is called immediately after driver model is available before
  210. * relocation. This is similar to arch_cpu_init() but is able to reference
  211. * devices
  212. *
  213. * @return 0 if OK, -ve on error
  214. */
  215. int arch_cpu_init_dm(void);
  216. /**
  217. * Reserve all necessary stacks
  218. *
  219. * This is used in generic board init sequence in common/board_f.c. Each
  220. * architecture could provide this function to tailor the required stacks.
  221. *
  222. * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
  223. * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
  224. * require only this can leave it untouched.
  225. *
  226. * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
  227. * positions of the stack. The stack pointer(s) will be set to this later.
  228. * gd->irq_sp is only required, if the architecture needs it.
  229. *
  230. * @return 0 if no error
  231. */
  232. __weak int arch_reserve_stacks(void);
  233. /**
  234. * Show the DRAM size in a board-specific way
  235. *
  236. * This is used by boards to display DRAM information in their own way.
  237. *
  238. * @param size Size of DRAM (which should be displayed along with other info)
  239. */
  240. void board_show_dram(phys_size_t size);
  241. /**
  242. * arch_fixup_fdt() - Write arch-specific information to fdt
  243. *
  244. * Defined in arch/$(ARCH)/lib/bootm-fdt.c
  245. *
  246. * @blob: FDT blob to write to
  247. * @return 0 if ok, or -ve FDT_ERR_... on failure
  248. */
  249. int arch_fixup_fdt(void *blob);
  250. /* common/flash.c */
  251. void flash_perror (int);
  252. /* common/cmd_source.c */
  253. int source (ulong addr, const char *fit_uname);
  254. extern ulong load_addr; /* Default Load Address */
  255. extern ulong save_addr; /* Default Save Address */
  256. extern ulong save_size; /* Default Save Size */
  257. /* common/cmd_net.c */
  258. int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  259. /* common/cmd_fat.c */
  260. int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
  261. /* common/cmd_ext2.c */
  262. int do_ext2load(cmd_tbl_t *, int, int, char * const []);
  263. /* common/cmd_nvedit.c */
  264. int env_init (void);
  265. void env_relocate (void);
  266. int envmatch (uchar *, int);
  267. /* Avoid unfortunate conflict with libc's getenv() */
  268. #ifdef CONFIG_SANDBOX
  269. #define getenv uboot_getenv
  270. #endif
  271. char *getenv (const char *);
  272. int getenv_f (const char *name, char *buf, unsigned len);
  273. ulong getenv_ulong(const char *name, int base, ulong default_val);
  274. /**
  275. * getenv_hex() - Return an environment variable as a hex value
  276. *
  277. * Decode an environment as a hex number (it may or may not have a 0x
  278. * prefix). If the environment variable cannot be found, or does not start
  279. * with hex digits, the default value is returned.
  280. *
  281. * @varname: Variable to decode
  282. * @default_val: Value to return on error
  283. */
  284. ulong getenv_hex(const char *varname, ulong default_val);
  285. /*
  286. * Read an environment variable as a boolean
  287. * Return -1 if variable does not exist (default to true)
  288. */
  289. int getenv_yesno(const char *var);
  290. int saveenv (void);
  291. int setenv (const char *, const char *);
  292. int setenv_ulong(const char *varname, ulong value);
  293. int setenv_hex(const char *varname, ulong value);
  294. /**
  295. * setenv_addr - Set an environment variable to an address in hex
  296. *
  297. * @varname: Environment variable to set
  298. * @addr: Value to set it to
  299. * @return 0 if ok, 1 on error
  300. */
  301. static inline int setenv_addr(const char *varname, const void *addr)
  302. {
  303. return setenv_hex(varname, (ulong)addr);
  304. }
  305. #ifdef CONFIG_AUTO_COMPLETE
  306. int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
  307. #endif
  308. int get_env_id (void);
  309. void pci_init (void);
  310. void pci_init_board(void);
  311. #if defined(CONFIG_DTB_RESELECT)
  312. int embedded_dtb_select(void);
  313. #endif
  314. int misc_init_f (void);
  315. int misc_init_r (void);
  316. /* common/exports.c */
  317. void jumptable_init(void);
  318. /* common/kallsysm.c */
  319. const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
  320. /* common/memsize.c */
  321. long get_ram_size (long *, long);
  322. phys_size_t get_effective_memsize(void);
  323. /* $(BOARD)/$(BOARD).c */
  324. void reset_phy (void);
  325. void fdc_hw_init (void);
  326. /* $(BOARD)/eeprom.c */
  327. #ifdef CONFIG_CMD_EEPROM
  328. void eeprom_init (int bus);
  329. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  330. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  331. #else
  332. /*
  333. * Some EEPROM code is depecated because it used the legacy I2C interface. Add
  334. * some macros here so we don't have to touch every one of those uses
  335. */
  336. #define eeprom_init(bus)
  337. #define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  338. #define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  339. #endif
  340. /*
  341. * Set this up regardless of board
  342. * type, to prevent errors.
  343. */
  344. #if defined(CONFIG_SPI) || !defined(CONFIG_SYS_I2C_EEPROM_ADDR)
  345. # define CONFIG_SYS_DEF_EEPROM_ADDR 0
  346. #else
  347. #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
  348. # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
  349. #endif
  350. #endif /* CONFIG_SPI || !defined(CONFIG_SYS_I2C_EEPROM_ADDR) */
  351. #if defined(CONFIG_SPI)
  352. extern void spi_init_f (void);
  353. extern void spi_init_r (void);
  354. extern ssize_t spi_read (uchar *, int, uchar *, int);
  355. extern ssize_t spi_write (uchar *, int, uchar *, int);
  356. #endif
  357. /* $(BOARD)/$(BOARD).c */
  358. int board_early_init_f (void);
  359. int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */
  360. int board_late_init (void);
  361. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  362. int board_early_init_r (void);
  363. void board_poweroff (void);
  364. #if defined(CONFIG_SYS_DRAM_TEST)
  365. int testdram(void);
  366. #endif /* CONFIG_SYS_DRAM_TEST */
  367. /* $(CPU)/start.S */
  368. int icache_status (void);
  369. void icache_enable (void);
  370. void icache_disable(void);
  371. int dcache_status (void);
  372. void dcache_enable (void);
  373. void dcache_disable(void);
  374. void mmu_disable(void);
  375. #if defined(CONFIG_ARM)
  376. void relocate_code(ulong);
  377. #else
  378. void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
  379. #endif
  380. ulong get_endaddr (void);
  381. void trap_init (ulong);
  382. /* $(CPU)/cpu.c */
  383. static inline int cpumask_next(int cpu, unsigned int mask)
  384. {
  385. for (cpu++; !((1 << cpu) & mask); cpu++)
  386. ;
  387. return cpu;
  388. }
  389. #define for_each_cpu(iter, cpu, num_cpus, mask) \
  390. for (iter = 0, cpu = cpumask_next(-1, mask); \
  391. iter < num_cpus; \
  392. iter++, cpu = cpumask_next(cpu, mask)) \
  393. int cpu_numcores (void);
  394. int cpu_num_dspcores(void);
  395. u32 cpu_mask (void);
  396. u32 cpu_dsp_mask(void);
  397. int is_core_valid (unsigned int);
  398. /**
  399. * arch_cpu_init() - basic cpu-dependent setup for an architecture
  400. *
  401. * This is called after early malloc is available. It should handle any
  402. * CPU- or SoC- specific init needed to continue the init sequence. See
  403. * board_f.c for where it is called. If this is not provided, a default
  404. * version (which does nothing) will be used.
  405. */
  406. int arch_cpu_init(void);
  407. int checkcpu (void);
  408. int checkicache (void);
  409. int checkdcache (void);
  410. void upmconfig (unsigned int, unsigned int *, unsigned int);
  411. ulong get_tbclk (void);
  412. void reset_misc (void);
  413. void reset_cpu (ulong addr);
  414. void ft_cpu_setup(void *blob, bd_t *bd);
  415. void ft_pci_setup(void *blob, bd_t *bd);
  416. void smp_set_core_boot_addr(unsigned long addr, int corenr);
  417. void smp_kick_all_cpus(void);
  418. /* $(CPU)/serial.c */
  419. int serial_init (void);
  420. void serial_setbrg (void);
  421. void serial_putc (const char);
  422. void serial_putc_raw(const char);
  423. void serial_puts (const char *);
  424. int serial_getc (void);
  425. int serial_tstc (void);
  426. /* $(CPU)/speed.c */
  427. int get_clocks (void);
  428. ulong get_bus_freq (ulong);
  429. int get_serial_clock(void);
  430. int cpu_init_r (void);
  431. /* $(CPU)/interrupts.c */
  432. int interrupt_init (void);
  433. void timer_interrupt (struct pt_regs *);
  434. void external_interrupt (struct pt_regs *);
  435. void irq_install_handler(int, interrupt_handler_t *, void *);
  436. void irq_free_handler (int);
  437. void reset_timer (void);
  438. /* Return value of monotonic microsecond timer */
  439. unsigned long timer_get_us(void);
  440. void enable_interrupts (void);
  441. int disable_interrupts (void);
  442. /* $(CPU)/.../commproc.c */
  443. int dpram_init (void);
  444. uint dpram_base(void);
  445. uint dpram_base_align(uint align);
  446. uint dpram_alloc(uint size);
  447. uint dpram_alloc_align(uint size,uint align);
  448. void bootcount_store (ulong);
  449. ulong bootcount_load (void);
  450. #define BOOTCOUNT_MAGIC 0xB001C041
  451. /* $(CPU)/.../<eth> */
  452. void mii_init (void);
  453. /* $(CPU)/.../lcd.c */
  454. ulong lcd_setmem (ulong);
  455. /* $(CPU)/.../video.c */
  456. ulong video_setmem (ulong);
  457. /* arch/$(ARCH)/lib/cache.c */
  458. void enable_caches(void);
  459. void flush_cache (unsigned long, unsigned long);
  460. void flush_dcache_all(void);
  461. void flush_dcache_range(unsigned long start, unsigned long stop);
  462. void invalidate_dcache_range(unsigned long start, unsigned long stop);
  463. void invalidate_dcache_all(void);
  464. void invalidate_icache_all(void);
  465. enum {
  466. /* Disable caches (else flush caches but leave them active) */
  467. CBL_DISABLE_CACHES = 1 << 0,
  468. CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1,
  469. CBL_ALL = 3,
  470. };
  471. /**
  472. * Clean up ready for linux
  473. *
  474. * @param flags Flags to control what is done
  475. */
  476. int cleanup_before_linux_select(int flags);
  477. /* arch/$(ARCH)/lib/ticks.S */
  478. uint64_t get_ticks(void);
  479. void wait_ticks (unsigned long);
  480. /* arch/$(ARCH)/lib/time.c */
  481. ulong usec2ticks (unsigned long usec);
  482. ulong ticks2usec (unsigned long ticks);
  483. /* lib/gunzip.c */
  484. int gunzip(void *, int, unsigned char *, unsigned long *);
  485. int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
  486. int stoponerr, int offset);
  487. /**
  488. * gzwrite progress indicators: defined weak to allow board-specific
  489. * overrides:
  490. *
  491. * gzwrite_progress_init called on startup
  492. * gzwrite_progress called during decompress/write loop
  493. * gzwrite_progress_finish called at end of loop to
  494. * indicate success (retcode=0) or failure
  495. */
  496. void gzwrite_progress_init(u64 expected_size);
  497. void gzwrite_progress(int iteration,
  498. u64 bytes_written,
  499. u64 total_bytes);
  500. void gzwrite_progress_finish(int retcode,
  501. u64 totalwritten,
  502. u64 totalsize,
  503. u32 expected_crc,
  504. u32 calculated_crc);
  505. /**
  506. * decompress and write gzipped image from memory to block device
  507. *
  508. * @param src compressed image address
  509. * @param len compressed image length in bytes
  510. * @param dev block device descriptor
  511. * @param szwritebuf bytes per write (pad to erase size)
  512. * @param startoffs offset in bytes of first write
  513. * @param szexpected expected uncompressed length
  514. * may be zero to use gzip trailer
  515. * for files under 4GiB
  516. */
  517. int gzwrite(unsigned char *src, int len,
  518. struct blk_desc *dev,
  519. unsigned long szwritebuf,
  520. u64 startoffs,
  521. u64 szexpected);
  522. /* lib/lz4_wrapper.c */
  523. int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
  524. /* lib/qsort.c */
  525. void qsort(void *base, size_t nmemb, size_t size,
  526. int(*compar)(const void *, const void *));
  527. int strcmp_compar(const void *, const void *);
  528. /* lib/uuid.c */
  529. #include <uuid.h>
  530. /* lib/vsprintf.c */
  531. #include <vsprintf.h>
  532. /* lib/strmhz.c */
  533. char * strmhz(char *buf, unsigned long hz);
  534. /* lib/crc32.c */
  535. #include <u-boot/crc.h>
  536. /* lib/rand.c */
  537. #define RAND_MAX -1U
  538. void srand(unsigned int seed);
  539. unsigned int rand(void);
  540. unsigned int rand_r(unsigned int *seedp);
  541. /*
  542. * STDIO based functions (can always be used)
  543. */
  544. /* serial stuff */
  545. int serial_printf (const char *fmt, ...)
  546. __attribute__ ((format (__printf__, 1, 2)));
  547. /* stdin */
  548. int getc(void);
  549. int tstc(void);
  550. /* stdout */
  551. #if !defined(CONFIG_SPL_BUILD) || \
  552. (defined(CONFIG_TPL_BUILD) && defined(CONFIG_TPL_SERIAL_SUPPORT)) || \
  553. (defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) && \
  554. defined(CONFIG_SPL_SERIAL_SUPPORT))
  555. void putc(const char c);
  556. void puts(const char *s);
  557. int printf(const char *fmt, ...)
  558. __attribute__ ((format (__printf__, 1, 2)));
  559. int vprintf(const char *fmt, va_list args);
  560. #else
  561. #define putc(...) do { } while (0)
  562. #define puts(...) do { } while (0)
  563. #define printf(...) do { } while (0)
  564. #define vprintf(...) do { } while (0)
  565. #endif
  566. /* stderr */
  567. #define eputc(c) fputc(stderr, c)
  568. #define eputs(s) fputs(stderr, s)
  569. #define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
  570. /*
  571. * FILE based functions (can only be used AFTER relocation!)
  572. */
  573. #define stdin 0
  574. #define stdout 1
  575. #define stderr 2
  576. #define MAX_FILES 3
  577. int fprintf(int file, const char *fmt, ...)
  578. __attribute__ ((format (__printf__, 2, 3)));
  579. void fputs(int file, const char *s);
  580. void fputc(int file, const char c);
  581. int ftstc(int file);
  582. int fgetc(int file);
  583. /* lib/gzip.c */
  584. int gzip(void *dst, unsigned long *lenp,
  585. unsigned char *src, unsigned long srclen);
  586. int zzip(void *dst, unsigned long *lenp, unsigned char *src,
  587. unsigned long srclen, int stoponerr,
  588. int (*func)(unsigned long, unsigned long));
  589. /* lib/net_utils.c */
  590. #include <net.h>
  591. static inline struct in_addr getenv_ip(char *var)
  592. {
  593. return string_to_ip(getenv(var));
  594. }
  595. int pcmcia_init (void);
  596. #ifdef CONFIG_LED_STATUS
  597. # include <status_led.h>
  598. #endif
  599. #include <bootstage.h>
  600. #ifdef CONFIG_SHOW_ACTIVITY
  601. void show_activity(int arg);
  602. #endif
  603. /* Multicore arch functions */
  604. #ifdef CONFIG_MP
  605. int cpu_status(int nr);
  606. int cpu_reset(int nr);
  607. int cpu_disable(int nr);
  608. int cpu_release(int nr, int argc, char * const argv[]);
  609. #endif
  610. #else /* __ASSEMBLY__ */
  611. /* Drop a C type modifier (like in 3UL) for constants used in assembly. */
  612. #define _AC(X, Y) X
  613. #endif /* __ASSEMBLY__ */
  614. /* Put only stuff here that the assembler can digest */
  615. /* Declare an unsigned long constant digestable both by C and an assembler. */
  616. #define UL(x) _AC(x, UL)
  617. #ifdef CONFIG_POST
  618. #define CONFIG_HAS_POST
  619. #ifndef CONFIG_POST_ALT_LIST
  620. #define CONFIG_POST_STD_LIST
  621. #endif
  622. #endif
  623. #ifdef CONFIG_INIT_CRITICAL
  624. #error CONFIG_INIT_CRITICAL is deprecated!
  625. #error Read section CONFIG_SKIP_LOWLEVEL_INIT in README.
  626. #endif
  627. #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
  628. /*
  629. * check_member() - Check the offset of a structure member
  630. *
  631. * @structure: Name of structure (e.g. global_data)
  632. * @member: Name of member (e.g. baudrate)
  633. * @offset: Expected offset in bytes
  634. */
  635. #define check_member(structure, member, offset) _Static_assert( \
  636. offsetof(struct structure, member) == offset, \
  637. "`struct " #structure "` offset for `" #member "` is not " #offset)
  638. /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
  639. #ifdef CONFIG_EFI_STUB
  640. #define ll_boot_init() false
  641. #else
  642. #define ll_boot_init() true
  643. #endif
  644. /* Pull in stuff for the build system */
  645. #ifdef DO_DEPS_ONLY
  646. # include <environment.h>
  647. #endif
  648. #endif /* __COMMON_H_ */