mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* Add bbenv-y support
@ 2014-02-25 14:18 Sascha Hauer
  2014-02-25 14:18 ` [PATCH 1/4] make: Add bbenv-y target to generate default environment files Sascha Hauer
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-25 14:18 UTC (permalink / raw)
  To: barebox

Currently we can build images for multiple boards at once, but
all share the same default environment. As a last step to real
multi image support this patchset changes this.

bbenv-y is a Makefile target which can be used to generate default
environment snippets. Boards can use it as:

bbenv-$(CONFIG_SOMETHING) += my-environment

The directory containing the files to compile into the binary
should be named my-environment.

This can be accessed in C code later as:

extern unsigned char __bbenv_my_environment_start[];
extern unsigned char __bbenv_my_environment_end[];

The defaultenv snippet can then be registered using defaultenv_append().

With this each board will find the environment it expects during runtime.

Sascha

----------------------------------------------------------------
Sascha Hauer (13):
      common/Makefile: reorder targets
      defaultenv: simplify env dependencies
      make: Add wildcard rules for compressed files
      defaultenv: use wildcard compression rules
      Kconfig: Select default compression type
      filetype: Add detection for barebox environment
      environment: constify arguments
      environment: Add function to load envfs from buffer
      defaultenv: Align defaultenv array
      make: Add bbenv-y target to generate default environment files
      move defaultenv-1 to defaultenv/defaultenv-1
      move defaultenv-2 to defaultenv/defaultenv-2-*
      defaultenv: Allow multiple defaultenvironment overlays

 Makefile                                           |  20 ++-
 commands/loadenv.c                                 |  34 +++-
 common/Kconfig                                     |  45 +++--
 common/Makefile                                    | 153 +++++------------
 common/environment.c                               | 183 +++++++++++++--------
 common/filetype.c                                  |   4 +
 common/startup.c                                   |  44 +----
 defaultenv/Makefile                                |  23 +++
 defaultenv/{ => defaultenv-1}/bin/_boot_help       |   0
 defaultenv/{ => defaultenv-1}/bin/_update          |   0
 defaultenv/{ => defaultenv-1}/bin/_update_help     |   0
 defaultenv/{ => defaultenv-1}/bin/boot             |   0
 defaultenv/{ => defaultenv-1}/bin/init             |   0
 defaultenv/{ => defaultenv-1}/bin/update           |   0
 defaultenv/{ => defaultenv-1}/config               |   0
 .../defaultenv-2-base}/bin/bootargs-ip             |   0
 .../base => defaultenv/defaultenv-2-base}/bin/ifup |   0
 .../base => defaultenv/defaultenv-2-base}/bin/init |   0
 .../defaultenv-2-base}/bin/mtdparts-add            |   0
 .../base => defaultenv/defaultenv-2-base}/boot/net |   0
 .../base => defaultenv/defaultenv-2-base}/config   |   0
 .../defaultenv-2-base}/data/ansi-colors            |   0
 .../defaultenv-2-base}/data/boot-template          |   0
 .../defaultenv-2-base}/init/automount              |   0
 .../base => defaultenv/defaultenv-2-base}/init/ps1 |   0
 .../defaultenv-2-base}/network/eth0                |   0
 .../defaultenv-2-menu}/menu/boot-entries-collect   |   0
 .../defaultenv-2-menu}/menu/boot-entries-edit      |   0
 .../defaultenv-2-menu}/menu/boot-entries-remove    |   0
 .../defaultenv-2-menu}/menu/boot-menu-add-entry    |   0
 .../menu/boot-menu-new-boot-entry                  |   0
 .../defaultenv-2-menu}/menu/init-entries-collect   |   0
 .../defaultenv-2-menu}/menu/init-entries-edit      |   0
 .../defaultenv-2-menu}/menu/init-menu-add-entry    |   0
 .../defaultenv-2-menu}/menu/mainmenu               |   0
 .../defaultenv-2-menu}/menu/settings               |   0
 defaultenv/defaultenv.c                            | 150 +++++++++++++++++
 include/envfs.h                                    |  36 +++-
 include/filetype.h                                 |   1 +
 scripts/Makefile.lib                               |  47 ++++++
 scripts/genenv                                     |  12 +-
 41 files changed, 503 insertions(+), 249 deletions(-)
 create mode 100644 defaultenv/Makefile
 rename defaultenv/{ => defaultenv-1}/bin/_boot_help (100%)
 rename defaultenv/{ => defaultenv-1}/bin/_update (100%)
 rename defaultenv/{ => defaultenv-1}/bin/_update_help (100%)
 rename defaultenv/{ => defaultenv-1}/bin/boot (100%)
 rename defaultenv/{ => defaultenv-1}/bin/init (100%)
 rename defaultenv/{ => defaultenv-1}/bin/update (100%)
 rename defaultenv/{ => defaultenv-1}/config (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/bootargs-ip (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/ifup (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/init (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/mtdparts-add (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/boot/net (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/config (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/data/ansi-colors (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/data/boot-template (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/init/automount (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/init/ps1 (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/network/eth0 (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-collect (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-edit (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-remove (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-menu-add-entry (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-menu-new-boot-entry (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/init-entries-collect (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/init-entries-edit (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/init-menu-add-entry (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/mainmenu (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/settings (100%)
 create mode 100644 defaultenv/defaultenv.c

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 1/4] make: Add bbenv-y target to generate default environment files
  2014-02-25 14:18 Add bbenv-y support Sascha Hauer
@ 2014-02-25 14:18 ` Sascha Hauer
  2014-02-25 14:18 ` [PATCH 2/4] move defaultenv-1 to defaultenv/defaultenv-1 Sascha Hauer
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-25 14:18 UTC (permalink / raw)
  To: barebox

This adds a target to generate environment files from directories.
These are compiled into the barebox binary.

use it as:

bbenv-$(CONFIG_SOMETHING) += my-environment

The directory containing the files to compile into the binary
should be named my-environment.

This can be accessed in C code later as:

extern unsigned char __bbenv_my_environment_start[];
extern unsigned char __bbenv_my_environment_end[];

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Makefile             |  2 +-
 scripts/Makefile.lib | 29 +++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index b48240a..779ad74 100644
--- a/Makefile
+++ b/Makefile
@@ -1022,7 +1022,7 @@ clean: archclean $(clean-dirs)
 	@find . $(RCS_FIND_IGNORE) \
 		\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
 		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-		-o -name '*.symtypes' \) \
+		-o -name '*.symtypes' -o -name '*.bbenv.S' -o -name "*.bbenv" \) \
 		-type f -print | xargs rm -f
 
 # mrproper - Delete all generated files, including .config
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index e87e401..f71c3b7 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -98,6 +98,7 @@ multi-objs-y	:= $(addprefix $(obj)/,$(multi-objs-y))
 multi-objs-m	:= $(addprefix $(obj)/,$(multi-objs-m))
 subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
 obj-dirs	:= $(addprefix $(obj)/,$(obj-dirs))
+bbenv-y		:= $(addprefix $(obj)/,$(bbenv-y))
 
 # These flags are needed for modversions and compiling, so we define them here
 # already
@@ -229,6 +230,34 @@ $(obj)/%.dtb: $(src)/%.dts FORCE
 
 dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
 
+obj-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).o,$(bbenv-y))
+extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX),$(bbenv-y))
+extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).S,$(bbenv-y))
+extra-y += $(patsubst %,%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).o,$(bbenv-y))
+
+quiet_cmd_env_S = ENV.S   $@
+cmd_env_S =							\
+(								\
+	echo '\#include <asm-generic/barebox.lds.h>';		\
+	echo '.section .bbenv.rodata.$(subst -,_,$(*F)),"a"';	\
+	echo '.balign STRUCT_ALIGNMENT';			\
+	echo '.global __bbenv_$(subst -,_,$(*F))_start';	\
+	echo '__bbenv_$(subst -,_,$(*F))_start:';		\
+	echo '.incbin "$<" ';					\
+	echo '__bbenv_$(subst -,_,$(*F))_end:';			\
+	echo '.global __bbenv_$(subst -,_,$(*F))_end';		\
+	echo '.balign STRUCT_ALIGNMENT';			\
+) > $@
+
+$(obj)/%.bbenv$(DEFAULT_COMPRESSION_SUFFIX).S: $(src)/%.bbenv$(DEFAULT_COMPRESSION_SUFFIX) FORCE
+	$(call if_changed,env_S)
+
+quiet_cmd_env = ENV     $@
+cmd_env=$(srctree)/scripts/genenv $(srctree) $(objtree) $@ $<
+
+%.bbenv$(DEFAULT_COMPRESSION_SUFFIX): % FORCE
+	$(call cmd,env)
+
 # Bzip2
 # ---------------------------------------------------------------------------
 
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/4] move defaultenv-1 to defaultenv/defaultenv-1
  2014-02-25 14:18 Add bbenv-y support Sascha Hauer
  2014-02-25 14:18 ` [PATCH 1/4] make: Add bbenv-y target to generate default environment files Sascha Hauer
