common.h 21 KB

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