linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/4] boot/loader: Load kernel directly from firmware
       [not found] <CGME20200130124000eucas1p137943be0fe3e5e1eb45e705dc5c46431@eucas1p1.samsung.com>
@ 2020-01-30 12:39 ` Łukasz Stelmach
       [not found]   ` <CGME20200130124251eucas1p2046004a71a1a9ff4274a6d1d96e2c260@eucas1p2.samsung.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Łukasz Stelmach @ 2020-01-30 12:39 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-samsung-soc; +Cc: Łukasz Stelmach

This patchset is a PoC showing, it is possible and advantageous to
integrate platform setup code in the kernel tree instead of maintaining
it in a separate bootloader project.

Bringing up a new ARM platform today requires developing the following
pieces code in both bootloader and kernel:

+ platform setup (DRAM, minimal set of clocks and PMICs etc)
  - minimal setup in bootloader
  - full setup in kernel
+ device drivers (storage, network interface, display)
  - in both bootloader and kernel

We've noticed that most code required in bootloader can be ported from
Linux. This isn't, however, effortless. We also consider further
maintenance of two copies of code an unnecessary burden. Making platform
setup code a part of kernel source tree makes it possible to reuse existing
Linux drivers in bootloading environment as well as to avoid creating
and maintainig two different drivers for new devices.

The following patches enables building Linux image that is loadable
directly by Odroid XU4's firmware (bl2). The goal for such arrangement
is to use Linux as a boot loader that later runs a full OS using kexec.

Hardkernel, the vendor of Odroid XU4, provides signed, and thus,
cumbersome to replace, platform setup code (bl1 and bl2). We decided not
to replace them, but rather make the kernel loadable by the bl2 code by
adding only a tiny amount of code to set up the consol. The kernel
needs, however, to be small enough to be loaded succesfully (1 MiB).

The patchset also provides hsinit (in tools/hsinit) userland program,
which is a tiny init program that extracts designated archive to
initramfs and executes /init. At the moment any initramfs image can be
used at this stage.

Although hsinit can be linked against glibc it makes little sense
because together with the kernel it wont fit in 1 MiB. Instead it is
recommended to link hsinit against musl libc. Install musl from your OS
vendor or follow the upstream instructions. With musl available enter
tools/hsinit and run the following commands.

--8<---------------cut here---------------start------------->8---
wget -P vendor/ https://libarchive.org/downloads/libarchive-3.3.2.tar.gz
wget -P vendor/ http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz

./bootstrap

MUSL_DIR=/usr/lib/arm-linux-musleabi/ \
GCC_CROSS_DIR=/usr/lib/gcc-cross/arm-linux-gnueabi/8/ \
CPPFLAGS='-nostdinc -isystem /usr/include/arm-linux-musleabi/' \
CFLAGS='-mthumb -Os -ffunction-sections -fdata-sections' \
LIBARCHIVE_CPP_FLAGS=-I/usr/include/arm-linux-musleabi/ \
LIBARCHIVE_C_FLAGS=$CFLAGS \
ZLIB_C_FLAGS=$CFLAGS \
LDFLAGS="-nostdlib -L${MUSL_DIR}/ -L${GCC_CROSS_DIR}/ ${MUSL_DIR}/crt1.o  ${MUSL_DIR}/crti.o  ${GCC_CROSS_DIR}/crtbegin.o -Wl,--gc-sections -Wl,--start-group  ${GCC_CROSS_DIR}/libgcc.a  ${GCC_CROSS_DIR}/libgcc_eh.a -Wl,--end-group ${GCC_CROSS_DIR}/crtend.o  ${MUSL_DIR}/crtn.o -s"  \
LIBS="-lc -lgcc" \
./configure --enable-local-libraries --host=arm-linux-gnueabi --enable-static

make
--8<---------------cut here---------------end--------------->8---

To build bootImage file that is loadable by Odroid XU4's bl2 the following
commands need to be issued (CROSS_COMPILE and ARCH ommited)

--8<---------------cut here---------------start------------->8---
make odroidxu4_bootloader_defconfig
make dtbs
make bootImage
--8<---------------cut here---------------end--------------->8---

The resulting arch/arm/boot/bootImage should be renamed to u-boot-mmc.bin and
flashed onto an SD or eMMC card with sd_fusing scritp.




Łukasz Stelmach (4):
  scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145
  scripts: add get_console_base.pl
  Add tools/hsinit
  boot/loader: Enable building bootloader replacement for Odroid XU4

 arch/arm/Kconfig                              |   8 +
 arch/arm/Makefile                             |   8 +-
 arch/arm/boot/Makefile                        |  17 +
 arch/arm/boot/loader/Kconfig                  |  23 ++
 arch/arm/boot/loader/Makefile                 |  42 +++
 arch/arm/boot/loader/odroid-console.c         | 136 ++++++++
 arch/arm/boot/loader/odroid-crt0.S            |  40 +++
 arch/arm/boot/loader/piggy.S                  |  14 +
 arch/arm/boot/loader/vectors.S                | 112 +++++++
 arch/arm/boot/loader/vmlinux.lds              |  17 +
 .../configs/odroidxu4_bootloader_defconfig    | 127 ++++++++
 scripts/dtc/.gitignore                        |   4 +
 scripts/dtc/Makefile                          |   5 +
 scripts/dtc/fdtget.c                          | 125 ++++----
 scripts/dtc/update-dtc-source.sh              |   4 +-
 scripts/get_console_base.pl                   |  26 ++
 tools/hsinit/Makefile.am                      |  29 ++
 tools/hsinit/README.org                       |  56 ++++
 tools/hsinit/bootstrap                        |   7 +
 tools/hsinit/configure.ac                     | 128 ++++++++
 tools/hsinit/hsinit.c                         | 299 ++++++++++++++++++
 tools/hsinit/vendor/.gitignore                |   5 +
 tools/hsinit/vendor/SHA256SUMS                |   2 +
 23 files changed, 1177 insertions(+), 57 deletions(-)
 create mode 100644 arch/arm/boot/loader/Kconfig
 create mode 100644 arch/arm/boot/loader/Makefile
 create mode 100644 arch/arm/boot/loader/odroid-console.c
 create mode 100644 arch/arm/boot/loader/odroid-crt0.S
 create mode 100644 arch/arm/boot/loader/piggy.S
 create mode 100644 arch/arm/boot/loader/vectors.S
 create mode 100644 arch/arm/boot/loader/vmlinux.lds
 create mode 100644 arch/arm/configs/odroidxu4_bootloader_defconfig
 create mode 100755 scripts/get_console_base.pl
 create mode 100644 tools/hsinit/Makefile.am
 create mode 100644 tools/hsinit/README.org
 create mode 100755 tools/hsinit/bootstrap
 create mode 100644 tools/hsinit/configure.ac
 create mode 100644 tools/hsinit/hsinit.c
 create mode 100644 tools/hsinit/vendor/.gitignore
 create mode 100644 tools/hsinit/vendor/SHA256SUMS

