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