1
2
3
4
5
6
7#ifndef __COMMON_H_
8#define __COMMON_H_ 1
9
10#ifndef __ASSEMBLY__
11
12typedef unsigned char uchar;
13typedef volatile unsigned long vu_long;
14typedef volatile unsigned short vu_short;
15typedef volatile unsigned char vu_char;
16
17#include <config.h>
18#include <errno.h>
19#include <time.h>
20#include <asm-offsets.h>
21#include <linux/bitops.h>
22#include <linux/bug.h>
23#include <linux/delay.h>
24#include <linux/types.h>
25#include <linux/printk.h>
26#include <linux/string.h>
27#include <linux/stringify.h>
28#include <asm/ptrace.h>
29#include <stdarg.h>
30#include <stdio.h>
31#include <linux/kernel.h>
32
33#include <part.h>
34#include <flash.h>
35#include <image.h>
36
37#ifdef __LP64__
38#define CONFIG_SYS_SUPPORT_64BIT_DATA
39#endif
40
41#include <log.h>
42
43typedef void (interrupt_handler_t)(void *);
44
45#include <asm/u-boot.h>
46#include <asm/global_data.h>
47
48#if defined(CONFIG_ENV_IS_EMBEDDED)
49#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
50#elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
51 (CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
52 defined(CONFIG_ENV_IS_IN_NVRAM)
53#define TOTAL_MALLOC_LEN (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
54#else
55#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
56#endif
57
58
59
60
61
62
63
64#include <init.h>
65
66
67
68
69void hang (void) __attribute__ ((noreturn));
70
71int cpu_init(void);
72
73#include <display_options.h>
74
75
76void main_loop (void);
77int run_command(const char *cmd, int flag);
78int run_command_repeatable(const char *cmd, int flag);
79
80
81
82
83
84
85
86
87
88
89
90
91int run_command_list(const char *cmd, int len, int flag);
92
93int checkflash(void);
94int checkdram(void);
95extern u8 __dtb_dt_begin[];
96extern u8 __dtb_dt_spl_begin[];
97int mdm_init(void);
98
99
100
101
102
103
104
105
106void board_show_dram(phys_size_t size);
107
108
109
110
111
112
113
114
115
116
117ulong board_get_usable_ram_top(ulong total_size);
118
119
120
121
122
123
124
125
126
127int arch_fixup_fdt(void *blob);
128
129
130void flash_perror (int);
131
132
133int source (ulong addr, const char *fit_uname);
134
135extern ulong load_addr;
136extern ulong save_addr;
137extern ulong save_size;
138
139
140int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
141
142
143int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
144
145
146int do_ext2load(cmd_tbl_t *, int, int, char * const []);
147
148
149int env_init (void);
150void env_relocate (void);
151int envmatch (uchar *, int);
152
153
154
155
156
157
158
159
160
161
162
163char *env_get(const char *varname);
164
165
166
167
168
169
170
171
172
173
174
175int env_get_f(const char *name, char *buf, unsigned len);
176
177
178
179
180
181
182
183
184
185
186
187
188ulong env_get_ulong(const char *name, int base, ulong default_val);
189
190
191
192
193
194
195
196
197
198
199
200ulong env_get_hex(const char *varname, ulong default_val);
201
202
203
204
205
206int env_get_yesno(const char *var);
207
208
209
210
211
212
213
214
215
216
217
218int env_set(const char *varname, const char *value);
219
220
221
222
223
224
225
226
227int env_set_ulong(const char *varname, ulong value);
228
229
230
231
232
233
234
235
236int env_set_hex(const char *varname, ulong value);
237
238
239
240
241
242
243
244
245static inline int env_set_addr(const char *varname, const void *addr)
246{
247 return env_set_hex(varname, (ulong)addr);
248}
249
250#ifdef CONFIG_AUTO_COMPLETE
251int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf,
252 bool dollar_comp);
253#endif
254int get_env_id (void);
255
256void pci_init_board(void);
257
258
259void jumptable_init(void);
260
261
262const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
263
264
265long get_ram_size (long *, long);
266phys_size_t get_effective_memsize(void);
267
268
269void reset_phy (void);
270void fdc_hw_init (void);
271
272
273#ifdef CONFIG_CMD_EEPROM
274void eeprom_init (int bus);
275int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
276int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
277#else
278
279
280
281
282#define eeprom_init(bus)
283#define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
284#define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
285#endif
286
287#if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C) && defined(CONFIG_SYS_I2C_EEPROM_ADDR)
288# define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
289#endif
290
291
292int board_early_init_f (void);
293int board_fix_fdt (void *rw_fdt_blob);
294int board_late_init (void);
295int board_postclk_init (void);
296int board_early_init_r (void);
297
298#if defined(CONFIG_SYS_DRAM_TEST)
299int testdram(void);
300#endif
301
302
303int icache_status (void);
304void icache_enable (void);
305void icache_disable(void);
306int dcache_status (void);
307void dcache_enable (void);
308void dcache_disable(void);
309void mmu_disable(void);
310#if defined(CONFIG_ARM)
311void relocate_code(ulong);
312#else
313void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
314#endif
315ulong get_endaddr (void);
316void trap_init (ulong);
317
318
319static inline int cpumask_next(int cpu, unsigned int mask)
320{
321 for (cpu++; !((1 << cpu) & mask); cpu++)
322 ;
323
324 return cpu;
325}
326
327#define for_each_cpu(iter, cpu, num_cpus, mask) \
328 for (iter = 0, cpu = cpumask_next(-1, mask); \
329 iter < num_cpus; \
330 iter++, cpu = cpumask_next(cpu, mask)) \
331
332int cpu_numcores (void);
333int cpu_num_dspcores(void);
334u32 cpu_mask (void);
335u32 cpu_dsp_mask(void);
336int is_core_valid (unsigned int);
337
338void s_init(void);
339
340int checkcpu (void);
341int checkicache (void);
342int checkdcache (void);
343void upmconfig (unsigned int, unsigned int *, unsigned int);
344ulong get_tbclk (void);
345void reset_misc (void);
346void reset_cpu (ulong addr);
347void ft_cpu_setup(void *blob, bd_t *bd);
348void ft_pci_setup(void *blob, bd_t *bd);
349
350void smp_set_core_boot_addr(unsigned long addr, int corenr);
351void smp_kick_all_cpus(void);
352
353
354int serial_init (void);
355void serial_setbrg (void);
356void serial_putc (const char);
357void serial_putc_raw(const char);
358void serial_puts (const char *);
359int serial_getc (void);
360int serial_tstc (void);
361
362
363int get_clocks (void);
364ulong get_bus_freq (ulong);
365int get_serial_clock(void);
366
367
368int interrupt_init (void);
369void timer_interrupt (struct pt_regs *);
370void external_interrupt (struct pt_regs *);
371void irq_install_handler(int, interrupt_handler_t *, void *);
372void irq_free_handler (int);
373void reset_timer (void);
374
375
376unsigned long timer_get_us(void);
377
378void enable_interrupts (void);
379int disable_interrupts (void);
380
381
382int dpram_init (void);
383uint dpram_base(void);
384uint dpram_base_align(uint align);
385uint dpram_alloc(uint size);
386uint dpram_alloc_align(uint size,uint align);
387void bootcount_store (ulong);
388ulong bootcount_load (void);
389
390
391void mii_init (void);
392
393
394ulong lcd_setmem (ulong);
395
396
397ulong video_setmem (ulong);
398
399
400void enable_caches(void);
401void flush_cache (unsigned long, unsigned long);
402void flush_dcache_all(void);
403void flush_dcache_range(unsigned long start, unsigned long stop);
404void invalidate_dcache_range(unsigned long start, unsigned long stop);
405void invalidate_dcache_all(void);
406void invalidate_icache_all(void);
407
408enum {
409
410 CBL_DISABLE_CACHES = 1 << 0,
411 CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1,
412
413 CBL_ALL = 3,
414};
415
416
417
418
419
420
421int cleanup_before_linux_select(int flags);
422
423
424uint64_t get_ticks(void);
425void wait_ticks (unsigned long);
426
427
428ulong usec2ticks (unsigned long usec);
429ulong ticks2usec (unsigned long ticks);
430
431
432int gzip_parse_header(const unsigned char *src, unsigned long len);
433int gunzip(void *, int, unsigned char *, unsigned long *);
434int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
435 int stoponerr, int offset);
436
437
438
439
440
441
442
443
444
445
446void gzwrite_progress_init(u64 expected_size);
447
448void gzwrite_progress(int iteration,
449 u64 bytes_written,
450 u64 total_bytes);
451
452void gzwrite_progress_finish(int retcode,
453 u64 totalwritten,
454 u64 totalsize,
455 u32 expected_crc,
456 u32 calculated_crc);
457
458
459
460
461
462
463
464
465
466
467
468
469
470int gzwrite(unsigned char *src, int len,
471 struct blk_desc *dev,
472 unsigned long szwritebuf,
473 u64 startoffs,
474 u64 szexpected);
475
476
477int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
478
479
480void qsort(void *base, size_t nmemb, size_t size,
481 int(*compar)(const void *, const void *));
482int strcmp_compar(const void *, const void *);
483
484
485#include <uuid.h>
486
487
488#include <vsprintf.h>
489
490
491char * strmhz(char *buf, unsigned long hz);
492
493
494#include <u-boot/crc.h>
495
496
497#define RAND_MAX -1U
498void srand(unsigned int seed);
499unsigned int rand(void);
500unsigned int rand_r(unsigned int *seedp);
501
502
503
504
505
506int serial_printf (const char *fmt, ...)
507 __attribute__ ((format (__printf__, 1, 2)));
508
509
510int gzip(void *dst, unsigned long *lenp,
511 unsigned char *src, unsigned long srclen);
512int zzip(void *dst, unsigned long *lenp, unsigned char *src,
513 unsigned long srclen, int stoponerr,
514 int (*func)(unsigned long, unsigned long));
515
516
517#include <net.h>
518static inline struct in_addr env_get_ip(char *var)
519{
520 return string_to_ip(env_get(var));
521}
522
523int pcmcia_init (void);
524
525#ifdef CONFIG_LED_STATUS
526# include <status_led.h>
527#endif
528
529#include <bootstage.h>
530
531#ifdef CONFIG_SHOW_ACTIVITY
532void show_activity(int arg);
533#endif
534
535
536#ifdef CONFIG_MP
537int cpu_status(u32 nr);
538int cpu_reset(u32 nr);
539int cpu_disable(u32 nr);
540int cpu_release(u32 nr, int argc, char * const argv[]);
541#endif
542
543#else
544
545#endif
546
547
548
549#ifdef CONFIG_POST
550#define CONFIG_HAS_POST
551#ifndef CONFIG_POST_ALT_LIST
552#define CONFIG_POST_STD_LIST
553#endif
554#endif
555
556#define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
557
558
559
560
561
562
563
564
565#define check_member(structure, member, offset) _Static_assert( \
566 offsetof(struct structure, member) == offset, \
567 "`struct " #structure "` offset for `" #member "` is not " #offset)
568
569
570#ifdef CONFIG_EFI_STUB
571#define ll_boot_init() false
572#else
573#define ll_boot_init() true
574#endif
575
576
577#ifdef DO_DEPS_ONLY
578# include <environment.h>
579#endif
580
581#endif
582