-- 
2.20.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145
       [not found]   ` <CGME20200130124251eucas1p2046004a71a1a9ff4274a6d1d96e2c260@eucas1p2.samsung.com>
@ 2020-01-30 12:42     ` Łukasz Stelmach
       [not found]       ` <CGME20200130124304eucas1p2f3381b1009cd71cd292169d5f10265c1@eucas1p2.samsung.com>
                         ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Łukasz Stelmach @ 2020-01-30 12:42 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-samsung-soc; +Cc: Łukasz Stelmach

Build and fdtget and add fdtget.c to the list of update source files.

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 scripts/dtc/.gitignore           |   4 +
 scripts/dtc/Makefile             |   5 ++
 scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
 scripts/dtc/update-dtc-source.sh |   4 +-
 4 files changed, 82 insertions(+), 56 deletions(-)

diff --git scripts/dtc/.gitignore scripts/dtc/.gitignore
index 2e6e60d64ede..80f6b50fdf77 100644
--- scripts/dtc/.gitignore
+++ scripts/dtc/.gitignore
@@ -1 +1,5 @@
 dtc
+dtc-lexer.lex.c
+dtc-parser.tab.c
+dtc-parser.tab.h
+fdtget
diff --git scripts/dtc/Makefile scripts/dtc/Makefile
index b5a5b1c548c9..74322d8dac25 100644
--- scripts/dtc/Makefile
+++ scripts/dtc/Makefile
@@ -2,12 +2,15 @@
 # scripts/dtc makefile
 
 hostprogs-$(CONFIG_DTC) := dtc
+hostprogs-$(CONFIG_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
 
+fdtget-objs     := fdtget.o util.o
+
 # Source files need to get at the userspace version of libfdt_env.h to compile
 HOST_EXTRACFLAGS := -I $(srctree)/$(src)/libfdt
 
@@ -26,5 +29,7 @@ endif
 HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
 HOSTCFLAGS_dtc-parser.tab.o := -I $(srctree)/$(src)
 
+HOSTLDLIBS_fdtget := -L$(obj)/libfdt -lfdt -Wl,-rpath='$$ORIGIN/libfdt'
+
 # dependencies on generated files need to be listed explicitly
 $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
diff --git scripts/dtc/fdtget.c scripts/dtc/fdtget.c
index c922f82246c6..777582e2d45f 100644
--- scripts/dtc/fdtget.c
+++ scripts/dtc/fdtget.c
@@ -39,6 +39,37 @@ static void report_error(const char *where, int err)
 	fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
 }
 
+/**
+ * Shows a list of cells in the requested format
+ *
+ * @param disp		Display information / options
+ * @param data		Data to display
+ * @param len		Maximum length of buffer
+ * @param size		Data size to use for display (e.g. 4 for 32-bit)
+ * @return 0 if ok, -1 on error
+ */
+static int show_cell_list(struct display_info *disp, const char *data, int len,
+			  int size)
+{
+	const uint8_t *p = (const uint8_t *)data;
+	char fmt[3];
+	int value;
+	int i;
+
+	fmt[0] = '%';
+	fmt[1] = disp->type ? disp->type : 'd';
+	fmt[2] = '\0';
+	for (i = 0; i < len; i += size, p += size) {
+		if (i)
+			printf(" ");
+		value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
+			size == 2 ? (*p << 8) | p[1] : *p;
+		printf(fmt, value);
+	}
+
+	return 0;
+}
+
 /**
  * Displays data of a given length according to selected options
  *
@@ -52,12 +83,9 @@ static void report_error(const char *where, int err)
  */
 static int show_data(struct display_info *disp, const char *data, int len)
 {
-	int i, size;
-	const uint8_t *p = (const uint8_t *)data;
+	int size;
 	const char *s;
-	int value;
 	int is_string;
-	char fmt[3];
 
 	/* no data, don't print */
 	if (len == 0)
@@ -85,17 +113,8 @@ static int show_data(struct display_info *disp, const char *data, int len)
 				"selected data size\n");
 		return -1;
 	}
-	fmt[0] = '%';
-	fmt[1] = disp->type ? disp->type : 'd';
-	fmt[2] = '\0';
-	for (i = 0; i < len; i += size, p += size) {
-		if (i)
-			printf(" ");
-		value = size == 4 ? fdt32_to_cpu(*(const uint32_t *)p) :
-			size == 2 ? (*p << 8) | p[1] : *p;
-		printf(fmt, value);
-	}
-	return 0;
+
+	return show_cell_list(disp, data, len, size);
 }
 
 /**
@@ -107,7 +126,6 @@ static int show_data(struct display_info *disp, const char *data, int len)
  */
 static int list_properties(const void *blob, int node)
 {
-	const struct fdt_property *data;
 	const char *name;
 	int prop;
 
@@ -116,8 +134,7 @@ static int list_properties(const void *blob, int node)
 		/* Stop silently when there are no more properties */
 		if (prop < 0)
 			return prop == -FDT_ERR_NOTFOUND ? 0 : prop;
-		data = fdt_get_property_by_offset(blob, prop, NULL);
-		name = fdt_string(blob, fdt32_to_cpu(data->nameoff));
+		fdt_getprop_by_offset(blob, prop, &name, NULL);
 		if (name)
 			puts(name);
 		prop = fdt_next_property_offset(blob, prop);
@@ -231,7 +248,7 @@ static int show_data_for_item(const void *blob, struct display_info *disp,
  * @param filename	Filename of blob file
  * @param arg		List of arguments to process
  * @param arg_count	Number of arguments
- * @param return 0 if ok, -ve on error
+ * @return 0 if ok, -ve on error
  */
 static int do_fdtget(struct display_info *disp, const char *filename,
 		     char **arg, int arg_count, int args_per_step)
@@ -240,7 +257,7 @@ static int do_fdtget(struct display_info *disp, const char *filename,
 	const char *prop;
 	int i, node;
 
-	blob = utilfdt_read(filename);
+	blob = utilfdt_read(filename, NULL);
 	if (!blob)
 		return -1;
 
@@ -252,44 +269,50 @@ static int do_fdtget(struct display_info *disp, const char *filename,
 				continue;
 			} else {
 				report_error(arg[i], node);
+				free(blob);
 				return -1;
 			}
 		}
 		prop = args_per_step == 1 ? NULL : arg[i + 1];
 
-		if (show_data_for_item(blob, disp, node, prop))
+		if (show_data_for_item(blob, disp, node, prop)) {
+			free(blob);
 			return -1;
+		}
 	}
+
+	free(blob);
+
 	return 0;
 }
 
-static const char *usage_msg =
-	"fdtget - read values from device tree\n"
-	"\n"
-	"Each value is printed on a new line.\n\n"
-	"Usage:\n"
+/* Usage related data. */
+static const char usage_synopsis[] =
+	"read values from device tree\n"
 	"	fdtget <options> <dt file> [<node> <property>]...\n"
 	"	fdtget -p <options> <dt file> [<node> ]...\n"
-	"Options:\n"
-	"\t-t <type>\tType of data\n"
-	"\t-p\t\tList properties for each node\n"
-	"\t-l\t\tList subnodes for each node\n"
-	"\t-d\t\tDefault value to display when the property is "
-			"missing\n"
-	"\t-h\t\tPrint this help\n\n"
+	"\n"
+	"Each value is printed on a new line.\n"
 	USAGE_TYPE_MSG;
-
-static void usage(const char *msg)
-{
-	if (msg)
-		fprintf(stderr, "Error: %s\n\n", msg);
-
-	fprintf(stderr, "%s", usage_msg);
-	exit(2);
-}
+static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
+static struct option const usage_long_opts[] = {
+	{"type",              a_argument, NULL, 't'},
+	{"properties",       no_argument, NULL, 'p'},
+	{"list",             no_argument, NULL, 'l'},
+	{"default",           a_argument, NULL, 'd'},
+	USAGE_COMMON_LONG_OPTS,
+};
+static const char * const usage_opts_help[] = {
+	"Type of data",
+	"List properties for each node",
+	"List subnodes for each node",
+	"Default value to display when the property is missing",
+	USAGE_COMMON_OPTS_HELP
+};
 
 int main(int argc, char *argv[])
 {
+	int opt;
 	char *filename = NULL;
 	struct display_info disp;
 	int args_per_step = 2;
@@ -298,20 +321,14 @@ int main(int argc, char *argv[])
 	memset(&disp, '\0', sizeof(disp));
 	disp.size = -1;
 	disp.mode = MODE_SHOW_VALUE;
-	for (;;) {
-		int c = getopt(argc, argv, "d:hlpt:");
-		if (c == -1)
-			break;
-
-		switch (c) {
-		case 'h':
-		case '?':
-			usage(NULL);
+	while ((opt = util_getopt_long()) != EOF) {
+		switch (opt) {
+		case_USAGE_COMMON_FLAGS
 
 		case 't':
 			if (utilfdt_decode_type(optarg, &disp.type,
 					&disp.size))
-				usage("Invalid type string");
+				usage("invalid type string");
 			break;
 
 		case 'p':
@@ -333,7 +350,7 @@ int main(int argc, char *argv[])
 	if (optind < argc)
 		filename = argv[optind++];
 	if (!filename)
-		usage("Missing filename");
+		usage("missing filename");
 
 	argv += optind;
 	argc -= optind;
@@ -344,7 +361,7 @@ int main(int argc, char *argv[])
 
 	/* Check for node, property arguments */
 	if (args_per_step == 2 && (argc % 2))
-		usage("Must have an even number of arguments");
+		usage("must have an even number of arguments");
 
 	if (do_fdtget(&disp, filename, argv, argc, args_per_step))
 		return 1;
diff --git scripts/dtc/update-dtc-source.sh scripts/dtc/update-dtc-source.sh
index 7dd29a0362b8..8db277546785 100755
--- scripts/dtc/update-dtc-source.sh
+++ scripts/dtc/update-dtc-source.sh
@@ -31,8 +31,8 @@ set -ev
 DTC_UPSTREAM_PATH=`pwd`/../dtc
 DTC_LINUX_PATH=`pwd`/scripts/dtc
 
-DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
-		srcpos.h treesource.c util.c util.h version_gen.h yamltree.c Makefile.dtc \
+DTC_SOURCE="checks.c data.c dtc.c dtc.h fdtget.c flattree.c fstree.c livetree.c
+		srcpos.c srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \
 		dtc-lexer.l dtc-parser.y"
 LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
 		fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 2/4] scripts: add get_console_base.pl
       [not found]       ` <CGME20200130124304eucas1p2f3381b1009cd71cd292169d5f10265c1@eucas1p2.samsung.com>
@ 2020-01-30 12:42         ` Łukasz Stelmach
  0 siblings, 0 replies; 8+ messages in thread
From: Łukasz Stelmach @ 2020-01-30 12:42 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-samsung-soc; +Cc: Łukasz Stelmach

Read UART base address from dtb for compile time configuration.

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 scripts/get_console_base.pl | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100755 scripts/get_console_base.pl

diff --git scripts/get_console_base.pl scripts/get_console_base.pl
new file mode 100755
index 000000000000..c707ee37a19f
--- /dev/null
+++ scripts/get_console_base.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl -w
+
+use strict;
+use File::Basename;
+use File::Spec::Functions;
+
+my $DTB=$ARGV[0];
+die "$0: DTB file not found: $DTB" unless (-f $DTB);
+
+my $scripts_dir=dirname($0);
+my $fdtget=catfile($scripts_dir, 'dtc', 'fdtget');
+
+my $stdout_path=`$fdtget  -ts "$DTB" /chosen stdout-path`;
+chomp $stdout_path;
+
+if ($stdout_path =~ m#([^/][^:]*)(?::.*)#) {
+	$stdout_path=`$fdtget -ts "$DTB" /aliases $1`;
+	chomp $stdout_path;
+}
+
+my $reg = `$fdtget -tx "$DTB" $stdout_path reg`;
+unless ($reg =~ m/^([[:xdigit:]]+)/) {
+	die "Base address not found";
+}
+$reg = $1;
+print "0x$reg\n";
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 3/4] Add tools/hsinit
       [not found]       ` <CGME20200130124314eucas1p11a244e77c9c5f583832832313ba93335@eucas1p1.samsung.com>
