summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-08-07 06:15:16 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-08-07 06:15:16 +0200
commit5b7b7ee5d943c6b58d9b7f974167d0105ca1b787 (patch)
tree5b01a8a5d8fa8f91f56547761df026adce9dabeb /scripts
parentf1ee4e8b73a356278056666da8d0c6b5aa53088d (diff)
parent07f93f54521c212558eb09adc812d97dffda443b (diff)
downloadbarebox-5b7b7ee5d943c6b58d9b7f974167d0105ca1b787.tar.gz
barebox-5b7b7ee5d943c6b58d9b7f974167d0105ca1b787.tar.xz
Merge branch 'for-next/metadata'
Conflicts: arch/arm/dts/Makefile common/Makefile lib/Makefile
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile2
-rw-r--r--scripts/Makefile.lib25
-rw-r--r--scripts/bareboximd.c161
-rw-r--r--scripts/dtc/.gitignore1
-rw-r--r--scripts/dtc/Makefile18
-rw-r--r--scripts/dtc/fdt.c (renamed from scripts/dtc/libfdt/fdt.c)0
-rw-r--r--scripts/dtc/fdt.h (renamed from scripts/dtc/libfdt/fdt.h)0
-rw-r--r--scripts/dtc/fdt_empty_tree.c (renamed from scripts/dtc/libfdt/fdt_empty_tree.c)0
-rw-r--r--scripts/dtc/fdt_ro.c (renamed from scripts/dtc/libfdt/fdt_ro.c)0
-rw-r--r--scripts/dtc/fdt_rw.c (renamed from scripts/dtc/libfdt/fdt_rw.c)0
-rw-r--r--scripts/dtc/fdt_strerror.c (renamed from scripts/dtc/libfdt/fdt_strerror.c)0
-rw-r--r--scripts/dtc/fdt_sw.c (renamed from scripts/dtc/libfdt/fdt_sw.c)0
-rw-r--r--scripts/dtc/fdt_wip.c (renamed from scripts/dtc/libfdt/fdt_wip.c)0
-rw-r--r--scripts/dtc/libfdt.h (renamed from scripts/dtc/libfdt/libfdt.h)0
-rw-r--r--scripts/dtc/libfdt_env.h (renamed from scripts/dtc/libfdt/libfdt_env.h)0
-rw-r--r--scripts/dtc/libfdt_internal.h (renamed from scripts/dtc/libfdt/libfdt_internal.h)0
-rwxr-xr-xscripts/gen-dtb-s56
17 files changed, 246 insertions, 17 deletions
diff --git a/scripts/Makefile b/scripts/Makefile
index 9c77680a17..2050ec497d 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -10,6 +10,7 @@ hostprogs-y += fix_size
hostprogs-y += bareboxenv
hostprogs-y += bareboxcrc32
hostprogs-y += kernel-install
+hostprogs-$(CONFIG_IMD) += bareboximd
hostprogs-$(CONFIG_KALLSYMS) += kallsyms
hostprogs-$(CONFIG_ARCH_MVEBU) += kwbimage kwboot
hostprogs-$(CONFIG_ARCH_NETX) += gen_netx_image
@@ -29,6 +30,7 @@ subdir-$(CONFIG_ARCH_TEGRA) += tegra
targetprogs-$(CONFIG_BAREBOXENV_TARGET) += bareboxenv-target
targetprogs-$(CONFIG_KERNEL_INSTALL_TARGET) += kernel-install-target
targetprogs-$(CONFIG_BAREBOXCRC32_TARGET) += bareboxcrc32-target
+targetprogs-$(CONFIG_IMD_TARGET) += bareboximd-target
# Let clean descend into subdirs
subdir- += basic kconfig setupmbr
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 08518704fe..7d97d573ab 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -14,6 +14,13 @@ obj-m := $(filter-out $(obj-y),$(obj-m))
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
+pbl-y += $(pbl-dtb-y)
+obj-y += $(obj-dtb-y)
+extra-y += $(patsubst %.dtb.o,%.dtb.S,$(obj-dtb-y))
+extra-y += $(patsubst %.dtb.o,%.dtb,$(obj-dtb-y))
+extra-y += $(patsubst %.dtb.o,%.dtb.S,$(pbl-dtb-y))
+extra-y += $(patsubst %.dtb.o,%.dtb,$(pbl-dtb-y))
+
# Handle objects in subdirs
# ---------------------------------------------------------------------------
# o if we encounter foo/ in $(obj-y), replace it by foo/built-in.o
@@ -203,21 +210,9 @@ cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
# Generate an assembly file to wrap the output of the device tree compiler
quiet_cmd_dt_S_dtb = DTB $@
-cmd_dt_S_dtb= \
-( \
- echo '\#include <asm-generic/barebox.lds.h>'; \
- echo '.section .dtb.rodata.$(subst -,_,$(*F)),"a"'; \
- echo '.balign STRUCT_ALIGNMENT'; \
- echo '.global __dtb_$(subst -,_,$(*F))_start'; \
- echo '__dtb_$(subst -,_,$(*F))_start:'; \
- echo '.incbin "$<" '; \
- echo '__dtb_$(subst -,_,$(*F))_end:'; \
- echo '.global __dtb_$(subst -,_,$(*F))_end'; \
- echo '.balign STRUCT_ALIGNMENT'; \
-) > $@
-
-$(obj)/%.dtb.S: $(obj)/%.dtb
- $(call cmd,dt_S_dtb)
+cmd_dt_S_dtb = $(srctree)/scripts/gen-dtb-s $(subst -,_,$(*F)) $< $(CONFIG_IMD) > $@
+$(obj)/%.dtb.S: $(obj)/%.dtb $(srctree)/scripts/gen-dtb-s FORCE
+ $(call if_changed,dt_S_dtb)
quiet_cmd_dtc = DTC $@
cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
new file mode 100644
index 0000000000..a3622af821
--- /dev/null
+++ b/scripts/bareboximd.c
@@ -0,0 +1,161 @@
+/*
+ * (C) Copyright 2014 Sascha Hauer, Pengutronix
+ *
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#define __ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask))
+#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a) - 1)
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <asm-generic/errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <string.h>
+#include <errno.h>
+#include <stdarg.h>
+
+#include "../include/image-metadata.h"
+
+static void debug(const char *fmt, ...)
+{
+ va_list ap;
+
+ if (!imd_command_verbose)
+ return;
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+}
+
+int imd_command_setenv(const char *variable_name, const char *value)
+{
+ fprintf(stderr, "-s option ignored\n");
+
+ return -EINVAL;
+}
+
+static int read_file_2(const char *filename, size_t *size, void **outbuf, loff_t max_size)
+{
+ off_t fsize;
+ ssize_t rsize;
+ int ret, fd;
+ void *buf;
+
+ *size = 0;
+ *outbuf = NULL;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "Cannot open %s: %s\n", filename, strerror(errno));
+ return -errno;
+ }
+
+ fsize = lseek(fd, 0, SEEK_END);
+ if (fsize == -1) {
+ fprintf(stderr, "Cannot get size %s: %s\n", filename, strerror(errno));
+ ret = -errno;
+ goto close;
+ }
+
+ if (fsize < max_size)
+ max_size = fsize;
+
+ if (lseek(fd, 0, SEEK_SET) == -1) {
+ fprintf(stderr, "Cannot seek to start %s: %s\n", filename, strerror(errno));
+ ret = -errno;
+ goto close;
+ }
+
+ buf = malloc(max_size);
+ if (!buf) {
+ fprintf(stderr, "Cannot allocate memory\n");
+ ret = -ENOMEM;
+ goto close;
+ }
+
+ *outbuf = buf;
+ while (*size < max_size) {
+ rsize = read(fd, buf, max_size-*size);
+ if (rsize == 0) {
+ ret = -EIO;
+ goto free;
+ } else if (rsize < 0) {
+ if (errno == EAGAIN)
+ continue;
+ else {
+ ret = -errno;
+ goto free;
+ }
+ } /* ret > 0 */
+ buf += rsize;
+ *size += rsize;
+ }
+
+ ret = 0;
+ goto close;
+free:
+ *outbuf = NULL;
+ free(buf);
+close:
+ close(fd);
+ return ret;
+}
+
+static unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base)
+{
+ return strtoul(cp, endp, base);
+}
+
+#include "../common/imd.c"
+
+static void usage(const char *prgname)
+{
+ printf(
+"Extract metadata from a barebox image\n"
+"\n"
+"Usage: %s [OPTIONS] FILE\n"
+"Options:\n"
+"-t <type> only show information of <type>\n"
+"-n <no> for tags with multiple strings only show string <no>\n"
+"\n"
+"Without options all information available is printed. Valid types are:\n"
+"release, build, model, of_compatible\n",
+ prgname);
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+
+ ret = imd_command(argc, argv);
+ if (ret == -ENOSYS) {
+ usage(argv[0]);
+ exit(1);
+ }
+
+ if (ret)
+ fprintf(stderr, "%s\n", strerror(-ret));
+
+ return ret ? 1 : 0;
+}
diff --git a/scripts/dtc/.gitignore b/scripts/dtc/.gitignore
index cdabdc95a6..80f6b50fdf 100644
--- a/scripts/dtc/.gitignore
+++ b/scripts/dtc/.gitignore
@@ -2,3 +2,4 @@ dtc
dtc-lexer.lex.c
dtc-parser.tab.c
dtc-parser.tab.h
+fdtget
diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile
index 2a48022c41..05973b12aa 100644
--- a/scripts/dtc/Makefile
+++ b/scripts/dtc/Makefile
@@ -1,15 +1,20 @@
# scripts/dtc makefile
-hostprogs-y := dtc
+hostprogs-y := dtc fdtget
always := $(hostprogs-y)
dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \
srcpos.o checks.o util.o
dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o
+libfdt-objs = fdt.o fdt_ro.o fdt_strerror.o fdt_wip.o
+libfdt-objs += fdt_empty_tree.o fdt_rw.o fdt_sw.o
+
+fdtget-objs += fdtget.o $(libfdt-objs) util.o
+
# Source files need to get at the userspace version of libfdt_env.h to compile
-HOSTCFLAGS_DTC := -I$(src) -I$(src)/libfdt
+HOSTCFLAGS_DTC := -I$(src)
HOSTCFLAGS_checks.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_data.o := $(HOSTCFLAGS_DTC)
@@ -21,6 +26,15 @@ HOSTCFLAGS_srcpos.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_treesource.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_util.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdt.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdt_ro.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdt_strerror.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdt_wip.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdt_empty_tree.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdt_rw.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdt_sw.o := $(HOSTCFLAGS_DTC)
+HOSTCFLAGS_fdtget.o := $(HOSTCFLAGS_DTC)
+
HOSTCFLAGS_dtc-lexer.lex.o := $(HOSTCFLAGS_DTC)
HOSTCFLAGS_dtc-parser.tab.o := $(HOSTCFLAGS_DTC)
diff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/fdt.c
index e56833ae9b..e56833ae9b 100644
--- a/scripts/dtc/libfdt/fdt.c
+++ b/scripts/dtc/fdt.c
diff --git a/scripts/dtc/libfdt/fdt.h b/scripts/dtc/fdt.h
index 48ccfd9100..48ccfd9100 100644
--- a/scripts/dtc/libfdt/fdt.h
+++ b/scripts/dtc/fdt.h
diff --git a/scripts/dtc/libfdt/fdt_empty_tree.c b/scripts/dtc/fdt_empty_tree.c
index f72d13b1d1..f72d13b1d1 100644
--- a/scripts/dtc/libfdt/fdt_empty_tree.c
+++ b/scripts/dtc/fdt_empty_tree.c
diff --git a/scripts/dtc/libfdt/fdt_ro.c b/scripts/dtc/fdt_ro.c
index 02b6d68753..02b6d68753 100644
--- a/scripts/dtc/libfdt/fdt_ro.c
+++ b/scripts/dtc/fdt_ro.c
diff --git a/scripts/dtc/libfdt/fdt_rw.c b/scripts/dtc/fdt_rw.c
index 24437dfc32..24437dfc32 100644
--- a/scripts/dtc/libfdt/fdt_rw.c
+++ b/scripts/dtc/fdt_rw.c
diff --git a/scripts/dtc/libfdt/fdt_strerror.c b/scripts/dtc/fdt_strerror.c
index e6c3ceee8c..e6c3ceee8c 100644
--- a/scripts/dtc/libfdt/fdt_strerror.c
+++ b/scripts/dtc/fdt_strerror.c
diff --git a/scripts/dtc/libfdt/fdt_sw.c b/scripts/dtc/fdt_sw.c
index 55ebebf1eb..55ebebf1eb 100644
--- a/scripts/dtc/libfdt/fdt_sw.c
+++ b/scripts/dtc/fdt_sw.c
diff --git a/scripts/dtc/libfdt/fdt_wip.c b/scripts/dtc/fdt_wip.c
index 6025fa1fe8..6025fa1fe8 100644
--- a/scripts/dtc/libfdt/fdt_wip.c
+++ b/scripts/dtc/fdt_wip.c
diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt.h
index 73f49759a5..73f49759a5 100644
--- a/scripts/dtc/libfdt/libfdt.h
+++ b/scripts/dtc/libfdt.h
diff --git a/scripts/dtc/libfdt/libfdt_env.h b/scripts/dtc/libfdt_env.h
index 213d7fb81c..213d7fb81c 100644
--- a/scripts/dtc/libfdt/libfdt_env.h
+++ b/scripts/dtc/libfdt_env.h
diff --git a/scripts/dtc/libfdt/libfdt_internal.h b/scripts/dtc/libfdt_internal.h
index 381133ba81..381133ba81 100644
--- a/scripts/dtc/libfdt/libfdt_internal.h
+++ b/scripts/dtc/libfdt_internal.h
diff --git a/scripts/gen-dtb-s b/scripts/gen-dtb-s
new file mode 100755
index 0000000000..434612f362
--- /dev/null
+++ b/scripts/gen-dtb-s
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+name=$1
+dtb=$2
+imd=$3
+
+echo "#include <asm-generic/barebox.lds.h>"
+
+le32() {
+ printf ".byte 0x%02x, 0x%02x, 0x%02x, 0x%02x\n" \
+ $(($1 & 0xff)) \
+ $((($1 >> 8) & 0xff)) \
+ $((($1 >> 16) & 0xff)) \
+ $((($1 >> 24) & 0xff))
+}
+
+FDTGET=scripts/dtc/fdtget
+
+if [ "$imd" = "y" ]; then
+ echo ".section .barebox_imd_0.${name},\"a\""
+ echo ".global __imd_${name}_start"
+ echo "__imd_${name}_start:"
+
+ compat=$($FDTGET -d notfound -t bi "$dtb" / compatible | sed "s^ ^,^g")
+ if [ "$compat" != "notfound" ]; then
+
+ compatlen=$($FDTGET -t s "$dtb" / compatible | wc -c)
+ le32 0x640c8005
+ le32 $compatlen
+ echo ".byte " $compat
+ echo ".balign 4"
+ fi
+
+ model=$($FDTGET -d notfound -t bi "$dtb" / model | sed "s^ ^,^g")
+
+ if [ "$model" != "notfound" ]; then
+ modellen=$($FDTGET -t s "$dtb" / model | wc -c)
+ le32 0x640c8004
+ le32 $compatlen
+ echo ".byte " $model
+ echo ".balign 4"
+ fi
+fi
+
+echo ".section .dtb.rodata.${name},\"a\""
+echo ".balign STRUCT_ALIGNMENT"
+echo ".global __dtb_${name}_start"
+echo "__dtb_${name}_start:"
+echo ".incbin \"$dtb\""
+echo "__dtb_${name}_end:"
+echo ".global __dtb_${name}_end"
+echo ".balign STRUCT_ALIGNMENT"
+
+if [ "$imd" = "y" ]; then
+ echo ".word __imd_${name}_start"
+fi