aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Kconfig6
-rw-r--r--common/board_f.c43
-rw-r--r--common/console.c64
-rw-r--r--common/memsize.c20
-rw-r--r--common/spl/spl_sata.c2
-rw-r--r--common/spl/spl_usb.c2
-rw-r--r--common/stdio.c8
-rw-r--r--common/usb_storage.c6
8 files changed, 138 insertions, 13 deletions
diff --git a/common/Kconfig b/common/Kconfig
index b776c5ca1e..6591acd2fd 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -186,6 +186,12 @@ config PRE_CON_BUF_ADDR
We should consider removing this option and allocating the memory
in board_init_f_init_reserve() instead.
+config CONSOLE_FLUSH_SUPPORT
+ bool "Enable console flush support"
+ default y
+ help
+ This enables compilation of flush() function for console flush support.
+
config CONSOLE_MUX
bool "Enable console multiplexing"
default y if DM_VIDEO || VIDEO || LCD
diff --git a/common/board_f.c b/common/board_f.c
index f92d7b9faf..3df4efeeff 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -57,6 +57,7 @@
#include <asm/sections.h>
#include <dm/root.h>
#include <linux/errno.h>
+#include <linux/log2.h>
/*
* Pointer to initial global data area
@@ -216,6 +217,36 @@ static int announce_dram_init(void)
return 0;
}
+/*
+ * From input size calculate its nearest rounded unit scale (multiply of 2^10)
+ * and value in calculated unit scale multiplied by 10 (as fractional fixed
+ * point number with one decimal digit), which is human natural format,
+ * same what uses print_size() function for displaying. Mathematically it is:
+ * round_nearest(val * 2^scale) = size * 10; where: 10 <= val < 10240.
+ *
+ * For example for size=87654321 we calculate scale=20 and val=836 which means
+ * that input has natural human format 83.6 M (mega = 2^20).
+ */
+#define compute_size_scale_val(size, scale, val) do { \
+ scale = ilog2(size) / 10 * 10; \
+ val = (10 * size + ((1ULL << scale) >> 1)) >> scale; \
+ if (val == 10240) { val = 10; scale += 10; } \
+} while (0)
+
+/*
+ * Check if the sizes in their natural units written in decimal format with
+ * one fraction number are same.
+ */
+static int sizes_near(unsigned long long size1, unsigned long long size2)
+{
+ unsigned int size1_scale, size1_val, size2_scale, size2_val;
+
+ compute_size_scale_val(size1, size1_scale, size1_val);
+ compute_size_scale_val(size2, size2_scale, size2_val);
+
+ return size1_scale == size2_scale && size1_val == size2_val;
+}
+
static int show_dram_config(void)
{
unsigned long long size;
@@ -232,7 +263,11 @@ static int show_dram_config(void)
}
debug("\nDRAM: ");
- print_size(size, "");
+ print_size(gd->ram_size, "");
+ if (!sizes_near(gd->ram_size, size)) {
+ printf(" (effective ");
+ print_size(size, ")");
+ }
board_add_ram_info(0);
putc('\n');
@@ -305,7 +340,7 @@ __weak int mach_cpu_init(void)
}
/* Get the top of usable RAM */
-__weak ulong board_get_usable_ram_top(ulong total_size)
+__weak phys_size_t board_get_usable_ram_top(phys_size_t total_size)
{
#if defined(CONFIG_SYS_SDRAM_BASE) && CONFIG_SYS_SDRAM_BASE > 0
/*
@@ -328,7 +363,7 @@ static int setup_dest_addr(void)
/*
* Ram is setup, size stored in gd !!
*/
- debug("Ram size: %08lX\n", (ulong)gd->ram_size);
+ debug("Ram size: %08llX\n", (unsigned long long)gd->ram_size);
#if CONFIG_VAL(SYS_MEM_TOP_HIDE)
/*
* Subtract specified amount of memory to hide so that it won't
@@ -348,7 +383,7 @@ static int setup_dest_addr(void)
gd->ram_top = gd->ram_base + get_effective_memsize();
gd->ram_top = board_get_usable_ram_top(gd->mon_len);
gd->relocaddr = gd->ram_top;
- debug("Ram top: %08lX\n", (ulong)gd->ram_top);
+ debug("Ram top: %08llX\n", (unsigned long long)gd->ram_top);
#if defined(CONFIG_MP) && (defined(CONFIG_MPC86xx) || defined(CONFIG_E500))
/*
* We need to make sure the location we intend to put secondary core
diff --git a/common/console.c b/common/console.c
index e5be6ff44b..0c9bf66c3f 100644
--- a/common/console.c
+++ b/common/console.c
@@ -199,6 +199,7 @@ static int console_setfile(int file, struct stdio_dev * dev)
case stdout:
gd->jt->putc = putc;
gd->jt->puts = puts;
+ STDIO_DEV_ASSIGN_FLUSH(gd->jt, flush);
gd->jt->printf = printf;
break;
}
@@ -364,6 +365,19 @@ static void console_puts(int file, const char *s)
}
}
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static void console_flush(int file)
+{
+ int i;
+ struct stdio_dev *dev;
+
+ for_each_console_dev(i, file, dev) {
+ if (dev->flush != NULL)
+ dev->flush(dev);
+ }
+}
+#endif
+
#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
static inline void console_doenv(int file, struct stdio_dev *dev)
{
@@ -413,6 +427,14 @@ static inline void console_puts(int file, const char *s)
stdio_devices[file]->puts(stdio_devices[file], s);
}
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static inline void console_flush(int file)
+{
+ if (stdio_devices[file]->flush)
+ stdio_devices[file]->flush(stdio_devices[file]);
+}
+#endif
+
#if CONFIG_IS_ENABLED(SYS_CONSOLE_IS_IN_ENV)
static inline void console_doenv(int file, struct stdio_dev *dev)
{
@@ -526,6 +548,14 @@ void fputs(int file, const char *s)
console_puts(file, s);
}
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void fflush(int file)
+{
+ if (file < MAX_FILES)
+ console_flush(file);
+}
+#endif
+
int fprintf(int file, const char *fmt, ...)
{
va_list args;
@@ -740,6 +770,40 @@ void puts(const char *s)
}
}
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+void flush(void)
+{
+ if (!gd)
+ return;
+
+ /* sandbox can send characters to stdout before it has a console */
+ if (IS_ENABLED(CONFIG_SANDBOX) && !(gd->flags & GD_FLG_SERIAL_READY)) {
+ os_flush();
+ return;
+ }
+
+ if (IS_ENABLED(CONFIG_DEBUG_UART) && !(gd->flags & GD_FLG_SERIAL_READY))
+ return;
+
+ if (IS_ENABLED(CONFIG_SILENT_CONSOLE) && (gd->flags & GD_FLG_SILENT))
+ return;
+
+ if (IS_ENABLED(CONFIG_DISABLE_CONSOLE) && (gd->flags & GD_FLG_DISABLE_CONSOLE))
+ return;
+
+ if (!gd->have_console)
+ return;
+
+ if (gd->flags & GD_FLG_DEVINIT) {
+ /* Send to the standard output */
+ fflush(stdout);
+ } else {
+ /* Send directly to the handler */
+ serial_flush();
+ }
+}
+#endif
+
#ifdef CONFIG_CONSOLE_RECORD
int console_record_init(void)
{
diff --git a/common/memsize.c b/common/memsize.c
index d5d13d51bf..3c80ad2c83 100644
--- a/common/memsize.c
+++ b/common/memsize.c
@@ -94,11 +94,23 @@ long get_ram_size(long *base, long maxsize)
phys_size_t __weak get_effective_memsize(void)
{
-#ifndef CONFIG_VERY_BIG_RAM
- return gd->ram_size;
+ phys_size_t ram_size = gd->ram_size;
+
+ /*
+ * Check for overflow and limit ram size to some representable value.
+ * It is required that ram_base + ram_size must be representable by
+ * phys_size_t type and must be aligned by direct access, therefore
+ * calculate it from last 4kB sector which should work as alignment
+ * on any platform.
+ */
+ if (gd->ram_base + ram_size < gd->ram_base)
+ ram_size = ((phys_size_t)~0xfffULL) - gd->ram_base;
+
+#ifndef CONFIG_MAX_MEM_MAPPED
+ return ram_size;
#else
/* limit stack to what we can reasonable map */
- return ((gd->ram_size > CONFIG_MAX_MEM_MAPPED) ?
- CONFIG_MAX_MEM_MAPPED : gd->ram_size);
+ return ((ram_size > CONFIG_MAX_MEM_MAPPED) ?
+ CONFIG_MAX_MEM_MAPPED : ram_size);
#endif
}
diff --git a/common/spl/spl_sata.c b/common/spl/spl_sata.c
index ea9f1756c0..6c36f2ca66 100644
--- a/common/spl/spl_sata.c
+++ b/common/spl/spl_sata.c
@@ -71,7 +71,7 @@ static int spl_sata_load_image(struct spl_image_info *spl_image,
/* try to recognize storage devices immediately */
scsi_scan(false);
- stor_dev = blk_get_devnum_by_type(UCLASS_SCSI, 0);
+ stor_dev = blk_get_devnum_by_uclass_id(UCLASS_SCSI, 0);
if (!stor_dev)
return -ENODEV;
diff --git a/common/spl/spl_usb.c b/common/spl/spl_usb.c
index 63c00f872b..479e2dc182 100644
--- a/common/spl/spl_usb.c
+++ b/common/spl/spl_usb.c
@@ -41,7 +41,7 @@ int spl_usb_load(struct spl_image_info *spl_image,
/* try to recognize storage devices immediately */
usb_stor_curr_dev = usb_stor_scan(1);
- stor_dev = blk_get_devnum_by_type(UCLASS_USB, usb_stor_curr_dev);
+ stor_dev = blk_get_devnum_by_uclass_id(UCLASS_USB, usb_stor_curr_dev);
if (!stor_dev)
return -ENODEV;
diff --git a/common/stdio.c b/common/stdio.c
index 92161a0df8..13083842cb 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -87,6 +87,13 @@ static void stdio_serial_puts(struct stdio_dev *dev, const char *s)
serial_puts(s);
}
+#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
+static void stdio_serial_flush(struct stdio_dev *dev)
+{
+ serial_flush();
+}
+#endif
+
static int stdio_serial_getc(struct stdio_dev *dev)
{
return serial_getc();
@@ -112,6 +119,7 @@ static void drv_system_init (void)
dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
dev.putc = stdio_serial_putc;
dev.puts = stdio_serial_puts;
+ STDIO_DEV_ASSIGN_FLUSH(&dev, stdio_serial_flush);
dev.getc = stdio_serial_getc;
dev.tstc = stdio_serial_tstc;
stdio_register (&dev);
diff --git a/common/usb_storage.c b/common/usb_storage.c
index 7d420160cd..e59c819bac 100644
--- a/common/usb_storage.c
+++ b/common/usb_storage.c
@@ -279,7 +279,7 @@ static int usb_stor_probe_device(struct usb_device *udev)
blkdev = &usb_dev_desc[usb_max_devs];
memset(blkdev, '\0', sizeof(struct blk_desc));
- blkdev->if_type = UCLASS_USB;
+ blkdev->uclass_id = UCLASS_USB;
blkdev->devnum = usb_max_devs;
blkdev->part_type = PART_TYPE_UNKNOWN;
blkdev->target = 0xff;
@@ -1577,8 +1577,8 @@ U_BOOT_DRIVER(usb_storage_blk) = {
};
#else
U_BOOT_LEGACY_BLK(usb) = {
- .if_typename = "usb",
- .if_type = UCLASS_USB,
+ .uclass_idname = "usb",
+ .uclass_id = UCLASS_USB,
.max_devs = USB_MAX_STOR_DEV,
.desc = usb_dev_desc,
};