@ 2020-01-30 12:42         ` Łukasz Stelmach
  0 siblings, 0 replies; 8+ messages in thread
From: Łukasz Stelmach @ 2020-01-30 12:42 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-samsung-soc
  Cc: Łukasz Stelmach, Mateusz Mościcki

Co-authored by M.Mościcki and Ł.Stelmach.

Signed-off-by: Mateusz Mościcki <m.moscicki2@partner.samsung.com>
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 tools/hsinit/Makefile.am       |  29 ++++
 tools/hsinit/README.org        |  56 ++++++
 tools/hsinit/bootstrap         |   7 +
 tools/hsinit/configure.ac      | 128 ++++++++++++++
 tools/hsinit/hsinit.c          | 299 +++++++++++++++++++++++++++++++++
 tools/hsinit/vendor/.gitignore |   5 +
 tools/hsinit/vendor/SHA256SUMS |   2 +
 7 files changed, 526 insertions(+)
 create mode 100644 tools/hsinit/Makefile.am
 create mode 100644 tools/hsinit/README.org
 create mode 100755 tools/hsinit/bootstrap
 create mode 100644 tools/hsinit/configure.ac
 create mode 100644 tools/hsinit/hsinit.c
 create mode 100644 tools/hsinit/vendor/.gitignore
 create mode 100644 tools/hsinit/vendor/SHA256SUMS

diff --git tools/hsinit/Makefile.am tools/hsinit/Makefile.am
new file mode 100644
index 000000000000..3c8b3cff1b64
--- /dev/null
+++ tools/hsinit/Makefile.am
@@ -0,0 +1,29 @@
+INITRAMFS_DIR = ./initramfs
+
+bin_PROGRAMS=hsinit
+hsinit_LDFLAGS = $(ENABLE_STATIC)
+hsinit_SOURCES = hsinit.c
+hsinit_LINK = $(CCLD) $(hsinit_CFLAGS) $(CFLAGS) $(hsinit_LDFLAGS) \
+        $(LDFLAGS) -o $@
+
+
+data_DATA = initramfs.cpio.xz
+
+CPIO = @CPIO@
+CPIO_FLAGS = -o --format=newc
+
+XZ=@XZ@
+XZ_FLAGS = --check=crc32 --lzma2=dict=1MiB -f -k
+
+ENABLE_STATIC = @ENABLE_STATIC@
+
+%.xz : %
+	xz $(XZ_FLAGS) $<
+
+initramfs.cpio: hsinit
+	for d in bin dev etc lib mnt proc root sbin sys; do \
+		mkdir -p $(INITRAMFS_DIR)/$$d; \
+	done
+	cp $< $(INITRAMFS_DIR)/init
+	cd $(INITRAMFS_DIR); find . -print0 | cpio --null $(CPIO_FLAGS) > ../$@
+
diff --git tools/hsinit/README.org tools/hsinit/README.org
new file mode 100644
index 000000000000..2874781b5e70
--- /dev/null
+++ tools/hsinit/README.org
@@ -0,0 +1,56 @@
+* hsinit
+
+  hsinit is a minimal init program for boot/loader (a.k.a. k-boot) on
+  Odroid XU4 and other platforms with limited size of bootloader
+  image. (1MiB on Odroid XU4). Its sole purpose is to unpack the rest
+  of the initramfs image from an archive pointed by the 'hs' parameter
+  in /proc/cmdline. For example:
+
+#+BEGIN_EXAMPLE:
+      hs=/dev/mmcblk1p6:uroot.cpio.gz
+#+END_EXAMPLE
+
+  will make hsinit mount /dev/mmcblk1p6 and unpack the content of
+  uroot.cpio.gz onto initramfs. Please note that unlike the old initrd
+  initramfs hasn't got fixed size and is much more suitable for hsinit
+  to work with.
+
+* Building hsinit
+
+  The basic way to build hsinit on a host system is
+
+#+BEGIN_SRC sh
+  ./bootstrap && ./configure && make
+#+END_SRC
+
+  The only direct dependency of hsinit is [[https://libarchive.org/][libarchive]], which, however,
+  needs at least zlib to support reasonable compression. You use
+  libarchive and libz packaged for your system or download appropriate
+  archives into the vendor directory (see vendor/SHA256SUMS) and the
+  libraries shall be built automatically.
+
+* Building for musl
+
+  While it is possible to build hsinit for the host system (e.g. x86)
+  and link it dynamically, it makes little sens. Most of the time you
+  will want to compile to for different CPU and link it statically against
+  a C library other than GNU C Library to make the binary small enough
+  to fit the image.
+
+  To cross-compile hsinit for ARM and link it statically against musl
+  run the following command.
+
+#+BEGIN_SRC sh
+  ./bootstrap && \
+    MUSL_DIR=/usr/lib/arm-linux-musleabi/ \
+    GCC_CROSS_DIR=/usr/lib/gcc-cross/arm-linux-gnueabi/8/ \
+    CPPFLAGS='-nostdinc -isystem /usr/include/arm-linux-musleabi/' \
+    CFLAGS='-mthumb -Os -ffunction-sections -fdata-sections' \
+    LIBARCHIVE_CPP_FLAGS=-I/usr/include/arm-linux-musleabi/ \
+    LIBARCHIVE_C_FLAGS=$CFLAGS \
+    ZLIB_C_FLAGS=$CFLAGS \
+    LDFLAGS="-nostdlib -L${MUSL_DIR}/ -L${GCC_CROSS_DIR}/ ${MUSL_DIR}/crt1.o  ${MUSL_DIR}/crti.o  ${GCC_CROSS_DIR}/crtbegin.o -Wl,--gc-sections -Wl,--start-group  ${GCC_CROSS_DIR}/libgcc.a  ${GCC_CROSS_DIR}/libgcc_eh.a -Wl,--end-group ${GCC_CROSS_DIR}/crtend.o  ${MUSL_DIR}/crtn.o -s"  \
+    LIBS="-lc -lgcc"
+  ./configure --enable-local-libraries --host=arm-linux-gnueabi --enable-static && \
+  make
+#+END_SRC
diff --git tools/hsinit/bootstrap tools/hsinit/bootstrap
new file mode 100755
index 000000000000..d3e9fbc8a6c3
--- /dev/null
+++ tools/hsinit/bootstrap
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+set -x -e
+#aclocal
+#autoheader
+#autoconf
+autoreconf -i -f -v
diff --git tools/hsinit/configure.ac tools/hsinit/configure.ac
new file mode 100644
index 000000000000..135f53354c9a
--- /dev/null
+++ tools/hsinit/configure.ac
@@ -0,0 +1,128 @@
+dnl
+dnl configure.ac for hsinit
+dnl
+
+AC_PREREQ(2.69)
+AC_INIT(hsinit, 1.0.0)
+AC_CONFIG_SRCDIR([./hsinit.c])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_INIT_AUTOMAKE([foreign])
+AC_CONFIG_HEADERS([config.h])
+AC_LANG(C)
+AC_PROG_CC
+PKG_PROG_PKG_CONFIG
+
+dnl -- Prepare for cross-compilation
+AC_CANONICAL_HOST
+if test "${build}" != "${host}" ; then
+        AC_CHECK_PROGS(BUILD_CC, [${build_alias}-gcc ${build}-gcc gcc])
+        AC_CHECK_PROGS(BUILD_LD, [${build_alias}-ld ${build}-ld ld])
+        AC_CHECK_PROGS(HOST_CC, [${host_alias}-gcc ${host}-gcc gcc])
+        AC_CHECK_PROGS(HOST_LD, [${host_alias}-ld ${host}-ld ld])
+else
+        BUILD_CC="$CC"
+        BUILD_LD="$LD"
+
+        HOST_CC="$CC"
+        HOST_LD="$LD"
+fi
+
+
+AC_ARG_ENABLE(local-libraries,
+  AS_HELP_STRING([--enable-local-libraries],[Build and use local versions of libarchive and zlib]),
+  ENABLE_LOCAL_LIBS=yes)
+
+AC_ARG_ENABLE(static,
+  AS_HELP_STRING([--enable-static], [Build static binary]),
+  ENABLE_STATIC=-static)
+
+AC_ARG_VAR(ZLIB_C_FLAGS, [CFLAGS for local zlib compilation])
+AC_ARG_VAR(ZLIB_CPP_FLAGS, [CPPFLAGS for local zlib compilation])
+AC_ARG_VAR(ZLIB_LD_FLAGS, [LDFLAGS for local zlib compilation])
+AC_ARG_VAR(LIBARCHIVE_C_FLAGS, [CFLAGS for local libarchive compilation])
+AC_ARG_VAR(LIBARCHIVE_CPP_FLAGS, [CPPFLAGS for local libarchive compilation])
+AC_ARG_VAR(LIBARCHIVE_LD_FLAGS, [LDFLAGS for local libarchive compilation])
+
+AC_SUBST(ENABLE_STATIC)
+AC_SUBST(HOST_CFLAGS, ["$CFLAGS"])
+AC_SUBST(HOST_CPPFLAGS, ["$CPPFLAGS"])
+AC_SUBST(HOST_LDFLAGS, ["$LDFLAGS"])
+
+AC_PATH_PROG(CPIO, cpio)
+AC_PATH_PROG(XZ, xz)
+AC_PATH_PROG(SHA256SUM, sha256sum)
+
+
+AS_IF([test -n "${ENABLE_LOCAL_LIBS}"],
+  AC_MSG_CHECKING([for local libraries])
+  AS_IF([cd $srcdir/vendor && $SHA256SUM -c SHA256SUMS --quiet && cd - > /dev/null],
+        AC_MSG_RESULT([ok]),
+        AC_MSG_ERROR([error])))
+AS_IF([test -n "${ENABLE_LOCAL_LIBS}" && /bin/true],
+  pushd vendor
+  mkdir -p libs
+  zlib_archive=$(grep -o zlib-.* SHA256SUMS)
+  zlib_dir=${zlib_archive%.tar.gz}
+  AC_MSG_NOTICE([Building ${zlib_dir}])
+  rm -rf "$zlib_dir"
+  tar -xf "$zlib_archive"
+  cd "$zlib_dir"
+  CFLAGS="${ZLIB_C_FLAGS}" \
+  CPPFLAGS="${ZLIB_CPP_FLAGS}" \
+  LDFLAGS="${ZLIB_LD_FLAGS}" \
+  CROSS_PREFIX="${host_alias:-${host}}-" ./configure ${ENABLE_STATIC:+--static} --prefix=$(pwd)/../libs
+  make -j8 install
+
+  cd ..
+  
+  libarchive_archive=$(grep -o libarchive-.* SHA256SUMS)
+  libarchive_dir=${libarchive_archive%.tar.gz}
+  rm -rf "$libarchive_dir"
+  tar -xf "$libarchive_archive"
+  cd $libarchive_dir
+
+  PKG_CONFIG_PATH=$(pwd)/../libs/lib/pkgconfig
+  CFLAGS="${LIBARCHIVE_C_FLAGS}" \
+  CPPFLAGS="${LIBARCHIVE_CPP_FLAGS}" \
+  LDFLAGS="${LIBARCHIVE_LD_FLAGS}" \
+  ./configure --host=${host_alias:-${host}} \
+  ${ENABLE_STATIC:+--enable-static --disable-shared} \
+  --prefix=$(pwd)/../libs \
+  --disable-bsdtar \
+  --disable-bsdcat \
+  --disable-bsdcpio \
+  --disable-xattr \
+  --disable-acl \
+  --disable-shared \
+  --disable-largefile \
+  --without-bz2lib \
+  --without-iconv \
+  --without-lz4  \
+  --without-lzma \
+  --without-lzo2 \
+  --without-cng     \
+  --without-nettle \
+  --without-openssl \
+  --without-xml2    \
+  --without-expat
+  make -j8 install
+  popd
+)
+
+AS_IF([test -n "${ENABLE_LOCAL_LIBS}"],
+  export PKG_CONFIG_PATH=$(pwd)/vendor/libs/lib/pkgconfig/
+)
+AS_IF([test -n "$ENABLE_STATIC"],
+  [PKG_CHECK_MODULES_STATIC([LIBARCHIVE], [libarchive])],
+  [PKG_CHECK_MODULES([LIBARCHIVE], [libarchive])])
+
+CFLAGS="$CFLAGS $LIBARCHIVE_CFLAGS"
+LIBS="$LIBS $LIBARCHIVE_LIBS"
+
+dnl ---Output
+AC_OUTPUT([Makefile])
+
+echo
+echo Host CC: $HOST_CC
+echo Build CC: $BUILD_CC
+echo
diff --git tools/hsinit/hsinit.c tools/hsinit/hsinit.c
new file mode 100644
index 000000000000..8332c06b8501
--- /dev/null
+++ tools/hsinit/hsinit.c
@@ -0,0 +1,299 @@
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <limits.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <archive.h>
+#include <archive_entry.h>
+#include <dirent.h>
+
+
+#define COMMAND_LINE_SIZE 512
+#define PARAM_NAME "hs"
+
+/*
+ * Based on examples:
+ * https://github.com/libarchive/libarchive/wiki/Examples
+ */
+int copy_data(struct archive *ar, struct archive *aw)
+{
+	int r;
+	const void *buff;
+	size_t size;
+	int64_t offset;
+
+	for (;;) {
+		r = archive_read_data_block(ar, &buff, &size, &offset);
+		if (r == ARCHIVE_EOF)
+			return (ARCHIVE_OK);
+		if (r < ARCHIVE_OK)
+			return (r);
+		r = archive_write_data_block(aw, buff, size, offset);
+		if (r < ARCHIVE_OK) {
+			printf("%s\n", archive_error_string(aw));
+			return (r);
+		}
+	}
+}
+
+static int extract(const char *filename)
+{
+	struct archive *a;
+	struct archive *ext;
+	struct archive_entry *entry;
+	int flags;
+	int r;
+
+	flags = ARCHIVE_EXTRACT_TIME;
+	flags |= ARCHIVE_EXTRACT_PERM;
+	flags |= ARCHIVE_EXTRACT_ACL;
+	flags |= ARCHIVE_EXTRACT_FFLAGS;
+
+	a = archive_read_new();
+	archive_read_support_format_cpio(a);
+	archive_read_support_filter_gzip(a);
+	ext = archive_write_disk_new();
+	archive_write_disk_set_options(ext, flags);
+	archive_write_disk_set_standard_lookup(ext);
+
+	if ((r = archive_read_open_filename(a, filename, 10240)))
+		return -1;
+
+	for (;;) {
+		r = archive_read_next_header(a, &entry);
+		if (r == ARCHIVE_EOF)
+			break;
+		if (r < ARCHIVE_OK)
+			printf("%s\n", archive_error_string(a));
+		if (r < ARCHIVE_WARN)
+			return -1;
+		r = archive_write_header(ext, entry);
+		if (r < ARCHIVE_OK)
+			printf("%s\n", archive_error_string(ext));
+		else if (archive_entry_size(entry) > 0) {
+			r = copy_data(a, ext);
+			if (r < ARCHIVE_OK)
+				printf("%s\n", archive_error_string(ext));
+			if (r < ARCHIVE_WARN)
+				return -1;
+		}
+
+		r = archive_write_finish_entry(ext);
+
+		if (r < ARCHIVE_OK)
+			printf("%s\n", archive_error_string(ext));
+		if (r < ARCHIVE_WARN)
+			return -1;
+	}
+
+	archive_read_close(a);
+	archive_read_free(a);
+	archive_write_close(ext);
+	archive_write_free(ext);
+
+	return 1;
+}
+
+int mount_sysfs()
+{
+	return mount("none", "/sys", "sysfs", MS_NOEXEC |
+					MS_RELATIME | MS_NODEV | MS_NOSUID, NULL);
+}
+
+int mount_procfs()
+{
+	return mount("none", "/proc", "proc", MS_NOEXEC |
+					MS_RELATIME | MS_NODEV | MS_NOSUID, NULL);
+}
+
+int mount_devfs()
+{
+	return mount("none", "/dev", "devtmpfs", MS_NOEXEC |
+					MS_RELATIME | MS_NOSUID, NULL);
+}
+
+int mount_storage(char *device)
+{
+	char BUFF[256];
+	sprintf(BUFF, "%s", device);
+	// mount("/dev/sdb6", "/mnt", "vfat", MS_RDONLY, NULL) = 0
+	return mount(BUFF, "/mnt", "vfat", 0, NULL);
+}
+
+void ls(char *dir)
+{
+	DIR *d = NULL;
+	struct dirent *de;
+
+	d = opendir(dir);
+
+	if (d == NULL) {
+		printf("Error opening directory: %s\n", dir);
+		return;
+	}
+
+	printf("Reading %s\n", dir);
+	while ((de = readdir(d)) != NULL) {
+		printf("%s\n", de->d_name);
+	}
+	printf("\n");
+}
+
+int umount_storage()
+{
+	return umount("/mnt");
+}
+
+int read_cmd_params(char *buff)
+{
+	int fd = open("/proc/cmdline", O_RDONLY);
+	if (fd < 0) {
+		printf("Open /proc/cmdline error: %s", strerror(errno));
+		return fd;
+	}
+
+	int readed = read(fd, buff, COMMAND_LINE_SIZE-1);
+
+	if (readed >= 0)
+		buff[readed] = '\0';
+	return readed;
+}
+
+/*
+ * Get param=value from /proc/cmdline
+ */
+const char *find_param(const char *cmdline, const char *param_name, char *value)
+{
+	const char *cur = cmdline;
+	bool in_quote = false;
+	bool begin = true;
+	int param_name_len = strlen(param_name);
+	int i, length;
+
+	while (*cur != '\0') {
+		if (begin) {
+			for (i = 0; *(param_name+i) != '\0' &&
+			     *(cur + i) == *(param_name+i); i++);
+
+			if (i == param_name_len && (*(cur+i) == '=')) {
+				cur += i+1;
+				break;
+			}
+			begin = false;
+		}
+
+		if (*cur == '\"')
+			in_quote = !in_quote;
+
+		if (!in_quote && *cur == ' ')
+			begin = true;
+
+		cur++;
+	}
+
+	if (*cur > 0) {
+		for (i = 0; *(cur+i) != ' ' && *(cur+i) != '\0' && *(cur+i) != '\n'; i++);
+		length = i > (COMMAND_LINE_SIZE - 1) ? (COMMAND_LINE_SIZE - 1) : i;
+		memcpy(value, cur, length);
+		value[length] = '\0';
+	}
+	return cur;
+}
+
+int parse_cmdline(const char *cmdline, char *device, char *dest)
+{
+	char value[COMMAND_LINE_SIZE];
+	const char *res = find_param(cmdline, PARAM_NAME, value);
+
+	if (*res == 0) {
+		printf("hs param not found\n");
+		return 0;
+	}
+
+	char *r = strtok(value, ":");
+	if (r == NULL) {
+		printf("Wrong sh parameter format\n");
+		return -1;
+	}
+
+	strncpy(device, r, NAME_MAX);
+
+	r = strtok(NULL, ":");
+	if (r == NULL) {
+		printf("Wrong hs parameter format\n");
+		return -1;
+	}
+
+	strncpy(dest, r, NAME_MAX);
+
+	return 1;
+}
+
+int main(void)
+{
+	char params[COMMAND_LINE_SIZE];
+	char device[NAME_MAX];
+	char initramfs_fn[NAME_MAX];
+	char full_irfs_file[PATH_MAX];
+
+	printf("Hello...\n");
+
+	if (mount_sysfs() < 0) {
+		printf("Mount sysfs error: %s\n", strerror(errno));
+		exit(1);
+	}
+
+	if (mount_procfs() < 0) {
+		printf("Mount procfs error: %s\n", strerror(errno));
+		exit(1);
+	}
+
+	if (mount_devfs() < 0) {
+		printf("Mount devfs error: %s\n", strerror(errno));
+		exit(1);
+	}
+
+	printf("Sleep zzZZ...\n");
+	sleep(1);
+	printf("Wake up :)\n");
+
+	ls("/dev");
+
+	if (read_cmd_params(params) < 0) {
+		printf("Read cmd_params error: %s\n", strerror(errno));
+		exit(1);
+	}
+
+	if (parse_cmdline(params, device, initramfs_fn) <= 0)
+		exit(1);
+
+	if (mount_storage(device) < 0) {
+		printf("Mount %s error: %s\n", device, strerror(errno));
+		exit(1);
+	}
+
+	sprintf(full_irfs_file, "/mnt/%s", initramfs_fn);
+
+	if (extract(full_irfs_file) <= 0) {
+		printf("Extract error: %s\n", strerror(errno));
+		exit(1);
+	}
+
+	umount_storage();
+
+	/*if (execl("/bin/busybox", "sh", NULL) <= 0)*/
+		/*printf("Execl error: %s\n", strerror(errno));*/
+
+	printf("Init...\n");
+
+	if (execl("/init", "/init", (char *)NULL) <= 0)
+		printf("Execl error: %s\n", strerror(errno));
+
+	return 0;
+}
diff --git tools/hsinit/vendor/.gitignore tools/hsinit/vendor/.gitignore
new file mode 100644
index 000000000000..07a4d737cb87
--- /dev/null
+++ tools/hsinit/vendor/.gitignore
@@ -0,0 +1,5 @@
+/zlib-*/
+/libarchive-*/
+/libs/
+/libarchive-*.tar.gz
+/zlib-*.tar.gz
diff --git tools/hsinit/vendor/SHA256SUMS tools/hsinit/vendor/SHA256SUMS
new file mode 100644
index 000000000000..fd42c44ba948
--- /dev/null
+++ tools/hsinit/vendor/SHA256SUMS
@@ -0,0 +1,2 @@
+c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1  zlib-1.2.11.tar.gz
+ed2dbd6954792b2c054ccf8ec4b330a54b85904a80cef477a1c74643ddafa0ce  libarchive-3.3.2.tar.gz
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [RFC PATCH 4/4] boot/loader: Enable building bootloader replacement for Odroid XU4
       [not found]       ` <CGME20200130124315eucas1p12d5380c44b68d08ae96849056303e175@eucas1p1.samsung.com>