@ 2014-02-25 14:18 ` Sascha Hauer
  2014-02-25 14:18 ` [PATCH 3/4] move defaultenv-2 to defaultenv/defaultenv-2-* Sascha Hauer
  2014-02-25 14:18 ` [PATCH 4/4] defaultenv: Allow multiple defaultenvironment overlays Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-25 14:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Makefile                                | 2 +-
 defaultenv/{ => defaultenv-1}/bin/_boot_help   | 0
 defaultenv/{ => defaultenv-1}/bin/_update      | 0
 defaultenv/{ => defaultenv-1}/bin/_update_help | 0
 defaultenv/{ => defaultenv-1}/bin/boot         | 0
 defaultenv/{ => defaultenv-1}/bin/init         | 0
 defaultenv/{ => defaultenv-1}/bin/update       | 0
 defaultenv/{ => defaultenv-1}/config           | 0
 8 files changed, 1 insertion(+), 1 deletion(-)
 rename defaultenv/{ => defaultenv-1}/bin/_boot_help (100%)
 rename defaultenv/{ => defaultenv-1}/bin/_update (100%)
 rename defaultenv/{ => defaultenv-1}/bin/_update_help (100%)
 rename defaultenv/{ => defaultenv-1}/bin/boot (100%)
 rename defaultenv/{ => defaultenv-1}/bin/init (100%)
 rename defaultenv/{ => defaultenv-1}/bin/update (100%)
 rename defaultenv/{ => defaultenv-1}/config (100%)

diff --git a/common/Makefile b/common/Makefile
index a52e96b..c88d1c6 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -58,7 +58,7 @@ endif
 endif
 
 ifeq ($(CONFIG_DEFAULT_ENVIRONMENT_GENERIC),y)
-DEFAULT_ENVIRONMENT_PATH = "defaultenv"
+DEFAULT_ENVIRONMENT_PATH = "defaultenv/defaultenv-1"
 endif
 
 ifneq ($(CONFIG_DEFAULT_ENVIRONMENT_PATH),"")
diff --git a/defaultenv/bin/_boot_help b/defaultenv/defaultenv-1/bin/_boot_help
similarity index 100%
rename from defaultenv/bin/_boot_help
rename to defaultenv/defaultenv-1/bin/_boot_help
diff --git a/defaultenv/bin/_update b/defaultenv/defaultenv-1/bin/_update
similarity index 100%
rename from defaultenv/bin/_update
rename to defaultenv/defaultenv-1/bin/_update
diff --git a/defaultenv/bin/_update_help b/defaultenv/defaultenv-1/bin/_update_help
similarity index 100%
rename from defaultenv/bin/_update_help
rename to defaultenv/defaultenv-1/bin/_update_help
diff --git a/defaultenv/bin/boot b/defaultenv/defaultenv-1/bin/boot
similarity index 100%
rename from defaultenv/bin/boot
rename to defaultenv/defaultenv-1/bin/boot
diff --git a/defaultenv/bin/init b/defaultenv/defaultenv-1/bin/init
similarity index 100%
rename from defaultenv/bin/init
rename to defaultenv/defaultenv-1/bin/init
diff --git a/defaultenv/bin/update b/defaultenv/defaultenv-1/bin/update
similarity index 100%
rename from defaultenv/bin/update
rename to defaultenv/defaultenv-1/bin/update
diff --git a/defaultenv/config b/defaultenv/defaultenv-1/config
similarity index 100%
rename from defaultenv/config
rename to defaultenv/defaultenv-1/config
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/4] move defaultenv-2 to defaultenv/defaultenv-2-*
  2014-02-25 14:18 Add bbenv-y support Sascha Hauer
  2014-02-25 14:18 ` [PATCH 1/4] make: Add bbenv-y target to generate default environment files Sascha Hauer
  2014-02-25 14:18 ` [PATCH 2/4] move defaultenv-1 to defaultenv/defaultenv-1 Sascha Hauer
@ 2014-02-25 14:18 ` Sascha Hauer
  2014-02-25 14:18 ` [PATCH 4/4] defaultenv: Allow multiple defaultenvironment overlays Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-25 14:18 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Makefile                                                       | 4 ++--
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/bootargs-ip   | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/ifup          | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/init          | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/mtdparts-add  | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/boot/net          | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/config            | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/data/ansi-colors  | 0
 .../base => defaultenv/defaultenv-2-base}/data/boot-template          | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/init/automount    | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/init/ps1          | 0
 {defaultenv-2/base => defaultenv/defaultenv-2-base}/network/eth0      | 0
 .../menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-collect   | 0
 .../menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-edit      | 0
 .../menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-remove    | 0
 .../menu => defaultenv/defaultenv-2-menu}/menu/boot-menu-add-entry    | 0
 .../defaultenv-2-menu}/menu/boot-menu-new-boot-entry                  | 0
 .../menu => defaultenv/defaultenv-2-menu}/menu/init-entries-collect   | 0
 .../menu => defaultenv/defaultenv-2-menu}/menu/init-entries-edit      | 0
 .../menu => defaultenv/defaultenv-2-menu}/menu/init-menu-add-entry    | 0
 {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/mainmenu     | 0
 {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/settings     | 0
 22 files changed, 2 insertions(+), 2 deletions(-)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/bootargs-ip (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/ifup (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/init (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/bin/mtdparts-add (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/boot/net (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/config (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/data/ansi-colors (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/data/boot-template (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/init/automount (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/init/ps1 (100%)
 rename {defaultenv-2/base => defaultenv/defaultenv-2-base}/network/eth0 (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-collect (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-edit (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-entries-remove (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-menu-add-entry (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/boot-menu-new-boot-entry (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/init-entries-collect (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/init-entries-edit (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/init-menu-add-entry (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/mainmenu (100%)
 rename {defaultenv-2/menu => defaultenv/defaultenv-2-menu}/menu/settings (100%)

diff --git a/common/Makefile b/common/Makefile
index c88d1c6..9c68f7b 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -51,9 +51,9 @@ $(obj)/startup.o: $(obj)/barebox_default_env.h
 $(obj)/env.o: $(obj)/barebox_default_env.h
 
 ifeq ($(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW),y)
-DEFAULT_ENVIRONMENT_PATH = "defaultenv-2/base"
+DEFAULT_ENVIRONMENT_PATH = "defaultenv/defaultenv-2-base"
 ifeq ($(CONFIG_CMD_MENU_MANAGEMENT),y)
-DEFAULT_ENVIRONMENT_PATH += "defaultenv-2/menu"
+DEFAULT_ENVIRONMENT_PATH += "defaultenv/defaultenv-2-menu"
 endif
 endif
 
diff --git a/defaultenv-2/base/bin/bootargs-ip b/defaultenv/defaultenv-2-base/bin/bootargs-ip
similarity index 100%
rename from defaultenv-2/base/bin/bootargs-ip
rename to defaultenv/defaultenv-2-base/bin/bootargs-ip
diff --git a/defaultenv-2/base/bin/ifup b/defaultenv/defaultenv-2-base/bin/ifup
similarity index 100%
rename from defaultenv-2/base/bin/ifup
rename to defaultenv/defaultenv-2-base/bin/ifup
diff --git a/defaultenv-2/base/bin/init b/defaultenv/defaultenv-2-base/bin/init
similarity index 100%
rename from defaultenv-2/base/bin/init
rename to defaultenv/defaultenv-2-base/bin/init
diff --git a/defaultenv-2/base/bin/mtdparts-add b/defaultenv/defaultenv-2-base/bin/mtdparts-add
similarity index 100%
rename from defaultenv-2/base/bin/mtdparts-add
rename to defaultenv/defaultenv-2-base/bin/mtdparts-add
diff --git a/defaultenv-2/base/boot/net b/defaultenv/defaultenv-2-base/boot/net
similarity index 100%
rename from defaultenv-2/base/boot/net
rename to defaultenv/defaultenv-2-base/boot/net
diff --git a/defaultenv-2/base/config b/defaultenv/defaultenv-2-base/config
similarity index 100%
rename from defaultenv-2/base/config
rename to defaultenv/defaultenv-2-base/config
diff --git a/defaultenv-2/base/data/ansi-colors b/defaultenv/defaultenv-2-base/data/ansi-colors
similarity index 100%
rename from defaultenv-2/base/data/ansi-colors
rename to defaultenv/defaultenv-2-base/data/ansi-colors
diff --git a/defaultenv-2/base/data/boot-template b/defaultenv/defaultenv-2-base/data/boot-template
similarity index 100%
rename from defaultenv-2/base/data/boot-template
rename to defaultenv/defaultenv-2-base/data/boot-template
diff --git a/defaultenv-2/base/init/automount b/defaultenv/defaultenv-2-base/init/automount
similarity index 100%
rename from defaultenv-2/base/init/automount
rename to defaultenv/defaultenv-2-base/init/automount
diff --git a/defaultenv-2/base/init/ps1 b/defaultenv/defaultenv-2-base/init/ps1
similarity index 100%
rename from defaultenv-2/base/init/ps1
rename to defaultenv/defaultenv-2-base/init/ps1
diff --git a/defaultenv-2/base/network/eth0 b/defaultenv/defaultenv-2-base/network/eth0
similarity index 100%
rename from defaultenv-2/base/network/eth0
rename to defaultenv/defaultenv-2-base/network/eth0
diff --git a/defaultenv-2/menu/menu/boot-entries-collect b/defaultenv/defaultenv-2-menu/menu/boot-entries-collect
similarity index 100%
rename from defaultenv-2/menu/menu/boot-entries-collect
rename to defaultenv/defaultenv-2-menu/menu/boot-entries-collect
diff --git a/defaultenv-2/menu/menu/boot-entries-edit b/defaultenv/defaultenv-2-menu/menu/boot-entries-edit
similarity index 100%
rename from defaultenv-2/menu/menu/boot-entries-edit
rename to defaultenv/defaultenv-2-menu/menu/boot-entries-edit
diff --git a/defaultenv-2/menu/menu/boot-entries-remove b/defaultenv/defaultenv-2-menu/menu/boot-entries-remove
similarity index 100%
rename from defaultenv-2/menu/menu/boot-entries-remove
rename to defaultenv/defaultenv-2-menu/menu/boot-entries-remove
diff --git a/defaultenv-2/menu/menu/boot-menu-add-entry b/defaultenv/defaultenv-2-menu/menu/boot-menu-add-entry
similarity index 100%
rename from defaultenv-2/menu/menu/boot-menu-add-entry
rename to defaultenv/defaultenv-2-menu/menu/boot-menu-add-entry
diff --git a/defaultenv-2/menu/menu/boot-menu-new-boot-entry b/defaultenv/defaultenv-2-menu/menu/boot-menu-new-boot-entry
similarity index 100%
rename from defaultenv-2/menu/menu/boot-menu-new-boot-entry
rename to defaultenv/defaultenv-2-menu/menu/boot-menu-new-boot-entry
diff --git a/defaultenv-2/menu/menu/init-entries-collect b/defaultenv/defaultenv-2-menu/menu/init-entries-collect
similarity index 100%
rename from defaultenv-2/menu/menu/init-entries-collect
rename to defaultenv/defaultenv-2-menu/menu/init-entries-collect
diff --git a/defaultenv-2/menu/menu/init-entries-edit b/defaultenv/defaultenv-2-menu/menu/init-entries-edit
similarity index 100%
rename from defaultenv-2/menu/menu/init-entries-edit
rename to defaultenv/defaultenv-2-menu/menu/init-entries-edit
diff --git a/defaultenv-2/menu/menu/init-menu-add-entry b/defaultenv/defaultenv-2-menu/menu/init-menu-add-entry
similarity index 100%
rename from defaultenv-2/menu/menu/init-menu-add-entry
rename to defaultenv/defaultenv-2-menu/menu/init-menu-add-entry
diff --git a/defaultenv-2/menu/menu/mainmenu b/defaultenv/defaultenv-2-menu/menu/mainmenu
similarity index 100%
rename from defaultenv-2/menu/menu/mainmenu
rename to defaultenv/defaultenv-2-menu/menu/mainmenu
diff --git a/defaultenv-2/menu/menu/settings b/defaultenv/defaultenv-2-menu/menu/settings
similarity index 100%
rename from defaultenv-2/menu/menu/settings
rename to defaultenv/defaultenv-2-menu/menu/settings
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 4/4] defaultenv: Allow multiple defaultenvironment overlays
  2014-02-25 14:18 Add bbenv-y support Sascha Hauer
                   ` (2 preceding siblings ...)
  2014-02-25 14:18 ` [PATCH 3/4] move defaultenv-2 to defaultenv/defaultenv-2-* Sascha Hauer
@ 2014-02-25 14:18 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-25 14:18 UTC (permalink / raw)
  To: barebox

We can compile barebox for multiple boards at once, but currently
they all share a single default environment. This patch adds a
defaultenv_append() which boards can call to customize the default
environment during runtime. Each board now generate default environment
snippets using bbenv-y and add them during runtime with defaultenv_append()

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 Makefile                |   3 +-
 commands/loadenv.c      |  34 +++++++++--
 common/Kconfig          |   6 ++
 common/Makefile         |  39 -------------
 common/environment.c    |   2 +-
 common/startup.c        |  35 +----------
 defaultenv/Makefile     |  23 ++++++++
 defaultenv/defaultenv.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/envfs.h         |  31 ++++++++++
 9 files changed, 243 insertions(+), 80 deletions(-)
 create mode 100644 defaultenv/Makefile
 create mode 100644 defaultenv/defaultenv.c

diff --git a/Makefile b/Makefile
index 779ad74..9ff2587 100644
--- a/Makefile
+++ b/Makefile
@@ -493,6 +493,7 @@ all: barebox-flash-image $(KBUILD_DTBS)
 endif
 
 common-$(CONFIG_PBL_IMAGE)	+= pbl/
+common-$(CONFIG_DEFAULT_ENVIRONMENT) += defaultenv/
 
 barebox-dirs	:= $(patsubst %/,%,$(filter %/, $(common-y)))
 
@@ -1022,7 +1023,7 @@ clean: archclean $(clean-dirs)
 	@find . $(RCS_FIND_IGNORE) \
 		\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
 		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-		-o -name '*.symtypes' -o -name '*.bbenv.S' -o -name "*.bbenv" \) \
+		-o -name '*.symtypes' -o -name '*.bbenv.*' -o -name "*.bbenv" \) \
 		-type f -print | xargs rm -f
 
 # mrproper - Delete all generated files, including .config
diff --git a/commands/loadenv.c b/commands/loadenv.c
index bad8894..96a0775 100644
--- a/commands/loadenv.c
+++ b/commands/loadenv.c
@@ -26,6 +26,7 @@
 #include <envfs.h>
 #include <errno.h>
 #include <fs.h>
+#include <malloc.h>
 
 static int do_loadenv(int argc, char *argv[])
 {
@@ -33,8 +34,9 @@ static int do_loadenv(int argc, char *argv[])
 	unsigned flags = 0;
 	int opt;
 	int scrub = 0;
+	int defaultenv = 0;
 
-	while ((opt = getopt(argc, argv, "ns")) > 0) {
+	while ((opt = getopt(argc, argv, "nsd")) > 0) {
 		switch (opt) {
 		case 'n':
 			flags |= ENV_FLAG_NO_OVERWRITE;
@@ -42,6 +44,9 @@ static int do_loadenv(int argc, char *argv[])
 		case 's':
 			scrub = 1;
 			break;
+		case 'd':
+			defaultenv = 1;
+			break;
 		default:
 			return COMMAND_ERROR_USAGE;
 		}
@@ -52,10 +57,26 @@ static int do_loadenv(int argc, char *argv[])
 	else
 		dirname = argv[optind + 1];
 
-	if (argc - optind < 1)
+	if (argc - optind < 1) {
 		filename = default_environment_path_get();
-	else
-		filename = argv[optind];
+	} else {
+		char *str = normalise_path(argv[optind]);
+
+		/*
+		 * /dev/defaultenv use to contain the defaultenvironment.
+		 * we do not have this file anymore, but maintain compatibility
+		 * to the 'loadenv -s /dev/defaultenv' command to restore the
+		 * default environment for some time.
+		 */
+		if (!strcmp(str, "/dev/defaultenv")) {
+			defaultenv = 1;
+			filename = "defaultenv";
+		} else {
+			filename = argv[optind];
+		}
+
+		free(str);
+	}
 
 	if (scrub) {
 		int ret;
@@ -77,7 +98,10 @@ static int do_loadenv(int argc, char *argv[])
 
 	printf("loading environment from %s\n", filename);
 
-	return envfs_load(filename, dirname, flags);
+	if (defaultenv)
+		return defaultenv_load(dirname);
+	else
+		return envfs_load(filename, dirname, flags);
 }
 
 BAREBOX_CMD_HELP_START(loadenv)
diff --git a/common/Kconfig b/common/Kconfig
index d6cda8c..d862c05 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -587,6 +587,12 @@ config DEFAULT_ENVIRONMENT_GENERIC_NEW
 	select CMD_BOOT
 	prompt "Generic environment template"
 
+config DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU
+	bool
+	depends on DEFAULT_ENVIRONMENT_GENERIC_NEW
+	depends on CONFIG_CMD_MENU_MANAGEMENT
+	default y
+
 config DEFAULT_ENVIRONMENT_GENERIC
 	bool
 	depends on !HAVE_DEFAULT_ENVIRONMENT_NEW
diff --git a/common/Makefile b/common/Makefile
index 9c68f7b..667c7b3 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -7,7 +7,6 @@ obj-y				+= misc.o
 obj-y				+= memsize.o
 obj-y				+= resource.o
 obj-y				+= bootsource.o
-extra-y				+= barebox_default_env barebox_default_env.h
 obj-$(CONFIG_AUTO_COMPLETE)	+= complete.o
 obj-$(CONFIG_BANNER)		+= version.o
 obj-$(CONFIG_BAREBOX_UPDATE)	+= bbu.o
@@ -45,44 +44,6 @@ obj-$(CONFIG_SHELL_HUSH)	+= hush.o
 obj-$(CONFIG_SHELL_SIMPLE)	+= parser.o
 obj-$(CONFIG_UIMAGE)		+= image.o uimage.o
 
-
-ifdef CONFIG_DEFAULT_ENVIRONMENT
-$(obj)/startup.o: $(obj)/barebox_default_env.h
-$(obj)/env.o: $(obj)/barebox_default_env.h
-
-ifeq ($(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW),y)
-DEFAULT_ENVIRONMENT_PATH = "defaultenv/defaultenv-2-base"
-ifeq ($(CONFIG_CMD_MENU_MANAGEMENT),y)
-DEFAULT_ENVIRONMENT_PATH += "defaultenv/defaultenv-2-menu"
-endif
-endif
-
-ifeq ($(CONFIG_DEFAULT_ENVIRONMENT_GENERIC),y)
-DEFAULT_ENVIRONMENT_PATH = "defaultenv/defaultenv-1"
-endif
-
-ifneq ($(CONFIG_DEFAULT_ENVIRONMENT_PATH),"")
-DEFAULT_ENVIRONMENT_PATH += $(CONFIG_DEFAULT_ENVIRONMENT_PATH)
-endif
-
-endif # ifdef CONFIG_DEFAULT_ENVIRONMENT
-
-#
-# Generate a barebox envfs image.
-#
-quiet_cmd_envs = ENV     $@
-cmd_envs = ($(srctree)/scripts/genenv $(srctree) $(objtree) $@ $(DEFAULT_ENVIRONMENT_PATH))
-
-$(obj)/barebox_default_env: FORCE
-	$(call cmd,envs)
-
-quiet_cmd_env_h = ENVH    $@
-cmd_env_h = cat $< | (cd $(obj) && $(objtree)/scripts/bin2c "__aligned(4) default_environment") > $@; \
-	echo "static const int default_environment_uncompress_size=`stat -c%s $(obj)/barebox_default_env`;" >> $@
-
-$(obj)/barebox_default_env.h: $(obj)/barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX) FORCE
-	$(call if_changed,env_h)
-
 quiet_cmd_pwd_h = PWDH    $@
 ifdef CONFIG_PASSWORD
 ifneq ($(CONFIG_PASSWORD_DEFAULT),"")
diff --git a/common/environment.c b/common/environment.c
index 19fb027..776fa3a 100644
--- a/common/environment.c
+++ b/common/environment.c
@@ -240,7 +240,7 @@ static int envfs_check_super(struct envfs_super *super, size_t *size)
 	return 0;
 }
 
-static int envfs_check_data(struct envfs_super *super, void *buf, size_t size)
+static int envfs_check_data(struct envfs_super *super, const void *buf, size_t size)
 {
 	uint32_t crc;
 
diff --git a/common/startup.c b/common/startup.c
index 6847b61..409cdd1 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -44,39 +44,6 @@
 extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
 		  __barebox_initcalls_end[];
 
-#ifdef CONFIG_DEFAULT_ENVIRONMENT
-#include "barebox_default_env.h"
-
-static int register_default_env(void)
-{
-	int ret;
-	void *defaultenv;
-
-	if (!IS_ENABLED(CONFIG_DEFAULT_COMPRESSION_NONE)) {
-
-		defaultenv = xzalloc(default_environment_uncompress_size);
-
-		ret = uncompress(default_environment, default_environment_size,
-				NULL, NULL,
-				defaultenv, NULL, uncompress_err_stdout);
-		if (ret) {
-			free(defaultenv);
-			return ret;
-		}
-	} else {
-		defaultenv = (void *)default_environment;
-	}
-
-
-	add_mem_device("defaultenv", (unsigned long)defaultenv,
-		       default_environment_uncompress_size,
-		       IORESOURCE_MEM_WRITEABLE);
-	return 0;
-}
-
-device_initcall(register_default_env);
-#endif
-
 #if defined CONFIG_FS_RAMFS && defined CONFIG_FS_DEVFS
 static int mount_root(void)
 {
@@ -120,7 +87,7 @@ void __noreturn start_barebox(void)
 			pr_err("no valid environment found on %s. "
 				"Using default environment\n",
 				default_environment_path);
-			envfs_load("/dev/defaultenv", "/env", 0);
+			defaultenv_load("/env");
 		}
 	}
 
diff --git a/defaultenv/Makefile b/defaultenv/Makefile
new file mode 100644
index 0000000..d449e02
--- /dev/null
+++ b/defaultenv/Makefile
@@ -0,0 +1,23 @@
+bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW) += defaultenv-2-base
+bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU) += defaultenv-2-menu
+bbenv-$(CONFIG_DEFAULT_ENVIRONMENT_GENERIC) += defaultenv-1
+obj-$(CONFIG_DEFAULT_ENVIRONMENT) += defaultenv.o
+extra-y += barebox_default_env barebox_default_env.h barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX)
+
+$(obj)/defaultenv.o: $(obj)/barebox_default_env.h
+
+#
+# Generate a barebox envfs image.
+#
+quiet_cmd_env_default = ENV     $@
+cmd_env_default = ($(srctree)/scripts/genenv $(srctree) $(objtree) $@ $(CONFIG_DEFAULT_ENVIRONMENT_PATH))
+
+$(obj)/barebox_default_env: FORCE
+	$(call cmd,env_default)
+
+quiet_cmd_env_h = ENVH    $@
+cmd_env_h = cat $< | (cd $(obj) && $(objtree)/scripts/bin2c "__aligned(4) default_environment") > $@; \
+	echo "static const int default_environment_uncompress_size=`stat -c%s $(obj)/barebox_default_env`;" >> $@
+
+$(obj)/barebox_default_env.h: $(obj)/barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX) FORCE
+	$(call if_changed,env_h)
diff --git a/defaultenv/defaultenv.c b/defaultenv/defaultenv.c
new file mode 100644
index 0000000..7859eb2
--- /dev/null
+++ b/defaultenv/defaultenv.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 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.
+ *
+ */
+#include <common.h>
+#include <envfs.h>
+#include <filetype.h>
+#include <uncompress.h>
+#include <malloc.h>
+#include <init.h>
+#include <asm/unaligned.h>
+#include "barebox_default_env.h"
+
+static LIST_HEAD(defaultenv_list);
+
+struct defaultenv {
+	struct list_head list;
+	const char *name;
+	void *buf;
+	size_t size;
+};
+
+static void defaultenv_add_base(void)
+{
+	static int base_added;
+
+	if (base_added)
+		return;
+
+	if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW))
+		defaultenv_append_directory(defaultenv_2_base);
+	if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC_NEW_MENU))
+		defaultenv_append_directory(defaultenv_2_menu);
+	if (IS_ENABLED(CONFIG_DEFAULT_ENVIRONMENT_GENERIC))
+		defaultenv_append_directory(defaultenv_1);
+
+	/*
+	 * The traditional environment given with CONFIG_DEFAULT_ENVIRONMENT_PATH.
+	 * Once all users are converted to bbenv-y this can go.
+	 */
+	defaultenv_append((void *)default_environment,
+			default_environment_size, "defaultenv");
+
+	base_added = 1;
+
+	return;
+}
+
+/*
+ * defaultenv_append - append a envfs buffer to the default environment
+ * @buf:	The buffer containing the binary environment. If it is
+ *              not a plain buffer it is assumed to be a compressed buffer.
+ * @size:	The length of the buffer
+ *
+ * This adds an overlay to the default environment. New files will be created,
+ * existing files will be overwritten with the overlay.
+ */
+void defaultenv_append(void *buf, unsigned int size, const char *name)
+{
+	struct defaultenv *df;
+
+	defaultenv_add_base();
+
+	df = xzalloc(sizeof(*df));
+	df->buf = buf;
+	df->size = size;
+	df->name = name;
+
+	list_add_tail(&df->list, &defaultenv_list);
+}
+
+static int defaultenv_load_one(struct defaultenv *df, const char *dir)
+{
+	void *freep = NULL;
+	void *buf;
+	enum filetype ft = file_detect_type(df->buf, df->size);
+	uint32_t size;
+	int ret;
+
+	pr_debug("loading %s\n", df->name);
+
+	if (!IS_ENABLED(CONFIG_DEFAULT_COMPRESSION_NONE) &&
+			ft != filetype_barebox_env) {
+		size = get_unaligned_le32(df->buf + df->size - 4);
+		freep = malloc(size);
+		if (!freep)
+			return -ENOMEM;
+
+		ret = uncompress(df->buf, df->size,
+				NULL, NULL,
+				freep, NULL, uncompress_err_stdout);
+		if (ret) {
+			free(freep);
+			pr_err("Failed to uncompress: %s\n", strerror(-ret));
+			return ret;
+		}
+
+		buf = freep;
+	} else {
+		buf = df->buf;
+		size = df->size;
+	}
+
+	ret = envfs_load_from_buf(buf, size, dir, 0);
+
+	free(freep);
+
+	if (ret)
+		pr_err("Failed to load defaultenv: %s\n", strerror(-ret));
+
+	return ret;
+}
+
+/*
+ * defaultenv_load - load the default environment
+ * @dir:	The directory the default environment should be loaded to.
+ *
+ * This loads all environment snippets previously registered with
+ * defaultenv_append to the directory given with @dir.
+ *
+ * Return: 0 for success, negative error code otherwise.
+ */
+int defaultenv_load(const char *dir)
+{
+	struct defaultenv *df;
+	int ret;
+
+	defaultenv_add_base();
+
+	list_for_each_entry(df, &defaultenv_list, list) {
+		ret = defaultenv_load_one(df, dir);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
diff --git a/include/envfs.h b/include/envfs.h
index b63683c..74479ee 100644
--- a/include/envfs.h
+++ b/include/envfs.h
@@ -3,6 +3,7 @@
 
 #ifdef __BAREBOX__
 #include <asm/byteorder.h>
+#include <linux/stringify.h>
 #endif
 
 #define ENVFS_MAJOR		1
@@ -111,4 +112,34 @@ static inline char *default_environment_path_get(void)
 
 int envfs_register_partition(const char *devname, unsigned int partnr);
 
+#ifdef CONFIG_DEFAULT_ENVIRONMENT
+void defaultenv_append(void *buf, unsigned int size, const char *name);
+int defaultenv_load(const char *dir);
+#else
+static inline void defaultenv_append(void *buf, unsigned int size, const char *name)
+{
+}
+
+static inline int defaultenv_load(const char *dir)
+{
+	return -ENOSYS;
+}
+#endif
+
+/*
+ * Append environment directory compiled into barebox with bbenv-y
+ * to the default environment. The symbol is generated from the filename
+ * during the build process. Replace '-' with '_' to get the name
+ * from the filename.
+ */
+#define defaultenv_append_directory(name)			\
+	{							\
+		extern char __bbenv_##name##_start[];		\
+		extern char __bbenv_##name##_end[];		\
+		defaultenv_append(__bbenv_##name##_start,	\
+				__bbenv_##name##_end -		\
+				__bbenv_##name##_start,		\
+				__stringify(name));		\
+	}
+
 #endif /* _ENVFS_H */
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2014-02-25 14:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-25 14:18 Add bbenv-y support Sascha Hauer
2014-02-25 14:18 ` [PATCH 1/4] make: Add bbenv-y target to generate default environment files Sascha Hauer
2014-02-25 14:18 ` [PATCH 2/4] move defaultenv-1 to defaultenv/defaultenv-1 Sascha Hauer
2014-02-25 14:18 ` [PATCH 3/4] move defaultenv-2 to defaultenv/defaultenv-2-* Sascha Hauer
2014-02-25 14:18 ` [PATCH 4/4] defaultenv: Allow multiple defaultenvironment overlays Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox