xref: /rk3399_rockchip-uboot/include/common.h (revision 9c170041dcf97ed3fe5bbd76e70cda2ed3fcbd92)
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 
8 #ifndef __COMMON_H_
9 #define __COMMON_H_	1
10 
11 #ifndef __ASSEMBLY__		/* put C only stuff in this section */
12 
13 typedef unsigned char		uchar;
14 typedef volatile unsigned long	vu_long;
15 typedef volatile unsigned short vu_short;
16 typedef volatile unsigned char	vu_char;
17 
18 /* Allow sharing constants with type modifiers between C and assembly. */
19 #define _AC(X, Y)       (X##Y)
20 
21 #include <config.h>
22 #include <errno.h>
23 #include <time.h>
24 #include <asm-offsets.h>
25 #include <linux/bitops.h>
26 #include <linux/bug.h>
27 #include <linux/delay.h>
28 #include <linux/types.h>
29 #include <linux/printk.h>
30 #include <linux/string.h>
31 #include <linux/stringify.h>
32 #include <asm/ptrace.h>
33 #include <smp.h>
34 #include <stdarg.h>
35 #include <stdio.h>
36 #include <linux/kernel.h>
37 
38 #include <part.h>
39 #include <flash.h>
40 #include <image.h>
41 #include <stacktrace.h>
42 
43 /* Bring in printf format macros if inttypes.h is included */
44 #define __STDC_FORMAT_MACROS
45 
46 #ifdef __LP64__
47 #define CONFIG_SYS_SUPPORT_64BIT_DATA
48 #endif
49 
50 #include <log.h>
51 
52 #if (__STDC_VERSION__ >= 201112L) || defined(__cplusplus)
53 # undef static_assert
54 # define static_assert _Static_assert
55 #endif
56 
57 #if !CONFIG_IS_ENABLED(IRQ)
58 typedef void (interrupt_handler_t)(void *);
59 #else
60 typedef void (interrupt_handler_t)(int, void *);
61 #endif
62 
63 #include <asm/u-boot.h> /* boot information for Linux kernel */
64 #include <asm/global_data.h>	/* global data used for startup functions */
65 
66 #if defined(CONFIG_ENV_IS_EMBEDDED)
67 #define TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
68 #elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
69 	(CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
70       defined(CONFIG_ENV_IS_IN_NVRAM)
71 #define	TOTAL_MALLOC_LEN	(CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
72 #else
73 #define	TOTAL_MALLOC_LEN	CONFIG_SYS_MALLOC_LEN
74 #endif
75 
76 /*
77  * Function Prototypes
78  */
79 int dram_init(void);
80 
81 /**
82  * dram_init_banksize() - Set up DRAM bank sizes
83  *
84  * This can be implemented by boards to set up the DRAM bank information in
85  * gd->bd->bi_dram(). It is called just before relocation, after dram_init()
86  * is called.
87  *
88  * If this is not provided, a default implementation will try to set up a
89  * single bank. It will do this if CONFIG_NR_DRAM_BANKS and
90  * CONFIG_SYS_SDRAM_BASE are set. The bank will have a start address of
91  * CONFIG_SYS_SDRAM_BASE and the size will be determined by a call to
92  * get_effective_memsize().
93  *
94  * @return 0 if OK, -ve on error
95  */
96 int dram_init_banksize(void);
97 
98 void	hang		(void) __attribute__ ((noreturn));
99 
100 int	timer_init(void);
101 int	cpu_init(void);
102 
103 #include <display_options.h>
104 
105 /* common/main.c */
106 void	main_loop	(void);
107 void autoboot_command_fail_handle(void);
108 int run_command(const char *cmd, int flag);
109 int run_command_repeatable(const char *cmd, int flag);
110 
111 /**
112  * Run a list of commands separated by ; or even \0
113  *
114  * Note that if 'len' is not -1, then the command does not need to be nul
115  * terminated, Memory will be allocated for the command in that case.
116  *
117  * @param cmd	List of commands to run, each separated bu semicolon
118  * @param len	Length of commands excluding terminator if known (-1 if not)
119  * @param flag	Execution flags (CMD_FLAG_...)
120  * @return 0 on success, or != 0 on error.
121  */
122 int run_command_list(const char *cmd, int len, int flag);
123 
124 /* arch/$(ARCH)/lib/board.c */
125 void board_init_f(ulong);
126 void board_init_r(gd_t *, ulong) __attribute__ ((noreturn));
127 
128 /**
129  * ulong board_init_f_alloc_reserve - allocate reserved area
130  *
131  * This function is called by each architecture very early in the start-up
132  * code to allow the C runtime to reserve space on the stack for writable
133  * 'globals' such as GD and the malloc arena.
134  *
135  * @top:	top of the reserve area, growing down.
136  * @return:	bottom of reserved area
137  */
138 ulong board_init_f_alloc_reserve(ulong top);
139 
140 /**
141  * board_init_f_init_reserve - initialize the reserved area(s)
142  *
143  * This function is called once the C runtime has allocated the reserved
144  * area on the stack. It must initialize the GD at the base of that area.
145  *
146  * @base:	top from which reservation was done
147  */
148 void board_init_f_init_reserve(ulong base);
149 
150 /*
151  * Board-specific Platform code can init serial earlier if needed
152  */
153 __weak int board_init_f_boot_flags(void);
154 
155 /**
156  * arch_setup_gd() - Set up the global_data pointer
157  *
158  * This pointer is special in some architectures and cannot easily be assigned
159  * to. For example on x86 it is implemented by adding a specific record to its
160  * Global Descriptor Table! So we we provide a function to carry out this task.
161  * For most architectures this can simply be:
162  *
163  *    gd = gd_ptr;
164  *
165  * @gd_ptr:	Pointer to global data
166  */
167 void arch_setup_gd(gd_t *gd_ptr);
168 
169 int checkboard(void);
170 int show_board_info(void);
171 int checkflash(void);
172 int checkdram(void);
173 int last_stage_init(void);
174 extern ulong monitor_flash_len;
175 int mac_read_from_eeprom(void);
176 extern u8 __dtb_dt_begin[];	/* embedded device tree blob */
177 extern u8 __dtb_dt_spl_begin[];	/* embedded device tree blob for SPL/TPL */
178 int set_cpu_clk_info(void);
179 int mdm_init(void);
180 int print_cpuinfo(void);
181 int update_flash_size(int flash_size);
182 int arch_early_init_r(void);
183 
184 typedef struct uspinlock {
185 	volatile uint32_t lock;
186 } uspinlock_t;
187 
188 #if CONFIG_IS_ENABLED(SMP)
189 void u_spin_lock(uspinlock_t *lock);
190 void u_spin_unlock(uspinlock_t *lock);
191 #else
192 static inline void u_spin_lock(uspinlock_t *lock) {}
193 static inline void u_spin_unlock(uspinlock_t *lock) {}
194 #endif
195 
196 /*
197  * setup_board_extra() - Fill in extra details in the bd_t structure
198  *
199  * @return 0 if OK, -ve on error
200  */
201 int setup_board_extra(void);
202 
203 /**
204  * arch_fsp_init() - perform firmware support package init
205  *
206  * Where U-Boot relies on binary blobs to handle part of the system init, this
207  * function can be used to set up the blobs. This is used on some Intel
208  * platforms.
209  */
210 int arch_fsp_init(void);
211 
212 /**
213  * arch_cpu_init_dm() - init CPU after driver model is available
214  *
215  * This is called immediately after driver model is available before
216  * relocation. This is similar to arch_cpu_init() but is able to reference
217  * devices
218  *
219  * @return 0 if OK, -ve on error
220  */
221 int arch_cpu_init_dm(void);
222 
223 /**
224  * Reserve all necessary stacks
225  *
226  * This is used in generic board init sequence in common/board_f.c. Each
227  * architecture could provide this function to tailor the required stacks.
228  *
229  * On entry gd->start_addr_sp is pointing to the suggested top of the stack.
230  * The callee ensures gd->start_add_sp is 16-byte aligned, so architectures
231  * require only this can leave it untouched.
232  *
233  * On exit gd->start_addr_sp and gd->irq_sp should be set to the respective
234  * positions of the stack. The stack pointer(s) will be set to this later.
235  * gd->irq_sp is only required, if the architecture needs it.
236  *
237  * @return 0 if no error
238  */
239 __weak int arch_reserve_stacks(void);
240 
241 /**
242  * Show the DRAM size in a board-specific way
243  *
244  * This is used by boards to display DRAM information in their own way.
245  *
246  * @param size	Size of DRAM (which should be displayed along with other info)
247  */
248 void board_show_dram(phys_size_t size);
249 
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 
260 int reserve_mmu(void);
261 /* common/flash.c */
262 void flash_perror (int);
263 
264 /* common/cmd_source.c */
265 int	source (ulong addr, const char *fit_uname);
266 
267 extern ulong load_addr;		/* Default Load Address */
268 extern ulong save_addr;		/* Default Save Address */
269 extern ulong save_size;		/* Default Save Size */
270 
271 /* common/cmd_net.c */
272 int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
273 
274 /* common/cmd_fat.c */
275 int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
276 
277 /* common/cmd_ext2.c */
278 int do_ext2load(cmd_tbl_t *, int, int, char * const []);
279 
280 /* common/cmd_nvedit.c */
281 int	env_init     (void);
282 void	env_relocate (void);
283 int	envmatch     (uchar *, int);
284 
285 /**
286  * env_get() - Look up the value of an environment variable
287  *
288  * In U-Boot proper this can be called before relocation (which is when the
289  * environment is loaded from storage, i.e. GD_FLG_ENV_READY is 0). In that
290  * case this function calls env_get_f().
291  *
292  * @varname:	Variable to look up
293  * @return value of variable, or NULL if not found
294  */
295 char *env_get(const char *varname);
296 
297 /**
298  * env_get_f() - Look up the value of an environment variable (early)
299  *
300  * This function is called from env_get() if the environment has not been
301  * loaded yet (GD_FLG_ENV_READY flag is 0). Some environment locations will
302  * support reading the value (slowly) and some will not.
303  *
304  * @varname:	Variable to look up
305  * @return value of variable, or NULL if not found
306  */
307 int env_get_f(const char *name, char *buf, unsigned len);
308 
309 /**
310  * env_get_ulong() - Return an environment variable as an integer value
311  *
312  * Most U-Boot environment variables store hex values. For those which store
313  * (e.g.) base-10 integers, this function can be used to read the value.
314  *
315  * @name:	Variable to look up
316  * @base:	Base to use (e.g. 10 for base 10, 2 for binary)
317  * @default_val: Default value to return if no value is found
318  * @return the value found, or @default_val if none
319  */
320 ulong env_get_ulong(const char *name, int base, ulong default_val);
321 
322 /**
323  * env_get_hex() - Return an environment variable as a hex value
324  *
325  * Decode an environment as a hex number (it may or may not have a 0x
326  * prefix). If the environment variable cannot be found, or does not start
327  * with hex digits, the default value is returned.
328  *
329  * @varname:		Variable to decode
330  * @default_val:	Value to return on error
331  */
332 ulong env_get_hex(const char *varname, ulong default_val);
333 
334 /*
335  * Read an environment variable as a boolean
336  * Return -1 if variable does not exist (default to true)
337  */
338 int env_get_yesno(const char *var);
339 
340 /**
341  * env_set() - set an environment variable
342  *
343  * This sets or deletes the value of an environment variable. For setting the
344  * value the variable is created if it does not already exist.
345  *
346  * @varname: Variable to adjust
347  * @value: Value to set for the variable, or NULL or "" to delete the variable
348  * @return 0 if OK, 1 on error
349  */
350 int env_set(const char *varname, const char *value);
351 
352 /**
353  * env_update() - update sub value of an environment variable
354  *
355  * This add/append/replace the sub value of an environment variable.
356  *
357  * @varname: Variable to adjust
358  * @valude: Value to append/replace
359  * @ignore: Value to be ignore if in varvalue
360  * @return 0 if OK, 1 on error
361  */
362 int env_update_filter(const char *varname, const char *varvalue,
363 		      const char *ignore);
364 
365 /**
366  * env_update_extract_subset() - extract subset value from an environment variable
367  *
368  * This extract subset value from an environment variable
369  *
370  * @varname: Parent Variable where to extract subset value, the subset value
371  *	     will be removed from it.
372  * @subset_varname: Variable to save subset value
373  * @subset_key: Key value to find out subset value
374  * @return 0 if OK, 1 on error
375  */
376 int env_update_extract_subset(const char *varname,
377 			      const char *subset_varname,
378 			      const char *subset_key);
379 /**
380  * env_update() - update sub value of an environment variable
381  *
382  * This add/append/replace the sub value of an environment variable.
383  *
384  * @varname: Variable to adjust
385  * @valude: Value to append/replace
386  * @return 0 if OK, 1 on error
387  */
388 int env_update(const char *varname, const char *varvalue);
389 
390 /**
391  * env_exist() - check sub value of an environment variable is exist or not
392  *
393  * @varname: Variable to look up
394  * @value: Value to check
395  * @return posItion of varvalue if exist, otherwise NULL
396  */
397 char *env_exist(const char *varname, const char *varvalue);
398 
399 /**
400  * env_delete() - delete sub value of an environment variable
401  *
402  * @varname: Variable to look up
403  * @value: Item head of value to delete
404  * @complete_match: complete match whole words
405  * @return 0 if ok, 1 on error
406  */
407 int env_delete(const char *varname, const char *varvalue, int complete_match);
408 
409 /**
410  * env_set_ulong() - set an environment variable to an integer
411  *
412  * @varname: Variable to adjust
413  * @value: Value to set for the variable (will be converted to a string)
414  * @return 0 if OK, 1 on error
415  */
416 int env_set_ulong(const char *varname, ulong value);
417 
418 /**
419  * env_set_hex() - set an environment variable to a hex value
420  *
421  * @varname: Variable to adjust
422  * @value: Value to set for the variable (will be converted to a hex string)
423  * @return 0 if OK, 1 on error
424  */
425 int env_set_hex(const char *varname, ulong value);
426 
427 /**
428  * env_set_addr - Set an environment variable to an address in hex
429  *
430  * @varname:	Environment variable to set
431  * @addr:	Value to set it to
432  * @return 0 if ok, 1 on error
433  */
434 static inline int env_set_addr(const char *varname, const void *addr)
435 {
436 	return env_set_hex(varname, (ulong)addr);
437 }
438 
439 #ifdef CONFIG_AUTO_COMPLETE
440 int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
441 #endif
442 int get_env_id (void);
443 
444 void	pci_init      (void);
445 void	pci_init_board(void);
446 
447 #if defined(CONFIG_DTB_RESELECT)
448 int	embedded_dtb_select(void);
449 #endif
450 
451 int	misc_init_f   (void);
452 int	misc_init_r   (void);
453 
454 /* common/exports.c */
455 void	jumptable_init(void);
456 
457 /* common/kallsysm.c */
458 const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
459 
460 /* common/memsize.c */
461 long	get_ram_size  (long *, long);
462 phys_size_t get_effective_memsize(void);
463 
464 /* $(BOARD)/$(BOARD).c */
465 void	reset_phy     (void);
466 void	fdc_hw_init   (void);
467 
468 /* $(BOARD)/eeprom.c */
469 #ifdef CONFIG_CMD_EEPROM
470 void eeprom_init  (int bus);
471 int  eeprom_read  (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
472 int  eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
473 #else
474 /*
475  * Some EEPROM code is depecated because it used the legacy I2C interface. Add
476  * some macros here so we don't have to touch every one of those uses
477  */
478 #define eeprom_init(bus)
479 #define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
480 #define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
481 #endif
482 
483 #if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
484 # define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
485 #endif
486 
487 #if defined(CONFIG_MPC8XX_SPI)
488 extern void spi_init_f (void);
489 extern void spi_init_r (void);
490 extern ssize_t spi_read	 (uchar *, int, uchar *, int);
491 extern ssize_t spi_write (uchar *, int, uchar *, int);
492 #endif
493 
494 /* $(BOARD)/$(BOARD).c */
495 int board_early_init_f (void);
496 int board_fix_fdt (void *rw_fdt_blob); /* manipulate the U-Boot fdt before its relocation */
497 int board_late_init (void);
498 int board_postclk_init (void); /* after clocks/timebase, before env/serial */
499 int board_early_init_r (void);
500 void board_poweroff (void);
501 void board_env_fixup(void);
502 
503 #if defined(CONFIG_SYS_DRAM_TEST)
504 int testdram(void);
505 #endif /* CONFIG_SYS_DRAM_TEST */
506 
507 /* $(CPU)/start.S */
508 int	icache_status (void);
509 void	icache_enable (void);
510 void	icache_disable(void);
511 int	dcache_status (void);
512 void	dcache_enable (void);
513 void	dcache_disable(void);
514 void	mmu_disable(void);
515 #if defined(CONFIG_ARM)
516 void	relocate_code(ulong);
517 #else
518 void	relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
519 #endif
520 ulong	get_endaddr   (void);
521 void	trap_init     (ulong);
522 
523 /* $(CPU)/cpu.c */
524 static inline int cpumask_next(int cpu, unsigned int mask)
525 {
526 	for (cpu++; !((1 << cpu) & mask); cpu++)
527 		;
528 
529 	return cpu;
530 }
531 
532 #define for_each_cpu(iter, cpu, num_cpus, mask) \
533 	for (iter = 0, cpu = cpumask_next(-1, mask); \
534 		iter < num_cpus; \
535 		iter++, cpu = cpumask_next(cpu, mask)) \
536 
537 int	cpu_numcores  (void);
538 int	cpu_num_dspcores(void);
539 u32	cpu_mask      (void);
540 u32	cpu_dsp_mask(void);
541 int	is_core_valid (unsigned int);
542 
543 /**
544  * arch_cpu_init() - basic cpu-dependent setup for an architecture
545  *
546  * This is called after early malloc is available. It should handle any
547  * CPU- or SoC- specific init needed to continue the init sequence. See
548  * board_f.c for where it is called. If this is not provided, a default
549  * version (which does nothing) will be used.
550  */
551 int arch_cpu_init(void);
552 
553 void s_init(void);
554 
555 int	checkcpu      (void);
556 int	checkicache   (void);
557 int	checkdcache   (void);
558 void	upmconfig     (unsigned int, unsigned int *, unsigned int);
559 ulong	get_tbclk     (void);
560 void	reset_misc    (void);
561 void	reset_cpu     (ulong addr);
562 void ft_cpu_setup(void *blob, bd_t *bd);
563 void ft_pci_setup(void *blob, bd_t *bd);
564 
565 void smp_set_core_boot_addr(unsigned long addr, int corenr);
566 void smp_kick_all_cpus(void);
567 
568 /* $(CPU)/serial.c */
569 int	serial_init   (void);
570 void	serial_setbrg (void);
571 void	serial_putc   (const char);
572 void	serial_clear  (void);
573 void	serial_putc_raw(const char);
574 void	serial_puts   (const char *);
575 int	serial_getc   (void);
576 int	serial_tstc   (void);
577 
578 /* $(CPU)/speed.c */
579 int	get_clocks (void);
580 ulong	get_bus_freq  (ulong);
581 int get_serial_clock(void);
582 
583 int	cpu_init_r    (void);
584 
585 /* $(CPU)/interrupts.c */
586 int	interrupt_init	   (void);
587 void	timer_interrupt	   (struct pt_regs *);
588 void	external_interrupt (struct pt_regs *);
589 void	irq_install_handler(int, interrupt_handler_t *, void *);
590 void	irq_free_handler   (int);
591 void	reset_timer	   (void);
592 
593 /* Return value of monotonic microsecond timer */
594 unsigned long timer_get_us(void);
595 
596 void	enable_interrupts  (void);
597 int	disable_interrupts (void);
598 
599 /* $(CPU)/.../commproc.c */
600 int	dpram_init (void);
601 uint	dpram_base(void);
602 uint	dpram_base_align(uint align);
603 uint	dpram_alloc(uint size);
604 uint	dpram_alloc_align(uint size,uint align);
605 void	bootcount_store (ulong);
606 ulong	bootcount_load (void);
607 #define BOOTCOUNT_MAGIC		0xB001C041
608 
609 /* $(CPU)/.../<eth> */
610 void mii_init (void);
611 
612 /* $(CPU)/.../lcd.c */
613 ulong	lcd_setmem (ulong);
614 
615 /* $(CPU)/.../video.c */
616 ulong	video_setmem (ulong);
617 
618 /* arch/$(ARCH)/lib/cache.c */
619 void	enable_caches(void);
620 void	flush_cache   (unsigned long, unsigned long);
621 void	flush_dcache_all(void);
622 void	flush_dcache_range(unsigned long start, unsigned long stop);
623 void	invalidate_dcache_range(unsigned long start, unsigned long stop);
624 void	invalidate_dcache_all(void);
625 void	invalidate_icache_all(void);
626 
627 enum {
628 	/* Disable caches (else flush caches but leave them active) */
629 	CBL_DISABLE_CACHES		= 1 << 0,
630 	CBL_SHOW_BOOTSTAGE_REPORT	= 1 << 1,
631 
632 	CBL_ALL				= 3,
633 };
634 
635 /**
636  * Clean up ready for linux
637  *
638  * @param flags		Flags to control what is done
639  */
640 int cleanup_before_linux_select(int flags);
641 
642 /* arch/$(ARCH)/lib/ticks.S */
643 uint64_t get_ticks(void);
644 void	wait_ticks    (unsigned long);
645 
646 /* arch/$(ARCH)/lib/time.c */
647 ulong	usec2ticks    (unsigned long usec);
648 ulong	ticks2usec    (unsigned long ticks);
649 
650 /* lib/gunzip.c */
651 int gzip_parse_header(const unsigned char *src, unsigned long len);
652 int gunzip(void *, int, unsigned char *, unsigned long *);
653 int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
654 						int stoponerr, int offset);
655 
656 /**
657  * gzwrite progress indicators: defined weak to allow board-specific
658  * overrides:
659  *
660  *	gzwrite_progress_init called on startup
661  *	gzwrite_progress called during decompress/write loop
662  *	gzwrite_progress_finish called at end of loop to
663  *		indicate success (retcode=0) or failure
664  */
665 void gzwrite_progress_init(u64 expected_size);
666 
667 void gzwrite_progress(int iteration,
668 		     u64 bytes_written,
669 		     u64 total_bytes);
670 
671 void gzwrite_progress_finish(int retcode,
672 			     u64 totalwritten,
673 			     u64 totalsize,
674 			     u32 expected_crc,
675 			     u32 calculated_crc);
676 
677 /**
678  * decompress and write gzipped image from memory to block device
679  *
680  * @param	src		compressed image address
681  * @param	len		compressed image length in bytes
682  * @param	dev		block device descriptor
683  * @param	szwritebuf	bytes per write (pad to erase size)
684  * @param	startoffs	offset in bytes of first write
685  * @param	szexpected	expected uncompressed length
686  *				may be zero to use gzip trailer
687  *				for files under 4GiB
688  */
689 int gzwrite(unsigned char *src, int len,
690 	    struct blk_desc *dev,
691 	    unsigned long szwritebuf,
692 	    u64 startoffs,
693 	    u64 szexpected);
694 
695 #include <u-boot/lz4.h>
696 
697 /* lib/qsort.c */
698 void qsort(void *base, size_t nmemb, size_t size,
699 	   int(*compar)(const void *, const void *));
700 int strcmp_compar(const void *, const void *);
701 
702 /* lib/uuid.c */
703 #include <uuid.h>
704 
705 /* lib/vsprintf.c */
706 #include <vsprintf.h>
707 
708 /* lib/strmhz.c */
709 char *	strmhz(char *buf, unsigned long hz);
710 
711 /* lib/crc32.c */
712 #include <u-boot/crc.h>
713 
714 /* lib/rand.c */
715 #define RAND_MAX -1U
716 void srand(unsigned int seed);
717 unsigned int rand(void);
718 unsigned int rand_r(unsigned int *seedp);
719 
720 /*
721  * STDIO based functions (can always be used)
722  */
723 /* serial stuff */
724 int	serial_printf (const char *fmt, ...)
725 		__attribute__ ((format (__printf__, 1, 2)));
726 
727 /* lib/gzip.c */
728 int gzip(void *dst, unsigned long *lenp,
729 		unsigned char *src, unsigned long srclen);
730 int zzip(void *dst, unsigned long *lenp, unsigned char *src,
731 		unsigned long srclen, int stoponerr,
732 		int (*func)(unsigned long, unsigned long));
733 
734 /* lib/net_utils.c */
735 #include <net.h>
736 static inline struct in_addr env_get_ip(char *var)
737 {
738 	return string_to_ip(env_get(var));
739 }
740 
741 int	pcmcia_init (void);
742 
743 #ifdef CONFIG_LED_STATUS
744 # include <status_led.h>
745 #endif
746 
747 #include <bootstage.h>
748 
749 #ifdef CONFIG_SHOW_ACTIVITY
750 void show_activity(int arg);
751 #endif
752 
753 /* Multicore arch functions */
754 #ifdef CONFIG_MP
755 int cpu_status(int nr);
756 int cpu_reset(int nr);
757 int cpu_disable(int nr);
758 int cpu_release(int nr, int argc, char * const argv[]);
759 #endif
760 
761 #else	/* __ASSEMBLY__ */
762 
763 /* Drop a C type modifier (like in 3UL) for constants used in assembly. */
764 #define _AC(X, Y)       X
765 
766 #endif	/* __ASSEMBLY__ */
767 
768 /* Put only stuff here that the assembler can digest */
769 
770 /* Declare an unsigned long constant digestable both by C and an assembler. */
771 #define UL(x)           _AC(x, UL)
772 
773 #ifdef CONFIG_POST
774 #define CONFIG_HAS_POST
775 #ifndef CONFIG_POST_ALT_LIST
776 #define CONFIG_POST_STD_LIST
777 #endif
778 #endif
779 
780 #ifdef CONFIG_INIT_CRITICAL
781 #error CONFIG_INIT_CRITICAL is deprecated!
782 #error Read section CONFIG_SKIP_LOWLEVEL_INIT in README.
783 #endif
784 
785 #define ROUND(a,b)		(((a) + (b) - 1) & ~((b) - 1))
786 
787 /*
788  * check_member() - Check the offset of a structure member
789  *
790  * @structure:	Name of structure (e.g. global_data)
791  * @member:	Name of member (e.g. baudrate)
792  * @offset:	Expected offset in bytes
793  */
794 #define check_member(structure, member, offset) _Static_assert( \
795 	offsetof(struct structure, member) == offset, \
796 	"`struct " #structure "` offset for `" #member "` is not " #offset)
797 
798 /* Avoid using CONFIG_EFI_STUB directly as we may boot from other loaders */
799 #ifdef CONFIG_EFI_STUB
800 #define ll_boot_init()	false
801 #else
802 #define ll_boot_init()	true
803 #endif
804 
805 /* Pull in stuff for the build system */
806 #ifdef DO_DEPS_ONLY
807 # include <environment.h>
808 #endif
809 
810 #endif	/* __COMMON_H_ */
811