2002-11-02 23:30:20 +00:00
|
|
|
/*
|
2004-01-02 14:00:00 +00:00
|
|
|
* (C) Copyright 2000-2004
|
2002-11-02 23:30:20 +00:00
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2004-01-04 16:28:35 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2002-11-02 23:30:20 +00:00
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __COMMON_H_
|
|
|
|
#define __COMMON_H_ 1
|
|
|
|
|
2007-07-05 16:01:39 +00:00
|
|
|
#include <stdio.h>
|
2007-10-04 10:37:06 +00:00
|
|
|
#include <module.h>
|
2002-11-02 23:30:20 +00:00
|
|
|
#include <config.h>
|
2015-09-23 13:12:06 +00:00
|
|
|
#include <clock.h>
|
2002-11-02 23:30:20 +00:00
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/string.h>
|
2008-08-11 08:00:03 +00:00
|
|
|
#include <linux/kernel.h>
|
2010-01-12 19:30:41 +00:00
|
|
|
#include <linux/stddef.h>
|
2007-07-05 16:02:16 +00:00
|
|
|
#include <asm/common.h>
|
2012-12-19 13:57:10 +00:00
|
|
|
#include <printk.h>
|
2002-11-02 23:30:20 +00:00
|
|
|
|
2012-06-28 07:56:23 +00:00
|
|
|
/*
|
|
|
|
* sanity check. The Linux Kernel defines only one of __LITTLE_ENDIAN and
|
|
|
|
* __BIG_ENDIAN. Endianess can then be tested with #ifdef __xx_ENDIAN. Userspace
|
|
|
|
* always defined both __LITTLE_ENDIAN and __BIG_ENDIAN and byteorder can then
|
|
|
|
* be tested with #if __BYTE_ORDER == __xx_ENDIAN.
|
|
|
|
*
|
|
|
|
* As we tend to use a lot of Kernel code in barebox we use the kernel way of
|
|
|
|
* determing the byte order. Make sure here that architecture code properly
|
|
|
|
* defines it.
|
|
|
|
*/
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#if defined __LITTLE_ENDIAN && defined __BIG_ENDIAN
|
|
|
|
#error "both __LITTLE_ENDIAN and __BIG_ENDIAN are defined"
|
|
|
|
#endif
|
|
|
|
#if !defined __LITTLE_ENDIAN && !defined __BIG_ENDIAN
|
|
|
|
#error "None of __LITTLE_ENDIAN and __BIG_ENDIAN are defined"
|
|
|
|
#endif
|
|
|
|
|
2009-12-15 08:11:09 +00:00
|
|
|
#include <asm/barebox.h> /* boot information for Linux kernel */
|
2002-11-02 23:30:20 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function Prototypes
|
|
|
|
*/
|
2007-07-05 16:02:14 +00:00
|
|
|
void reginfo(void);
|
2002-11-02 23:30:20 +00:00
|
|
|
|
2010-03-30 08:18:29 +00:00
|
|
|
void __noreturn hang (void);
|
2002-11-02 23:30:20 +00:00
|
|
|
|
2012-12-17 15:48:25 +00:00
|
|
|
char *size_human_readable(unsigned long long size);
|
2002-11-02 23:30:20 +00:00
|
|
|
|
2007-07-05 16:01:48 +00:00
|
|
|
int readline (const char *prompt, char *buf, int len);
|
2003-07-24 23:38:38 +00:00
|
|
|
|
2004-01-06 22:38:14 +00:00
|
|
|
/* common/memsize.c */
|
2006-11-06 16:06:36 +00:00
|
|
|
long get_ram_size (volatile long *, long);
|
2004-01-06 22:38:14 +00:00
|
|
|
|
2002-11-02 23:30:20 +00:00
|
|
|
/* $(CPU)/cpu.c */
|
2012-06-13 19:43:07 +00:00
|
|
|
void __noreturn poweroff(void);
|
2002-11-02 23:30:20 +00:00
|
|
|
|
|
|
|
/* common/console.c */
|
|
|
|
int ctrlc (void);
|
|
|
|
|
2012-01-26 11:26:22 +00:00
|
|
|
#ifdef ARCH_HAS_STACK_DUMP
|
|
|
|
void dump_stack(void);
|
|
|
|
#else
|
|
|
|
static inline void dump_stack(void)
|
|
|
|
{
|
|
|
|
printf("no stack data available\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-18 15:21:18 +00:00
|
|
|
int parse_area_spec(const char *str, loff_t *start, loff_t *size);
|
2007-07-05 16:01:23 +00:00
|
|
|
|
|
|
|
/* Just like simple_strtoul(), but this one honors a K/M/G suffix */
|
|
|
|
unsigned long strtoul_suffix(const char *str, char **endp, int base);
|
2011-10-14 10:05:09 +00:00
|
|
|
unsigned long long strtoull_suffix(const char *str, char **endp, int base);
|
2007-07-05 16:01:23 +00:00
|
|
|
|
2013-01-20 12:59:47 +00:00
|
|
|
/*
|
|
|
|
* Function pointer to the main barebox function. Defaults
|
|
|
|
* to run_shell() when a shell is enabled.
|
|
|
|
*/
|
|
|
|
extern int (*barebox_main)(void);
|
|
|
|
|
2013-01-20 12:36:20 +00:00
|
|
|
void __noreturn start_barebox(void);
|
2009-12-15 08:11:09 +00:00
|
|
|
void shutdown_barebox(void);
|
2007-09-16 09:16:08 +00:00
|
|
|
|
2013-06-03 23:13:49 +00:00
|
|
|
#define ALIGN_DOWN(x, a) ((x) & ~((typeof(x))(a) - 1))
|
2010-02-09 16:33:50 +00:00
|
|
|
|
|
|
|
#define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
|
2007-09-28 17:46:37 +00:00
|
|
|
|
2013-10-19 12:20:48 +00:00
|
|
|
/*
|
|
|
|
* The STACK_ALIGN_ARRAY macro is used to allocate a buffer on the stack that
|
|
|
|
* meets a minimum alignment requirement.
|
|
|
|
*
|
|
|
|
* Note that the size parameter is the number of array elements to allocate,
|
|
|
|
* not the number of bytes.
|
|
|
|
*/
|
|
|
|
#define STACK_ALIGN_ARRAY(type, name, size, align) \
|
|
|
|
char __##name[sizeof(type) * (size) + (align) - 1]; \
|
|
|
|
type *name = (type *)ALIGN((uintptr_t)__##name, align)
|
|
|
|
|
2010-02-09 16:33:50 +00:00
|
|
|
#define PAGE_SIZE 4096
|
2011-07-29 09:20:11 +00:00
|
|
|
#define PAGE_SHIFT 12
|
2013-01-15 13:48:45 +00:00
|
|
|
#define PAGE_ALIGN(s) (((s) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
|
2013-01-15 13:48:46 +00:00
|
|
|
#define PAGE_ALIGN_DOWN(x) ((x) & ~(PAGE_SIZE - 1))
|
2010-02-09 16:33:50 +00:00
|
|
|
|
2013-03-01 10:59:57 +00:00
|
|
|
int memory_display(const void *addr, loff_t offs, unsigned nbytes, int size, int swab);
|
2010-10-15 06:24:45 +00:00
|
|
|
|
2013-07-25 08:34:35 +00:00
|
|
|
#define DUMP_PREFIX_OFFSET 0
|
|
|
|
static inline void print_hex_dump(const char *level, const char *prefix_str,
|
|
|
|
int prefix_type, int rowsize, int groupsize,
|
|
|
|
const void *buf, size_t len, bool ascii)
|
|
|
|
{
|
|
|
|
memory_display(buf, 0, len, 4, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-17 08:46:42 +00:00
|
|
|
int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
|
|
|
|
char **sourcefile, char **destfile, int *swab);
|
2013-04-17 08:53:18 +00:00
|
|
|
#define RW_BUF_SIZE (unsigned)4096
|
2013-04-17 08:46:42 +00:00
|
|
|
|
2010-10-15 07:29:37 +00:00
|
|
|
extern const char version_string[];
|
2014-07-17 14:17:19 +00:00
|
|
|
extern const char release_string[];
|
2012-01-08 06:10:07 +00:00
|
|
|
#ifdef CONFIG_BANNER
|
2011-04-01 13:13:55 +00:00
|
|
|
void barebox_banner(void);
|
2012-01-08 06:10:07 +00:00
|
|
|
#else
|
|
|
|
static inline void barebox_banner(void) {}
|
|
|
|
#endif
|
2010-10-15 07:29:37 +00:00
|
|
|
|
2013-08-14 14:12:31 +00:00
|
|
|
const char *barebox_get_model(void);
|
2013-08-15 06:50:18 +00:00
|
|
|
void barebox_set_model(const char *);
|
2013-08-14 19:54:40 +00:00
|
|
|
const char *barebox_get_hostname(void);
|
|
|
|
void barebox_set_hostname(const char *);
|
2013-06-03 13:04:21 +00:00
|
|
|
|
2014-09-10 07:42:18 +00:00
|
|
|
#if defined(CONFIG_MIPS)
|
|
|
|
#include <asm/addrspace.h>
|
|
|
|
|
|
|
|
#define IOMEM(addr) ((void __force __iomem *)CKSEG1ADDR(addr))
|
|
|
|
#else
|
2010-11-18 13:29:27 +00:00
|
|
|
#define IOMEM(addr) ((void __force __iomem *)(addr))
|
2014-09-10 07:42:18 +00:00
|
|
|
#endif
|
2010-11-18 13:29:27 +00:00
|
|
|
|
2012-10-03 13:28:22 +00:00
|
|
|
/*
|
|
|
|
* Check if two regions overlap. returns true if they do, false otherwise
|
|
|
|
*/
|
|
|
|
static inline bool region_overlap(unsigned long starta, unsigned long lena,
|
|
|
|
unsigned long startb, unsigned long lenb)
|
|
|
|
{
|
|
|
|
if (starta + lena <= startb)
|
|
|
|
return 0;
|
|
|
|
if (startb + lenb <= starta)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-11-02 23:30:20 +00:00
|
|
|
#endif /* __COMMON_H_ */
|