summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Kconfig5
-rw-r--r--common/Makefile1
-rw-r--r--common/filetype.c68
-rw-r--r--common/globalvar.c10
-rw-r--r--common/meminfo.c23
-rw-r--r--common/oftree.c4
-rw-r--r--common/startup.c21
7 files changed, 97 insertions, 35 deletions
diff --git a/common/Kconfig b/common/Kconfig
index b97392cfdb..0597c9cb62 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -96,6 +96,10 @@ config BANNER
bool "display banner"
default y
+config MEMINFO
+ bool "display memory info"
+ default y
+
config ENVIRONMENT_VARIABLES
bool "environment variables support"
@@ -575,6 +579,7 @@ config DEFAULT_ENVIRONMENT_GENERIC
select CMD_CRC
select CMD_CRC_CMP
select CMD_AUTOMOUNT if HAVE_DEFAULT_ENVIRONMENT_NEW
+ select CMD_GLOBAL
prompt "Default environment generic"
help
With this option barebox will use the generic default
diff --git a/common/Makefile b/common/Makefile
index df9f301234..68582b78e1 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_MALLOC_TLSF) += tlsf.o
obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
obj-y += clock.o
obj-$(CONFIG_BANNER) += version.o
+obj-$(CONFIG_MEMINFO) += meminfo.o
obj-$(CONFIG_COMMAND_SUPPORT) += command.o
obj-$(CONFIG_CONSOLE_FULL) += console.o
obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o
diff --git a/common/filetype.c b/common/filetype.c
index e736d43efe..6a0dcfb760 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -26,6 +26,7 @@
#include <fcntl.h>
#include <fs.h>
#include <malloc.h>
+#include <errno.h>
static const char *filetype_str[] = {
[filetype_unknown] = "unknown",
@@ -42,6 +43,7 @@ static const char *filetype_str[] = {
[filetype_sh] = "Bourne Shell",
[filetype_mips_barebox] = "MIPS barebox image",
[filetype_fat] = "FAT filesytem",
+ [filetype_mbr] = "MBR sector",
};
const char *file_type_to_string(enum filetype f)
@@ -52,26 +54,51 @@ const char *file_type_to_string(enum filetype f)
return NULL;
}
-static int is_fat(u8 *buf)
+#define MBR_StartSector 8 /* MBR: Offset of Starting Sector in Partition Table Entry */
+#define BS_55AA 510 /* Boot sector signature (2) */
+#define MBR_Table 446 /* MBR: Partition table offset (2) */
+#define BS_FilSysType32 82 /* File system type (1) */
+#define BS_FilSysType 54 /* File system type (1) */
+
+enum filetype is_fat_or_mbr(const unsigned char *sector, unsigned long *bootsec)
{
- if (get_unaligned_le16(&buf[510]) != 0xAA55)
- return 0;
+ /*
+ * bootsec can be used to return index of the first sector in the
+ * first partition
+ */
+ if (bootsec)
+ *bootsec = 0;
+
+ /*
+ * Check record signature (always placed at offset 510 even if the
+ * sector size is > 512)
+ */
+ if (get_unaligned_le16(&sector[BS_55AA]) != 0xAA55)
+ return filetype_unknown;
+
+ /* Check "FAT" string */
+ if ((get_unaligned_le32(&sector[BS_FilSysType]) & 0xFFFFFF) == 0x544146)
+ return filetype_fat;
- /* FAT */
- if ((get_unaligned_le32(&buf[54]) & 0xFFFFFF) == 0x544146)
- return 1;
+ if ((get_unaligned_le32(&sector[BS_FilSysType32]) & 0xFFFFFF) == 0x544146)
+ return filetype_fat;
- /* FAT32 */
- if ((get_unaligned_le32(&buf[82]) & 0xFFFFFF) == 0x544146)
- return 1;
+ if (bootsec)
+ /*
+ * This must be an MBR, so return the starting sector of the
+ * first partition so we could check if there is a FAT boot
+ * sector there
+ */
+ *bootsec = get_unaligned_le16(&sector[MBR_Table + MBR_StartSector]);
- return 0;
+ return filetype_mbr;
}
enum filetype file_detect_type(void *_buf)
{
u32 *buf = _buf;
u8 *buf8 = _buf;
+ enum filetype type;
if (strncmp(buf8, "#!/bin/sh", 9) == 0)
return filetype_sh;
@@ -99,8 +126,9 @@ enum filetype file_detect_type(void *_buf)
return filetype_aimage;
if (strncmp(buf8 + 0x10, "barebox", 7) == 0)
return filetype_mips_barebox;
- if (is_fat(buf8))
- return filetype_fat;
+ type = is_fat_or_mbr(buf8, NULL);
+ if (type != filetype_unknown)
+ return type;
return filetype_unknown;
}
@@ -110,6 +138,7 @@ enum filetype file_name_detect_type(const char *filename)
int fd, ret;
void *buf;
enum filetype type = filetype_unknown;
+ unsigned long bootsec;
fd = open(filename, O_RDONLY);
if (fd < 0)
@@ -123,6 +152,21 @@ enum filetype file_name_detect_type(const char *filename)
type = file_detect_type(buf);
+ if (type == filetype_mbr) {
+ /*
+ * Get the first partition start sector
+ * and check for FAT in it
+ */
+ is_fat_or_mbr(buf, &bootsec);
+ ret = lseek(fd, (bootsec) * 512, SEEK_SET);
+ if (ret < 0)
+ goto err_out;
+ ret = read(fd, buf, 512);
+ if (ret < 0)
+ goto err_out;
+ type = is_fat_or_mbr((u8 *)buf, NULL);
+ }
+
err_out:
close(fd);
free(buf);
diff --git a/common/globalvar.c b/common/globalvar.c
index 71296ff5a3..a8aaa72553 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -46,6 +46,16 @@ char *globalvar_get_match(const char *match, const char *seperator)
return val;
}
+void globalvar_set_match(const char *match, const char *val)
+{
+ struct param_d *param;
+
+ list_for_each_entry(param, &global_device.parameters, list) {
+ if (!strncmp(match, param->name, strlen(match)))
+ dev_set_param(&global_device, param->name, val);
+ }
+}
+
/*
* globalvar_add_simple
*
diff --git a/common/meminfo.c b/common/meminfo.c
new file mode 100644
index 0000000000..06fce5afb4
--- /dev/null
+++ b/common/meminfo.c
@@ -0,0 +1,23 @@
+#include <common.h>
+#include <init.h>
+#include <memory.h>
+#include <asm-generic/memory_layout.h>
+
+static int display_meminfo(void)
+{
+ ulong mstart = mem_malloc_start();
+ ulong mend = mem_malloc_end();
+ ulong msize = mend - mstart + 1;
+
+ debug("barebox code: 0x%p -> 0x%p\n", _stext, _etext);
+ debug("bss segment: 0x%p -> 0x%p\n", __bss_start, __bss_stop);
+ printf("malloc space: 0x%08lx -> 0x%08lx (size %s)\n",
+ mstart, mend, size_human_readable(msize));
+#ifdef CONFIG_ARM
+ printf("stack space: 0x%08x -> 0x%08x (size %s)\n",
+ STACK_BASE, STACK_BASE + STACK_SIZE,
+ size_human_readable(STACK_SIZE));
+#endif
+ return 0;
+}
+late_initcall(display_meminfo);
diff --git a/common/oftree.c b/common/oftree.c
index 677e934a98..3e8c6f8c65 100644
--- a/common/oftree.c
+++ b/common/oftree.c
@@ -57,7 +57,7 @@ static int is_printable_string(const void *data, int len)
* a string, concatenated strings, a byte, word, double word, or (if all
* else fails) it is printed as a stream of bytes.
*/
-static void print_data(const void *data, int len)
+void of_print_property(const void *data, int len)
{
int j;
@@ -169,7 +169,7 @@ int fdt_print(struct fdt_header *working_fdt, const char *pathp)
printf_indent(level, "%s;\n", pathp);
} else {
printf_indent(level, "%s = ", pathp);
- print_data(nodep, len);
+ of_print_property(nodep, len);
printf(";\n");
}
break;
diff --git a/common/startup.c b/common/startup.c
index abd1b774bd..e639d05cc7 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -33,34 +33,15 @@
#include <init.h>
#include <command.h>
#include <malloc.h>
-#include <memory.h>
#include <debug_ll.h>
#include <fs.h>
#include <linux/stat.h>
#include <environment.h>
-#include <asm-generic/memory_layout.h>
#include <asm/sections.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
__barebox_initcalls_end[];
-static void display_meminfo(void)
-{
- ulong mstart = mem_malloc_start();
- ulong mend = mem_malloc_end();
- ulong msize = mend - mstart + 1;
-
- debug("barebox code: 0x%p -> 0x%p\n", _stext, _etext);
- debug("bss segment: 0x%p -> 0x%p\n", __bss_start, __bss_stop);
- printf("Malloc space: 0x%08lx -> 0x%08lx (size %s)\n",
- mstart, mend, size_human_readable(msize));
-#ifdef CONFIG_ARM
- printf("Stack space : 0x%08x -> 0x%08x (size %s)\n",
- STACK_BASE, STACK_BASE + STACK_SIZE,
- size_human_readable(STACK_SIZE));
-#endif
-}
-
#ifdef CONFIG_DEFAULT_ENVIRONMENT
#include <generated/barebox_default_env.h>
@@ -128,8 +109,6 @@ void start_barebox (void)
debug("initcalls done\n");
- display_meminfo();
-
#ifdef CONFIG_ENV_HANDLING
if (envfs_load(default_environment_path, "/env")) {
#ifdef CONFIG_DEFAULT_ENVIRONMENT