X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=include%2Fcommon.h;h=a7fb05e52ee13c6f85b615750623c3e73e4dcdf6;hb=d923a5d59f2ca2ba4d31b424ff36ff282f858eb5;hp=d244bd40b5bc5b12d2e6bfd9831156a92c7eb525;hpb=33b48657df484e591af9ec3495a059c9cf1d84d7;p=oweals%2Fu-boot.git diff --git a/include/common.h b/include/common.h index d244bd40b5..a7fb05e52e 100644 --- a/include/common.h +++ b/include/common.h @@ -116,20 +116,26 @@ typedef volatile unsigned char vu_char; #include #include -#ifdef DEBUG -#define debug(fmt,args...) printf (fmt ,##args) -#define debugX(level,fmt,args...) if (DEBUG>=level) printf(fmt,##args); -#else -#define debug(fmt,args...) -#define debugX(level,fmt,args...) -#endif /* DEBUG */ - #ifdef DEBUG -# define _DEBUG 1 +#define _DEBUG 1 #else -# define _DEBUG 0 +#define _DEBUG 0 #endif +/* + * Output a debug text when condition "cond" is met. The "cond" should be + * computed by a preprocessor in the best case, allowing for the best + * optimization. + */ +#define debug_cond(cond, fmt, args...) \ + do { \ + if (cond) \ + printf(fmt, ##args); \ + } while (0) + +#define debug(fmt, args...) \ + debug_cond(_DEBUG, fmt, ##args) + /* * An assertion is run-time check done in debug mode only. If DEBUG is not * defined then it is skipped. If DEBUG is defined and the assertion fails, @@ -216,6 +222,31 @@ typedef void (interrupt_handler_t)(void *); #define MIN(x, y) min(x, y) #define MAX(x, y) max(x, y) +/* + * Return the absolute value of a number. + * + * This handles unsigned and signed longs, ints, shorts and chars. For all + * input types abs() returns a signed long. + * + * For 64-bit types, use abs64() + */ +#define abs(x) ({ \ + long ret; \ + if (sizeof(x) == sizeof(long)) { \ + long __x = (x); \ + ret = (__x < 0) ? -__x : __x; \ + } else { \ + int __x = (x); \ + ret = (__x < 0) ? -__x : __x; \ + } \ + ret; \ + }) + +#define abs64(x) ({ \ + s64 __x = (x); \ + (__x < 0) ? -__x : __x; \ + }) + #if defined(CONFIG_ENV_IS_EMBEDDED) #define TOTAL_MALLOC_LEN CONFIG_SYS_MALLOC_LEN #elif ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \ @@ -254,12 +285,30 @@ int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen); /* common/main.c */ void main_loop (void); -int run_command (const char *cmd, int flag); +int run_command(const char *cmd, int flag); + +/** + * Run a list of commands separated by ; or even \0 + * + * Note that if 'len' is not -1, then the command does not need to be nul + * terminated, Memory will be allocated for the command in that case. + * + * @param cmd List of commands to run, each separated bu semicolon + * @param len Length of commands excluding terminator if known (-1 if not) + * @param flag Execution flags (CMD_FLAG_...) + * @return 0 on success, or != 0 on error. + */ +int run_command_list(const char *cmd, int len, int flag); int readline (const char *const prompt); -int readline_into_buffer (const char *const prompt, char * buffer); +int readline_into_buffer(const char *const prompt, char *buffer, + int timeout); int parse_line (char *, char *[]); void init_cmd_timeout(void); void reset_cmd_timeout(void); +#ifdef CONFIG_MENU +int abortboot(int bootdelay); +#endif +extern char console_buffer[]; /* arch/$(ARCH)/lib/board.c */ void board_init_f (ulong) __attribute__ ((noreturn)); @@ -270,6 +319,8 @@ int checkdram (void); int last_stage_init(void); extern ulong monitor_flash_len; int mac_read_from_eeprom(void); +extern u8 _binary_dt_dtb_start[]; /* embedded device tree blob */ +int set_cpu_clk_info(void); /* common/flash.c */ void flash_perror (int); @@ -278,21 +329,35 @@ void flash_perror (int); int source (ulong addr, const char *fit_uname); extern ulong load_addr; /* Default Load Address */ +extern ulong save_addr; /* Default Save Address */ +extern ulong save_size; /* Default Save Size */ /* common/cmd_doc.c */ void doc_probe(unsigned long physadr); +/* common/cmd_net.c */ +int do_tftpb(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); + +/* common/cmd_fat.c */ +int do_fat_fsload(cmd_tbl_t *, int, int, char * const []); + +/* common/cmd_ext2.c */ +int do_ext2load(cmd_tbl_t *, int, int, char * const []); + /* common/cmd_nvedit.c */ int env_init (void); void env_relocate (void); int envmatch (uchar *, int); char *getenv (const char *); int getenv_f (const char *name, char *buf, unsigned len); +ulong getenv_ulong(const char *name, int base, ulong default_val); int saveenv (void); #ifdef CONFIG_PPC /* ARM version to be fixed! */ int inline setenv (const char *, const char *); #else int setenv (const char *, const char *); +int setenv_ulong(const char *varname, ulong value); +int setenv_addr(const char *varname, const void *addr); #endif /* CONFIG_PPC */ #ifdef CONFIG_ARM # include @@ -302,6 +367,16 @@ int setenv (const char *, const char *); #ifdef CONFIG_X86 /* x86 version to be fixed! */ # include #endif /* CONFIG_X86 */ +#ifdef CONFIG_SANDBOX +# include /* TODO(sjg) what needs to be fixed? */ +#endif +#ifdef CONFIG_NDS32 +# include +# include +#endif /* CONFIG_NDS32 */ +#ifdef CONFIG_MIPS +# include +#endif /* CONFIG_MIPS */ #ifdef CONFIG_AUTO_COMPLETE int env_complete(char *var, int maxv, char *cmdv[], int maxsz, char *buf); @@ -485,7 +560,22 @@ void ddr_enable_ecc(unsigned int dram_size); #endif /* $(CPU)/cpu.c */ +static inline int cpumask_next(int cpu, unsigned int mask) +{ + for (cpu++; !((1 << cpu) & mask); cpu++) + ; + + return cpu; +} + +#define for_each_cpu(iter, cpu, num_cpus, mask) \ + for (iter = 0, cpu = cpumask_next(-1, mask); \ + iter < num_cpus; \ + iter++, cpu = cpumask_next(cpu, mask)) \ + int cpu_numcores (void); +u32 cpu_mask (void); +int is_core_valid (unsigned int); int probecpu (void); int checkcpu (void); int checkicache (void); @@ -503,7 +593,6 @@ void ft_pci_setup(void *blob, bd_t *bd); /* $(CPU)/serial.c */ int serial_init (void); -void serial_exit (void); void serial_setbrg (void); void serial_putc (const char); void serial_putc_raw(const char); @@ -565,10 +654,12 @@ ulong get_PERCLK3(void); ulong get_bus_freq (ulong); int get_serial_clock(void); +#if defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx) +ulong get_ddr_freq(ulong); +#endif #if defined(CONFIG_MPC85xx) typedef MPC85xx_SYS_INFO sys_info_t; void get_sys_info ( sys_info_t * ); -ulong get_ddr_freq (ulong); #endif #if defined(CONFIG_MPC86xx) typedef MPC86xx_SYS_INFO sys_info_t; @@ -660,13 +751,6 @@ int gunzip(void *, int, unsigned char *, unsigned long *); int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, int stoponerr, int offset); -/* lib/net_utils.c */ -#include -static inline IPaddr_t getenv_IPaddr (char *var) -{ - return (string_to_ip(getenv(var))); -} - /* lib/qsort.c */ void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); @@ -674,17 +758,14 @@ int strcmp_compar(const void *, const void *); /* lib/time.c */ void udelay (unsigned long); +void mdelay(unsigned long); + +/* lib/uuid.c */ +void uuid_str_to_bin(const char *uuid, unsigned char *out); +int uuid_str_valid(const char *uuid); /* lib/vsprintf.c */ -ulong simple_strtoul(const char *cp,char **endp,unsigned int base); -int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); -unsigned long long simple_strtoull(const char *cp,char **endp,unsigned int base); -long simple_strtol(const char *cp,char **endp,unsigned int base); -void panic(const char *fmt, ...) - __attribute__ ((format (__printf__, 1, 2), noreturn)); -int sprintf(char * buf, const char *fmt, ...) - __attribute__ ((format (__printf__, 2, 3))); -int vsprintf(char *buf, const char *fmt, va_list args); +#include /* lib/strmhz.c */ char * strmhz(char *buf, unsigned long hz); @@ -692,6 +773,16 @@ char * strmhz(char *buf, unsigned long hz); /* lib/crc32.c */ #include +/* lib/rand.c */ +#if defined(CONFIG_RANDOM_MACADDR) || \ + defined(CONFIG_BOOTP_RANDOM_DELAY) || \ + defined(CONFIG_CMD_LINK_LOCAL) +#define RAND_MAX -1U +void srand(unsigned int seed); +unsigned int rand(void); +unsigned int rand_r(unsigned int *seedp); +#endif + /* common/console.c */ int console_init_f(void); /* Before relocation; uses the serial stuff */ int console_init_r(void); /* After relocation; uses the console stuff */ @@ -738,6 +829,20 @@ void fputc(int file, const char c); int ftstc(int file); int fgetc(int file); +/* lib/gzip.c */ +int gzip(void *dst, unsigned long *lenp, + unsigned char *src, unsigned long srclen); +int zzip(void *dst, unsigned long *lenp, unsigned char *src, + unsigned long srclen, int stoponerr, + int (*func)(unsigned long, unsigned long)); + +/* lib/net_utils.c */ +#include +static inline IPaddr_t getenv_IPaddr(char *var) +{ + return string_to_ip(getenv(var)); +} + /* * CONSOLE multiplexing. */ @@ -750,10 +855,12 @@ int pcmcia_init (void); #ifdef CONFIG_STATUS_LED # include #endif -/* - * Board-specific Platform code can reimplement show_boot_progress () if needed - */ -void show_boot_progress(int val); + +#include + +#ifdef CONFIG_SHOW_ACTIVITY +void show_activity(int arg); +#endif /* Multicore arch functions */ #ifdef CONFIG_MP @@ -765,6 +872,14 @@ int cpu_release(int nr, int argc, char * const argv[]); #endif /* __ASSEMBLY__ */ +#ifdef CONFIG_PPC +/* + * Has to be included outside of the #ifndef __ASSEMBLY__ section. + * Otherwise might lead to compilation errors in assembler files. + */ +#include +#endif + /* Put only stuff here that the assembler can digest */ #ifdef CONFIG_POST @@ -789,6 +904,86 @@ int cpu_release(int nr, int argc, char * const argv[]); #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) +/* + * ARCH_DMA_MINALIGN is defined in asm/cache.h for each architecture. It + * is used to align DMA buffers. + */ +#ifndef __ASSEMBLY__ +#include +#endif + +/* + * The ALLOC_CACHE_ALIGN_BUFFER macro is used to allocate a buffer on the + * stack that meets the minimum architecture alignment requirements for DMA. + * Such a buffer is useful for DMA operations where flushing and invalidating + * the cache before and after a read and/or write operation is required for + * correct operations. + * + * When called the macro creates an array on the stack that is sized such + * that: + * + * 1) The beginning of the array can be advanced enough to be aligned. + * + * 2) The size of the aligned portion of the array is a multiple of the minimum + * architecture alignment required for DMA. + * + * 3) The aligned portion contains enough space for the original number of + * elements requested. + * + * The macro then creates a pointer to the aligned portion of this array and + * assigns to the pointer the address of the first element in the aligned + * portion of the array. + * + * Calling the macro as: + * + * ALLOC_CACHE_ALIGN_BUFFER(uint32_t, buffer, 1024); + * + * Will result in something similar to saying: + * + * uint32_t buffer[1024]; + * + * The following differences exist: + * + * 1) The resulting buffer is guaranteed to be aligned to the value of + * ARCH_DMA_MINALIGN. + * + * 2) The buffer variable created by the macro is a pointer to the specified + * type, and NOT an array of the specified type. This can be very important + * if you want the address of the buffer, which you probably do, to pass it + * to the DMA hardware. The value of &buffer is different in the two cases. + * In the macro case it will be the address of the pointer, not the address + * of the space reserved for the buffer. However, in the second case it + * would be the address of the buffer. So if you are replacing hard coded + * stack buffers with this macro you need to make sure you remove the & from + * the locations where you are taking the address of the buffer. + * + * Note that the size parameter is the number of array elements to allocate, + * not the number of bytes. + * + * This macro can not be used outside of function scope, or for the creation + * of a function scoped static buffer. It can not be used to create a cache + * line aligned global buffer. + */ +#define ALLOC_ALIGN_BUFFER(type, name, size, align) \ + char __##name[ROUND(size * sizeof(type), align) + (align - 1)]; \ + \ + type *name = (type *) ALIGN((uintptr_t)__##name, align) +#define ALLOC_CACHE_ALIGN_BUFFER(type, name, size) \ + ALLOC_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN) + +/* + * DEFINE_CACHE_ALIGN_BUFFER() is similar to ALLOC_CACHE_ALIGN_BUFFER, but it's + * purpose is to allow allocating aligned buffers outside of function scope. + * Usage of this macro shall be avoided or used with extreme care! + */ +#define DEFINE_ALIGN_BUFFER(type, name, size, align) \ + static char __##name[roundup(size * sizeof(type), align)] \ + __attribute__((aligned(align))); \ + \ + static type *name = (type *)__##name +#define DEFINE_CACHE_ALIGN_BUFFER(type, name, size) \ + DEFINE_ALIGN_BUFFER(type, name, size, ARCH_DMA_MINALIGN) + /* Pull in stuff for the build system */ #ifdef DO_DEPS_ONLY # include