@ 2020-01-30 12:42         ` Łukasz Stelmach
  0 siblings, 0 replies; 8+ messages in thread
From: Łukasz Stelmach @ 2020-01-30 12:42 UTC (permalink / raw)
  To: linux-kernel, linux-arm-kernel, linux-samsung-soc; +Cc: Łukasz Stelmach

This code enables booting of Linux kernel on Odroid XU4 without u-boot

Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
---
 arch/arm/Kconfig                              |   8 ++
 arch/arm/Makefile                             |   8 +-
 arch/arm/boot/Makefile                        |  17 +++
 arch/arm/boot/loader/Kconfig                  |  23 +++
 arch/arm/boot/loader/Makefile                 |  42 ++++++
 arch/arm/boot/loader/odroid-console.c         | 136 ++++++++++++++++++
 arch/arm/boot/loader/odroid-crt0.S            |  40 ++++++
 arch/arm/boot/loader/piggy.S                  |  14 ++
 arch/arm/boot/loader/vectors.S                | 112 +++++++++++++++
 arch/arm/boot/loader/vmlinux.lds              |  17 +++
 .../configs/odroidxu4_bootloader_defconfig    | 127 ++++++++++++++++
 11 files changed, 543 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/boot/loader/Kconfig
 create mode 100644 arch/arm/boot/loader/Makefile
 create mode 100644 arch/arm/boot/loader/odroid-console.c
 create mode 100644 arch/arm/boot/loader/odroid-crt0.S
 create mode 100644 arch/arm/boot/loader/piggy.S
 create mode 100644 arch/arm/boot/loader/vectors.S
 create mode 100644 arch/arm/boot/loader/vmlinux.lds
 create mode 100644 arch/arm/configs/odroidxu4_bootloader_defconfig

diff --git arch/arm/Kconfig arch/arm/Kconfig
index 96dab76da3b3..576d90071ba5 100644
--- arch/arm/Kconfig
+++ arch/arm/Kconfig
@@ -1715,6 +1715,13 @@ endmenu
 
 menu "Boot options"
 
+menu "Bootloader"
+	depends on BLK_DEV_INITRD
+
+source "arch/arm/boot/loader/Kconfig"
+
+endmenu
+
 config USE_OF
 	bool "Flattened Device Tree support"
 	select IRQ_DOMAIN
@@ -1982,6 +1989,7 @@ config DMI
 	  firmware need to be enabled. This would require the DMI subsystem
 	  to be enabled much earlier than we do on ARM, which is non-trivial.
 
+
 endmenu
 
 menu "CPU Power Management"
diff --git arch/arm/Makefile arch/arm/Makefile
index db857d07114f..0c2c3d0039ec 100644
--- arch/arm/Makefile
+++ arch/arm/Makefile
@@ -328,11 +328,17 @@ archprepare:
 # Convert bzImage to zImage
 bzImage: zImage
 
-BOOT_TARGETS	= zImage Image xipImage bootpImage uImage
+BOOT_TARGETS	= zImage Image xipImage bootImage bootpImage uImage
 INSTALL_TARGETS	= zinstall uinstall install
 
 PHONY += bzImage $(BOOT_TARGETS) $(INSTALL_TARGETS)
 
+ifeq ($(compress-y),)
+bootImage: Image
+else
+bootImage: zImage
+endif
+
 bootpImage uImage: zImage
 zImage: Image
 
diff --git arch/arm/boot/Makefile arch/arm/boot/Makefile
index 0b3cd7a33a26..20fc5cccaa1e 100644
--- arch/arm/boot/Makefile
+++ arch/arm/boot/Makefile
@@ -66,8 +66,25 @@ $(obj)/compressed/vmlinux: $(obj)/Image FORCE
 $(obj)/zImage:	$(obj)/compressed/vmlinux FORCE
 	$(call if_changed,objcopy)
 
+compress-$(CONFIG_KERNEL_GZIP) = gzip
+compress-$(CONFIG_KERNEL_LZO)  = lzo
+compress-$(CONFIG_KERNEL_LZMA) = lzma
+compress-$(CONFIG_KERNEL_XZ)   = xzkern
+compress-$(CONFIG_KERNEL_LZ4)  = lz4
+
+ifeq ($(compress-y),)
+$(obj)/loader/vmlinux: $(obj)/Image dtbs FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/loader $@
+else
+$(obj)/loader/vmlinux: $(obj)/zImage FORCE
+	$(Q)$(MAKE) $(build)=$(obj)/loader $@
+endif
+
 endif
 
+$(obj)/bootImage: $(obj)/loader/vmlinux FORCE
+	$(call if_changed,objcopy)
+
 ifneq ($(LOADADDR),)
   UIMAGE_LOADADDR=$(LOADADDR)
 else
diff --git arch/arm/boot/loader/Kconfig arch/arm/boot/loader/Kconfig
new file mode 100644
index 000000000000..bc69bf59241a
--- /dev/null
+++ arch/arm/boot/loader/Kconfig
@@ -0,0 +1,23 @@
+choice
+  prompt "Select platform to boot"
+
+  config BOOT_LOADER_XU4
+    bool "Odroid XU4"
+    depends on ARCH_EXYNOS5
+    help
+      Build a kernel loadable by XU4 firmware
+
+  config BOOT_LOADER_XU3
+    bool "Odroid XU3"
+    depends on ARCH_EXYNOS5
+    help
+      Build a kernel loadable by XU3 firmware
+endchoice
+
+config BOOT_LOADER_PLATFORM
+  string
+  default exynos5422-odroidxu4 if BOOT_LOADER_XU4
+  default exynos5422-odroidxu3 if BOOT_LOADER_XU3
+  default ""
+
+
diff --git arch/arm/boot/loader/Makefile arch/arm/boot/loader/Makefile
new file mode 100644
index 000000000000..014ccbf6885a
--- /dev/null
+++ arch/arm/boot/loader/Makefile
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# linux/arch/arm/boot/loader/Makefile
+#
+# create a bootable image for selected platform
+#
+
+
+DTB  := $(subst $(quote),,$(obj)/../dts/$(CONFIG_BOOT_LOADER_PLATFORM).dtb)
+OBJS =
+
+loader-$(CONFIG_BOOT_LOADER_XU3) = odroid-console.o odroid-crt0.o
+loader-$(CONFIG_BOOT_LOADER_XU4) = odroid-console.o odroid-crt0.o
+
+compress-$(CONFIG_KERNEL_GZIP) = gzip
+compress-$(CONFIG_KERNEL_LZO)  = lzo
+compress-$(CONFIG_KERNEL_LZMA) = lzma
+compress-$(CONFIG_KERNEL_XZ)   = xzkern
+compress-$(CONFIG_KERNEL_LZ4)  = lz4
+
+ifeq ($(compress-y),)
+IMAGE = $(obj)/../Image
+else
+IMAGE = $(obj)/../zImage
+endif
+AFLAGS_piggy.o	= -DIMAGE=\"$(IMAGE)\" -DFDT=\"$(DTB)\"
+
+$(obj)/piggy.o: $(IMAGE) $(DTB)
+
+CFLAGS_odroid-console.o = -D__UART_BASE=$(shell $(srctree)/scripts/get_console_base.pl $(obj)/../dts/$(CONFIG_BOOT_LOADER_PLATFORM).dtb)
+
+targets		:= vmlinux
+
+LDFLAGS_vmlinux =
+# Next argument is a linker script
+LDFLAGS_vmlinux += -Ttext 0x43E00000 -T
+
+targets		:= vmlinux vectors.o piggy.o $(loader-y)
+
+$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/vectors.o $(addprefix $(obj)/, $(loader-y)) \
+		$(obj)/piggy.o FORCE
+	$(call if_changed,ld)
diff --git arch/arm/boot/loader/odroid-console.c arch/arm/boot/loader/odroid-console.c
new file mode 100644
index 000000000000..40dec77fd0ed
--- /dev/null
+++ arch/arm/boot/loader/odroid-console.c
@@ -0,0 +1,136 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2020 Samsung Electronics, Co. Ltd. */
+
+#include <asm/io.h>
+
+/* Dummy functions to avoid linker complaints */
+void __aeabi_unwind_cpp_pr0(void)
+{
+};
+#define arm_heavy_mb()
+
+#define GPIO_BASE	((void*)0x14010000)
+#define GPA1CON	(GPIO_BASE + 0x20)
+#define GPA1DAT	(GPIO_BASE + 0x24)
+#define GPA1PUD	(GPIO_BASE + 0x28)
+#define GPA1DRV_SR	(GPIO_BASE + 0x2c)
+#define GPA1CONPDN	(GPIO_BASE + 0x20)
+#define GPA1PUDPDN	(GPIO_BASE + 0x24)
+
+#define GPA1CON0_UART2RX	(0x2 << 0)
+#define GPA1CON1_UART2TX	(0x2 << 4)
+#define GPA1CON2_UART2CTS	(0x2 << 8)
+#define GPA1CON3_UART2RTS	(0x2 << 12)
+
+#define GPA1_UART2MASK		(0xffff)
+#define GPA1PUD_UART2MASK	(0xff)
+
+#ifndef __UART_BASE
+#error __UART_BASE not defined
+#else
+#define UART_BASE ((void*)__UART_BASE)
+#endif
+
+#define S3C2410_ULCON		(0x00)
+#define S3C2410_UCON		(0x04)
+#define S3C2410_UFCON		(0x08)
+#define S3C2410_UMCON		(0x0C)
+#define S3C2410_UBRDIV		(0x28)
+#define S3C2410_FRACVAL	(0x2C)
+
+#define UART_ULCON	(UART_BASE + S3C2410_ULCON)
+#define UART_UCON	(UART_BASE + S3C2410_UCON)
+#define UART_UFCON	(UART_BASE + S3C2410_UFCON)
+#define UART_UMCON	(UART_BASE + S3C2410_UMCON)
+#define UART_UBRDIV	(UART_BASE + S3C2410_UBRDIV)
+#define UART_UFRACVAL	(UART_BASE + S3C2410_FRACVAL)
+
+#define S5PV210_ULCON_CS5	(0)
+#define S5PV210_ULCON_CS6	(1)
+#define S5PV210_ULCON_CS7	(2)
+#define S5PV210_ULCON_CS8	(3)
+#define S5PV210_ULCON_CSTOPB	(1 << 2) /* two stop bits */
+#define S5PV210_ULCON_PARODD	(4 << 3) /* parity check: odd */
+#define S5PV210_ULCON_PAREVN	(5 << 3) /* parity check: even */
+#define S5PV210_ULCON_IRDA	(1 << 6) /* Infrared Mode */
+#define S5PV210_ULCON_DEFAULT	(S5PV210_ULCON_CS8) /* 8N1 */
+
+#define S3C2410_UCON_RXIRQMODE		(1<<0)
+#define S3C2410_UCON_TXIRQMODE		(1<<2)
+#define S3C2410_UCON_SBREAK		(1<<4)
+#define S3C2443_UCON_LOOPBACK		(1<<5)
+#define S3C2443_UCON_RXERR_IRQEN	(1<<6)
+#define S3C2410_UCON_RXFIFO_TOI	(1<<7)
+#define S3C2410_UCON_RXILEVEL		(1<<8)
+#define S3C2410_UCON_TXILEVEL		(1<<9)
+#define S5PV210_UCON_DEFAULT		( \
+					 S3C2410_UCON_RXIRQMODE |	\
+					 S3C2410_UCON_TXIRQMODE |   \
+					 S3C2443_UCON_RXERR_IRQEN | 0)
+
+#define S3C2410_UFCON_FIFOMODE		(1<<0)
+#define S3C2410_UFCON_RESETRX		(1<<1)
+#define S3C2410_UFCON_RESETTX		(1<<2)
+#define S3C2410_UFCON_RESETBOTH	(3<<1)
+
+#define S5PV210_UFCON_DEFAULT	(S3C2410_UFCON_FIFOMODE |	\
+				 S3C2410_UFCON_RESETBOTH)
+
+
+/* CLK_SRC_PERIC0 */
+#define PWM_SEL	6
+#define UART3_SEL	6
+#define UART2_SEL	6
+#define UART1_SEL	6
+#define UART0_SEL	6
+/* SRC_CLOCK = SCLK_MPLL */
+#define CLK_SRC_PERIC0_VAL	((PWM_SEL << 24)	\
+				| (UART3_SEL << 12)	\
+				| (UART2_SEL << 8)	 \
+				| (UART1_SEL << 4)	\
+				| (UART0_SEL))
+
+
+#define UART5_RATIO	7
+#define UART4_RATIO	7
+#define UART3_RATIO	7
+#define UART2_RATIO	7
+#define UART1_RATIO	7
+#define UART0_RATIO	7
+
+#define CLK_DIV_PERIC0_VAL	((UART3_RATIO << 12)	\
+				| (UART2_RATIO << 8)	\
+				| (UART1_RATIO << 4)	\
+				| (UART0_RATIO))
+
+
+#define CLK_SRC_PERIC0 (0x10020250)
+#define CLK_DIV_PERIC0 (0x10020558)
+
+void console_on(void) {
+	int a;
+	a = readl(GPA1CON);
+	a = (a & ~GPA1_UART2MASK) |
+		GPA1CON0_UART2RX |
+		GPA1CON1_UART2TX |
+		GPA1CON2_UART2CTS |
+		GPA1CON3_UART2RTS;
+	writel(a, GPA1CON);
+
+	a = readl(GPA1PUD) & ~GPA1PUD_UART2MASK;
+	writel(a, GPA1PUD);
+
+	/* UART2_SEL: SCLK_MPLL (3)*/
+	/* MPLL_M: 266 */
+	/* MPLL_P: 3 */
+	/* MPLL_S: 2 */
+	/* UART2_RATIO: 9 */
+
+	writel(S5PV210_UFCON_DEFAULT, UART_UFCON);
+	writel(0, UART_UMCON);
+	writel(S5PV210_ULCON_DEFAULT, UART_ULCON);
+	writel(S5PV210_UCON_DEFAULT, UART_UCON);
+
+	writel(0x1b, UART_UBRDIV);
+	writel(0x0d, UART_UFRACVAL);
+}
diff --git arch/arm/boot/loader/odroid-crt0.S arch/arm/boot/loader/odroid-crt0.S
new file mode 100644
index 000000000000..586bb8e18d78
--- /dev/null
+++ arch/arm/boot/loader/odroid-crt0.S
@@ -0,0 +1,40 @@
+/*
+ *  crt0 - C-runtime startup Code for ARM
+ *
+ *  Copyright (c) 2012  Albert ARIBAUD <albert.u.boot@aribaud.net>
+ *  Copyright (c) 2020  Samsung Electronics, Co. Ltd.
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+#include <linux/linkage.h>
+
+splash:	.asciz "boot/loader\r\n\7"
+/*
+ * entry point of crt0 sequence
+ */
+	.arm
+ENTRY(_main)
+	ldr	sp, =user_stack_end
+	bl	console_on
+	mov	r0,  #0x12C00000
+	add	r0, r0, #0x20000
+	adr	r2, splash
+_putc:	ldrb	r1, [r2]
+	teq	r1, #0
+	beq	_done
+	strb	r1, [r0, #0x20] /* UTXH */
+	add	r2, r2, #1
+	b	_putc
+_done:
+	mov	r0, #0
+	mov     r1, #~0
+	ldr	r2, =dt_blob_start
+ 	b	zImage
+ENDPROC(_main)
+
+
+	.align 2
+	.section ".stack", "aw", %nobits
+user_stack:	.space  64
+user_stack_end:
diff --git arch/arm/boot/loader/piggy.S arch/arm/boot/loader/piggy.S
new file mode 100644
index 000000000000..ae0c9f770741
--- /dev/null
+++ arch/arm/boot/loader/piggy.S
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+	.section .piggydata,#alloc
+	.align  12
+	.globl  dt_blob_start
+dt_blob_start:
+	.incbin FDT
+	.globl dt_blob_end
+dt_blob_end:
+	.align 12
+	.globl	zImage
+zImage:
+        .incbin IMAGE
+	.globl	zImage_end
+zImage_end:
diff --git arch/arm/boot/loader/vectors.S arch/arm/boot/loader/vectors.S
new file mode 100644
index 000000000000..744ee4625b6e
--- /dev/null
+++ arch/arm/boot/loader/vectors.S
@@ -0,0 +1,112 @@
+/*
+ *  vectors - Generic ARM exception table code
+ *
+ *  Copyright (c) 1998	Dan Malek <dmalek@jlc.net>
+ *  Copyright (c) 1999	Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
+ *  Copyright (c) 2000	Wolfgang Denk <wd@denx.de>
+ *  Copyright (c) 2001	Alex Züpke <azu@sysgo.de>
+ *  Copyright (c) 2001	Marius Gröger <mag@sysgo.de>
+ *  Copyright (c) 2002	Alex Züpke <azu@sysgo.de>
+ *  Copyright (c) 2002	Gary Jennejohn <garyj@denx.de>
+ *  Copyright (c) 2002	Kyle Harris <kharris@nexus-tech.net>
+ *  Copyright (c) 2020  Samsung Electronics, Co. Ltd.
+ *
+ * SPDX-License-Identifier:	GPL-2.0
+ */
+
+/* From head.S */
+ AR_CLASS(      .arch   armv7-a )
+ M_CLASS(       .arch   armv7-m )
+
+/*
+ *************************************************************************
+ *
+ * Symbol _start is referenced elsewhere, so make it global
+ *
+ *************************************************************************
+ */
+
+.globl _start
+
+/*
+ *************************************************************************
+ *
+ * Vectors have their own section so linker script can map them easily
+ *
+ *************************************************************************
+ */
+
+	.section ".vectors", "ax"
+	.arm
+
+/*
+ *************************************************************************
+ *
+ * Exception vectors as described in ARM reference manuals
+ *
+ * Uses indirect branch to allow reaching handlers anywhere in memory.
+ *
+ *************************************************************************
+ */
+
+_start:
+	b	_main
+	ldr	pc, _undefined_instruction
+	ldr	pc, _software_interrupt
+	ldr	pc, _prefetch_abort
+	ldr	pc, _data_abort
+	ldr	pc, _not_used
+	ldr	pc, _irq
+	ldr	pc, _fiq
+
+/*
+ *************************************************************************
+ *
+ * Indirect vectors table
+ *
+ * Symbols referenced here must be defined somewhere else
+ *
+ *************************************************************************
+ */
+
+	.globl	_undefined_instruction
+	.globl	_software_interrupt
+	.globl	_prefetch_abort
+	.globl	_data_abort
+	.globl	_not_used
+	.globl	_irq
+	.globl	_fiq
+
+_undefined_instruction:	.word undefined_instruction
+_software_interrupt:	.word software_interrupt
+_prefetch_abort:	.word prefetch_abort
+_data_abort:		.word data_abort
+_not_used:		.word not_used
+_irq:			.word irq
+_fiq:			.word fiq
+
+	.balignl 16,0xdeadbeef
+
+/*
+ *************************************************************************
+ *
+ * Interrupt handling
+ *
+ *************************************************************************
+ */
+
+/* SPL interrupt handling: just hang */
+
+	.align	5
+undefined_instruction:
+software_interrupt:
+prefetch_abort:
+data_abort:
+not_used:
+irq:
+fiq:
+
+1:
+	bl	1b			/* hang and never return */
+
+
diff --git arch/arm/boot/loader/vmlinux.lds arch/arm/boot/loader/vmlinux.lds
new file mode 100644
index 000000000000..bbd45def56a2
--- /dev/null
+++ arch/arm/boot/loader/vmlinux.lds
@@ -0,0 +1,17 @@
+OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_ARCH(arm)
+ENTRY(_start)
+SECTIONS
+{
+ . = 0x00000000;
+ . = ALIGN(4);
+ .text :
+ {
+  *(.vectors)
+  *(.text*)
+ }
+ . = ALIGN(4096);
+ .piggydata : { *(.piggydata) }
+ . = ALIGN(8);
+ .stack : { *(.stack) }
+}
diff --git arch/arm/configs/odroidxu4_bootloader_defconfig arch/arm/configs/odroidxu4_bootloader_defconfig
new file mode 100644
index 000000000000..88961d952613
--- /dev/null
+++ arch/arm/configs/odroidxu4_bootloader_defconfig
@@ -0,0 +1,127 @@
+CONFIG_BOOT_LOADER_XU4=y
+CONFIG_LOCALVERSION="-boot-loader"
+CONFIG_KERNEL_XZ=y
+CONFIG_DEFAULT_HOSTNAME="boot-loader"
+# CONFIG_SWAP is not set
+# CONFIG_CROSS_MEMORY_ATTACH is not set
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE="tools/hsinit/initramfs.cpio"
+# CONFIG_RD_GZIP is not set
+# CONFIG_RD_BZIP2 is not set
+# CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
+# CONFIG_RD_LZ4 is not set
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+# CONFIG_MULTIUSER is not set
+# CONFIG_SYSFS_SYSCALL is not set
+# CONFIG_FHANDLE is not set
+# CONFIG_BUG is not set
+# CONFIG_BASE_FULL is not set
+# CONFIG_SHMEM is not set
+# CONFIG_AIO is not set
+# CONFIG_IO_URING is not set
+# CONFIG_ADVISE_SYSCALLS is not set
+# CONFIG_MEMBARRIER is not set
+# CONFIG_KALLSYMS is not set
+# CONFIG_RSEQ is not set
+CONFIG_EMBEDDED=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_SLOB=y
+CONFIG_ARCH_EXYNOS=y
+# CONFIG_ARCH_EXYNOS3 is not set
+# CONFIG_ARCH_EXYNOS4 is not set
+# CONFIG_SOC_EXYNOS5250 is not set
+# CONFIG_SOC_EXYNOS5260 is not set
+# CONFIG_SOC_EXYNOS5410 is not set
+# CONFIG_SOC_EXYNOS5800 is not set
+CONFIG_HAVE_ARM_ARCH_TIMER=y
+CONFIG_THUMB2_KERNEL=y
+CONFIG_HIGHMEM=y
+CONFIG_SECCOMP=y
+# CONFIG_ATAGS is not set
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_ARM_APPENDED_DTB=y
+CONFIG_CMDLINE="earlycon debug console=ttySAC2,115200n8 clk_ignore_unused hs=/dev/mmcblk1p6:uroot.cpio.gz"
+CONFIG_KEXEC=y
+CONFIG_VFP=y
+# CONFIG_SUSPEND is not set
+CONFIG_PM=y
+# CONFIG_BLK_DEV_BSG is not set
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_MQ_IOSCHED_DEADLINE is not set
+# CONFIG_MQ_IOSCHED_KYBER is not set
+# CONFIG_COREDUMP is not set
+# CONFIG_COMPACTION is not set
+CONFIG_DEVTMPFS=y
+CONFIG_DEVTMPFS_MOUNT=y
+CONFIG_SCSI=y
+CONFIG_BLK_DEV_SD=y
+CONFIG_CHR_DEV_SG=y
+# CONFIG_INPUT is not set
+# CONFIG_SERIO is not set
+# CONFIG_VT is not set
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_DEVMEM is not set
+CONFIG_SERIAL_SAMSUNG=y
+CONFIG_SERIAL_SAMSUNG_CONSOLE=y
+# CONFIG_HW_RANDOM is not set
+CONFIG_I2C=y
+CONFIG_I2C_CHARDEV=y
+CONFIG_I2C_MUX=y
+CONFIG_I2C_ARB_GPIO_CHALLENGE=y
+CONFIG_I2C_GPIO=y
+CONFIG_I2C_S3C2410=y
+CONFIG_SENSORS_PWM_FAN=y
+CONFIG_THERMAL_EMULATION=y
+CONFIG_MFD_SEC_CORE=y
+CONFIG_REGULATOR=y
+CONFIG_REGULATOR_FIXED_VOLTAGE=y
+CONFIG_REGULATOR_GPIO=y
+CONFIG_REGULATOR_S2MPS11=y
+# CONFIG_USB_SUPPORT is not set
+CONFIG_MMC=y
+# CONFIG_PWRSEQ_SIMPLE is not set
+CONFIG_MMC_BLOCK_MINORS=16
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_S3C=y
+CONFIG_MMC_SDHCI_S3C_DMA=y
+CONFIG_MMC_DW=y
+CONFIG_MMC_DW_EXYNOS=y
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+CONFIG_LEDS_CLASS_FLASH=y
+CONFIG_LEDS_GPIO=y
+CONFIG_LEDS_PWM=y
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+# CONFIG_VIRTIO_MENU is not set
+CONFIG_COMMON_CLK_S2MPS11=y
+# CONFIG_EXYNOS_AUDSS_CLK_CON is not set
+# CONFIG_IOMMU_SUPPORT is not set
+CONFIG_PWM=y
+CONFIG_PWM_SAMSUNG=y
+# CONFIG_PHY_EXYNOS_DP_VIDEO is not set
+# CONFIG_PHY_EXYNOS_MIPI_VIDEO is not set
+CONFIG_NVMEM=y
+# CONFIG_FILE_LOCKING is not set
+# CONFIG_DNOTIFY is not set
+# CONFIG_INOTIFY_USER is not set
+CONFIG_VFAT_FS=y
+# CONFIG_PROC_SYSCTL is not set
+# CONFIG_PROC_PAGE_MONITOR is not set
+# CONFIG_MISC_FILESYSTEMS is not set
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_PRINTK_TIME=y
+# CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_DEBUG_MISC is not set
+# CONFIG_SCHED_DEBUG is not set
+# CONFIG_FTRACE is not set
+CONFIG_DEBUG_LL=y
+CONFIG_DEBUG_S3C_UART2=y
+CONFIG_DEBUG_UNCOMPRESS=y
+# CONFIG_RUNTIME_TESTING_MENU is not set
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145
  2020-01-30 12:42     ` [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 Łukasz Stelmach
                         ` (2 preceding siblings ...)
       [not found]       ` <CGME20200130124315eucas1p12d5380c44b68d08ae96849056303e175@eucas1p1.samsung.com>
@ 2020-01-30 12:47       ` Russell King - ARM Linux admin
       [not found]         ` <CGME20200130125530eucas1p282d9749764c3a5c21c85c829d372b650@eucas1p2.samsung.com>
  2020-01-30 14:16       ` Rob Herring
  4 siblings, 1 reply; 8+ messages in thread
From: Russell King - ARM Linux admin @ 2020-01-30 12:47 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: linux-kernel, linux-arm-kernel, linux-samsung-soc

On Thu, Jan 30, 2020 at 01:42:30PM +0100, Łukasz Stelmach wrote:
> Build and fdtget and add fdtget.c to the list of update source files.
> 
> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> ---
>  scripts/dtc/.gitignore           |   4 +
>  scripts/dtc/Makefile             |   5 ++
>  scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
>  scripts/dtc/update-dtc-source.sh |   4 +-
>  4 files changed, 82 insertions(+), 56 deletions(-)
> 
> diff --git scripts/dtc/.gitignore scripts/dtc/.gitignore
> index 2e6e60d64ede..80f6b50fdf77 100644
> --- scripts/dtc/.gitignore
> +++ scripts/dtc/.gitignore
> @@ -1 +1,5 @@
>  dtc
> +dtc-lexer.lex.c
> +dtc-parser.tab.c
> +dtc-parser.tab.h
> +fdtget
> diff --git scripts/dtc/Makefile scripts/dtc/Makefile
> index b5a5b1c548c9..74322d8dac25 100644
> --- scripts/dtc/Makefile
> +++ scripts/dtc/Makefile
> @@ -2,12 +2,15 @@
>  # scripts/dtc makefile
>  
>  hostprogs-$(CONFIG_DTC) := dtc
> +hostprogs-$(CONFIG_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
>  
> +fdtget-objs     := fdtget.o util.o
> +
>  # Source files need to get at the userspace version of libfdt_env.h to compile
>  HOST_EXTRACFLAGS := -I $(srctree)/$(src)/libfdt
>  
> @@ -26,5 +29,7 @@ endif
>  HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
>  HOSTCFLAGS_dtc-parser.tab.o := -I $(srctree)/$(src)
>  
> +HOSTLDLIBS_fdtget := -L$(obj)/libfdt -lfdt -Wl,-rpath='$$ORIGIN/libfdt'
> +
>  # dependencies on generated files need to be listed explicitly
>  $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
> diff --git scripts/dtc/fdtget.c scripts/dtc/fdtget.c
> index c922f82246c6..777582e2d45f 100644
> --- scripts/dtc/fdtget.c
> +++ scripts/dtc/fdtget.c
> @@ -39,6 +39,37 @@ static void report_error(const char *where, int err)
>  	fprintf(stderr, "Error at '%s': %s\n", where, fdt_strerror(err));
>  }
>  
> +/**
> + * Shows a list of cells in the requested format
> + *
> + * @param disp		Display information / options
> + * @param data		Data to display
> + * @param len		Maximum length of buffer
> + * @param size		Data size to use for display (e.g. 4 for 32-bit)
> + * @return 0 if ok, -1 on error
> + */
> +static int show_cell_list(struct display_info *disp, const char *data, int len,
> +			  int size)
> +{
> +	const uint8_t *p = (const uint8_t *)data;
> +	char fmt[3];
> +	int value;
> +	int i;
> +
> +	fmt[0] = '%';
> +	fmt[1] = disp->type ? disp->type : 'd';
> +	fmt[2] = '\0';
> +	for (i = 0; i < len; i += size, p += size) {
> +		if (i)
> +			printf(" ");
> +		value = size == 4 ? fdt32_ld((const fdt32_t *)p) :
> +			size == 2 ? (*p << 8) | p[1] : *p;
> +		printf(fmt, value);
> +	}
> +
> +	return 0;
> +}
> +
>  /**
>   * Displays data of a given length according to selected options
>   *
> @@ -52,12 +83,9 @@ static void report_error(const char *where, int err)
>   */
>  static int show_data(struct display_info *disp, const char *data, int len)
>  {
> -	int i, size;
> -	const uint8_t *p = (const uint8_t *)data;
> +	int size;
>  	const char *s;
> -	int value;
>  	int is_string;
> -	char fmt[3];
>  
>  	/* no data, don't print */
>  	if (len == 0)
> @@ -85,17 +113,8 @@ static int show_data(struct display_info *disp, const char *data, int len)
>  				"selected data size\n");
>  		return -1;
>  	}
> -	fmt[0] = '%';
> -	fmt[1] = disp->type ? disp->type : 'd';
> -	fmt[2] = '\0';
> -	for (i = 0; i < len; i += size, p += size) {
> -		if (i)
> -			printf(" ");
> -		value = size == 4 ? fdt32_to_cpu(*(const uint32_t *)p) :
> -			size == 2 ? (*p << 8) | p[1] : *p;
> -		printf(fmt, value);
> -	}
> -	return 0;
> +
> +	return show_cell_list(disp, data, len, size);
>  }
>  
>  /**
> @@ -107,7 +126,6 @@ static int show_data(struct display_info *disp, const char *data, int len)
>   */
>  static int list_properties(const void *blob, int node)
>  {
> -	const struct fdt_property *data;
>  	const char *name;
>  	int prop;
>  
> @@ -116,8 +134,7 @@ static int list_properties(const void *blob, int node)
>  		/* Stop silently when there are no more properties */
>  		if (prop < 0)
>  			return prop == -FDT_ERR_NOTFOUND ? 0 : prop;
> -		data = fdt_get_property_by_offset(blob, prop, NULL);
> -		name = fdt_string(blob, fdt32_to_cpu(data->nameoff));
> +		fdt_getprop_by_offset(blob, prop, &name, NULL);
>  		if (name)
>  			puts(name);
>  		prop = fdt_next_property_offset(blob, prop);
> @@ -231,7 +248,7 @@ static int show_data_for_item(const void *blob, struct display_info *disp,
>   * @param filename	Filename of blob file
>   * @param arg		List of arguments to process
>   * @param arg_count	Number of arguments
> - * @param return 0 if ok, -ve on error
> + * @return 0 if ok, -ve on error
>   */
>  static int do_fdtget(struct display_info *disp, const char *filename,
>  		     char **arg, int arg_count, int args_per_step)
> @@ -240,7 +257,7 @@ static int do_fdtget(struct display_info *disp, const char *filename,
>  	const char *prop;
>  	int i, node;
>  
> -	blob = utilfdt_read(filename);
> +	blob = utilfdt_read(filename, NULL);
>  	if (!blob)
>  		return -1;
>  
> @@ -252,44 +269,50 @@ static int do_fdtget(struct display_info *disp, const char *filename,
>  				continue;
>  			} else {
>  				report_error(arg[i], node);
> +				free(blob);
>  				return -1;
>  			}
>  		}
>  		prop = args_per_step == 1 ? NULL : arg[i + 1];
>  
> -		if (show_data_for_item(blob, disp, node, prop))
> +		if (show_data_for_item(blob, disp, node, prop)) {
> +			free(blob);
>  			return -1;
> +		}
>  	}
> +
> +	free(blob);
> +
>  	return 0;
>  }
>  
> -static const char *usage_msg =
> -	"fdtget - read values from device tree\n"
> -	"\n"
> -	"Each value is printed on a new line.\n\n"
> -	"Usage:\n"
> +/* Usage related data. */
> +static const char usage_synopsis[] =
> +	"read values from device tree\n"
>  	"	fdtget <options> <dt file> [<node> <property>]...\n"
>  	"	fdtget -p <options> <dt file> [<node> ]...\n"
> -	"Options:\n"
> -	"\t-t <type>\tType of data\n"
> -	"\t-p\t\tList properties for each node\n"
> -	"\t-l\t\tList subnodes for each node\n"
> -	"\t-d\t\tDefault value to display when the property is "
> -			"missing\n"
> -	"\t-h\t\tPrint this help\n\n"
> +	"\n"
> +	"Each value is printed on a new line.\n"
>  	USAGE_TYPE_MSG;
> -
> -static void usage(const char *msg)
> -{
> -	if (msg)
> -		fprintf(stderr, "Error: %s\n\n", msg);
> -
> -	fprintf(stderr, "%s", usage_msg);
> -	exit(2);
> -}
> +static const char usage_short_opts[] = "t:pld:" USAGE_COMMON_SHORT_OPTS;
> +static struct option const usage_long_opts[] = {
> +	{"type",              a_argument, NULL, 't'},
> +	{"properties",       no_argument, NULL, 'p'},
> +	{"list",             no_argument, NULL, 'l'},
> +	{"default",           a_argument, NULL, 'd'},
> +	USAGE_COMMON_LONG_OPTS,
> +};
> +static const char * const usage_opts_help[] = {
> +	"Type of data",
> +	"List properties for each node",
> +	"List subnodes for each node",
> +	"Default value to display when the property is missing",
> +	USAGE_COMMON_OPTS_HELP
> +};
>  
>  int main(int argc, char *argv[])
>  {
> +	int opt;
>  	char *filename = NULL;
>  	struct display_info disp;
>  	int args_per_step = 2;
> @@ -298,20 +321,14 @@ int main(int argc, char *argv[])
>  	memset(&disp, '\0', sizeof(disp));
>  	disp.size = -1;
>  	disp.mode = MODE_SHOW_VALUE;
> -	for (;;) {
> -		int c = getopt(argc, argv, "d:hlpt:");
> -		if (c == -1)
> -			break;
> -
> -		switch (c) {
> -		case 'h':
> -		case '?':
> -			usage(NULL);
> +	while ((opt = util_getopt_long()) != EOF) {
> +		switch (opt) {
> +		case_USAGE_COMMON_FLAGS
>  
>  		case 't':
>  			if (utilfdt_decode_type(optarg, &disp.type,
>  					&disp.size))
> -				usage("Invalid type string");
> +				usage("invalid type string");
>  			break;
>  
>  		case 'p':
> @@ -333,7 +350,7 @@ int main(int argc, char *argv[])
>  	if (optind < argc)
>  		filename = argv[optind++];
>  	if (!filename)
> -		usage("Missing filename");
> +		usage("missing filename");
>  
>  	argv += optind;
>  	argc -= optind;
> @@ -344,7 +361,7 @@ int main(int argc, char *argv[])
>  
>  	/* Check for node, property arguments */
>  	if (args_per_step == 2 && (argc % 2))
> -		usage("Must have an even number of arguments");
> +		usage("must have an even number of arguments");
>  
>  	if (do_fdtget(&disp, filename, argv, argc, args_per_step))
>  		return 1;
> diff --git scripts/dtc/update-dtc-source.sh scripts/dtc/update-dtc-source.sh
> index 7dd29a0362b8..8db277546785 100755
> --- scripts/dtc/update-dtc-source.sh
> +++ scripts/dtc/update-dtc-source.sh
> @@ -31,8 +31,8 @@ set -ev
>  DTC_UPSTREAM_PATH=`pwd`/../dtc
>  DTC_LINUX_PATH=`pwd`/scripts/dtc
>  
> -DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
> -		srcpos.h treesource.c util.c util.h version_gen.h yamltree.c Makefile.dtc \
> +DTC_SOURCE="checks.c data.c dtc.c dtc.h fdtget.c flattree.c fstree.c livetree.c
> +		srcpos.c srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \

This looks like you're dropping yamltree.c.  Is that intentional?

>  		dtc-lexer.l dtc-parser.y"
>  LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
>  		fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145
       [not found]         ` <CGME20200130125530eucas1p282d9749764c3a5c21c85c829d372b650@eucas1p2.samsung.com>
@ 2020-01-30 12:55           ` Łukasz Stelmach
  0 siblings, 0 replies; 8+ messages in thread
From: Łukasz Stelmach @ 2020-01-30 12:55 UTC (permalink / raw)
  To: Russell King - ARM Linux admin
  Cc: linux-kernel, linux-arm-kernel, linux-samsung-soc

[-- Attachment #1: Type: text/plain, Size: 1914 bytes --]

It was <2020-01-30 czw 12:47>, when Russell King - ARM Linux admin wrote:
> On Thu, Jan 30, 2020 at 01:42:30PM +0100, Łukasz Stelmach wrote:
>> Build and fdtget and add fdtget.c to the list of update source files.
>> 
>> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
>> ---
>>  scripts/dtc/.gitignore           |   4 +
>>  scripts/dtc/Makefile             |   5 ++
>>  scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
>>  scripts/dtc/update-dtc-source.sh |   4 +-
>>  4 files changed, 82 insertions(+), 56 deletions(-)
>> 

[...]

>> diff --git scripts/dtc/update-dtc-source.sh scripts/dtc/update-dtc-source.sh
>> index 7dd29a0362b8..8db277546785 100755
>> --- scripts/dtc/update-dtc-source.sh
>> +++ scripts/dtc/update-dtc-source.sh
>> @@ -31,8 +31,8 @@ set -ev
>>  DTC_UPSTREAM_PATH=`pwd`/../dtc
>>  DTC_LINUX_PATH=`pwd`/scripts/dtc
>>  
>> -DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \
>> -		srcpos.h treesource.c util.c util.h version_gen.h yamltree.c Makefile.dtc \
>> +DTC_SOURCE="checks.c data.c dtc.c dtc.h fdtget.c flattree.c fstree.c livetree.c
>> +		srcpos.c srcpos.h treesource.c util.c util.h version_gen.h Makefile.dtc \
>
> This looks like you're dropping yamltree.c.  Is that intentional?
>

Not it isn't. Thanks. Fixed.

>>  		dtc-lexer.l dtc-parser.y"
>>  LIBFDT_SOURCE="Makefile.libfdt fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \
>>  		fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \
>> -- 
>> 2.20.1
>> 
>> 
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@lists.infradead.org
>> https://protect2.fireeye.com/url?k=c03cfed5-9df03751-c03d759a-0cc47aa8f5ba-45d60c6701b8fc7a&u=http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

-- 
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145
  2020-01-30 12:42     ` [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 Łukasz Stelmach
                         ` (3 preceding siblings ...)
  2020-01-30 12:47       ` [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 Russell King - ARM Linux admin
@ 2020-01-30 14:16       ` Rob Herring
  4 siblings, 0 replies; 8+ messages in thread
From: Rob Herring @ 2020-01-30 14:16 UTC (permalink / raw)
  To: Łukasz Stelmach
  Cc: linux-kernel,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-samsung-soc

On Thu, Jan 30, 2020 at 6:42 AM Łukasz Stelmach <l.stelmach@samsung.com> wrote:
>
> Build and fdtget and add fdtget.c to the list of update source files.

Why does the kernel need fdtget and why not use the version from your distro?

Please Cc the DT list next time.

> Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
> ---
>  scripts/dtc/.gitignore           |   4 +
>  scripts/dtc/Makefile             |   5 ++
>  scripts/dtc/fdtget.c             | 125 ++++++++++++++++++-------------
>  scripts/dtc/update-dtc-source.sh |   4 +-

Separate changes by updates to this script, running the script (to get
fdtget.c), and updates to kernel files.

>  4 files changed, 82 insertions(+), 56 deletions(-)
>
> diff --git scripts/dtc/.gitignore scripts/dtc/.gitignore
> index 2e6e60d64ede..80f6b50fdf77 100644
> --- scripts/dtc/.gitignore
> +++ scripts/dtc/.gitignore
> @@ -1 +1,5 @@
>  dtc
> +dtc-lexer.lex.c
> +dtc-parser.tab.c
> +dtc-parser.tab.h

These are needed regardless. Probably a treewide rule for *.lex.c,
*.tab.c, *.tab.h would be better.

> +fdtget
> diff --git scripts/dtc/Makefile scripts/dtc/Makefile
> index b5a5b1c548c9..74322d8dac25 100644
> --- scripts/dtc/Makefile
> +++ scripts/dtc/Makefile
> @@ -2,12 +2,15 @@
>  # scripts/dtc makefile
>
>  hostprogs-$(CONFIG_DTC) := dtc
> +hostprogs-$(CONFIG_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
>
> +fdtget-objs     := fdtget.o util.o
> +
>  # Source files need to get at the userspace version of libfdt_env.h to compile
>  HOST_EXTRACFLAGS := -I $(srctree)/$(src)/libfdt
>
> @@ -26,5 +29,7 @@ endif
>  HOSTCFLAGS_dtc-lexer.lex.o := -I $(srctree)/$(src)
>  HOSTCFLAGS_dtc-parser.tab.o := -I $(srctree)/$(src)
>
> +HOSTLDLIBS_fdtget := -L$(obj)/libfdt -lfdt -Wl,-rpath='$$ORIGIN/libfdt'
> +

We never build libfdt as a library, so how does this work unless it
pulls in the distro copy?

Rob

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-01-30 14:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200130124000eucas1p137943be0fe3e5e1eb45e705dc5c46431@eucas1p1.samsung.com>
2020-01-30 12:39 ` [RFC PATCH 0/4] boot/loader: Load kernel directly from firmware Łukasz Stelmach
     [not found]   ` <CGME20200130124251eucas1p2046004a71a1a9ff4274a6d1d96e2c260@eucas1p2.samsung.com>
2020-01-30 12:42     ` [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 Łukasz Stelmach
     [not found]       ` <CGME20200130124304eucas1p2f3381b1009cd71cd292169d5f10265c1@eucas1p2.samsung.com>
2020-01-30 12:42         ` [RFC PATCH 2/4] scripts: add get_console_base.pl Łukasz Stelmach
     [not found]       ` <CGME20200130124314eucas1p11a244e77c9c5f583832832313ba93335@eucas1p1.samsung.com>
2020-01-30 12:42         ` [RFC PATCH 3/4] Add tools/hsinit Łukasz Stelmach
     [not found]       ` <CGME20200130124315eucas1p12d5380c44b68d08ae96849056303e175@eucas1p1.samsung.com>
2020-01-30 12:42         ` [RFC PATCH 4/4] boot/loader: Enable building bootloader replacement for Odroid XU4 Łukasz Stelmach
2020-01-30 12:47       ` [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 Russell King - ARM Linux admin
     [not found]         ` <CGME20200130125530eucas1p282d9749764c3a5c21c85c829d372b650@eucas1p2.samsung.com>
2020-01-30 12:55           ` Łukasz Stelmach
2020-01-30 14:16       ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).