common.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. int reserve_mmu(void);
  251. /* common/flash.c */
  252. void flash_perror (int);
  253. /* common/cmd_source.c */
  254. int source (ulong addr, const char *fit_uname);
  255. extern ulong load_addr; /* Default Load Address */
  256. extern ulong save_addr; /* Default Save Address */
  257. extern ulong save_size; /* Default Save Size */
  258. /* common/cmd_net.c */
  259. int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  260. /* common/cmd_fat.c */
  261. int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
  262. /* common/cmd_ext2.c */
  263. int do_ext2load(cmd_tbl_t *, int, int, char * const []);
  264. /* common/cmd_nvedit.c */
  265. int env_init (void);
  266. void env_relocate (void);
  267. int envmatch (uchar *, int);
  268. /**
  269. * env_get() - Look up the value of an environment variable
  270. *
  271. * In U-Boot proper this can be called before relocation (which is when the
  272. * environment is loaded from storage, i.e. GD_FLG_ENV_READY is 0). In that
  273. * case this function calls env_get_f().
  274. *
  275. * @varname: Variable to look up
  276. * @return value of variable, or NULL if not found
  277. */
  278. char *env_get(const char *varname);
  279. /**
  280. * env_get_f() - Look up the value of an environment variable (early)
  281. *
  282. * This function is called from env_get() if the environment has not been
  283. * loaded yet (GD_FLG_ENV_READY flag is 0). Some environment locations will
  284. * support reading the value (slowly) and some will not.
  285. *
  286. * @varname: Variable to look up
  287. * @return value of variable, or NULL if not found
  288. */
  289. int env_get_f(const char *name, char *buf, unsigned len);
  290. /**
  291. * env_get_ulong() - Return an environment variable as an integer value
  292. *
  293. * Most U-Boot environment variables store hex values. For those which store
  294. * (e.g.) base-10 integers, this function can be used to read the value.
  295. *
  296. * @name: Variable to look up
  297. * @base: Base to use (e.g. 10 for base 10, 2 for binary)
  298. * @default_val: Default value to return if no value is found
  299. * @return the value found, or @default_val if none
  300. */
  301. ulong env_get_ulong(const char *name, int base, ulong default_val);
  302. /**
  303. * env_get_hex() - Return an environment variable as a hex value
  304. *
  305. * Decode an environment as a hex number (it may or may not have a 0x
  306. * prefix). If the environment variable cannot be found, or does not start
  307. * with hex digits, the default value is returned.
  308. *
  309. * @varname: Variable to decode
  310. * @default_val: Value to return on error
  311. */
  312. ulong env_get_hex(const char *varname, ulong default_val);
  313. /*
  314. * Read an environment variable as a boolean
  315. * Return -1 if variable does not exist (default to true)
  316. */
  317. int env_get_yesno(const char *var);
  318. /**
  319. * env_set() - set an environment variable
  320. *
  321. * This sets or deletes the value of an environment variable. For setting the
  322. * value the variable is created if it does not already exist.
  323. *
  324. * @varname: Variable to adjust
  325. * @value: Value to set for the variable, or NULL or "" to delete the variable
  326. * @return 0 if OK, 1 on error
  327. */
  328. int env_set(const char *varname, const char *value);
  329. /**
  330. * env_set_ulong() - set an environment variable to an integer
  331. *
  332. * @varname: Variable to adjust
  333. * @value: Value to set for the variable (will be converted to a string)
  334. * @return 0 if OK, 1 on error
  335. */
  336. int env_set_ulong(const char *varname, ulong value);
  337. /**
  338. * env_set_hex() - set an environment variable to a hex value
  339. *
  340. * @varname: Variable to adjust
  341. * @value: Value to set for the variable (will be converted to a hex string)
  342. * @return 0 if OK, 1 on error
  343. */
  344. int env_set_hex(const char *varname, ulong value);
  345. /**
  346. * env_set_addr - Set an environment variable to an address in hex
  347. *
  348. * @varname: Environment variable to set
  349. * @addr: Value to set it to
  350. * @return 0 if ok, 1 on error
  351. */
  352. static inline int env_set_addr(const char *varname, const void *addr)
  353. {
  354. return env_set_hex(varname, (ulong)addr);
  355. }
  356. #ifdef CONFIG_AUTO_COMPLETE
  357. int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
  358. #endif
  359. int get_env_id (void);
  360. void pci_init (void);
  361. void pci_init_board(void);
  362. #if defined(CONFIG_DTB_RESELECT)
  363. int embedded_dtb_select(void);
  364. #endif
  365. int misc_init_f (void);
  366. int misc_init_r (void);
  367. /* common/exports.c */
  368. void jumptable_init(void);
  369. /* common/kallsysm.c */
  370. const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
  371. /* common/memsize.c */
  372. long get_ram_size (long *, long);
  373. phys_size_t get_effective_memsize(void);
  374. /* $(BOARD)/$(BOARD).c */
  375. void reset_phy (void);
  376. void fdc_hw_init (void);
  377. /* $(BOARD)/eeprom.c */
  378. #ifdef CONFIG_CMD_EEPROM
  379. void eeprom_init (int bus);
  380. int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  381. int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
  382. #else
  383. /*
  384. * Some EEPROM code is depecated because it used the legacy I2C interface. Add
  385. * some macros here so we don't have to touch every one of those uses
  386. */
  387. #define eeprom_init(bus)
  388. #define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  389. #define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
  390. #endif
  391. /*
  392. * Set this up regardless of board
  393. * type, to prevent errors.
  394. */
  395. #if defined(CONFIG_SPI) || !defined(CONFIG_SYS_I2C_EEPROM_ADDR)
  396. # define CONFIG_SYS_DEF_EEPROM_ADDR 0
  397. #else
  398. #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
  399. # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
  400. #endif
  401. #endif /* CONFIG_SPI || !defined(CONFIG_SYS_I2C_EEPROM_ADDR) */
  402. #if defined(CONFIG_SPI)
  403. extern void spi_init_f (void);
  404. extern void spi_init_r (void);
  405. extern ssize_t spi_read (uchar *, int, uchar *, int);
  406. extern ssize_t spi_write (uchar *, int, uchar *, int);
  407. #endif
  408. /* $(BOARD)/$(BOARD).c */
  409. int board_early_init_f (void);
  410. int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */
  411. int board_late_init (void);
  412. int board_postclk_init (void); /* after clocks/timebase, before env/serial */
  413. int board_early_init_r (void);
  414. void board_poweroff (void);
  415. #if defined(CONFIG_SYS_DRAM_TEST)
  416. int testdram(void);
  417. #endif /* CONFIG_SYS_DRAM_TEST */
  418. /* $(CPU)/start.S */
  419. int icache_status (void);
  420. void icache_enable (void);
  421. void icache_disable(void);
  422. int dcache_status (void);
  423. void dcache_enable (void);
  424. void dcache_disable(void);
  425. void mmu_disable(void);
  426. #if defined(CONFIG_ARM)
  427. void relocate_code(ulong);
  428. #else
  429. void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
  430. #endif
  431. ulong get_endaddr (void);
  432. void trap_init (ulong);
  433. /* $(CPU)/cpu.c */
  434. static inline int cpumask_next(int cpu, unsigned int mask)
  435. {
  436. for (cpu++; !((1 << cpu) & mask); cpu++)
  437. ;
  438. return cpu;
  439. }
  440. #define for_each_cpu(iter, cpu, num_cpus, mask) \
  441. for (iter = 0, cpu = cpumask_next(-1, mask); \
  442. iter < num_cpus; \
  443. iter++, cpu = cpumask_next(cpu, mask)) \
  444. int cpu_numcores (void);
  445. int cpu_num_dspcores(void);
  446. u32 cpu_mask (void);
  447. u32 cpu_dsp_mask(void);
  448. int is_core_valid (unsigned int);
  449. /**
  450. * arch_cpu_init() - basic cpu-dependent setup for an architecture
  451. *
  452. * This is called after early malloc is available. It should handle any
  453. * CPU- or SoC- specific init needed to continue the init sequence. See
  454. * board_f.c for where it is called. If this is not provided, a default
  455. * version (which does nothing) will be used.
  456. */
  457. int arch_cpu_init(void);
  458. int checkcpu (void);
  459. int checkicache (void);
  460. int checkdcache (void);
  461. void upmconfig (unsigned int, unsigned int *, unsigned int);
  462. ulong get_tbclk (void);
  463. void reset_misc (void);
  464. void reset_cpu (ulong addr);
  465. void ft_cpu_setup(void *blob, bd_t *bd);
  466. void ft_pci_setup(void *blob, bd_t *bd);
  467. void smp_set_core_boot_addr(unsigned long addr, int corenr);
  468. void smp_kick_all_cpus(void);
  469. /* $(CPU)/serial.c */
  470. int serial_init (void);
  471. void serial_setbrg (void);
  472. void serial_putc (const char);
  473. void serial_putc_raw(const char);
  474. void serial_puts (const char *);
  475. int serial_getc (void);
  476. int serial_tstc (void);
  477. /* $(CPU)/speed.c */
  478. int get_clocks (void);
  479. ulong get_bus_freq (ulong);
  480. int get_serial_clock(void);
  481. int cpu_init_r (void);
  482. /* $(CPU)/interrupts.c */
  483. int interrupt_init (void);
  484. void timer_interrupt (struct pt_regs *);
  485. void external_interrupt (struct pt_regs *);
  486. void irq_install_handler(int, interrupt_handler_t *, void *);
  487. void irq_free_handler (int);
  488. void reset_timer (void);
  489. /* Return value of monotonic microsecond timer */
  490. unsigned long timer_get_us(void);
  491. void enable_interrupts (void);
  492. int disable_interrupts (void);
  493. /* $(CPU)/.../commproc.c */
  494. int dpram_init (void);
  495. uint dpram_base(void);
  496. uint dpram_base_align(uint align);
  497. uint dpram_alloc(uint size);
  498. uint dpram_alloc_align(uint size,uint align);
  499. void bootcount_store (ulong);
  500. ulong bootcount_load (void);
  501. #define BOOTCOUNT_MAGIC 0xB001C041
  502. /* $(CPU)/.../<eth> */
  503. void mii_init (void);
  504. /* $(CPU)/.../lcd.c */
  505. ulong lcd_setmem (ulong);
  506. /* $(CPU)/.../video.c */
  507. ulong video_setmem (ulong);
  508. /* arch/$(ARCH)/lib/cache.c */
  509. void enable_caches(void);
  510. void flush_cache (unsigned long, unsigned long);
  511. void flush_dcache_all(void);
  512. void flush_dcache_range(unsigned long start, unsigned long stop);
  513. void invalidate_dcache_range(unsigned long start, unsigned long stop);
  514. void invalidate_dcache_all(void);
  515. void invalidate_icache_all(void);
  516. enum {
  517. /* Disable caches (else flush caches but leave them active) */
  518. CBL_DISABLE_CACHES = 1 << 0,
  519. CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1,
  520. CBL_ALL = 3,
  521. };
  522. /**
  523. * Clean up ready for linux
  524. *
  525. * @param flags Flags to control what is done
  526. */
  527. int cleanup_before_linux_select(int flags);
  528. /* arch/$(ARCH)/lib/ticks.S */
  529. uint64_t get_ticks(void);
  530. void wait_ticks (unsigned long);
  531. /* arch/$(ARCH)/lib/time.c */
  532. ulong usec2ticks (unsigned long usec);
  533. ulong ticks2usec (unsigned long ticks);
  534. /* lib/gunzip.c */
  535. int gunzip(void *, int, unsigned char *, unsigned long *);
  536. int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
  537. int stoponerr, int offset);
  538. /**
  539. * gzwrite progress indicators: defined weak to allow board-specific
  540. * overrides:
  541. *
  542. * gzwrite_progress_init called on startup
  543. * gzwrite_progress called during decompress/write loop
  544. * gzwrite_progress_finish called at end of loop to
  545. * indicate success (retcode=0) or failure
  546. */
  547. void gzwrite_progress_init(u64 expected_size);
  548. void gzwrite_progress(int iteration,
  549. u64 bytes_written,
  550. u64 total_bytes);
  551. void gzwrite_progress_finish(int retcode,
  552. u64 totalwritten,
  553. u64 totalsize,
  554. u32 expected_crc,
  555. u32 calculated_crc);
  556. /**
  557. * decompress and write gzipped image from memory to block device
  558. *
  559. * @param src compressed image address
  560. * @param len compressed image length in bytes
  561. * @param dev block device descriptor
  562. * @param szwritebuf bytes per write (pad to erase size)
  563. * @param startoffs offset in bytes of first write
  564. * @param szexpected expected uncompressed length
  565. * may be zero to use gzip trailer
  566. * for files under 4GiB
  567. */
  568. int gzwrite(unsigned char *src, int len,
  569. struct blk_desc *dev,
  570. unsigned long szwritebuf,
  571. u64 startoffs,
  572. u64 szexpected);
  573. /* lib/lz4_wrapper.c */
  574. int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
  575. /* lib/qsort.c */
  576. void qsort(void *base, size_t nmemb, size_t size,
  577. int(*compar)(const void *, const void *));
  578. int strcmp_compar(const void *, const void *);
  579. /* lib/uuid.c */
  580. #include <uuid.h>
  581. /* lib/vsprintf.c */
  582. #include <vsprintf.h>
  583. /* lib/strmhz.c */
  584. char * strmhz(char *buf, unsigned long hz);
  585. /* lib/crc32.c */
  586. #include <u-boot/crc.h>
  587. /* lib/rand.c */
  588. #define RAND_MAX -1U
  589. void srand(unsigned int seed);
  590. unsigned int rand(void);
  591. unsigned int rand_r(unsigned int *seedp);
  592. /*
  593. * STDIO based functions (can always be used)
  594. */
  595. /* serial stuff */
  596. int serial_printf (const char *fmt, ...)
  597. __attribute__ ((format (__printf__, 1, 2)));
  598. /* stdin */
  599. int getc(void);
  600. int tstc(void);
  601. /* stdout */
  602. #if !defined(CONFIG_SPL_BUILD) || \
  603. (defined(CONFIG_TPL_BUILD) && defined(CONFIG_TPL_SERIAL_SUPPORT)) || \
  604. (defined(CONFIG_SPL_BUILD) && !defined(CONFIG_TPL_BUILD) && \
  605. defined(CONFIG_SPL_SERIAL_SUPPORT))
  606. void putc(const char c);
  607. void puts(const char *s);
  608. int printf(const char *fmt, ...)
  609. __attribute__ ((format (__printf__, 1, 2)));
  610. int vprintf(const char *fmt, va_list args);
  611. #else
  612. #define putc(...) do { } while (0)
  613. #define puts(...) do { } while (0)
  614. #define printf(...) do { } while (0)
  615. #define vprintf(...) do { } while (0)
  616. #endif
  617. /* stderr */
  618. #define eputc(c) fputc(stderr, c)
  619. #define eputs(s) fputs(stderr, s)
  620. #define eprintf(fmt,args...) fprintf(stderr,fmt ,##args)
  621. /*
  622. * FILE based functions (can only be used AFTER relocation!)
  623. */
  624. #define stdin 0
  625. #define stdout 1
  626. #define stderr 2
  627. #define MAX_FILES 3
  628. int fprintf(int file, const char *fmt, ...)
  629. __attribute__ ((format (__printf__, 2, 3)));
  630. void fputs(int file, const char *s);
  631. void fputc(int file, const char c);
  632. int ftstc(int file);
  633. int fgetc(int file);
  634. /* lib/gzip.c */
  635. int gzip(void *dst, unsigned long *lenp,
  636. unsigned char *src, unsigned long srclen);
  637. int zzip(void *dst, unsigned long *lenp, unsigned char *src,
  638. unsigned long srclen, int stoponerr,
  639. int (*func)(unsigned long, unsigned long));
  640. /* lib/net_utils.c */
  641. #include <net.h>
  642. static inline struct in_addr getenv_ip(char *var)
  643. {
  644. return string_to_ip(env_get(var));
  645. }
  646. int pcmcia_init (void);
  647. #ifdef CONFIG_LED_STATUS
  648. # include <status_led.h>
  649. #endif
  650. #include <bootstage.h>
  651. #ifdef CONFIG_SHOW_ACTIVITY
  652. void show_activity(int arg);
  653. #endif
  654. /* Multicore arch functions */
  655. #ifdef CONFIG_MP
  656. int cpu_status(int nr);
  657. int cpu_reset(int nr);
  658. int cpu_disable(int nr);
  659. int cpu_release(int nr, int argc, char * const argv[]);
  660. #endif
  661. #else /* __ASSEMBLY__ */
  662. /* Drop a C type modifier (like in 3UL) for constants used in assembly. */
  663. #define _AC(X, Y) X
  664. #endif /* __ASSEMBLY__ */
  665. /* Put only stuff here that the assembler can digest */
  666. /* Declare an unsigned long constant digestable both by C and an assembler. */
  667. #define UL(x) _AC(x, UL)
  668. #ifdef CONFIG_POST
  669. #define CONFIG_HAS_POST
  670. #ifndef CONFIG_POST_ALT_LIST
  671. #define CONFIG_POST_STD_LIST
  672. #endif
  673. #endif
  674. #ifdef CONFIG_INIT_CRITICAL
  675. #error CONFIG_INIT_CRITICAL is deprecated!
  676. #error Read section CONFIG_SKIP_LOWLEVEL_INIT in README.
  677. #endif
  678. #define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
  679. /*
  680. * check_member() - Check the offset of a structure member
  681. *
  682. * @structure: Name of structure (e.g. global_data)
  683. * @member: Name of member (e.g. baudrate)
  684. * @offset: Expected offset in bytes
  685. */
  686. #define check_member(structure, member, offset) _Static_assert( \
  687. offsetof(struct structure, member) == offset, \
  688. "`struct " #structure "` offset for `" #member "` is not " #offset)
  689. /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
  690. #ifdef CONFIG_EFI_STUB
  691. #define ll_boot_init() false
  692. #else
  693. #define ll_boot_init() true
  694. #endif
  695. /* Pull in stuff for the build system */
  696. #ifdef DO_DEPS_ONLY
  697. # include <environment.h>
  698. #endif
  699. #endif /* __COMMON_H_ */