1
2
3
4
5
6
7
8#ifndef __COMMON_H_
9#define __COMMON_H_ 1
10
11#ifndef __ASSEMBLY__
12
13typedef unsigned char uchar;
14typedef volatile unsigned long vu_long;
15typedef volatile unsigned short vu_short;
16typedef volatile unsigned char vu_char;
17
18
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 <stdarg.h>
34#include <stdio.h>
35#include <linux/kernel.h>
36
37#include <part.h>
38#include <flash.h>
39#include <image.h>
40
41
42#define __STDC_FORMAT_MACROS
43
44#ifdef __LP64__
45#define CONFIG_SYS_SUPPORT_64BIT_DATA
46#endif
47
48#include <log.h>
49
50typedef void (interrupt_handler_t)(void *);
51
52#include <asm/u-boot.h>
53#include <asm/global_data.h>
54
55#if defined(CONFIG_ENV_IS_EMBEDDED)
56#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
57#elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \
58 (CONFIG_ENV_ADDR >= (CONFIG_SYS_MONITOR_BASE + CONFIG_SYS_MONITOR_LEN)) ) || \
59 defined(CONFIG_ENV_IS_IN_NVRAM)
60#define TOTAL_MALLOC_LEN (CONFIG_SYS_MALLOC_LEN + CONFIG_ENV_SIZE)
61#else
62#define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN
63#endif
64
65
66
67
68int dram_init(void);
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85int dram_init_banksize(void);
86
87void hang (void) __attribute__ ((noreturn));
88
89int timer_init(void);
90int cpu_init(void);
91
92#include <display_options.h>
93
94
95void main_loop (void);
96int run_command(const char *cmd, int flag);
97int run_command_repeatable(const char *cmd, int flag);
98
99
100
101
102
103
104
105
106
107
108
109
110int run_command_list(const char *cmd, int len, int flag);
111
112
113void board_init_f(ulong);
114void board_init_r(gd_t *, ulong) __attribute__ ((noreturn));
115
116
117
118
119
120
121
122
123
124
125
126ulong board_init_f_alloc_reserve(ulong top);
127
128
129
130
131
132
133
134
135
136void board_init_f_init_reserve(ulong base);
137
138
139
140
141
142
143
144
145
146
147
148
149
150void arch_setup_gd(gd_t *gd_ptr);
151
152int checkboard(void);
153int show_board_info(void);
154int checkflash(void);
155int checkdram(void);
156int last_stage_init(void);
157extern ulong monitor_flash_len;
158int mac_read_from_eeprom(void);
159extern u8 __dtb_dt_begin[];
160extern u8 __dtb_dt_spl_begin[];
161int set_cpu_clk_info(void);
162int mdm_init(void);
163int print_cpuinfo(void);
164int update_flash_size(int flash_size);
165int arch_early_init_r(void);
166
167
168
169
170
171
172int setup_board_extra(void);
173
174
175
176
177
178
179
180
181int arch_fsp_init(void);
182
183
184
185
186
187
188
189
190
191
192int arch_cpu_init_dm(void);
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210__weak int arch_reserve_stacks(void);
211
212
213
214
215
216
217
218
219void board_show_dram(phys_size_t size);
220
221
222
223
224
225
226
227
228
229int arch_fixup_fdt(void *blob);
230
231int reserve_mmu(void);
232
233void flash_perror (int);
234
235
236int source (ulong addr, const char *fit_uname);
237
238extern ulong load_addr;
239extern ulong save_addr;
240extern ulong save_size;
241
242
243int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
244
245
246int do_fat_fsload(cmd_tbl_t *, int, int, char * const []);
247
248
249int do_ext2load(cmd_tbl_t *, int, int, char * const []);
250
251
252int env_init (void);
253void env_relocate (void);
254int envmatch (uchar *, int);
255
256
257
258
259
260
261
262
263
264
265
266char *env_get(const char *varname);
267
268
269
270
271
272
273
274
275
276
277
278int env_get_f(const char *name, char *buf, unsigned len);
279
280
281
282
283
284
285
286
287
288
289
290
291ulong env_get_ulong(const char *name, int base, ulong default_val);
292
293
294
295
296
297
298
299
300
301
302
303ulong env_get_hex(const char *varname, ulong default_val);
304
305
306
307
308
309int env_get_yesno(const char *var);
310
311
312
313
314
315
316
317
318
319
320
321int env_set(const char *varname, const char *value);
322
323
324
325
326
327
328
329
330int env_set_ulong(const char *varname, ulong value);
331
332
333
334
335
336
337
338
339int env_set_hex(const char *varname, ulong value);
340
341
342
343
344
345
346
347
348static inline int env_set_addr(const char *varname, const void *addr)
349{
350 return env_set_hex(varname, (ulong)addr);
351}
352
353#ifdef CONFIG_AUTO_COMPLETE
354int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf);
355#endif
356int get_env_id (void);
357
358void pci_init (void);
359void pci_init_board(void);
360
361#if defined(CONFIG_DTB_RESELECT)
362int embedded_dtb_select(void);
363#endif
364
365int misc_init_f (void);
366int misc_init_r (void);
367
368
369void jumptable_init(void);
370
371
372const char *symbol_lookup(unsigned long addr, unsigned long *caddr);
373
374
375long get_ram_size (long *, long);
376phys_size_t get_effective_memsize(void);
377
378
379void reset_phy (void);
380void fdc_hw_init (void);
381
382
383#ifdef CONFIG_CMD_EEPROM
384void eeprom_init (int bus);
385int eeprom_read (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
386int eeprom_write (unsigned dev_addr, unsigned offset, uchar *buffer, unsigned cnt);
387#else
388
389
390
391
392#define eeprom_init(bus)
393#define eeprom_read(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
394#define eeprom_write(dev_addr, offset, buffer, cnt) ((void)-ENOSYS)
395#endif
396
397
398
399
400
401#if defined(CONFIG_SPI) || !defined(CONFIG_SYS_I2C_EEPROM_ADDR)
402# define CONFIG_SYS_DEF_EEPROM_ADDR 0
403#else
404#if !defined(CONFIG_ENV_EEPROM_IS_ON_I2C)
405# define CONFIG_SYS_DEF_EEPROM_ADDR CONFIG_SYS_I2C_EEPROM_ADDR
406#endif
407#endif
408
409#if defined(CONFIG_SPI)
410extern void spi_init_f (void);
411extern void spi_init_r (void);
412extern ssize_t spi_read (uchar *, int, uchar *, int);
413extern ssize_t spi_write (uchar *, int, uchar *, int);
414#endif
415
416
417int board_early_init_f (void);
418int board_fix_fdt (void *rw_fdt_blob);
419int board_late_init (void);
420int board_postclk_init (void);
421int board_early_init_r (void);
422void board_poweroff (void);
423
424#if defined(CONFIG_SYS_DRAM_TEST)
425int testdram(void);
426#endif
427
428
429int icache_status (void);
430void icache_enable (void);
431void icache_disable(void);
432int dcache_status (void);
433void dcache_enable (void);
434void dcache_disable(void);
435void mmu_disable(void);
436#if defined(CONFIG_ARM)
437void relocate_code(ulong);
438#else
439void relocate_code(ulong, gd_t *, ulong) __attribute__ ((noreturn));
440#endif
441ulong get_endaddr (void);
442void trap_init (ulong);
443
444
445static inline int cpumask_next(int cpu, unsigned int mask)
446{
447 for (cpu++; !((1 << cpu) & mask); cpu++)
448 ;
449
450 return cpu;
451}
452
453#define for_each_cpu(iter, cpu, num_cpus, mask) \
454 for (iter = 0, cpu = cpumask_next(-1, mask); \
455 iter < num_cpus; \
456 iter++, cpu = cpumask_next(cpu, mask)) \
457
458int cpu_numcores (void);
459int cpu_num_dspcores(void);
460u32 cpu_mask (void);
461u32 cpu_dsp_mask(void);
462int is_core_valid (unsigned int);
463
464
465
466
467
468
469
470
471
472int arch_cpu_init(void);
473
474void s_init(void);
475
476int checkcpu (void);
477int checkicache (void);
478int checkdcache (void);
479void upmconfig (unsigned int, unsigned int *, unsigned int);
480ulong get_tbclk (void);
481void reset_misc (void);
482void reset_cpu (ulong addr);
483void ft_cpu_setup(void *blob, bd_t *bd);
484void ft_pci_setup(void *blob, bd_t *bd);
485
486void smp_set_core_boot_addr(unsigned long addr, int corenr);
487void smp_kick_all_cpus(void);
488
489
490int serial_init (void);
491void serial_setbrg (void);
492void serial_putc (const char);
493void serial_putc_raw(const char);
494void serial_puts (const char *);
495int serial_getc (void);
496int serial_tstc (void);
497
498
499int get_clocks (void);
500ulong get_bus_freq (ulong);
501int get_serial_clock(void);
502
503int cpu_init_r (void);
504
505
506int interrupt_init (void);
507void timer_interrupt (struct pt_regs *);
508void external_interrupt (struct pt_regs *);
509void irq_install_handler(int, interrupt_handler_t *, void *);
510void irq_free_handler (int);
511void reset_timer (void);
512
513
514unsigned long timer_get_us(void);
515
516void enable_interrupts (void);
517int disable_interrupts (void);
518
519
520int dpram_init (void);
521uint dpram_base(void);
522uint dpram_base_align(uint align);
523uint dpram_alloc(uint size);
524uint dpram_alloc_align(uint size,uint align);
525void bootcount_store (ulong);
526ulong bootcount_load (void);
527#define BOOTCOUNT_MAGIC 0xB001C041
528
529
530void mii_init (void);
531
532
533ulong lcd_setmem (ulong);
534
535
536ulong video_setmem (ulong);
537
538
539void enable_caches(void);
540void flush_cache (unsigned long, unsigned long);
541void flush_dcache_all(void);
542void flush_dcache_range(unsigned long start, unsigned long stop);
543void invalidate_dcache_range(unsigned long start, unsigned long stop);
544void invalidate_dcache_all(void);
545void invalidate_icache_all(void);
546
547enum {
548
549 CBL_DISABLE_CACHES = 1 << 0,
550 CBL_SHOW_BOOTSTAGE_REPORT = 1 << 1,
551
552 CBL_ALL = 3,
553};
554
555
556
557
558
559
560int cleanup_before_linux_select(int flags);
561
562
563uint64_t get_ticks(void);
564void wait_ticks (unsigned long);
565
566
567ulong usec2ticks (unsigned long usec);
568ulong ticks2usec (unsigned long ticks);
569
570
571int gzip_parse_header(const unsigned char *src, unsigned long len);
572int gunzip(void *, int, unsigned char *, unsigned long *);
573int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
574 int stoponerr, int offset);
575
576
577
578
579
580
581
582
583
584
585void gzwrite_progress_init(u64 expected_size);
586
587void gzwrite_progress(int iteration,
588 u64 bytes_written,
589 u64 total_bytes);
590
591void gzwrite_progress_finish(int retcode,
592 u64 totalwritten,
593 u64 totalsize,
594 u32 expected_crc,
595 u32 calculated_crc);
596
597
598
599
600
601
602
603
604
605
606
607
608
609int gzwrite(unsigned char *src, int len,
610 struct blk_desc *dev,
611 unsigned long szwritebuf,
612 u64 startoffs,
613 u64 szexpected);
614
615
616int ulz4fn(const void *src, size_t srcn, void *dst, size_t *dstn);
617
618
619void qsort(void *base, size_t nmemb, size_t size,
620 int(*compar)(const void *, const void *));
621int strcmp_compar(const void *, const void *);
622
623
624#include <uuid.h>
625
626
627#include <vsprintf.h>
628
629
630char * strmhz(char *buf, unsigned long hz);
631
632
633#include <u-boot/crc.h>
634
635
636#define RAND_MAX -1U
637void srand(unsigned int seed);
638unsigned int rand(void);
639unsigned int rand_r(unsigned int *seedp);
640
641
642
643
644
645int serial_printf (const char *fmt, ...)
646 __attribute__ ((format (__printf__, 1, 2)));
647
648
649int gzip(void *dst, unsigned long *lenp,
650 unsigned char *src, unsigned long srclen);
651int zzip(void *dst, unsigned long *lenp, unsigned char *src,
652 unsigned long srclen, int stoponerr,
653 int (*func)(unsigned long, unsigned long));
654
655
656#include <net.h>
657static inline struct in_addr env_get_ip(char *var)
658{
659 return string_to_ip(env_get(var));
660}
661
662int pcmcia_init (void);
663
664#ifdef CONFIG_LED_STATUS
665# include <status_led.h>
666#endif
667
668#include <bootstage.h>
669
670#ifdef CONFIG_SHOW_ACTIVITY
671void show_activity(int arg);
672#endif
673
674
675#ifdef CONFIG_MP
676int cpu_status(int nr);
677int cpu_reset(int nr);
678int cpu_disable(int nr);
679int cpu_release(int nr, int argc, char * const argv[]);
680#endif
681
682#else
683
684
685#define _AC(X, Y) X
686
687#endif
688
689
690
691
692#define UL(x) _AC(x, UL)
693
694#ifdef CONFIG_POST
695#define CONFIG_HAS_POST
696#ifndef CONFIG_POST_ALT_LIST
697#define CONFIG_POST_STD_LIST
698#endif
699#endif
700
701#ifdef CONFIG_INIT_CRITICAL
702#error CONFIG_INIT_CRITICAL is deprecated!
703#error Read section CONFIG_SKIP_LOWLEVEL_INIT in README.
704#endif
705
706#define ROUND(a,b) (((a) + (b) - 1) & ~((b) - 1))
707
708
709
710
711
712
713
714
715#define check_member(structure, member, offset) _Static_assert( \
716 offsetof(struct structure, member) == offset, \
717 "`struct " #structure "` offset for `" #member "` is not " #offset)
718
719
720#ifdef CONFIG_EFI_STUB
721#define ll_boot_init() false
722#else
723#define ll_boot_init() true
724#endif
725
726
727#ifdef DO_DEPS_ONLY
728# include <environment.h>
729#endif
730
731#endif
732