Browse Source

libreCMC v1.3 RC3

RISCi_ATOM 9 years ago
parent
commit
233392fb05
100 changed files with 2332 additions and 1252 deletions
  1. 0 4
      Makefile
  2. 35 0
      README
  3. 47 34
      config/Config-build.in
  4. 33 12
      config/Config-devel.in
  5. 21 20
      config/Config-images.in
  6. 50 21
      config/Config-kernel.in
  7. 0 0
      feeds.conf
  8. 15 12
      include/cmake.mk
  9. 2 1
      include/download.mk
  10. 26 0
      include/feeds.mk
  11. 124 114
      include/image.mk
  12. 5 3
      include/kernel-build.mk
  13. 22 18
      include/kernel-defaults.mk
  14. 14 31
      include/kernel-version.mk
  15. 13 17
      include/kernel.mk
  16. 129 50
      include/netfilter.mk
  17. 2 2
      include/package-bin.mk
  18. 7 1
      include/package-defaults.mk
  19. 9 3
      include/package-dumpinfo.mk
  20. 69 35
      include/package-ipkg.mk
  21. 21 18
      include/package.mk
  22. 14 1
      include/prereq-build.mk
  23. 1 1
      include/prereq.mk
  24. 6 2
      include/scan.mk
  25. 5 0
      include/site/aarch64-librecmc-linux-gnu
  26. 28 0
      include/site/aarch64-linux
  27. 5 0
      include/site/aarch64_be-librecmc-linux-gnu
  28. 28 0
      include/site/aarch64_be-linux
  29. 5 0
      include/site/armeb-librecmc-linux-gnu
  30. 5 0
      include/site/armeb-librecmc-linux-gnueabi
  31. 5 0
      include/site/armeb-librecmc-linux-musl
  32. 5 0
      include/site/armeb-librecmc-linux-muslgnueabi
  33. 5 0
      include/site/armeb-librecmc-linux-uclibc
  34. 5 0
      include/site/armeb-librecmc-linux-uclibcgnueabi
  35. 28 0
      include/site/armeb-linux
  36. 5 0
      include/site/avr32-librecmc-linux-gnu
  37. 5 0
      include/site/avr32-librecmc-linux-uclibc
  38. 28 0
      include/site/avr32-linux
  39. 5 0
      include/site/cris-librecmc-linux-gnu
  40. 5 0
      include/site/cris-librecmc-linux-uclibc
  41. 28 0
      include/site/cris-linux
  42. 5 0
      include/site/m68k-librecmc-linux-gnu
  43. 5 0
      include/site/m68k-librecmc-linux-uclibc
  44. 26 0
      include/site/m68k-linux
  45. 5 0
      include/site/mips64-librecmc-linux-gnu
  46. 5 0
      include/site/mips64-librecmc-linux-uclibc
  47. 28 0
      include/site/mips64-linux
  48. 5 0
      include/site/mips64el-librecmc-linux-gnu
  49. 5 0
      include/site/mips64el-librecmc-linux-uclibc
  50. 28 0
      include/site/mips64el-linux
  51. 5 0
      include/site/mipsel-librecmc-linux2.4-uclibc
  52. 5 0
      include/site/powerpc-librecmc-linux-gnu
  53. 5 0
      include/site/powerpc-librecmc-linux-gnuspe
  54. 5 0
      include/site/powerpc-librecmc-linux-musl
  55. 5 0
      include/site/powerpc-librecmc-linux-uclibc
  56. 5 0
      include/site/powerpc-librecmc-linux-uclibcspe
  57. 28 0
      include/site/powerpc-linux
  58. 5 0
      include/site/sparc-librecmc-linux-gnu
  59. 5 0
      include/site/sparc-librecmc-linux-uclibc
  60. 28 0
      include/site/sparc-linux
  61. 5 0
      include/site/sparc-linux-gnu
  62. 3 3
      include/subdir.mk
  63. 24 12
      include/target.mk
  64. 16 1
      include/toplevel.mk
  65. 26 7
      include/version.mk
  66. 28 16
      package/Makefile
  67. 13 9
      package/base-files/Makefile
  68. 14 0
      package/base-files/files/bin/board_detect
  69. 172 0
      package/base-files/files/bin/config_generate
  70. 2 2
      package/base-files/files/bin/login.sh
  71. 13 0
      package/base-files/files/etc/banner.failsafe
  72. 0 4
      package/base-files/files/etc/config/network
  73. 1 0
      package/base-files/files/etc/config/system
  74. 3 0
      package/base-files/files/etc/device_info
  75. 15 3
      package/base-files/files/etc/init.d/boot
  76. 1 5
      package/base-files/files/etc/init.d/done
  77. 1 1
      package/base-files/files/etc/init.d/led
  78. 2 4
      package/base-files/files/etc/init.d/sysfixtime
  79. 0 2
      package/base-files/files/etc/init.d/system
  80. 7 7
      package/base-files/files/etc/librecmc_release
  81. 2 0
      package/base-files/files/etc/preinit
  82. 1 0
      package/base-files/files/etc/profile
  83. 5 0
      package/base-files/files/etc/rc.button/power
  84. 5 6
      package/base-files/files/etc/rc.common
  85. 3 1
      package/base-files/files/etc/sysctl.conf
  86. 1 1
      package/base-files/files/etc/uci-defaults/12_network-generate-ula
  87. 100 388
      package/base-files/files/lib/functions.sh
  88. 159 318
      package/base-files/files/lib/functions/network.sh
  89. 87 0
      package/base-files/files/lib/functions/preinit.sh
  90. 0 23
      package/base-files/files/lib/functions/service.sh
  91. 112 0
      package/base-files/files/lib/functions/system.sh
  92. 302 0
      package/base-files/files/lib/functions/uci-defaults-new.sh
  93. 5 3
      package/base-files/files/lib/functions/uci-defaults.sh
  94. 51 23
      package/base-files/files/lib/upgrade/common.sh
  95. 1 0
      package/base-files/files/lib/upgrade/keep.d/base-files-essential
  96. 4 4
      package/base-files/files/sbin/led.sh
  97. 10 2
      package/base-files/files/sbin/sysupgrade
  98. 1 1
      package/base-files/files/sbin/wifi
  99. 55 6
      package/base-files/image-config.in
  100. 9 0
      package/boot/uboot-envtools/Config.in

+ 0 - 4
Makefile

@@ -20,10 +20,6 @@ world:
 include $(TOPDIR)/include/host.mk
 
 ifneq ($(LIBRECMC_BUILD),1)
-  # XXX: these three lines are normally defined by rules.mk
-  # but we can't include that file in this context
-  empty:=
-  space:= $(empty) $(empty)
   _SINGLE=export MAKEFLAGS=$(space);
 
   override LIBRECMC_BUILD=1

+ 35 - 0
README

@@ -0,0 +1,35 @@
+This is the buildsystem for the libreCMC Linux distribution.
+
+Please use "make menuconfig" to configure your appreciated
+configuration for the toolchain and firmware.
+
+You need to have installed gcc, binutils, bzip2, flex, python, perl, make,
+find, grep, diff, unzip, gawk, getopt, subversion, libz-dev and libc headers.
+
+Run "./scripts/feeds update -a" to get all the latest package definitions
+defined in feeds.conf / feeds.conf.default respectively
+and "./scripts/feeds install -a" to install symlinks of all of them into
+package/feeds/.
+
+Use "make menuconfig" to configure your image.
+
+Simply running "make" will build your firmware.
+It will download all sources, build the cross-compile toolchain, 
+the kernel and all choosen applications.
+
+You can use "scripts/flashing/flash.sh" for remotely updating your embedded
+system via tftp.
+
+The libreCMC system is documented in docs/. You will need a LaTeX distribution
+and the tex4ht package to build the documentation. Type "make -C docs/" to build it.
+
+To build your own firmware you need to have access to a Linux, BSD or MacOSX system
+(case-sensitive filesystem required). Cygwin will not be supported because of
+the lack of case sensitiveness in the file system.
+
+
+Sunshine!
+	Your libreCMC Project
+	http://openwrt.org
+
+

+ 47 - 34
config/Config-build.in

@@ -20,23 +20,25 @@ menu "Global build settings"
 		default y
 		bool "Compile with support for patented functionality"
 		help
-		  When this option is disabled, software which provides patented functionality will not be built.
-		  In case software provides optional support for patented functionality,
-		  this optional support will get disabled for this package.
+		  When this option is disabled, software which provides patented functionality
+		  will not be built.  In case software provides optional support for patented
+		  functionality, this optional support will get disabled for this package.
 
 	config BUILD_NLS
 		default n
 		bool "Compile with full language support"
 		help
-		  When this option is enabled, packages are built with the full versions of iconv and GNU gettext
-		  instead of the default libreCMC stubs. If uClibc is used, it is also built with locale support.
+		  When this option is enabled, packages are built with the full versions of
+		  iconv and GNU gettext instead of the default libreCMC stubs. If uClibc is
+		  used, it is also built with locale support.
 
 	config BUILD_STATIC_TOOLS
 		default n
 		bool "Attempt to link host utilities statically"
 		help
-		  Linking host utilities like sed or firmware-utils statically increases the portability of the
-		  generated ImageBuilder and SDK tarballs, however it may fail on some Linux distributions.
+		  Linking host utilities like sed or firmware-utils statically increases the
+		  portability of the generated ImageBuilder and SDK tarballs; however, it may
+		  fail on some Linux distributions.
 
 	config SHADOW_PASSWORDS
 		bool
@@ -50,7 +52,8 @@ menu "Global build settings"
 		prompt "Remove ipkg/opkg status data files in final images"
 		default n
 		help
-		  This removes all ipkg/opkg status data files from the target directory before building the root fs
+		  This removes all ipkg/opkg status data files from the target directory
+		  before building the root filesystem.
 
 	config COLLECT_KERNEL_DEBUG
 		bool
@@ -59,7 +62,8 @@ menu "Global build settings"
 		default n
 		help
 		  This collects debugging symbols from the kernel and all compiled modules.
-		  Useful for release builds, so that kernel issues can be debugged offline later.
+		  Useful for release builds, so that kernel issues can be debugged offline
+		  later.
 
 	comment "Kernel build options"
 
@@ -72,27 +76,36 @@ menu "Global build settings"
 		prompt "Compile packages with debugging info"
 		default n
 		help
-		  Adds -g3 to the CFLAGS
+		  Adds -g3 to the CFLAGS.
 
 	config IPV6
 		bool
 		prompt "Enable IPv6 support in packages"
 		default y
 		help
-		  Enable IPV6 support in packages (passes --enable-ipv6 to configure scripts).
+		  Enable IPv6 support in packages (passes --enable-ipv6 to configure scripts).
 
 	config PKG_BUILD_PARALLEL
 		bool
 		prompt "Compile certain packages parallelized"
 		default y
 		help
-		  This adds a -jX option to certain packages that are known to
-		  behave well for parallel build. By default the package make processes
-		  use the main jobserver, in which case this option only takes effect
-		  when you add -jX to the make command.
+		  This adds a -jX option to certain packages that are known to behave well
+		  for parallel build. By default, the package make processes use the main
+		  jobserver, in which case this option only takes effect when you add -jX
+		  to the make command.
 
 		  If you are unsure, select N.
 
+	config PKG_CHECK_FORMAT_SECURITY
+		bool
+		prompt "Enable gcc format-security"
+		default n
+		help
+		  Add -Wformat -Werror=format-security to the CFLAGS.  You can disable
+		  this per package by adding PKG_CHECK_FORMAT_SECURITY:=0 in the package
+		  Makefile.
+
 	config PKG_BUILD_USE_JOBSERVER
 		bool
 		prompt "Use top-level make jobserver for packages"
@@ -100,16 +113,15 @@ menu "Global build settings"
 		default y
 		help
 		  This passes the main make process jobserver fds to package builds,
-		  enabling full parallelization across different packages
+		  enabling full parallelization across different packages.
 
 		  Note that disabling this may overcommit CPU resources depending on the
-		  -j level of the main make process, the number of package
-		  submake jobs selected below and the number of actual CPUs present.
+		  -j level of the main make process, the number of package submake jobs
+		  selected below and the number of actual CPUs present.
 		  Example: If the main make is passed a -j4 and the submake -j
 		  is also set to 4, we may end up with 16 parallel make processes
 		  in the worst case.
 
-
 	config PKG_BUILD_JOBS
 		int
 		prompt "Number of package submake jobs (2-512)"
@@ -128,12 +140,12 @@ menu "Global build settings"
 		help
 		  Always set the default package build rules to parallel build.
 
-		  WARNING: This may break build or kill your cat, as it builds
-		  packages with multiple jobs that are probably not tested in
-		  a parallel build environment.
+		  WARNING: This may break build or kill your cat, as it builds packages
+		  with multiple jobs that are probably not tested in a parallel build
+		  environment.
 
-		  Only say Y, if you don't mind fixing broken packages.
-		  Before reporting build bugs, set this to N and re-run the build.
+		  Only say Y if you don't mind fixing broken packages.  Before reporting
+		  build bugs, set this to N and re-run the build.
 
 	comment "Stripping options"
 
@@ -148,12 +160,13 @@ menu "Global build settings"
 		config NO_STRIP
 			bool "none"
 			help
-			  This will install unstripped binaries (useful for native compiling/debugging)
+			  This will install unstripped binaries (useful for native
+		 	  compiling/debugging).
 
 		config USE_STRIP
 			bool "strip"
 			help
-			  This will install binaries stripped using strip from binutils
+			  This will install binaries stripped using strip from binutils.
 
 
 		config USE_SSTRIP
@@ -162,7 +175,7 @@ menu "Global build settings"
 			depends on !USE_GLIBC
 			depends on !USE_EGLIBC
 			help
-			  This will install binaries stripped using sstrip
+			  This will install binaries stripped using sstrip.
 	endchoice
 
 	config STRIP_ARGS
@@ -172,22 +185,22 @@ menu "Global build settings"
 		default "--strip-unneeded --remove-section=.comment --remove-section=.note" if DEBUG
 		default "--strip-all"
 		help
-		  Specifies arguments passed to the strip command when stripping binaries
+		  Specifies arguments passed to the strip command when stripping binaries.
 
 	config STRIP_KERNEL_EXPORTS
 		bool "Strip unnecessary exports from the kernel image"
 		help
-		  Reduces kernel size by stripping unused kernel exports from the kernel image
-		  Note that this might make the kernel incompatible with any kernel modules that
-		  were not selected at the time the kernel image was created
+		  Reduces kernel size by stripping unused kernel exports from the kernel
+		  image.  Note that this might make the kernel incompatible with any kernel
+		  modules that were not selected at the time the kernel image was created.
 
 	config USE_MKLIBS
 		bool "Strip unnecessary functions from libraries"
 		help
 		  Reduces libraries to only those functions that are necessary for using all
-		  selected packages (including those selected as <M>)
-		  Note that this will make the system libraries incompatible with most of the packages
-		  that are not selected during the build process
+		  selected packages (including those selected as <M>).  Note that this will
+		  make the system libraries incompatible with most of the packages that are
+		  not selected during the build process.
 
 	choice
 		prompt "Preferred standard C++ library"

+ 33 - 12
config/Config-devel.in

@@ -15,10 +15,19 @@ menuconfig DEVEL
 	config BINARY_FOLDER
 		string "Binary folder" if DEVEL
 		default ""
+		help
+		  Store built firmware images and filesystem images in this directory.
+		  If not set, uses './bin/$(BOARD)'
 
 	config DOWNLOAD_FOLDER
 		string "Download folder" if DEVEL
 		default ""
+		help
+		  Store downloaded source bundles in this directory.
+		  If not set then defaults to './dl', which is removed by operations such as
+		  'git clean -xdf' or 'make distclean'.
+		  This option is useful if you have a low bandwidth Internet connection, and by
+		  setting a path outside the libreCMC tree downloads will be saved.
 
 	config LOCALMIRROR
 		string "Local mirror for source packages" if DEVEL
@@ -28,26 +37,29 @@ menuconfig DEVEL
 		bool "Automatic rebuild of packages" if DEVEL
 		default y
 		help
-		  Automatically rebuild packages when their files change
+		  Automatically rebuild packages when their files change.
 
 	config BUILD_SUFFIX
-		string "Build suffix to append to the BUILD_DIR variable" if DEVEL
+		string "Build suffix to append to the target BUILD_DIR variable" if DEVEL
 		default ""
 		help
-		  Build suffix to append to the BUILD_DIR variable, i.e: build_dir_suffix
+		  Build suffix to append to the BUILD_DIR variable, i.e: './build_dir/{target-build-dir}_$(BUILD_SUFFIX)'.
+		  This allows you to switch to a different .config whilst retaining all the build
+		  objects generated by the first .config
 
 	config TARGET_ROOTFS_DIR
 		string "Override the default TARGET_ROOTFS_DIR variable" if DEVEL
 		default ""
 		help
-		  Override the default TARGET_ROOTFS_DIR variable content $(BUILD_DIR) with custom path.
-		  Use this option to re-define the location of the target root file system directory.
+		  Override the default TARGET_ROOTFS_DIR variable content $(BUILD_DIR) with
+		  custom path.  Use this option to re-define the location of the target
+		  root filesystem directory.
 
 	config CCACHE
 		bool "Use ccache" if DEVEL
 		default n
 		help
-		  Compiler cache; see http://ccache.samba.org/
+		  Compiler cache; see http://ccache.samba.org/.
 
 	config EXTERNAL_KERNEL_TREE
 		string "Use external kernel tree" if DEVEL
@@ -59,21 +71,30 @@ menuconfig DEVEL
 		help
 		  Enter the full git repository path i.e.:
 		  git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
-		  This will create a git clone of the kernel in your build
-		  directory.
+		  This will create a git clone of the kernel in your build directory.
 
 	config KERNEL_GIT_LOCAL_REPOSITORY
 		string "Enter path to local reference repository" if DEVEL
+		depends on (KERNEL_GIT_CLONE_URI != "")
 		default ""
 		help
 		  Enter a full pathname to a local reference git repository.
-		  In this instance, the --refererence option of git clone will
+		  In this instance, the --reference option of git clone will
 		  be used thus creating a quick local clone of your repo.
 
+	config KERNEL_GIT_BRANCH
+		string "Enter git branch to clone" if DEVEL
+		depends on (KERNEL_GIT_CLONE_URI != "")
+		default ""
+		help
+		  Enter the branch name to checkout after cloning the git repository.
+		  In this instance, the --branch option of git clone will be used.
+		  If unused, the clone's repository HEAD will be checked-out.
+
 	config BUILD_LOG
 		bool "Enable log files during build process" if DEVEL
 		help
-		  If enabled log files will be written to the ./log directory
+		  If enabled, log files will be written to the ./log directory.
 
 	config SRC_TREE_OVERRIDE
 		bool "Enable package source tree override" if DEVEL
@@ -81,10 +102,10 @@ menuconfig DEVEL
 		  If enabled, you can force a package to use a git tree as source
 		  code instead of the normal tarball. Create a symlink 'git-src'
 		  in the package directory, pointing to the .git tree that you want
-		  to pull the source code from
+		  to pull the source code from.
 
 	config EXTRA_OPTIMIZATION
 		string "Additional compiler options" if DEVEL
 		default "-fno-caller-saves"
 		help
-		  Extra Target-independent optimizations to use when building for the target.
+		  Extra target-independent optimizations to use when building for the target.

+ 21 - 20
config/Config-images.in

@@ -10,7 +10,7 @@ menu "Target Images"
 		bool "ramdisk"
 		default y if USES_INITRAMFS
 		help
-		  Embed the rootfs into the kernel (initramfs)
+		  Embed the root filesystem into the kernel (initramfs).
 
 		choice
 			prompt "Compression"
@@ -48,7 +48,7 @@ menu "Target Images"
 			prompt "Use external cpio" if TARGET_ROOTFS_INITRAMFS
 			default ""
 			help
-			  Kernel uses specified external cpio as INITRAMFS_SOURCE
+			  Kernel uses specified external cpio as INITRAMFS_SOURCE.
 
 	comment "Root filesystem archives"
 
@@ -56,13 +56,13 @@ menu "Target Images"
 		bool "cpio.gz"
 		default y if USES_CPIOGZ
 		help
-		  Build a compressed cpio archive of the the root filesystem
+		  Build a compressed cpio archive of the root filesystem.
 
 	config TARGET_ROOTFS_TARGZ
 		bool "tar.gz"
 		default y if USES_TARGZ
 		help
-		  Build a compressed tar archive of the the root filesystem
+		  Build a compressed tar archive of the root filesystem.
 
 	comment "Root filesystem images"
 
@@ -70,28 +70,28 @@ menu "Target Images"
 		bool "ext4"
 		default y if USES_EXT4
 		help
-		  Build a ext4 root filesystem
+		  Build an ext4 root filesystem.
 
 		config TARGET_EXT4_MAXINODE
 			int "Maximum number of inodes in root filesystem"
 			depends on TARGET_ROOTFS_EXT4FS
 			default 6000
 			help
-			  Allows you to change the maximum number of inodes in the root filesystem
+			  Select the maximum number of inodes in the root filesystem.
 
 		config TARGET_EXT4_RESERVED_PCT
 			int "Percentage of reserved blocks in root filesystem"
 			depends on TARGET_ROOTFS_EXT4FS
 			default 0
 			help
-			  Allows you to change the percentage of reserved blocks in the root filesystem
+			  Select the percentage of reserved blocks in the root filesystem.
 
 		choice
 			prompt "Root filesystem block size"
 			default TARGET_EXT4_BLOCKSIZE_4K
 			depends on TARGET_ROOTFS_EXT4FS
 			help
-			  Allows you to change the block size of the root filesystem
+			  Select the block size of the root filesystem.
 
 			config TARGET_EXT4_BLOCKSIZE_4K
 				bool "4k"
@@ -115,33 +115,33 @@ menu "Target Images"
 			depends on TARGET_ROOTFS_EXT4FS
 			default n
 			help
-			  Create an ext4 filesystem with a journal
+			  Create an ext4 filesystem with a journal.
 
 	config TARGET_ROOTFS_ISO
 		bool "iso"
 		default n
 		depends on TARGET_x86_generic
 		help
-		  Create some bootable ISO image
+		  Create a bootable ISO image.
 
 	config TARGET_ROOTFS_JFFS2
 		bool "jffs2"
 		default y if USES_JFFS2
 		help
-		  Build a jffs2 root filesystem
+		  Build a JFFS2 root filesystem.
 
 	config TARGET_ROOTFS_JFFS2_NAND
 		bool "jffs2 for NAND"
 		default y if USES_JFFS2_NAND
 		depends on USES_JFFS2_NAND
 		help
-		  Build a jffs2 root filesystem for NAND flash
+		  Build a JFFS2 root filesystem for NAND flash.
 
 	menuconfig TARGET_ROOTFS_SQUASHFS
 		bool "squashfs"
 		default y if USES_SQUASHFS
 		help
-		  Build a squashfs-lzma root filesystem
+		  Build a squashfs-lzma root filesystem.
 
 		config TARGET_SQUASHFS_BLOCK_SIZE
 			int "Block size (in KiB)"
@@ -154,7 +154,7 @@ menu "Target Images"
 		default y if USES_UBIFS
 		depends on USES_UBIFS
 		help
-		  Build a ubifs root filesystem
+		  Build a UBIFS root filesystem.
 
 		choice
 			prompt "compression"
@@ -177,7 +177,7 @@ menu "Target Images"
 			bool "free space fixup" if TARGET_ROOTFS_UBIFS
 			default y
 			help
-			  The file-system free space has to be fixed up on first mount
+			  The filesystem free space has to be fixed up on first mount.
 
 		config TARGET_UBIFS_JOURNAL_SIZE
 			string
@@ -262,16 +262,17 @@ menu "Target Images"
 		depends on GRUB_IMAGES || TARGET_ROOTFS_EXT4FS || TARGET_rb532
 		default 48
 		help
-		  Allows you to change the root filesystem partition size
+		  Select the root filesystem partition size.
 
 	config TARGET_ROOTFS_PARTNAME
 		string "Root partition on target device"
 		depends on OLPC_BOOTSCRIPT_IMAGES || GRUB_IMAGES
 		default "/dev/xvda2" if TARGET_x86_xen_domu
-		default "/dev/sda2" if ! TARGET_x86_xen_domu
+		default "/dev/sda2" if TARGET_x86 && ! TARGET_x86_xen_domu
 		help
-		  The root partition on the final device.  If you don't know,
-		  you probably want the default (/dev/sda2).
+		  Override the root partition on the final device. If left empty,
+		  it will be mounted by PARTUUID which makes the kernel find the
+		  appropriate disk automatically.
 
 
 	menuconfig TARGET_ROOTFS_INCLUDE_KERNEL
@@ -279,7 +280,7 @@ menu "Target Images"
 		depends on TARGET_ROOTFS_UBIFS || TARGET_ROOTFS_EXT4FS
 		default n
 		help
-		  Include the kernel image in the rootfs. Typically the image is placed
+		  Include the kernel image in the rootfs. Typically, the image is placed
 		  below /boot.
 
 		config TARGET_ROOTFS_INCLUDE_UIMAGE

+ 50 - 21
config/Config-kernel.in

@@ -1,16 +1,30 @@
-# Copyright (C) 2006-2013 OpenWrt.org
+# Copyright (C) 2006-2014 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
 #
 
+config KERNEL_PRINTK
+	bool "Enable support for printk"
+	default y
+
+config KERNEL_CRASHLOG
+	bool "Crash logging"
+	depends on !(arm || powerpc || sparc || TARGET_uml)
+	default y
+
+config KERNEL_SWAP
+	bool "Support for paging of anonymous memory (swap)"
+	default y
+
 config KERNEL_DEBUG_FS
-	bool "Compile the kernel with Debug FileSystem enabled"
+	bool "Compile the kernel with debug filesystem enabled"
 	default y
 	help
 	  debugfs is a virtual file system that kernel developers use to put
 	  debugging files into. Enable this option to be able to read and
-	  write to these files.
+	  write to these files. Many common debugging facilities, such as
+	  ftrace, require the existence of debugfs.
 
 config KERNEL_PERF_EVENTS
 	bool
@@ -28,7 +42,7 @@ config KERNEL_KALLSYMS
 	bool "Compile the kernel with symbol table information"
 	default y
 	help
-	  This will give you more information in stack traces from kernel oopses
+	  This will give you more information in stack traces from kernel oopses.
 
 config KERNEL_FTRACE
 	bool "Compile the kernel with tracing support"
@@ -66,7 +80,7 @@ config KERNEL_DEBUG_LL
 	depends on arm
 	select KERNEL_DEBUG_LL_UART_NONE
 	help
-	  ARM low level debugging
+	  ARM low level debugging.
 
 config KERNEL_DYNAMIC_DEBUG 
 	bool "Compile the kernel with dynamic printk"
@@ -87,9 +101,8 @@ config KERNEL_EARLY_PRINTK
 	select KERNEL_DEBUG_KERNEL
 	select KERNEL_DEBUG_LL if arm
 	help
-	  Compile the kernel with early printk support.
-	  This is only useful for debugging purposes to send messages
-	  over the serial console in early boot.
+	  Compile the kernel with early printk support.  This is only useful for
+	  debugging purposes to send messages over the serial console in early boot.
 	  Enable this to debug early boot problems.
 
 config KERNEL_AIO
@@ -121,6 +134,20 @@ config KERNEL_PRINTK_TIME
 	bool "Enable printk timestamps"
 	default y
 
+config KERNEL_SLUB_DEBUG
+	bool
+
+config KERNEL_SLUB_DEBUG_ON
+	bool
+
+config KERNEL_SLABINFO
+	select KERNEL_SLUB_DEBUG
+	select KERNEL_SLUB_DEBUG_ON
+	bool "Enable /proc slab debug info"
+
+config KERNEL_PROC_PAGE_MONITOR
+	bool "Enable /proc page monitoring"
+
 config KERNEL_RELAY
 	bool
 
@@ -131,6 +158,10 @@ config USE_RFKILL
 	bool "Enable rfkill support"
 	default RFKILL_SUPPORT
 
+config USE_SPARSE
+	bool "Enable sparse check during kernel build"
+	default n
+
 #
 # CGROUP support symbols
 #
@@ -155,7 +186,7 @@ if KERNEL_CGROUPS
 
 	config KERNEL_CGROUP_FREEZER
 		bool "Freezer cgroup subsystem"
-		default n
+		default y
 		help
 		  Provides a way to freeze and unfreeze all tasks in a
 		  cgroup.
@@ -213,11 +244,11 @@ if KERNEL_CGROUPS
 		  usage tracking struct at boot. Total amount of this is printed out
 		  at boot.
 
-		  Only enable when you're ok with these trade offs and really
+		  Only enable when you're ok with these tradeoffs and really
 		  sure you need the memory resource controller. Even when you enable
 		  this, you can set "cgroup_disable=memory" at your boot option to
-		  disable memory resource controller and you can avoid overheads.
-		  (and lose benefits of memory resource controller)
+		  disable memory resource controller and you can avoid overheads
+		  (but lose benefits of memory resource controller).
 
 		  This config option also selects MM_OWNER config option, which
 		  could in turn add some fork/exit overhead.
@@ -251,8 +282,9 @@ if KERNEL_CGROUPS
 		  which want to enable the feature but keep it disabled by default
 		  and let the user enable it by swapaccount boot command line
 		  parameter should have this option unselected.
-		  For those who want to have the feature enabled by default should
-		  select this option (if, for some reason, they need to disable it
+
+		  Those who want to have the feature enabled by default should
+		  select this option (if, for some reason, they need to disable it,
 		  then swapaccount=0 does the trick).
 
 
@@ -268,12 +300,9 @@ if KERNEL_CGROUPS
 		  the kmem extension can use it to guarantee that no group of processes
 		  will ever exhaust kernel resources alone.
 
-	config KERNEL_PERF_EVENTS
-		bool
-		default y if KERNEL_CGROUP_PERF
-
 	config KERNEL_CGROUP_PERF
 		bool "Enable perf_event per-cpu per-container group (cgroup) monitoring"
+		select KERNEL_PERF_EVENTS
 		default n
 		help
 		  This option extends the per-cpu mode to restrict monitoring to
@@ -367,14 +396,14 @@ if KERNEL_NAMESPACES
 		bool "UTS namespace"
 		default y
 		help
-		  In this namespace tasks see different info provided
-		  with the uname() system call
+		  In this namespace, tasks see different info provided
+		  with the uname() system call.
 
 	config KERNEL_IPC_NS
 		bool "IPC namespace"
 		default y
 		help
-		  In this namespace tasks work with IPC ids which correspond to
+		  In this namespace, tasks work with IPC ids which correspond to
 		  different IPC objects in different namespaces.
 
 	config KERNEL_USER_NS

+ 0 - 0
feeds.conf


+ 15 - 12
include/cmake.mk

@@ -6,18 +6,17 @@ endif
 
 CMAKE_SOURCE_DIR:=.
 
+ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
+  cmake_tool=$(TOOLCHAIN_DIR)/bin/$(1)
+else
+  cmake_tool=$(shell which $(1))
+endif
+
 ifeq ($(CONFIG_CCACHE),)
- ifeq ($(CONFIG_EXTERNAL_TOOLCHAIN),)
-  CMAKE_C_COMPILER:=$(TOOLCHAIN_DIR)/bin/$(TARGET_CC)
-  CMAKE_C_COMPILER_ARG1:=
-  CMAKE_CXX_COMPILER:=$(TOOLCHAIN_DIR)/bin/$(TARGET_CXX)
-  CMAKE_CXX_COMPILER_ARG1:=
- else
-  CMAKE_C_COMPILER:=$(shell which $(TARGET_CC))
-  CMAKE_C_COMPILER_ARG1:=
-  CMAKE_CXX_COMPILER:=$(shell which $(TARGET_CXX))
-  CMAKE_CXX_COMPILER_ARG1:=
- endif
+ CMAKE_C_COMPILER:=$(call cmake_tool,$(TARGET_CC))
+ CMAKE_CXX_COMPILER:=$(call cmake_tool,$(TARGET_CXX))
+ CMAKE_C_COMPILER_ARG1:=
+ CMAKE_CXX_COMPILER_ARG1:=
 else
   CCACHE:=$(shell which ccache)
   ifeq ($(CCACHE),)
@@ -28,6 +27,8 @@ else
   CMAKE_CXX_COMPILER:=$(CCACHE)
   CMAKE_CXX_COMPILER_ARG1:=$(TARGET_CXX_NOCACHE)
 endif
+CMAKE_AR:=$(call cmake_tool,$(TARGET_CROSS)ar)
+CMAKE_RANLIB:=$(call cmake_tool,$(TARGET_CROSS)ranlib)
 
 define Build/Configure/Default
 	(cd $(PKG_BUILD_DIR); \
@@ -48,6 +49,8 @@ define Build/Configure/Default
 			-DCMAKE_EXE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
 			-DCMAKE_MODULE_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
 			-DCMAKE_SHARED_LINKER_FLAGS:STRING="$(TARGET_LDFLAGS)" \
+			-DCMAKE_AR="$(CMAKE_AR)" \
+			-DCMAKE_RANLIB="$(CMAKE_RANLIB)" \
 			-DCMAKE_FIND_ROOT_PATH="$(STAGING_DIR);$(TOOLCHAIN_DIR)" \
 			-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=BOTH \
 			-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
@@ -55,7 +58,7 @@ define Build/Configure/Default
 			-DCMAKE_STRIP=: \
 			-DCMAKE_INSTALL_PREFIX=/usr \
 			-DDL_LIBRARY=$(STAGING_DIR) \
-                        -DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
+			-DCMAKE_PREFIX_PATH=$(STAGING_DIR) \
 			$(CMAKE_OPTIONS) \
 		$(CMAKE_SOURCE_DIR) \
 	)

+ 2 - 1
include/download.mk

@@ -11,7 +11,7 @@ DOWNLOAD_RDEP=$(STAMP_PREPARED) $(HOST_STAMP_PREPARED)
 define dl_method
 $(strip \
   $(if $(2),$(2), \
-    $(if $(filter @GNOME/% @GNU/% @KERNEL/% @SF/% ftp://% http://% https://% file://%,$(1)),default, \
+    $(if $(filter @GNOME/% @GNU/% @KERNEL/% @SF/% @SAVANNAH/% ftp://% http://% https://% file://%,$(1)),default, \
       $(if $(filter git://%,$(1)),git, \
         $(if $(filter svn://%,$(1)),svn, \
           $(if $(filter cvs://%,$(1)),cvs, \
@@ -31,6 +31,7 @@ endef
 # code for creating tarballs from cvs/svn/git/bzr/hg/darcs checkouts - useful for mirror support
 dl_pack/bz2=$(TAR) cjf $(1) $(2)
 dl_pack/gz=$(TAR) czf $(1) $(2)
+dl_pack/xz=$(TAR) c $(2) | xz -zc > $(1)
 dl_pack/unknown=echo "ERROR: Unknown pack format for file $(1)"; false
 define dl_pack
 	$(if $(dl_pack/$(call ext,$(1))),$(dl_pack/$(call ext,$(1))),$(dl_pack/unknown))

+ 26 - 0
include/feeds.mk

@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2014 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+-include $(TMP_DIR)/.packagefeeds
+
+FEEDS_AVAILABLE:=$(shell $(SCRIPT_DIR)/feeds list -n)
+FEEDS_INSTALLED:=$(notdir $(wildcard $(TOPDIR)/package/feeds/*))
+FEEDS_ENABLED:=$(foreach feed,$(FEEDS_INSTALLED),$(if $(CONFIG_FEED_$(feed)),$(feed)))
+FEEDS_DISABLED:=$(filter-out $(FEEDS_ENABLED),$(FEEDS_AVAILABLE))
+
+PKG_CONFIG_DEPENDS += \
+	CONFIG_PER_FEED_REPO \
+	CONFIG_PER_FEED_REPO_ADD_DISABLED \
+	CONFIG_PER_FEED_REPO_ADD_COMMENTED \
+	$(foreach feed,$(FEEDS_INSTALLED),CONFIG_FEED_$(feed))
+
+# 1: package name
+define FeedPackageDir
+$(strip $(if $(CONFIG_PER_FEED_REPO), \
+  $(abspath $(PACKAGE_DIR)/$(if $(Package/$(1)/feed),$(Package/$(1)/feed),base)), \
+  $(PACKAGE_DIR)))
+endef

+ 124 - 114
include/image.mk

@@ -10,10 +10,11 @@ include $(INCLUDE_DIR)/prereq.mk
 include $(INCLUDE_DIR)/kernel.mk
 include $(INCLUDE_DIR)/host.mk
 
-.NOTPARALLEL:
-override MAKEFLAGS=
-override MAKE:=$(SUBMAKE)
+override MAKE:=$(_SINGLE)$(SUBMAKE)
+override NO_TRACE_MAKE:=$(_SINGLE)$(NO_TRACE_MAKE)
+
 KDIR=$(KERNEL_BUILD_DIR)
+DTS_DIR:=$(LINUX_DIR)/arch/$(ARCH)/boot/dts/
 
 IMG_PREFIX:=librecmc-$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))
 
@@ -46,7 +47,7 @@ endif
 
 JFFS2OPTS += $(MKFS_DEVTABLE_OPT)
 
-SQUASHFS_BLOCKSIZE := 256k
+SQUASHFS_BLOCKSIZE := $(CONFIG_TARGET_SQUASHFS_BLOCK_SIZE)k
 SQUASHFSOPT := -b $(SQUASHFS_BLOCKSIZE)
 SQUASHFSOPT += -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1'
 SQUASHFSCOMP := gzip
@@ -63,6 +64,17 @@ endif
 
 JFFS2_BLOCKSIZE ?= 64k 128k
 
+fs-types-$(CONFIG_TARGET_ROOTFS_SQUASHFS) += squashfs
+fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addprefix jffs2-,$(JFFS2_BLOCKSIZE))
+fs-types-$(CONFIG_TARGET_ROOTFS_JFFS2_NAND) += $(addprefix jffs2-nand-,$(NAND_BLOCKSIZE))
+fs-types-$(CONFIG_TARGET_ROOTFS_EXT4FS) += ext4
+fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
+fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
+fs-subtypes-$(CONFIG_TARGET_ROOTFS_CPIOGZ) += cpiogz
+fs-subtypes-$(CONFIG_TARGET_ROOTFS_TARGZ) += targz
+
+TARGET_FILESYSTEMS := $(fs-types-y)
+
 define add_jffs2_mark
 	echo -ne '\xde\xad\xc0\xde' >> $(1)
 endef
@@ -71,20 +83,15 @@ define toupper
 $(shell echo $(1) | tr '[:lower:]' '[:upper:]')
 endef
 
-# pad to 4k, 8k, 64k, 128k 256k and add jffs2 end-of-filesystem mark
+# pad to 4k, 8k, 16k, 64k, 128k, 256k and add jffs2 end-of-filesystem mark
 define prepare_generic_squashfs
-	$(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 64 128 256
+	$(STAGING_DIR_HOST)/bin/padjffs2 $(1) 4 8 16 64 128 256
 endef
 
-ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
-  define Image/BuildKernel/Initramfs
+define Image/BuildKernel/Initramfs
 	cp $(KDIR)/vmlinux-initramfs.elf $(BIN_DIR)/$(IMG_PREFIX)-vmlinux-initramfs.elf
 	$(call Image/Build/Initramfs)
-  endef
-else
-  define Image/BuildKernel/Initramfs
-  endef
-endif
+endef
 
 define Image/BuildKernel/MkuImage
 	mkimage -A $(ARCH) -O linux -T kernel -C $(1) -a $(2) -e $(3) \
@@ -99,37 +106,74 @@ define Image/BuildKernel/MkFIT
 endef
 
 define Image/mkfs/jffs2/sub
-		# FIXME: removing this line will cause strange behaviour in the foreach loop below
 		$(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) --pad -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2) -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
-		$(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2)-raw -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
 		$(call add_jffs2_mark,$(KDIR)/root.jffs2-$(2))
-		$(call Image/Build,jffs2-$(2))
 endef
 
-ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2),)
-    define Image/mkfs/jffs2
-		$(foreach SZ,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/sub,$(SZ),$(SZ),$(JFFS2OPTS)))
-    endef
-endif
+define Image/mkfs/jffs2/sub-raw
+		$(STAGING_DIR_HOST)/bin/mkfs.jffs2 $(3) -e $(patsubst %k,%KiB,$(1)) -o $(KDIR)/root.jffs2-$(2)-raw -d $(TARGET_DIR) -v 2>&1 1>/dev/null | awk '/^.+$$$$/'
+endef
 
-ifneq ($(CONFIG_TARGET_ROOTFS_JFFS2_NAND),)
-    define Image/mkfs/jffs2_nand
-		$(foreach SZ,$(NAND_BLOCKSIZE), $(call Image/mkfs/jffs2/sub, \
-			$(word 2,$(subst :, ,$(SZ))),nand-$(subst :,-,$(SZ)), \
-			$(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst :, ,$(SZ)))) \
-		)
-    endef
-endif
+define Image/mkfs/jffs2/template
+  Image/mkfs/jffs2-$(1) = $$(call Image/mkfs/jffs2/sub,$(1),$(1),$(JFFS2OPTS))
+  Image/mkfs/jffs2-$(1)-raw = $$(call Image/mkfs/jffs2/sub-raw,$(1),$(1),$(JFFS2OPTS))
+
+endef
+
+define Image/mkfs/jffs2-nand/template
+  Image/mkfs/jffs2-nand-$(1) = \
+	$$(call Image/mkfs/jffs2/sub, \
+		$(word 2,$(subst -, ,$(1))),nand-$(1), \
+			$(JFFS2OPTS) --no-cleanmarkers --pagesize=$(word 1,$(subst -, ,$(1))))
+
+endef
+
+$(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
+$(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
+
+define Image/mkfs/squashfs
+	$(STAGING_DIR_HOST)/bin/mksquashfs4 $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) -processors $(if $(CONFIG_PKG_BUILD_JOBS),$(CONFIG_PKG_BUILD_JOBS),1)
+endef
+
+# $(1): board name
+# $(2): rootfs type
+# $(3): kernel image
+ifneq ($(CONFIG_NAND_SUPPORT),)
+   define Image/Build/SysupgradeNAND
+	mkdir -p "$(KDIR_TMP)/sysupgrade-$(1)/"
+	echo "BOARD=$(1)" > "$(KDIR_TMP)/sysupgrade-$(1)/CONTROL"
+	[ -z "$(2)" ] || $(CP) "$(KDIR)/root.$(2)" "$(KDIR_TMP)/sysupgrade-$(1)/root"
+	[ -z "$(3)" ] || $(CP) "$(3)" "$(KDIR_TMP)/sysupgrade-$(1)/kernel"
+	(cd "$(KDIR_TMP)"; $(TAR) cvf \
+		"$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(2)-sysupgrade.tar" sysupgrade-$(1))
+   endef
+# $(1) board name
+# $(2) ubinize-image options (e.g. --uboot-env and/or --kernel kernelimage)
+# $(3) rootfstype (e.g. squashfs or ubifs)
+# $(4) options to pass-through to ubinize (i.e. $($(PROFILE)_UBI_OPTS)))
+   define Image/Build/UbinizeImage
+	sh $(TOPDIR)/scripts/ubinize-image.sh $(2) \
+		"$(KDIR)/root.$(3)" \
+		"$(BIN_DIR)/$(IMG_PREFIX)-$(1)-$(3)-ubinized.bin" \
+		$(4)
+   endef
 
-ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),)
-    define Image/mkfs/squashfs
-		@mkdir -p $(TARGET_DIR)/overlay
-		$(STAGING_DIR_HOST)/bin/mksquashfs4 $(TARGET_DIR) $(KDIR)/root.squashfs -nopad -noappend -root-owned -comp $(SQUASHFSCOMP) $(SQUASHFSOPT) -processors $(if $(CONFIG_PKG_BUILD_JOBS),$(CONFIG_PKG_BUILD_JOBS),1)
-		$(call Image/Build,squashfs)
-    endef
 endif
 
 ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
+    define Image/mkfs/ubifs/generate
+	$(CP) ./ubinize$(1).cfg $(KDIR)
+	( cd $(KDIR); \
+		$(STAGING_DIR_HOST)/bin/ubinize \
+		$(if $($(PROFILE)_UBI_OPTS), \
+			$(shell echo $($(PROFILE)_UBI_OPTS)), \
+			$(shell echo $(UBI_OPTS)) \
+		) \
+		-o $(KDIR)/root$(1).ubi \
+		ubinize$(1).cfg \
+	)
+    endef
+
     define Image/mkfs/ubifs
 
         ifneq ($($(PROFILE)_UBIFS_OPTS)$(UBIFS_OPTS),)
@@ -150,61 +194,38 @@ ifneq ($(CONFIG_TARGET_ROOTFS_UBIFS),)
 	$(call Image/Build,ubifs)
 
         ifneq ($($(PROFILE)_UBI_OPTS)$(UBI_OPTS),)
-		$(CP) ./ubinize.cfg $(KDIR)
-		( cd $(KDIR); \
-		$(STAGING_DIR_HOST)/bin/ubinize \
-			$(if $($(PROFILE)_UBI_OPTS), \
-				$(shell echo $($(PROFILE)_UBI_OPTS)), \
-				$(shell echo $(UBI_OPTS)) \
-			) \
-			-o $(KDIR)/root.ubi \
-			ubinize.cfg \
-		)
+		$(call Image/mkfs/ubifs/generate,)
+		$(if $(wildcard ./ubinize-overlay.cfg),$(call Image/mkfs/ubifs/generate,-overlay))
         endif
 	$(call Image/Build,ubi)
     endef
 endif
 
-ifneq ($(CONFIG_TARGET_ROOTFS_CPIOGZ),)
-  define Image/mkfs/cpiogz
-		( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
-  endef
-endif
+define Image/mkfs/cpiogz
+	( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9 >$(BIN_DIR)/$(IMG_PREFIX)-rootfs.cpio.gz )
+endef
 
-ifneq ($(CONFIG_TARGET_ROOTFS_TARGZ),)
-  define Image/mkfs/targz
-		# Preserve permissions (-p) when building as non-root user
-		$(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE),-$(PROFILE))-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
-  endef
-endif
+define Image/mkfs/targz
+	$(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE),-$(PROFILE))-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
+endef
 
-ifneq ($(CONFIG_TARGET_ROOTFS_EXT4FS),)
-  E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024)))
+E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024/$(CONFIG_TARGET_EXT4_BLOCKSIZE))))
 
-  define Image/mkfs/ext4
+define Image/mkfs/ext4
 # generate an ext2 fs
-	$(STAGING_DIR_HOST)/bin/genext2fs -U -b $(E2SIZE) -d $(TARGET_DIR)/ $(KDIR)/root.ext4  $(MKFS_DEVTABLE_OPT)
+	$(STAGING_DIR_HOST)/bin/genext2fs -U -B $(CONFIG_TARGET_EXT4_BLOCKSIZE) -b $(E2SIZE) -N $(CONFIG_TARGET_EXT4_MAXINODE) -d $(TARGET_DIR)/ $(KDIR)/root.ext4 -m $(CONFIG_TARGET_EXT4_RESERVED_PCT) $(MKFS_DEVTABLE_OPT)
 # convert it to ext4
-	$(STAGING_DIR_HOST)/bin/tune2fs -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
+	$(STAGING_DIR_HOST)/bin/tune2fs $(if $(CONFIG_TARGET_EXT4_JOURNAL),-j) -O extents,uninit_bg,dir_index $(KDIR)/root.ext4
 # fix it up
 	$(STAGING_DIR_HOST)/bin/e2fsck -fy $(KDIR)/root.ext4
-	$(call Image/Build,ext4)
-  endef
-endif
-
-ifneq ($(CONFIG_TARGET_ROOTFS_ISO),)
-  define Image/mkfs/iso
-		$(call Image/Build,iso)
-  endef
-endif
-
+endef
 
 define Image/mkfs/prepare/default
 	# Use symbolic permissions to avoid clobbering SUID/SGID/sticky bits
 	- $(FIND) $(TARGET_DIR) -type f -not -perm +0100 -not -name 'ssh_host*' -not -name 'shadow' -print0 | $(XARGS) -0 chmod u+rw,g+r,o+r
 	- $(FIND) $(TARGET_DIR) -type f -perm +0100 -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
 	- $(FIND) $(TARGET_DIR) -type d -print0 | $(XARGS) -0 chmod u+rwx,g+rx,o+rx
-	$(INSTALL_DIR) $(TARGET_DIR)/tmp
+	$(INSTALL_DIR) $(TARGET_DIR)/tmp $(TARGET_DIR)/overlay
 	chmod 1777 $(TARGET_DIR)/tmp
 endef
 
@@ -220,60 +241,49 @@ define Image/Checksum
 	)
 endef
 
+define BuildImage/mkfs
+  install: mkfs-$(1)
+  .PHONY: mkfs-$(1)
+  mkfs-$(1): mkfs_prepare
+	$(Image/mkfs/$(1))
+
+endef
 
 define BuildImage
 
   download:
   prepare:
+  compile:
+  clean:
+  image_prepare:
 
   ifeq ($(IB),)
-    compile: compile-targets FORCE
-		$(call Build/Compile)
-  else
+    .PHONY: download prepare compile clean image_prepare mkfs_prepare kernel_prepare install
     compile:
-  endif
+		$(call Build/Compile)
 
-  ifeq ($(IB),)
-    install: compile install-targets FORCE
+    clean:
+		$(call Build/Clean)
+
+    image_prepare: compile
 		$(call Image/Prepare)
-		$(call Image/mkfs/prepare)
-		$(call Image/BuildKernel)
-		$(call Image/BuildKernel/Initramfs)
-		$(call Image/InstallKernel)
-		$(call Image/mkfs/cpiogz)
-		$(call Image/mkfs/targz)
-		$(call Image/mkfs/ext4)
-		$(call Image/mkfs/iso)
-		$(call Image/mkfs/jffs2)
-		$(call Image/mkfs/jffs2_nand)
-		$(call Image/mkfs/squashfs)
-		$(call Image/mkfs/ubifs)
-		$(call Image/Checksum)
-  else
-    install: compile install-targets
-		$(call Image/BuildKernel)
-		$(call Image/BuildKernel/Initramfs)
-		$(call Image/InstallKernel)
-		$(call Image/mkfs/cpiogz)
-		$(call Image/mkfs/targz)
-		$(call Image/mkfs/ext4)
-		$(call Image/mkfs/iso)
-		$(call Image/mkfs/jffs2)
-		$(call Image/mkfs/jffs2_nand)
-		$(call Image/mkfs/squashfs)
-		$(call Image/mkfs/ubifs)
-		$(call Image/Checksum)
   endif
 
-  ifeq ($(IB),)
-    clean: clean-targets
-		$(call Build/Clean)
-  else
-    clean:
-  endif
+  mkfs_prepare: image_prepare
+	$(call Image/mkfs/prepare)
 
-  compile-targets:
-  install-targets:
-  clean-targets:
+  kernel_prepare: mkfs_prepare
+	$(call Image/BuildKernel)
+	$(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Image/BuildKernel/Initramfs))
+	$(call Image/InstallKernel)
+
+  $(foreach fs,$(TARGET_FILESYSTEMS) $(fs-subtypes-y),$(call BuildImage/mkfs,$(fs)))
+
+  install: kernel_prepare
+	$(foreach fs,$(TARGET_FILESYSTEMS),
+		$(call Image/Build,$(fs))
+	)
+	$(call Image/mkfs/ubifs)
+	$(call Image/Checksum)
 
 endef

+ 5 - 3
include/kernel-build.mk

@@ -51,7 +51,7 @@ ifdef CONFIG_COLLECT_KERNEL_DEBUG
 	mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
 	$(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
 	-$(CP) \
-		$(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
+		$(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)-gnu/* \
 		$(KERNEL_BUILD_DIR)/debug/modules/
 	$(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
 	$(TAR) c -C $(KERNEL_BUILD_DIR) debug | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
@@ -62,6 +62,8 @@ define BuildKernel
   $(if $(QUILT),$(Build/Quilt))
   $(if $(LINUX_SITE),$(call Download,kernel))
 
+  .NOTPARALLEL:
+
   $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
 	-rm -rf $(KERNEL_BUILD_DIR)
 	-mkdir -p $(KERNEL_BUILD_DIR)
@@ -76,7 +78,7 @@ define BuildKernel
 		xargs $(TARGET_CROSS)nm | \
 		awk '$$$$1 == "U" { print $$$$2 } ' | \
 		sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
-	$(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep -F ' r __ksymtab' | sed -e 's,........ r __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
+	$(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' [rR] __ksymtab' | sed -e 's,........ [rR] __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
 	grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
 	grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
 	( \
@@ -117,7 +119,7 @@ define BuildKernel
   define BuildKernel
   endef
 
-  download: $(DL_DIR)/$(LINUX_SOURCE)
+  download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
   prepare: $(STAMP_CONFIGURED)
   compile: $(LINUX_DIR)/.modules
 	$(MAKE) -C image compile TARGET_BUILD=

+ 22 - 18
include/kernel-defaults.mk

@@ -24,10 +24,24 @@ ifneq (,$(KERNEL_CC))
   KERNEL_MAKEOPTS += CC="$(KERNEL_CC)"
 endif
 
+ifdef CONFIG_USE_SPARSE
+  KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse
+endif
+
 export HOST_EXTRACFLAGS=-I$(STAGING_DIR_HOST)/include
 
 # defined in quilt.mk
 Kernel/Patch:=$(Kernel/Patch/Default)
+
+KERNEL_GIT_OPTS:=
+ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
+  KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
+endif
+
+ifneq ($(strip $(CONFIG_KERNEL_GIT_BRANCH)),"")
+  KERNEL_GIT_OPTS+=--branch $(CONFIG_KERNEL_GIT_BRANCH)
+endif
+
 ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
   ifeq ($(strip $(CONFIG_KERNEL_GIT_CLONE_URI)),"")
     define Kernel/Prepare/Default
@@ -36,15 +50,9 @@ ifeq ($(strip $(CONFIG_EXTERNAL_KERNEL_TREE)),"")
 	touch $(LINUX_DIR)/.quilt_used
     endef
   else
-    ifeq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
-      define Kernel/Prepare/Default
-	git clone $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
-      endef
-    else
-      define Kernel/Prepare/Default
-	git clone --reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY) $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
-      endef
-    endif
+    define Kernel/Prepare/Default
+	git clone $(KERNEL_GIT_OPTS) $(CONFIG_KERNEL_GIT_CLONE_URI) $(LINUX_DIR)
+    endef
   endif
 else
   define Kernel/Prepare/Default
@@ -132,17 +140,15 @@ endif
 define Kernel/CopyImage
 	$(KERNEL_CROSS)objcopy -O binary $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)$(1)
 	$(KERNEL_CROSS)objcopy $(OBJCOPY_STRIP) -S $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux$(1).elf
-ifneq ($(subst ",,$(KERNELNAME)),)
-	#")
-	$(foreach k,$(filter-out dtbs,$(subst ",,$(KERNELNAME))),$(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1);)
-	#")
+	$(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/vmlinux.debug
+ifneq ($(KERNELNAME),)
+	$(foreach k,$(filter-out dtbs,$(KERNELNAME)),$(CP) $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/$(IMAGES_DIR)/$(k) $(KERNEL_BUILD_DIR)/$(k)$(1);)
 endif
 endef
 
 define Kernel/CompileImage/Default
 	rm -f $(TARGET_DIR)/init
-	+$(MAKE) $(KERNEL_MAKEOPTS) $(subst ",,$(KERNELNAME))
-	#")
+	+$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
 	$(call Kernel/CopyImage)
 endef
 
@@ -151,9 +157,7 @@ define Kernel/CompileImage/Initramfs
 	$(call Kernel/Configure/Initramfs)
 	$(CP) $(GENERIC_PLATFORM_DIR)/base-files/init $(TARGET_DIR)/init
 	rm -rf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/usr/initramfs_data.cpio*
-	+$(MAKE) $(KERNEL_MAKEOPTS) $(subst ",,$(KERNELNAME))
-	#")
-	#")
+	+$(MAKE) $(KERNEL_MAKEOPTS) $(if $(KERNELNAME),$(KERNELNAME),all) modules
 	$(call Kernel/CopyImage,-initramfs)
 endef
 else

+ 14 - 31
include/kernel-version.mk

@@ -2,41 +2,24 @@
 
 LINUX_RELEASE?=1
 
-ifeq ($(LINUX_VERSION),3.3.8)
-  LINUX_KERNEL_MD5SUM:=f1058f64eed085deb44f10cee8541d50
-endif
-ifeq ($(LINUX_VERSION),3.6.11)
-  LINUX_KERNEL_MD5SUM:=3d602ad7f7984509c3e923a5ae90bc54
-endif
-ifeq ($(LINUX_VERSION),3.7.10)
-  LINUX_KERNEL_MD5SUM:=09624c3702107076efcac5e1cd8a18ec
-endif
-ifeq ($(LINUX_VERSION),3.8.13)
-  LINUX_KERNEL_MD5SUM:=2af19d06cd47ec459519159cdd10542d
-endif
-ifeq ($(LINUX_VERSION),3.9.11)
-  LINUX_KERNEL_MD5SUM:=edbf88eb7f7d34dbd5d3887726790755
-endif
-ifeq ($(LINUX_VERSION),3.10.32)
-  LINUX_KERNEL_MD5SUM:=770bc9977800ca281f875764f0a1c4e9
-endif
-ifeq ($(LINUX_VERSION),3.12.10)
-  LINUX_KERNEL_MD5SUM:=93325074b7b1d7bb76fb7d4348f0aa7a
-endif
-ifeq ($(LINUX_VERSION),3.13.2)
-  LINUX_KERNEL_MD5SUM:=664821d4e47361439e2329c67ee1876d
-endif
+LINUX_VERSION-3.10 = .58
+LINUX_VERSION-3.14 = .26
+LINUX_VERSION-3.18 =
 
-# disable the md5sum check for unknown kernel versions
-LINUX_KERNEL_MD5SUM?=x
+LINUX_KERNEL_MD5SUM-3.10.58 = bca8cde0dddf27d980fe1d393ea743f7
+LINUX_KERNEL_MD5SUM-3.14.26 = 69b27733f335c557946edd58554debb7
+LINUX_KERNEL_MD5SUM-3.18    = 9e854df51ca3fef8bfe566dbd7b89241
+
+ifdef KERNEL_PATCHVER
+  LINUX_VERSION:=$(KERNEL_PATCHVER)$(strip $(LINUX_VERSION-$(KERNEL_PATCHVER)))
+endif
 
 split_version=$(subst ., ,$(1))
 merge_version=$(subst $(space),.,$(1))
 KERNEL_BASE=$(firstword $(subst -, ,$(LINUX_VERSION)))
 KERNEL=$(call merge_version,$(wordlist 1,2,$(call split_version,$(KERNEL_BASE))))
-ifeq ($(firstword $(call split_version,$(KERNEL_BASE))),2)
-  KERNEL_PATCHVER=$(call merge_version,$(wordlist 1,3,$(call split_version,$(KERNEL_BASE))))
-else
-  KERNEL_PATCHVER=$(KERNEL)
-endif
+KERNEL_PATCHVER ?= $(KERNEL)
 
+# disable the md5sum check for unknown kernel versions
+LINUX_KERNEL_MD5SUM:=$(LINUX_KERNEL_MD5SUM-$(strip $(LINUX_VERSION)))
+LINUX_KERNEL_MD5SUM?=x

+ 13 - 17
include/kernel.mk

@@ -34,7 +34,7 @@ else
     FILES_DIR ?= $(foreach dir,$(wildcard ./files ./files-$(KERNEL_PATCHVER)),"$(dir)")
   endif
   KERNEL_BUILD_DIR ?= $(BUILD_DIR)/linux-$(BOARD)$(if $(SUBTARGET),_$(SUBTARGET))
-  LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(shell echo $(LINUX_VERSION) | cut -d"-" -f1 -)
+  LINUX_DIR ?= $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)
   ifeq ($(strip $(call CompareKernelPatchVer,$(KERNEL_PATCHVER),ge,3.7.0)),1)
     LINUX_UAPI_DIR=uapi/
   endif
@@ -43,22 +43,22 @@ else
 
   LINUX_UNAME_VERSION:=$(if $(word 3,$(subst ., ,$(KERNEL_BASE))),$(KERNEL_BASE),$(KERNEL_BASE).0)
   ifneq ($(findstring -rc,$(LINUX_VERSION)),)
-    makeLINUX_UNAME_VERSION:=$(LINUX_UNAME_VERSION)-$(strip $(lastword $(subst -, ,$(LINUX_VERSION))))
+    LINUX_UNAME_VERSION:=$(LINUX_UNAME_VERSION)-$(strip $(lastword $(subst -, ,$(LINUX_VERSION))))
   endif
 
-  MODULES_SUBDIR:=lib/modules/$(LINUX_UNAME_VERSION)-gnu
+  MODULES_SUBDIR:=lib/modules/$(LINUX_VERSION)-gnu
   TARGET_MODULES_DIR := $(LINUX_TARGET_DIR)/$(MODULES_SUBDIR)
 
   LINUX_KERNEL:=$(KERNEL_BUILD_DIR)/vmlinux
 
-  LINUX_SOURCE:=linux-libre-$(LINUX_VERSION).tar.xz
+  LINUX_SOURCE:=linux-libre-$(LINUX_VERSION)-gnu.tar.xz
   TESTING:=$(if $(findstring -rc,$(LINUX_VERSION)),/testing,)
   ifeq ($(call qstrip,$(CONFIG_EXTERNAL_KERNEL_TREE))$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),)
-      LINUX_SITE:=@KERNEL/$(LINUX_VERSION)
+      LINUX_SITE:=@KERNEL/linux/kernel/v3.x$(TESTING)
   endif
 
   ifneq ($(TARGET_BUILD),1)
-    PKG_BUILD_DIR ?= $(KERNEL_BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(shell echo $(PKG_VERSION) | cut -d"-" -f1 -))
+    PKG_BUILD_DIR ?= $(KERNEL_BUILD_DIR)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
   endif
 endif
 
@@ -66,7 +66,7 @@ ifneq (,$(findstring uml,$(BOARD)))
   LINUX_KARCH=um
 else
   ifeq (,$(LINUX_KARCH))
-    LINUX_KARCH=$(strip $(subst i386,x86,$(subst armeb,arm,$(subst mipsel,mips,$(subst mips64,mips,$(subst mips64el,mips,$(subst sh2,sh,$(subst sh3,sh,$(subst sh4,sh,$(ARCH))))))))))
+    LINUX_KARCH=$(strip $(subst i386,x86,$(subst armeb,arm,$(subst mipsel,mips,$(subst mips64,mips,$(subst mips64el,mips,$(subst sh2,sh,$(subst sh3,sh,$(subst sh4,sh,$(subst aarch64,arm64,$(subst aarch64_be,arm64,$(ARCH))))))))))))
   endif
 endif
 
@@ -84,10 +84,8 @@ define ModuleAutoLoad
 		boot="$$$$$$$$2"; \
 		shift 2; \
 		for mod in $$$$$$$$mods; do \
-			if [ -e $(2)/$(MODULES_SUBDIR)/$$$$$$$$mod.ko ]; then \
-				mkdir -p $(2)/etc/modules.d; \
-				echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$(1); \
-			fi; \
+			mkdir -p $(2)/etc/modules.d; \
+			echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$(1); \
 		done; \
 		if [ -e $(2)/etc/modules.d/$(1) ]; then \
 			if [ "$$$$$$$$boot" = "1" ]; then \
@@ -103,10 +101,8 @@ define ModuleAutoLoad
 		boot="$$$$$$$$3"; \
 		shift 3; \
 		for mod in $$$$$$$$mods; do \
-			if [ -e $(2)/$(MODULES_SUBDIR)/$$$$$$$$mod.ko ]; then \
-				mkdir -p $(2)/etc/modules.d; \
-				echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$$$$$$$$priority-$(1); \
-			fi; \
+			mkdir -p $(2)/etc/modules.d; \
+			echo "$$$$$$$$mod" >> $(2)/etc/modules.d/$$$$$$$$priority-$(1); \
 		done; \
 		if [ -e $(2)/etc/modules.d/$$$$$$$$priority-$(1) ]; then \
 			if [ "$$$$$$$$boot" = "1" ]; then \
@@ -151,7 +147,7 @@ define KernelPackage
     CATEGORY:=Kernel modules
     DESCRIPTION:=$(DESCRIPTION)
     EXTRA_DEPENDS:=kernel (=$(LINUX_VERSION)-$(LINUX_RELEASE)-$(LINUX_VERMAGIC))
-    VERSION:=$(shell echo $(LINUX_VERSION) | cut -d"-" -f1 -)$(if $(PKG_VERSION),+$(PKG_VERSION))-$(if $(PKG_RELEASE),$(PKG_RELEASE),$(LINUX_RELEASE))
+    VERSION:=$(LINUX_VERSION)$(if $(PKG_VERSION),+$(PKG_VERSION))-$(if $(PKG_RELEASE),$(PKG_RELEASE),$(LINUX_RELEASE))
     $(call KernelPackage/$(1))
     $(call KernelPackage/$(1)/$(BOARD))
   endef
@@ -171,7 +167,7 @@ $(call KernelPackage/$(1)/config)
   $(call KernelPackage/depends)
 
   ifneq ($(if $(filter-out %=y %=n %=m,$(KCONFIG)),$(filter m y,$(foreach c,$(filter-out %=y %=n %=m,$(KCONFIG)),$($(c)))),.),)
-    ifneq ($(strip $(FILES)),)
+    ifneq ($(if $(SDK),$(filter-out $(LINUX_DIR)/%.ko,$(FILES)),$(strip $(FILES))),)
       define Package/kmod-$(1)/install
 		  @for mod in $$(FILES); do \
 			if [ -e $$$$$$$$mod ]; then \

+ 129 - 50
include/netfilter.mk

@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006-2012 OpenWrt.org
+# Copyright (C) 2006-2014 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -30,23 +30,30 @@ endef
 # core
 
 # kernel only
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_CORE,CONFIG_NETFILTER_XTABLES, $(P_XT)x_tables $(P_XT)xt_tcpudp),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_CORE,CONFIG_IP_NF_IPTABLES, $(P_V4)ip_tables),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_IPT,CONFIG_IP_NF_IPTABLES, $(P_V4)ip_tables),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_IPT,CONFIG_NETFILTER_XTABLES, $(P_XT)x_tables),))
+
+$(eval $(if $(NF_KMOD),$(call nf_add,IPT_CORE,CONFIG_NETFILTER_XTABLES, $(P_XT)xt_tcpudp),))
 $(eval $(if $(NF_KMOD),$(call nf_add,IPT_CORE,CONFIG_IP_NF_FILTER, $(P_V4)iptable_filter),))
 $(eval $(if $(NF_KMOD),$(call nf_add,IPT_CORE,CONFIG_IP_NF_MANGLE, $(P_V4)iptable_mangle),))
 
 # userland only
-$(eval $(if $(NF_KMOD),,$(call nf_add,IPT_CORE,CONFIG_IP_NF_IPTABLES, xt_standard ipt_icmp xt_tcp xt_udp xt_comment xt_set xt_SET)))
+$(eval $(if $(NF_KMOD),,$(call nf_add,IPT_CORE,CONFIG_IP_NF_IPTABLES, xt_standard ipt_icmp xt_tcp xt_udp xt_comment xt_id xt_set xt_SET)))
 
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MATCH_LIMIT, $(P_XT)xt_limit))
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MATCH_MAC, $(P_XT)xt_mac))
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MATCH_MULTIPORT, $(P_XT)xt_multiport))
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MATCH_COMMENT, $(P_XT)xt_comment))
+$(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MATCH_ID, $(P_XT)xt_id))
+
+#cluster
+$(eval $(call nf_add,IPT_CLUSTER,CONFIG_NETFILTER_XT_MATCH_CLUSTER, $(P_XT)xt_cluster))
 
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_TARGET_LOG, $(P_XT)xt_LOG, ge 3.4.0))
 $(eval $(call nf_add,IPT_CORE,CONFIG_IP_NF_TARGET_LOG, $(P_V4)ipt_LOG, lt 3.4.0))
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_TARGET_TCPMSS, $(P_XT)xt_TCPMSS))
 $(eval $(call nf_add,IPT_CORE,CONFIG_IP_NF_TARGET_REJECT, $(P_V4)ipt_REJECT))
+$(eval $(call nf_add,IPT_CORE,CONFIG_IP_NF_TARGET_REJECT, $(P_V4)nf_reject_ipv4, ge 3.18.0))
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MATCH_TIME, $(P_XT)xt_time))
 $(eval $(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MARK, $(P_XT)xt_mark))
 
@@ -58,9 +65,10 @@ $(eval $(if $(NF_KMOD),,$(call nf_add,IPT_CORE,CONFIG_NETFILTER_XT_MARK, $(P_XT)
 # conntrack
 
 # kernel only
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_CONNTRACK,CONFIG_NF_CONNTRACK, $(P_XT)nf_conntrack),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_CONNTRACK,CONFIG_NF_DEFRAG_IPV4, $(P_V4)nf_defrag_ipv4),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_CONNTRACK,CONFIG_NF_CONNTRACK_IPV4, $(P_V4)nf_conntrack_ipv4),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_CONNTRACK,CONFIG_NF_CONNTRACK, $(P_XT)nf_conntrack),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_CONNTRACK,CONFIG_NF_CONNTRACK_RTCACHE, $(P_XT)nf_conntrack_rtcache),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_CONNTRACK,CONFIG_NF_DEFRAG_IPV4, $(P_V4)nf_defrag_ipv4),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_CONNTRACK,CONFIG_NF_CONNTRACK_IPV4, $(P_V4)nf_conntrack_ipv4),))
 
 $(eval $(call nf_add,IPT_CONNTRACK,CONFIG_NETFILTER_XT_MATCH_STATE, $(P_XT)xt_state))
 $(eval $(call nf_add,IPT_CONNTRACK,CONFIG_IP_NF_RAW, $(P_V4)iptable_raw))
@@ -72,6 +80,7 @@ $(eval $(call nf_add,IPT_CONNTRACK,CONFIG_NETFILTER_XT_MATCH_CONNTRACK, $(P_XT)x
 # conntrack-extra
 
 $(eval $(call nf_add,IPT_CONNTRACK_EXTRA,CONFIG_NETFILTER_XT_MATCH_CONNBYTES, $(P_XT)xt_connbytes))
+$(eval $(call nf_add,IPT_CONNTRACK_EXTRA,CONFIG_NETFILTER_XT_MATCH_CONNLIMIT, $(P_XT)xt_connlimit))
 $(eval $(call nf_add,IPT_CONNTRACK_EXTRA,CONFIG_NETFILTER_XT_CONNMARK, $(P_XT)xt_connmark))
 $(eval $(call nf_add,IPT_CONNTRACK_EXTRA,CONFIG_NETFILTER_XT_MATCH_HELPER, $(P_XT)xt_helper))
 $(eval $(call nf_add,IPT_CONNTRACK_EXTRA,CONFIG_NETFILTER_XT_MATCH_RECENT, $(P_XT)xt_recent))
@@ -113,7 +122,7 @@ $(eval $(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_MATCH_ECN, $(P_XT)xt_ecn))
 # userland only
 $(eval $(if $(NF_KMOD),,$(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_MATCH_DSCP, xt_tos)))
 $(eval $(if $(NF_KMOD),,$(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_TARGET_DSCP, xt_TOS)))
-$(eval $(if $(NF_KMOD),,$(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_TARGET_HL, ipt_ttl)))
+$(eval $(if $(NF_KMOD),,$(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_MATCH_HL, ipt_ttl)))
 $(eval $(if $(NF_KMOD),,$(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_TARGET_HL, ipt_TTL)))
 
 $(eval $(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_MATCH_HL, $(P_XT)xt_hl))
@@ -122,6 +131,8 @@ $(eval $(call nf_add,IPT_IPOPT,CONFIG_NETFILTER_XT_TARGET_HL, $(P_XT)xt_HL))
 # iprange
 $(eval $(call nf_add,IPT_IPRANGE,CONFIG_NETFILTER_XT_MATCH_IPRANGE, $(P_XT)xt_iprange))
 
+#clusterip
+$(eval $(call nf_add,IPT_CLUSTERIP,CONFIG_IP_NF_TARGET_CLUSTERIP, $(P_V4)ipt_CLUSTERIP))
 
 # ipsec
 $(eval $(call nf_add,IPT_IPSEC,CONFIG_IP_NF_MATCH_AH, $(P_V4)ipt_ah))
@@ -132,9 +143,11 @@ $(eval $(call nf_add,IPT_IPSEC,CONFIG_NETFILTER_XT_MATCH_POLICY, $(P_XT)xt_polic
 # IPv6
 
 # kernel only
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_IPV6,CONFIG_NF_DEFRAG_IPV6, $(P_V6)nf_defrag_ipv6),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_IPV6,CONFIG_NF_CONNTRACK_IPV6, $(P_V6)nf_conntrack_ipv6),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_IPV6,CONFIG_IP6_NF_IPTABLES, $(P_V6)ip6_tables),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_IPT6,CONFIG_IP6_NF_IPTABLES, $(P_V6)ip6_tables),))
+
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_CONNTRACK6,CONFIG_NF_DEFRAG_IPV6, $(P_V6)nf_defrag_ipv6),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_CONNTRACK6,CONFIG_NF_CONNTRACK_IPV6, $(P_V6)nf_conntrack_ipv6),))
+
 $(eval $(if $(NF_KMOD),$(call nf_add,IPT_IPV6,CONFIG_IP6_NF_FILTER, $(P_V6)ip6table_filter),))
 $(eval $(if $(NF_KMOD),$(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MANGLE, $(P_V6)ip6table_mangle),))
 $(eval $(if $(NF_KMOD),$(call nf_add,IPT_IPV6,CONFIG_IP6_NF_QUEUE, $(P_V6)ip6_queue),))
@@ -142,24 +155,34 @@ $(eval $(if $(NF_KMOD),$(call nf_add,IPT_IPV6,CONFIG_IP6_NF_RAW, $(P_V6)ip6table
 
 $(eval $(if $(NF_KMOD),,$(call nf_add,IPT_IPV6,CONFIG_IP6_NF_IPTABLES, ip6t_icmp6)))
 
-$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MATCH_AH, $(P_V6)ip6t_ah))
-$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MATCH_EUI64, $(P_V6)ip6t_eui64))
-$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MATCH_FRAG, $(P_V6)ip6t_frag))
-$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MATCH_IPV6HEADER, $(P_V6)ip6t_ipv6header))
-$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MATCH_MH, $(P_V6)ip6t_mh))
-$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MATCH_OPTS, $(P_V6)ip6t_hbh))
-$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_MATCH_RT, $(P_V6)ip6t_rt))
 
 $(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_TARGET_LOG, $(P_V6)ip6t_LOG))
 $(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_TARGET_REJECT, $(P_V6)ip6t_REJECT))
+$(eval $(call nf_add,IPT_IPV6,CONFIG_IP6_NF_TARGET_REJECT, $(P_V6)nf_reject_ipv6, ge 3.18.0))
+
+# ipv6 extra
+$(eval $(call nf_add,IPT_IPV6_EXTRA,CONFIG_IP6_NF_MATCH_IPV6HEADER, $(P_V6)ip6t_ipv6header))
+$(eval $(call nf_add,IPT_IPV6_EXTRA,CONFIG_IP6_NF_MATCH_AH, $(P_V6)ip6t_ah))
+$(eval $(call nf_add,IPT_IPV6_EXTRA,CONFIG_IP6_NF_MATCH_MH, $(P_V6)ip6t_mh))
+$(eval $(call nf_add,IPT_IPV6_EXTRA,CONFIG_IP6_NF_MATCH_EUI64, $(P_V6)ip6t_eui64))
+$(eval $(call nf_add,IPT_IPV6_EXTRA,CONFIG_IP6_NF_MATCH_OPTS, $(P_V6)ip6t_hbh))
+$(eval $(call nf_add,IPT_IPV6_EXTRA,CONFIG_IP6_NF_MATCH_FRAG, $(P_V6)ip6t_frag))
+$(eval $(call nf_add,IPT_IPV6_EXTRA,CONFIG_IP6_NF_MATCH_RT, $(P_V6)ip6t_rt))
 
 # nat
 
 # kernel only
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_NF_NAT, $(P_V4)nf_nat $(P_V4)iptable_nat, lt 3.7.0),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_NF_NAT, $(P_XT)nf_nat $(P_XT)xt_nat, ge 3.7.0),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_NF_NAT_IPV4, $(P_V4)nf_nat_ipv4 $(P_V4)iptable_nat, ge 3.7.0),))
-$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT6,CONFIG_NF_NAT_IPV6, $(P_V6)nf_nat_ipv6 $(P_V6)ip6table_nat, ge 3.7.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_NAT,CONFIG_NF_NAT, $(P_V4)nf_nat, lt 3.7.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_NAT,CONFIG_NF_NAT, $(P_XT)nf_nat, ge 3.7.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_NAT,CONFIG_NF_NAT_IPV4, $(P_V4)nf_nat_ipv4, ge 3.7.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NF_NAT6,CONFIG_NF_NAT_IPV6, $(P_V6)nf_nat_ipv6, ge 3.7.0),))
+
+$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_NF_NAT, $(P_XT)xt_nat, ge 3.7.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_NETFILTER_XT_NAT, $(P_XT)xt_nat, ge 3.18.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_NF_NAT, $(P_V4)iptable_nat, lt 3.7.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_NF_NAT_IPV4, $(P_V4)iptable_nat, ge 3.7.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT,CONFIG_IP_NF_NAT, $(P_V4)iptable_nat, ge 3.18.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT6,CONFIG_NF_NAT_IPV6, $(P_V6)ip6table_nat, ge 3.7.0),))
 $(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT6,CONFIG_IP6_NF_TARGET_MASQUERADE, $(P_V6)ip6t_MASQUERADE, ge 3.7.0),))
 $(eval $(if $(NF_KMOD),$(call nf_add,IPT_NAT6,CONFIG_IP6_NF_TARGET_NPT, $(P_V6)ip6t_NPT, ge 3.7.0),))
 
@@ -168,6 +191,7 @@ $(eval $(if $(NF_KMOD),,$(call nf_add,IPT_NAT,CONFIG_NF_NAT, ipt_SNAT ipt_DNAT))
 $(eval $(if $(NF_KMOD),,$(call nf_add,IPT_NAT6,CONFIG_IP6_NF_TARGET_NPT, ip6t_DNPT ip6t_SNPT)))
 
 $(eval $(call nf_add,IPT_NAT,CONFIG_IP_NF_TARGET_MASQUERADE, $(P_V4)ipt_MASQUERADE))
+$(eval $(call nf_add,IPT_NAT,CONFIG_IP_NF_TARGET_MASQUERADE, $(P_V4)nf_nat_masquerade_ipv4, ge 3.18.0))
 $(eval $(call nf_add,IPT_NAT,CONFIG_IP_NF_TARGET_REDIRECT, $(P_XT)xt_REDIRECT, ge 3.7.0))
 $(eval $(call nf_add,IPT_NAT,CONFIG_IP_NF_TARGET_REDIRECT, $(P_V4)ipt_REDIRECT, lt 3.7.0))
 
@@ -180,35 +204,35 @@ $(eval $(call nf_add,IPT_NAT_EXTRA,CONFIG_IP_NF_TARGET_NETMAP, $(P_V4)ipt_NETMAP
 
 # nathelper
 
-$(eval $(call nf_add,IPT_NATHELPER,CONFIG_IP_NF_NAT_FTP, $(P_V4)ip_nat_ftp))
-$(eval $(call nf_add,IPT_NATHELPER,CONFIG_NF_CONNTRACK_FTP, $(P_XT)nf_conntrack_ftp))
-$(eval $(call nf_add,IPT_NATHELPER,CONFIG_NF_CONNTRACK_IRC, $(P_XT)nf_conntrack_irc))
-$(eval $(call nf_add,IPT_NATHELPER,CONFIG_NF_NAT_FTP, $(P_XT)nf_nat_ftp, ge 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER,CONFIG_NF_NAT_IRC, $(P_XT)nf_nat_irc, ge 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER,CONFIG_NF_NAT_FTP, $(P_V4)nf_nat_ftp, lt 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER,CONFIG_NF_NAT_IRC, $(P_V4)nf_nat_irc, lt 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER,CONFIG_IP_NF_NAT_FTP, $(P_V4)ip_nat_ftp))
+$(eval $(call nf_add,NF_NATHELPER,CONFIG_NF_CONNTRACK_FTP, $(P_XT)nf_conntrack_ftp))
+$(eval $(call nf_add,NF_NATHELPER,CONFIG_NF_CONNTRACK_IRC, $(P_XT)nf_conntrack_irc))
+$(eval $(call nf_add,NF_NATHELPER,CONFIG_NF_NAT_FTP, $(P_XT)nf_nat_ftp, ge 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER,CONFIG_NF_NAT_IRC, $(P_XT)nf_nat_irc, ge 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER,CONFIG_NF_NAT_FTP, $(P_V4)nf_nat_ftp, lt 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER,CONFIG_NF_NAT_IRC, $(P_V4)nf_nat_irc, lt 3.7.0))
 
 
 # nathelper-extra
 
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_BROADCAST, $(P_XT)nf_conntrack_broadcast))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_AMANDA, $(P_XT)nf_conntrack_amanda))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_AMANDA, $(P_XT)nf_nat_amanda, ge 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_AMANDA, $(P_V4)nf_nat_amanda, lt 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CT_PROTO_GRE, $(P_XT)nf_conntrack_proto_gre))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_PROTO_GRE, $(P_V4)nf_nat_proto_gre))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_H323, $(P_XT)nf_conntrack_h323))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_H323, $(P_V4)nf_nat_h323))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_PPTP, $(P_XT)nf_conntrack_pptp))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_PPTP, $(P_V4)nf_nat_pptp))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_SIP, $(P_XT)nf_conntrack_sip))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_SIP, $(P_XT)nf_nat_sip, ge 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_SIP, $(P_V4)nf_nat_sip, lt 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_SNMP, $(P_XT)nf_conntrack_snmp))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_SNMP_BASIC, $(P_V4)nf_nat_snmp_basic))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_TFTP, $(P_XT)nf_conntrack_tftp))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_TFTP, $(P_XT)nf_nat_tftp, ge 3.7.0))
-$(eval $(call nf_add,IPT_NATHELPER_EXTRA,CONFIG_NF_NAT_TFTP, $(P_V4)nf_nat_tftp, lt 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_BROADCAST, $(P_XT)nf_conntrack_broadcast))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_AMANDA, $(P_XT)nf_conntrack_amanda))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_AMANDA, $(P_XT)nf_nat_amanda, ge 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_AMANDA, $(P_V4)nf_nat_amanda, lt 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CT_PROTO_GRE, $(P_XT)nf_conntrack_proto_gre))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_PROTO_GRE, $(P_V4)nf_nat_proto_gre))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_H323, $(P_XT)nf_conntrack_h323))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_H323, $(P_V4)nf_nat_h323))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_PPTP, $(P_XT)nf_conntrack_pptp))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_PPTP, $(P_V4)nf_nat_pptp))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_SIP, $(P_XT)nf_conntrack_sip))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_SIP, $(P_XT)nf_nat_sip, ge 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_SIP, $(P_V4)nf_nat_sip, lt 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_SNMP, $(P_XT)nf_conntrack_snmp))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_SNMP_BASIC, $(P_V4)nf_nat_snmp_basic))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_CONNTRACK_TFTP, $(P_XT)nf_conntrack_tftp))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_TFTP, $(P_XT)nf_nat_tftp, ge 3.7.0))
+$(eval $(call nf_add,NF_NATHELPER_EXTRA,CONFIG_NF_NAT_TFTP, $(P_V4)nf_nat_tftp, lt 3.7.0))
 
 
 # queue
@@ -221,6 +245,16 @@ $(eval $(call nf_add,IPT_QUEUE,CONFIG_IP_NF_QUEUE, $(P_V4)ip_queue, lt 3.5.0))
 $(eval $(call nf_add,IPT_ULOG,CONFIG_IP_NF_TARGET_ULOG, $(P_V4)ipt_ULOG))
 
 
+# nflog
+
+$(eval $(call nf_add,IPT_NFLOG,CONFIG_NETFILTER_XT_TARGET_NFLOG, $(P_XT)xt_NFLOG))
+
+
+# nfqueue
+
+$(eval $(call nf_add,IPT_NFQUEUE,CONFIG_NETFILTER_XT_TARGET_NFQUEUE, $(P_XT)xt_NFQUEUE))
+
+
 # debugging
 
 $(eval $(call nf_add,IPT_DEBUG,CONFIG_NETFILTER_XT_TARGET_TRACE, $(P_XT)xt_TRACE))
@@ -241,6 +275,19 @@ $(eval $(call nf_add,IPT_TEE,CONFIG_NETFILTER_XT_TARGET_TEE, $(P_XT)xt_TEE))
 
 $(eval $(call nf_add,IPT_U32,CONFIG_NETFILTER_XT_MATCH_U32, $(P_XT)xt_u32))
 
+
+# netlink
+
+$(eval $(call nf_add,NFNETLINK,CONFIG_NETFILTER_NETLINK, $(P_XT)nfnetlink))
+
+# nflog
+
+$(eval $(call nf_add,NFNETLINK_LOG,CONFIG_NETFILTER_NETLINK_LOG, $(P_XT)nfnetlink_log))
+
+# nfqueue
+
+$(eval $(call nf_add,NFNETLINK_QUEUE,CONFIG_NETFILTER_NETLINK_QUEUE, $(P_XT)nfnetlink_queue))
+
 #
 # ebtables
 #
@@ -275,26 +322,58 @@ $(eval $(call nf_add,EBTABLES_IP4,CONFIG_BRIDGE_EBT_SNAT, $(P_EBT)ebt_snat))
 $(eval $(call nf_add,EBTABLES_WATCHERS,CONFIG_BRIDGE_EBT_LOG, $(P_EBT)ebt_log))
 $(eval $(call nf_add,EBTABLES_WATCHERS,CONFIG_BRIDGE_EBT_ULOG, $(P_EBT)ebt_ulog))
 $(eval $(call nf_add,EBTABLES_WATCHERS,CONFIG_BRIDGE_EBT_NFLOG, $(P_EBT)ebt_nflog))
-
+$(eval $(call nf_add,EBTABLES_WATCHERS,CONFIG_BRIDGE_EBT_NFQUEUE, $(P_EBT)ebt_nfqueue))
+
+# nftables
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NF_TABLES, $(P_XT)nf_tables, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NF_TABLES_INET, $(P_XT)nf_tables_inet, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_EXTHDR, $(P_XT)nft_exthdr, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_META, $(P_XT)nft_meta, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_CT, $(P_XT)nft_ct, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_RBTREE, $(P_XT)nft_rbtree, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_HASH, $(P_XT)nft_hash, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_COUNTER, $(P_XT)nft_counter, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_LOG, $(P_XT)nft_log, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_LIMIT, $(P_XT)nft_limit, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_REJECT, $(P_XT)nft_reject $(P_V4)nft_reject_ipv4 $(P_V6)nft_reject_ipv6, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_REJECT_INET, $(P_XT)nft_reject_inet, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NF_TABLES_IPV4, $(P_V4)nf_tables_ipv4, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_CHAIN_ROUTE_IPV4, $(P_V4)nft_chain_route_ipv4, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NF_TABLES_IPV6, $(P_V6)nf_tables_ipv6, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_CORE,CONFIG_NFT_CHAIN_ROUTE_IPV6, $(P_V6)nft_chain_route_ipv6, ge 3.14.0),))
+
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_NAT,CONFIG_NFT_NAT, $(P_XT)nft_nat, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_NAT,CONFIG_NFT_CHAIN_NAT_IPV4, $(P_V4)nft_chain_nat_ipv4, ge 3.14.0),))
+$(eval $(if $(NF_KMOD),$(call nf_add,NFT_NAT6,CONFIG_NFT_CHAIN_NAT_IPV6, $(P_V6)nft_chain_nat_ipv6, ge 3.14.0),))
 
 # userland only
+IPT_BUILTIN += $(NF_IPT-y) $(NF_IPT-m)
 IPT_BUILTIN += $(IPT_CORE-y) $(IPT_CORE-m)
+IPT_BUILTIN += $(NF_CONNTRACK-y)
+IPT_BUILTIN += $(NF_CONNTRACK6-y)
 IPT_BUILTIN += $(IPT_CONNTRACK-y)
 IPT_BUILTIN += $(IPT_CONNTRACK_EXTRA-y)
 IPT_BUILTIN += $(IPT_EXTRA-y)
 IPT_BUILTIN += $(IPT_FILTER-y)
 IPT_BUILTIN += $(IPT_IPOPT-y)
 IPT_BUILTIN += $(IPT_IPRANGE-y)
+IPT_BUILTIN += $(IPT_CLUSTER-y)
+IPT_BUILTIN += $(IPT_CLUSTERIP-y)
 IPT_BUILTIN += $(IPT_IPSEC-y)
 IPT_BUILTIN += $(IPT_IPV6-y) $(IPT_IPV6-m)
+IPT_BUILTIN += $(NF_NAT-y)
+IPT_BUILTIN += $(NF_NAT6-y)
 IPT_BUILTIN += $(IPT_NAT-y)
 IPT_BUILTIN += $(IPT_NAT6-y)
 IPT_BUILTIN += $(IPT_NAT_EXTRA-y)
-IPT_BUILTIN += $(IPT_NATHELPER-y)
-IPT_BUILTIN += $(IPT_NATHELPER_EXTRA-y)
+IPT_BUILTIN += $(NF_NATHELPER-y)
+IPT_BUILTIN += $(NF_NATHELPER_EXTRA-y)
 IPT_BUILTIN += $(IPT_ULOG-y)
 IPT_BUILTIN += $(IPT_DEBUG-y)
 IPT_BUILTIN += $(IPT_TPROXY-y)
+IPT_BUILTIN += $(NFNETLINK-y)
+IPT_BUILTIN += $(NFNETLINK_LOG-y)
+IPT_BUILTIN += $(NFNETLINK_QUEUE-y)
 IPT_BUILTIN += $(EBTABLES-y)
 IPT_BUILTIN += $(EBTABLES_IP4-y)
 IPT_BUILTIN += $(EBTABLES_IP6-y)

+ 2 - 2
include/package-bin.mk

@@ -1,5 +1,5 @@
 # 
-# Copyright (C) 2007 OpenWrt.org
+# Copyright (C) 2007-2014 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -9,7 +9,7 @@ ifeq ($(DUMP),)
   define BuildTarget/bin
     ifeq ($(if $(VARIANT),$(BUILD_VARIANT)),$(VARIANT))
     ifdef Package/$(1)/install
-      ifneq ($(CONFIG_PACKAGE_$(1))$(SDK)$(DEVELOPER),)
+      ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
         compile: install-bin-$(1)
       else
         compile: $(1)-disabled

+ 7 - 1
include/package-defaults.mk

@@ -19,6 +19,7 @@ define Package/Default
   CATEGORY:=Extra packages
   DEPENDS:=
   MDEPENDS:=
+  CONFLICTS:=
   PROVIDES:=
   EXTRA_DEPENDS:=
   MAINTAINER:=$(PKG_MAINTAINER)
@@ -53,6 +54,8 @@ define Package/Default
   HIDDEN:=
   URL:=
   VARIANT:=
+  DEFAULT_VARIANT:=
+  USERID:=
 endef
 
 Build/Patch:=$(Build/Patch/Default)
@@ -64,6 +67,7 @@ ifneq ($(strip $(PKG_UNPACK)),)
 endif
 
 EXTRA_CXXFLAGS = $(EXTRA_CFLAGS)
+DISABLE_NLS:=--disable-nls
 
 CONFIGURE_PREFIX:=/usr
 CONFIGURE_ARGS = \
@@ -96,7 +100,9 @@ CONFIGURE_VARS = \
 CONFIGURE_PATH = .
 CONFIGURE_CMD = ./configure
 
-replace_script=$(FIND) $(1) -name $(2) | $(XARGS) chmod u+w; $(FIND) $(1) -name $(2) | $(XARGS) -n1 cp $(SCRIPT_DIR)/$(2);
+replace_script=$(FIND) $(1) -name $(2) | $(XARGS) chmod u+w; \
+	       $(FIND) $(1) -name $(2) | $(XARGS) -n1 cp --remove-destination \
+	       $(SCRIPT_DIR)/$(2);
 
 define Build/Configure/Default
 	(cd $(PKG_BUILD_DIR)/$(CONFIGURE_PATH)/$(strip $(3)); \

+ 9 - 3
include/package-dumpinfo.mk

@@ -31,21 +31,27 @@ $(if $(MENU),Menu: $(MENU)
 )$(if $(findstring $(PREREQ_CHECK),1),Prereq-Check: 1
 )Version: $(VERSION)
 Depends: $(call PKG_FIXUP_DEPENDS,$(1),$(DEPENDS))
+Conflicts: $(CONFLICTS)
 Menu-Depends: $(MDEPENDS)
 Provides: $(PROVIDES)
 $(if $(VARIANT),Build-Variant: $(VARIANT)
-)$(if $(PKG_BUILD_DEPENDS),Build-Depends: $(PKG_BUILD_DEPENDS)
+$(if $(DEFAULT_VARIANT),Default-Variant: $(VARIANT)
+))$(if $(PKG_BUILD_DEPENDS),Build-Depends: $(PKG_BUILD_DEPENDS)
 )$(if $(HOST_BUILD_DEPENDS),Build-Depends/host: $(HOST_BUILD_DEPENDS)
 )$(if $(BUILD_TYPES),Build-Types: $(BUILD_TYPES)
 )Section: $(SECTION)
 Category: $(CATEGORY)
 Title: $(TITLE)
 Maintainer: $(MAINTAINER)
-Source: $(PKG_SOURCE)
-Type: $(if $(Package/$(1)/targets),$(Package/$(1)/targets),$(if $(PKG_TARGETS),$(PKG_TARGETS),ipkg))
+$(if $(USERID),Require-User: $(USERID)
+)Source: $(PKG_SOURCE)
+$(if $(PKG_LICENSE),License: $(PKG_LICENSE)
+)$(if $(PKG_LICENSE_FILES),LicenseFiles: $(PKG_LICENSE_FILES)
+)Type: $(if $(Package/$(1)/targets),$(Package/$(1)/targets),$(if $(PKG_TARGETS),$(PKG_TARGETS),ipkg))
 $(if $(KCONFIG),Kernel-Config: $(KCONFIG)
 )$(if $(BUILDONLY),Build-Only: $(BUILDONLY)
 )$(if $(HIDDEN),Hidden: $(HIDDEN)
+)$(if $(FEED),Feed: $(FEED)
 )Description: $(if $(Package/$(1)/description),$(Package/$(1)/description),$(TITLE))
 $(if $(URL),$(URL)
 )$(MAINTAINER)

+ 69 - 35
include/package-ipkg.mk

@@ -1,20 +1,26 @@
 #
-# Copyright (C) 2006,2007 OpenWrt.org
+# Copyright (C) 2006-2014 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
 #
 
+include $(INCLUDE_DIR)/feeds.mk
+
 # invoke ipkg-build with some default options
 IPKG_BUILD:= \
-  ipkg-build -c -o 0 -g 0
+  $(STAGING_DIR_HOST)/bin/ipkg-build -c -o 0 -g 0
 
 IPKG_STATE_DIR:=$(TARGET_DIR)/usr/lib/opkg
 
+# 1: package name
+# 2: variable name
+# 3: variable suffix
 define BuildIPKGVariable
 ifdef Package/$(1)/$(2)
+  $$(IPKG_$(1)) : VAR_$(2)$(3)=$$(Package/$(1)/$(2))
   $(call shexport,Package/$(1)/$(2))
-  $(1)_COMMANDS += var2file "$(call shvar,Package/$(1)/$(2))" $(2);
+  $(1)_COMMANDS += echo "$$$$$$$$$(call shvar,Package/$(1)/$(2))" > $(2)$(3);
 endif
 endef
 
@@ -72,15 +78,23 @@ ifneq ($(PKG_NAME),toolchain)
   endef
 endif
 
+_addsep=$(word 1,$(1))$(foreach w,$(wordlist 2,$(words $(1)),$(1)),$(strip $(2) $(w)))
+_cleansep=$(subst $(space)$(2)$(space),$(2)$(space),$(1))
+mergelist=$(call _cleansep,$(call _addsep,$(1),$(comma)),$(comma))
+addfield=$(if $(strip $(2)),$(1): $(2))
+_define=define
+_endef=endef
+
 ifeq ($(DUMP),)
   define BuildTarget/ipkg
-    IPKG_$(1):=$(PACKAGE_DIR)/$(1)_$(VERSION)_$(PKGARCH).ipk
+    PDIR_$(1):=$(call FeedPackageDir,$(1))
+    IPKG_$(1):=$$(PDIR_$(1))/$(1)_$(VERSION)_$(PKGARCH).ipk
     IDIR_$(1):=$(PKG_BUILD_DIR)/ipkg-$(PKGARCH)/$(1)
     KEEP_$(1):=$(strip $(call Package/$(1)/conffiles))
 
     ifeq ($(BUILD_VARIANT),$$(if $$(VARIANT),$$(VARIANT),$(BUILD_VARIANT)))
     ifdef Package/$(1)/install
-      ifneq ($(CONFIG_PACKAGE_$(1))$(SDK)$(DEVELOPER),)
+      ifneq ($(CONFIG_PACKAGE_$(1))$(DEVELOPER),)
         IPKGS += $(1)
         compile: $$(IPKG_$(1)) $(PKG_INFO_DIR)/$(1).provides $(STAGING_DIR_ROOT)/stamp/.$(1)_installed
         ifneq ($(ABI_VERSION),)
@@ -99,9 +113,7 @@ ifeq ($(DUMP),)
 			echo "$(1)" >> $(PKG_INSTALL_STAMP)
         endif
       else
-        compile: $(1)-disabled
-        $(1)-disabled:
-		@echo "WARNING: skipping $(1) -- package not selected" >&2
+        $(if $(CONFIG_PACKAGE_$(1)),$$(info WARNING: skipping $(1) -- package not selected))
       endif
     endif
     endif
@@ -114,8 +126,8 @@ ifeq ($(DUMP),)
 
     $(eval $(call BuildIPKGVariable,$(1),conffiles))
     $(eval $(call BuildIPKGVariable,$(1),preinst))
-    $(eval $(call BuildIPKGVariable,$(1),postinst))
-    $(eval $(call BuildIPKGVariable,$(1),prerm))
+    $(eval $(call BuildIPKGVariable,$(1),postinst,-pkg))
+    $(eval $(call BuildIPKGVariable,$(1),prerm,-pkg))
     $(eval $(call BuildIPKGVariable,$(1),postrm))
 
     $(STAGING_DIR_ROOT)/stamp/.$(1)_installed: $(STAMP_BUILT)
@@ -131,9 +143,34 @@ ifeq ($(DUMP),)
 	echo '$(ABI_VERSION)' | cmp -s - $$@ || \
 		echo '$(ABI_VERSION)' > $$@
 
+    Package/$(1)/DEPENDS := $$(call mergelist,$$(filter-out @%,$$(IDEPEND_$(1))))
+    ifneq ($$(EXTRA_DEPENDS),)
+      Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
+    endif
+
+$(_define) Package/$(1)/CONTROL
+Package: $(1)
+Version: $(VERSION)
+$$(call addfield,Depends,$$(Package/$(1)/DEPENDS)
+)$$(call addfield,Conflicts,$$(call mergelist,$(CONFLICTS))
+)$$(call addfield,Provides,$(PROVIDES)
+)$$(call addfield,Source,$(SOURCE)
+)$$(call addfield,License,$$(PKG_LICENSE)
+)$$(call addfield,LicenseFiles,$$(PKG_LICENSE_FILES)
+)$$(call addfield,Section,$(SECTION)
+)$$(call addfield,Require-User,$(USERID)
+)$(if $(filter hold,$(PKG_FLAGS)),Status: unknown hold not-installed
+)$(if $(filter essential,$(PKG_FLAGS)),Essential: yes
+)$(if $(MAINTAINER),Maintainer: $(MAINTAINER)
+)Architecture: $(PKGARCH)
+Installed-Size: 0
+$(_endef)
+
     $(PKG_INFO_DIR)/$(1).provides: $$(IPKG_$(1))
+    $$(IPKG_$(1)) : export CONTROL=$$(Package/$(1)/CONTROL)
+    $$(IPKG_$(1)) : export DESCRIPTION=$$(Package/$(1)/description)
     $$(IPKG_$(1)): $(STAMP_BUILT) $(INCLUDE_DIR)/package-ipkg.mk
-	@rm -rf $(PACKAGE_DIR)/$(1)_* $$(IDIR_$(1))
+	@rm -rf $$(PDIR_$(1))/$(1)_* $$(IDIR_$(1))
 	mkdir -p $(PACKAGE_DIR) $$(IDIR_$(1))/CONTROL $(PKG_INFO_DIR)
 	$(call Package/$(1)/install,$$(IDIR_$(1)))
 	-find $$(IDIR_$(1)) -name 'CVS' -o -name '.svn' -o -name '.#*' -o -name '*~'| $(XARGS) rm -rf
@@ -149,28 +186,24 @@ ifeq ($(DUMP),)
 	$(CheckDependencies)
 
 	$(RSTRIP) $$(IDIR_$(1))
-	( \
-		echo "Package: $(1)"; \
-		echo "Version: $(VERSION)"; \
-		DEPENDS='$(EXTRA_DEPENDS)'; \
-		for depend in $$(filter-out @%,$$(IDEPEND_$(1))); do \
-			DEPENDS=$$$${DEPENDS:+$$$$DEPENDS, }$$$${depend##+}; \
-		done; \
-		[ -z "$$$$DEPENDS" ] || echo "Depends: $$$$DEPENDS"; \
-		$(if $(PROVIDES), echo "Provides: $(PROVIDES)"; ) \
-		echo "Source: $(SOURCE)"; \
-		$(if $(PKG_LICENSE), echo "License: $(PKG_LICENSE)"; ) \
-		$(if $(PKG_LICENSE_FILES), echo "LicenseFiles: $(PKG_LICENSE_FILES)"; ) \
-		echo "Section: $(SECTION)"; \
-		$(if $(filter hold,$(PKG_FLAGS)),echo "Status: unknown hold not-installed"; ) \
-		$(if $(filter essential,$(PKG_FLAGS)), echo "Essential: yes"; ) \
-		$(if $(MAINTAINER),echo "Maintainer: $(MAINTAINER)"; ) \
-		echo "Architecture: $(PKGARCH)"; \
-		echo "Installed-Size: 0"; \
-		echo -n "Description: "; $(SH_FUNC) getvar $(call shvar,Package/$(1)/description) | sed -e 's,^[[:space:]]*, ,g'; \
- 	) > $$(IDIR_$(1))/CONTROL/control
-	chmod 644 $$(IDIR_$(1))/CONTROL/control
-	$(SH_FUNC) (cd $$(IDIR_$(1))/CONTROL; \
+	(cd $$(IDIR_$(1))/CONTROL; \
+		( \
+			echo "$$$$CONTROL"; \
+			printf "Description: "; echo "$$$$DESCRIPTION" | sed -e 's,^[[:space:]]*, ,g'; \
+		) > control; \
+		chmod 644 control; \
+		( \
+			echo "#!/bin/sh"; \
+			echo "[ \"\$$$${IPKG_NO_SCRIPT}\" = \"1\" ] && exit 0"; \
+			echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
+			echo "default_postinst \$$$$0 \$$$$@"; \
+		) > postinst; \
+		( \
+			echo "#!/bin/sh"; \
+			echo ". \$$$${IPKG_INSTROOT}/lib/functions.sh"; \
+			echo "default_prerm \$$$$0 \$$$$@"; \
+		) > prerm; \
+		chmod 0755 prerm; \
 		$($(1)_COMMANDS) \
 	)
 
@@ -187,11 +220,12 @@ ifeq ($(DUMP),)
 		)
     endif
 
-	$(IPKG_BUILD) $$(IDIR_$(1)) $(PACKAGE_DIR)
+	$(INSTALL_DIR) $$(PDIR_$(1))
+	$(IPKG_BUILD) $$(IDIR_$(1)) $$(PDIR_$(1))
 	@[ -f $$(IPKG_$(1)) ]
 
     $(1)-clean:
-	rm -f $(PACKAGE_DIR)/$(1)_*
+	rm -f $$(PDIR_$(1))/$(1)_*
 
     clean: $(1)-clean
 

+ 21 - 18
include/package.mk

@@ -14,6 +14,7 @@ PKG_INSTALL_DIR ?= $(PKG_BUILD_DIR)/ipkg-install
 PKG_MD5SUM ?= unknown
 PKG_BUILD_PARALLEL ?=
 PKG_USE_MIPS16 ?= 1
+PKG_CHECK_FORMAT_SECURITY ?= 1
 
 ifneq ($(CONFIG_PKG_BUILD_USE_JOBSERVER),)
   MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) -j)
@@ -33,6 +34,11 @@ ifdef CONFIG_USE_MIPS16
     TARGET_CFLAGS += -mips16 -minterlink-mips16
   endif
 endif
+ifdef CONFIG_PKG_CHECK_FORMAT_SECURITY
+  ifeq ($(strip $(PKG_CHECK_FORMAT_SECURITY)),1)
+    TARGET_CFLAGS += -Wformat -Werror=format-security
+  endif
+endif
 
 include $(INCLUDE_DIR)/prereq.mk
 include $(INCLUDE_DIR)/host.mk
@@ -66,6 +72,12 @@ ifneq ($(if $(CONFIG_SRC_TREE_OVERRIDE),$(wildcard ./git-src)),)
   USE_GIT_TREE:=1
   QUILT:=1
 endif
+ifdef USE_SOURCE_DIR
+  QUILT:=1
+endif
+ifneq ($(wildcard $(PKG_BUILD_DIR)/.source_dir),)
+  QUILT:=1
+endif
 
 PKG_DIR_NAME:=$(lastword $(subst /,$(space),$(CURDIR)))
 PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
@@ -95,20 +107,6 @@ ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
   endif
 endif
 
-ifeq ($(CONFIG_$(PKG_NAME)_USE_CUSTOM_SOURCE_DIR),y)
-# disable load stage
-PKG_SOURCE_URL:=
-# add hook to install a link to customer source path of dedicated package
-Hooks/Prepare/Pre += prepare_custom_source_directory
-ifeq ($(filter autoreconf,$(Hooks/Configure/Pre)),)
-  Hooks/Configure/Pre += autoreconf_target
-endif
-# define empty default action
-define Build/Prepare/Default
-	@: 
-endef
-endif
-
 define Download/default
   FILE:=$(PKG_SOURCE)
   URL:=$(PKG_SOURCE_URL)
@@ -127,6 +125,14 @@ ifdef USE_GIT_TREE
 	( cd $(PKG_BUILD_DIR); git checkout .)
   endef
 endif
+ifdef USE_SOURCE_DIR
+  define Build/Prepare/Default
+	rm -rf $(PKG_BUILD_DIR)
+	$(if $(wildcard $(USE_SOURCE_DIR)/*),,@echo "Error: USE_SOURCE_DIR=$(USE_SOURCE_DIR) path not found"; false)
+	ln -snf $(USE_SOURCE_DIR) $(PKG_BUILD_DIR)
+	touch $(PKG_BUILD_DIR)/.source_dir
+  endef
+endif
 
 define Build/Exports/Default
   $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR)/usr/share/aclocal $$(STAGING_DIR)/usr/share/aclocal-* $$(STAGING_DIR)/host/share/aclocal $$(STAGING_DIR)/host/share/aclocal-*),-I $$(p))
@@ -141,7 +147,7 @@ Build/Exports=$(Build/Exports/Default)
 
 define Build/DefaultTargets
   $(if $(QUILT),$(Build/Quilt))
-  $(if $(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
+  $(if $(USE_SOURCE_DIR)$(USE_GIT_TREE),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
   $(call Build/Autoclean)
 
   download:
@@ -245,9 +251,6 @@ endif
     endif
   )
 
-  $(call shexport,Package/$(1)/description)
-  $(call shexport,Package/$(1)/config)
-
   $(if $(DUMP), \
     $(Dumpinfo/Package), \
     $(foreach target, \

+ 14 - 1
include/prereq-build.mk

@@ -168,8 +168,17 @@ $(eval $(call RequireCommand,svn, \
 	Please install the subversion client. \
 ))
 
+define Require/libssl
+	echo 'int main(int argc, char **argv) { SSL_library_init(); return 0; }' | \
+		gcc -include openssl/ssl.h -x c -o $(TMP_DIR)/a.out - -lcrypto -lssl
+endef
+
+$(eval $(call Require,libssl, \
+	Please install the openssl library (with development headers) \
+))
+
 $(eval $(call RequireCommand,openssl, \
-	Please install openssl. \
+       Please install openssl. \
 ))
 
 define Require/gnu-find
@@ -187,3 +196,7 @@ endef
 $(eval $(call Require,getopt-extended, \
 	Please install an extended getopt version that supports --long \
 ))
+
+$(eval $(call RequireCommand,file, \
+	Please install the 'file' package. \
+))

+ 1 - 1
include/prereq.mk

@@ -39,6 +39,7 @@ define Require
     CHECK_$(1):=1
 
     .SILENT: prereq-$(1) check-$(1)
+    .NOTPARALLEL:
   endif
 endef
 
@@ -59,4 +60,3 @@ define RequireHeader
   $$(eval $$(call Require,$(1),$(2)))
 endef
 
-.NOTPARALLEL:

+ 6 - 2
include/scan.mk

@@ -21,15 +21,19 @@ else
   endef
 endif
 
+define feedname
+$(if $(patsubst feeds/%,,$(1)),,$(word 2,$(subst /, ,$(1))))
+endef
+
 define PackageDir
   $(TMP_DIR)/.$(SCAN_TARGET): $(TMP_DIR)/info/.$(SCAN_TARGET)-$(1)
   $(TMP_DIR)/info/.$(SCAN_TARGET)-$(1): $(SCAN_DIR)/$(2)/Makefile $(SCAN_STAMP) $(foreach DEP,$(DEPS_$(SCAN_DIR)/$(2)/Makefile) $(SCAN_DEPS),$(wildcard $(if $(filter /%,$(DEP)),$(DEP),$(SCAN_DIR)/$(2)/$(DEP))))
 	{ \
 		$$(call progress,Collecting $(SCAN_NAME) info: $(SCAN_DIR)/$(2)) \
 		echo Source-Makefile: $(SCAN_DIR)/$(2)/Makefile; \
-		$(NO_TRACE_MAKE) --no-print-dir -r DUMP=1 -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) 2>/dev/null || { \
+		$(NO_TRACE_MAKE) --no-print-dir -r DUMP=1 FEED="$(call feedname,$(2))" -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) 2>/dev/null || { \
 			mkdir -p "$(TOPDIR)/logs/$(SCAN_DIR)/$(2)"; \
-			$(NO_TRACE_MAKE) --no-print-dir -r DUMP=1 -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) > $(TOPDIR)/logs/$(SCAN_DIR)/$(2)/dump.txt 2>&1; \
+			$(NO_TRACE_MAKE) --no-print-dir -r DUMP=1 FEED="$(call feedname,$(2))" -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) > $(TOPDIR)/logs/$(SCAN_DIR)/$(2)/dump.txt 2>&1; \
 			$$(call progress,ERROR: please fix $(SCAN_DIR)/$(2)/Makefile - see logs/$(SCAN_DIR)/$(2)/dump.txt for details\n) \
 			rm -f $$@; \
 		}; \

+ 5 - 0
include/site/aarch64-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/aarch64-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 28 - 0
include/site/aarch64-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=yes}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=no}
+
+ac_cv_sizeof___int64=8
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=8
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=8
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=8
+ac_cv_sizeof_ssize_t=8
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=8
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=8

+ 5 - 0
include/site/aarch64_be-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/aarch64-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 28 - 0
include/site/aarch64_be-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=no}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=yes}
+
+ac_cv_sizeof___int64=8
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=8
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=8
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=8
+ac_cv_sizeof_ssize_t=8
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=8
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=8

+ 5 - 0
include/site/armeb-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/armeb-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/armeb-librecmc-linux-gnueabi

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/armeb-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/armeb-librecmc-linux-musl

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/armeb-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 5 - 0
include/site/armeb-librecmc-linux-muslgnueabi

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/armeb-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 5 - 0
include/site/armeb-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/armeb-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 5 - 0
include/site/armeb-librecmc-linux-uclibcgnueabi

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/armeb-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 28 - 0
include/site/armeb-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=no}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=yes}
+
+ac_cv_sizeof___int64=0
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=4
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=4
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=4
+ac_cv_sizeof_ssize_t=4
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=4
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=4

+ 5 - 0
include/site/avr32-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/avr32-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/avr32-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/avr32-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 28 - 0
include/site/avr32-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=no}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=yes}
+
+ac_cv_sizeof___int64=0
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=4
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=4
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=4
+ac_cv_sizeof_ssize_t=4
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=4
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=4

+ 5 - 0
include/site/cris-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/cris-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/cris-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/cris-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 28 - 0
include/site/cris-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=yes}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=no}
+
+ac_cv_sizeof___int64=0
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=4
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=4
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=4
+ac_cv_sizeof_ssize_t=4
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=4
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=4

+ 5 - 0
include/site/m68k-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/m68k-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/m68k-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/m68k-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 26 - 0
include/site/m68k-linux

@@ -0,0 +1,26 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=no}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=yes}
+
+ac_cv_sizeof___int64=0
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=4
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=4
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=4
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=4
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=4

+ 5 - 0
include/site/mips64-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/mips64-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/mips64-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/mips64-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 28 - 0
include/site/mips64-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=no}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=yes}
+
+ac_cv_sizeof___int64=8
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=8
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=8
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=8
+ac_cv_sizeof_ssize_t=8
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=8
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=8

+ 5 - 0
include/site/mips64el-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/mips64-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/mips64el-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/mips64-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 28 - 0
include/site/mips64el-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=yes}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=no}
+
+ac_cv_sizeof___int64=8
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=8
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=8
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=8
+ac_cv_sizeof_ssize_t=8
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=8
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=8

+ 5 - 0
include/site/mipsel-librecmc-linux2.4-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/mipsel-linux
+. $TOPDIR/include/site/linux-uclibc
+ac_cv_header_sys_inotify_h=no

+ 5 - 0
include/site/powerpc-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/powerpc-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/powerpc-librecmc-linux-gnuspe

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/powerpc-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/powerpc-librecmc-linux-musl

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/powerpc-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 5 - 0
include/site/powerpc-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/powerpc-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 5 - 0
include/site/powerpc-librecmc-linux-uclibcspe

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/powerpc-linux
+. $TOPDIR/include/site/linux-uclibc
+

+ 28 - 0
include/site/powerpc-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=no}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=yes}
+
+ac_cv_sizeof___int64=0
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=4
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=4
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=4
+ac_cv_sizeof_ssize_t=4
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=4
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=4

+ 5 - 0
include/site/sparc-librecmc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/sparc-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 5 - 0
include/site/sparc-librecmc-linux-uclibc

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/sparc-linux
+. $TOPDIR/include/site/linux
+

+ 28 - 0
include/site/sparc-linux

@@ -0,0 +1,28 @@
+ac_cv_c_littleendian=${ac_cv_c_littleendian=no}
+ac_cv_c_bigendian=${ac_cv_c_bigendian=yes}
+
+ac_cv_sizeof___int64=0
+ac_cv_sizeof_char=1
+ac_cv_sizeof_int=4
+ac_cv_sizeof_int16_t=2
+ac_cv_sizeof_int32_t=4
+ac_cv_sizeof_int64_t=8
+ac_cv_sizeof_long_int=4
+ac_cv_sizeof_long_long=8
+ac_cv_sizeof_long=4
+ac_cv_sizeof_off_t=8
+ac_cv_sizeof_short_int=2
+ac_cv_sizeof_short=2
+ac_cv_sizeof_size_t=4
+ac_cv_sizeof_ssize_t=4
+ac_cv_sizeof_u_int16_t=2
+ac_cv_sizeof_u_int32_t=4
+ac_cv_sizeof_u_int64_t=8
+ac_cv_sizeof_uint16_t=2
+ac_cv_sizeof_uint32_t=4
+ac_cv_sizeof_uint64_t=8
+ac_cv_sizeof_unsigned_int=4
+ac_cv_sizeof_unsigned_long=4
+ac_cv_sizeof_unsigned_long_long=8
+ac_cv_sizeof_unsigned_short=2
+ac_cv_sizeof_void_p=4

+ 5 - 0
include/site/sparc-linux-gnu

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. $TOPDIR/include/site/sparc-linux
+. $TOPDIR/include/site/linux-gnu
+

+ 3 - 3
include/subdir.mk

@@ -37,13 +37,13 @@ define subdir
     $(foreach target,$(SUBTARGETS),
       $(foreach btype,$(buildtypes-$(bd)),
         $(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(btype)/$(target): $(if $(QUILT),,$($(1)/$(bd)/$(btype)/$(target)) $(call $(1)//$(btype)/$(target),$(1)/$(bd)/$(btype))))
-		  $(if $(call debug,$(1)/$(bd),v),,@)+$$(SUBMAKE) -C $(1)/$(bd) $(btype)-$(target) $(if $(findstring $(bd),$($(1)/builddirs-ignore-$(btype)-$(target))), || $(call ERROR,$(1),   ERROR: $(1)/$(bd) [$(btype)] failed to build.))
+		  $(if $(call debug,$(1)/$(bd),v),,@)+$$(SUBMAKE) -r -C $(1)/$(bd) $(btype)-$(target) $(if $(findstring $(bd),$($(1)/builddirs-ignore-$(btype)-$(target))), || $(call ERROR,$(1),   ERROR: $(1)/$(bd) [$(btype)] failed to build.))
         $(if $(call diralias,$(bd)),$(call warn_eval,$(1)/$(bd),l,T,$(1)/$(call diralias,$(bd))/$(btype)/$(target): $(1)/$(bd)/$(btype)/$(target)))
       )
       $(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(target): $(if $(QUILT),,$($(1)/$(bd)/$(target)) $(call $(1)//$(target),$(1)/$(bd))))
 	  	$(if $(BUILD_LOG),@mkdir -p $(BUILD_LOG_DIR)/$(1)/$(bd))
         $(foreach variant,$(if $(BUILD_VARIANT),$(BUILD_VARIANT),$(if $(strip $($(1)/$(bd)/variants)),$($(1)/$(bd)/variants),$(if $($(1)/$(bd)/default-variant),$($(1)/$(bd)/default-variant),__default))),
-			$(if $(call debug,$(1)/$(bd),v),,@)+$(if $(BUILD_LOG),set -o pipefail;) $$(SUBMAKE) -C $(1)/$(bd) $(target) BUILD_VARIANT="$(filter-out __default,$(variant))" $(if $(BUILD_LOG),SILENT= 2>&1 | tee $(BUILD_LOG_DIR)/$(1)/$(bd)/$(target).txt) $(if $(findstring $(bd),$($(1)/builddirs-ignore-$(target))), || $(call ERROR,$(1),   ERROR: $(1)/$(bd) failed to build$(if $(filter-out __default,$(variant)), (build variant: $(variant))).))
+			$(if $(call debug,$(1)/$(bd),v),,@)+$(if $(BUILD_LOG),set -o pipefail;) $$(SUBMAKE) -r -C $(1)/$(bd) $(target) BUILD_VARIANT="$(filter-out __default,$(variant))" $(if $(BUILD_LOG),SILENT= 2>&1 | tee $(BUILD_LOG_DIR)/$(1)/$(bd)/$(target).txt) $(if $(findstring $(bd),$($(1)/builddirs-ignore-$(target))), || $(call ERROR,$(1),   ERROR: $(1)/$(bd) failed to build$(if $(filter-out __default,$(variant)), (build variant: $(variant))).))
         )
       $(if $(PREREQ_ONLY)$(DUMP_TARGET_DB),,
         # aliases
@@ -57,7 +57,7 @@ endef
 ifndef DUMP_TARGET_DB
 # Parameters: <subdir> <name> <target> <depends> <config options> <stampfile location>
 define stampfile
-  $(1)/stamp-$(3):=$(if $(6),$(6),$(STAGING_DIR))/stamp/.$(2)_$(3)$(if $(5),_$(call confvar,$(5)))
+  $(1)/stamp-$(3):=$(if $(6),$(6),$(STAGING_DIR))/stamp/.$(2)_$(3)$(5)
   $$($(1)/stamp-$(3)): $(TMP_DIR)/.build $(4)
 	@+$(SCRIPT_DIR)/timestamp.pl -n $$($(1)/stamp-$(3)) $(1) $(4) || \
 		$(MAKE) $(if $(QUIET),--no-print-directory) $$($(1)/flags-$(3)) $(1)/$(3)

+ 24 - 12
include/target.mk

@@ -12,9 +12,11 @@ __target_inc=1
 DEVICE_TYPE?=router
 
 # Default packages - the really basic set
-DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg netifd
+DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg netifd fstools
+# For nas targets
+DEFAULT_PACKAGES.nas:=block-mount fdisk lvm2 lsblk mdadm
 # For router targets
-DEFAULT_PACKAGES.router:=dnsmasq iptables ip6tables ppp ppp-mod-pppoe kmod-ipt-nathelper firewall odhcpd odhcp6c
+DEFAULT_PACKAGES.router:=dnsmasq iptables ip6tables ppp ppp-mod-pppoe kmod-nf-nathelper firewall odhcpd odhcp6c
 DEFAULT_PACKAGES.bootloader:=
 
 ifneq ($(DUMP),)
@@ -51,6 +53,9 @@ endif
 # Add device specific packages (here below to allow device type set from subtarget)
 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
 
+filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
+extra_packages = $(if $(filter wpad-mini wpad nas,$(1)),iwinfo)
+
 define Profile/Default
   NAME:=
   PACKAGES:=
@@ -60,20 +65,20 @@ ifndef Profile
 define Profile
   $(eval $(call Profile/Default))
   $(eval $(call Profile/$(1)))
-  $(eval $(call shexport,Profile/$(1)/Config))
-  $(eval $(call shexport,Profile/$(1)/Description))
+  dumpinfo : $(call shexport,Profile/$(1)/Config)
+  dumpinfo : $(call shexport,Profile/$(1)/Description)
   DUMPINFO += \
 	echo "Target-Profile: $(1)"; \
 	echo "Target-Profile-Name: $(NAME)"; \
-	echo "Target-Profile-Packages: $(PACKAGES)"; \
+	echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
 	if [ -f ./config/profile-$(1) ]; then \
 		echo "Target-Profile-Kconfig: yes"; \
 	fi; \
 	echo "Target-Profile-Config: "; \
-	$(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Config)"; \
+	echo "$$$$$$$$$(call shvar,Profile/$(1)/Config)"; \
 	echo "@@"; \
 	echo "Target-Profile-Description:"; \
-	$(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Description)"; \
+	echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
 	echo "@@"; \
 	echo;
   ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_))$(1)),y)
@@ -101,8 +106,6 @@ else
   endif
 endif
 
-$(eval $(call shexport,Target/Description))
-
 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
   include $(INCLUDE_DIR)/kernel-version.mk
 endif
@@ -211,6 +214,8 @@ ifeq ($(DUMP),1)
     CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
     CPU_CFLAGS_24kec = -mips32r2 -mtune=24kec
     CPU_CFLAGS_34kc = -mips32r2 -mtune=34kc
+    CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
+    CPU_CFLAGS_octeon = -march=octeon -mabi=64
     CPU_CFLAGS_dsp = -mdsp
     CPU_CFLAGS_dsp2 = -mdspr2
   endif
@@ -225,9 +230,11 @@ ifeq ($(DUMP),1)
     CPU_CFLAGS_arm926ej-s = -march=armv5te -mtune=arm926ej-s
     CPU_CFLAGS_arm1136j-s = -march=armv6 -mtune=arm1136j-s
     CPU_CFLAGS_arm1176jzf-s = -march=armv6 -mtune=arm1176jzf-s
+    CPU_CFLAGS_cortex-a5 = -march=armv7-a -mtune=cortex-a5
     CPU_CFLAGS_cortex-a7 = -march=armv7-a -mtune=cortex-a7
     CPU_CFLAGS_cortex-a8 = -march=armv7-a -mtune=cortex-a8
     CPU_CFLAGS_cortex-a9 = -march=armv7-a -mtune=cortex-a9
+    CPU_CFLAGS_cortex-a15 = -march=armv7-a -mtune=cortex-a15
     CPU_CFLAGS_fa526 = -march=armv4 -mtune=fa526
     CPU_CFLAGS_mpcore = -march=armv6k -mtune=mpcore
     CPU_CFLAGS_xscale = -march=armv5te -mtune=xscale
@@ -247,11 +254,16 @@ ifeq ($(DUMP),1)
     CPU_TYPE = sparc
     CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
   endif
+  ifeq ($(ARCH),aarch64)
+    CPU_TYPE ?= armv8-a
+    CPU_CFLAGS_armv8-a = -mcpu=armv8-a
+  endif
   DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
 endif
 
 define BuildTargets/DumpCurrent
   .PHONY: dumpinfo
+  dumpinfo : export DESCRIPTION=$$(Target/Description)
   dumpinfo:
 	@echo 'Target: $(TARGETID)'; \
 	 echo 'Target-Board: $(BOARD)'; \
@@ -266,11 +278,11 @@ define BuildTargets/DumpCurrent
 	 echo 'Linux-Version: $(LINUX_VERSION)'; \
 	 echo 'Linux-Release: $(LINUX_RELEASE)'; \
 	 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
-	$(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; ))
+	$(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
 	 echo 'Target-Description:'; \
-	 $(SH_FUNC) getvar $(call shvar,Target/Description); \
+	 echo "$$$$DESCRIPTION"; \
 	 echo '@@'; \
-	 echo 'Default-Packages: $(DEFAULT_PACKAGES)'; \
+	 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
 	 $(DUMPINFO)
 	$(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
 endef

+ 16 - 1
include/toplevel.mk

@@ -6,7 +6,7 @@
 # See /LICENSE for more information.
 #
 
-RELEASE:=Delusional Dan
+RELEASE:=Elegant Eleanor
 PREP_MK= LIBRECMC_BUILD= QUIET=0
 
 export IS_TTY=$(shell tty -s && echo 1 || echo 0)
@@ -43,6 +43,8 @@ unexport LPATH
 # make sure that a predefined CFLAGS variable does not disturb packages
 export CFLAGS=
 
+unexport TAR_OPTIONS
+
 ifneq ($(shell $(HOSTCC) 2>&1 | grep clang),)
   export HOSTCC_REAL?=$(HOSTCC)
   export HOSTCC_WRAPPER:=$(TOPDIR)/scripts/clang-gcc-wrapper
@@ -71,7 +73,9 @@ prepare-tmpinfo: FORCE
 		f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
 		[ "$$t" -nt "$$f" ] || ./scripts/metadata.pl $${type}_config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
 	done
+	[ tmp/.config-feeds.in -nt tmp/.packagefeeds ] || ./scripts/feeds feed_config > tmp/.config-feeds.in
 	./scripts/metadata.pl package_mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
+	./scripts/metadata.pl package_feeds tmp/.packageinfo > tmp/.packagefeeds || { rm -f tmp/.packagefeeds; false; }
 	touch $(TOPDIR)/tmp/.build
 
 .config: ./scripts/config/conf $(if $(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
@@ -156,6 +160,15 @@ prereq:: prepare-tmpinfo .config
 	@+$(MAKE) -r -s tmp/.prereq-build $(PREP_MK)
 	@+$(NO_TRACE_MAKE) -r -s $@
 
+ifeq ($(SDK),1)
+
+%::
+	@+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
+	@./scripts/config/conf --defconfig=.config Config.in
+	@+$(ULIMIT_FIX) $(SUBMAKE) -r $@
+
+else
+
 %::
 	@+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
 	@( \
@@ -167,6 +180,8 @@ prereq:: prepare-tmpinfo .config
 	)
 	@+$(ULIMIT_FIX) $(SUBMAKE) -r $@
 
+endif
+
 help:
 	cat README
 

+ 26 - 7
include/version.mk

@@ -12,23 +12,37 @@ PKG_CONFIG_DEPENDS += \
 	CONFIG_VERSION_NUMBER \
 	CONFIG_VERSION_NICK \
 	CONFIG_VERSION_REPO \
-	CONFIG_VERSION_DIST
+	CONFIG_VERSION_DIST \
+	CONFIG_VERSION_MANUFACTURER \
+	CONFIG_VERSION_PRODUCT \
+	CONFIG_VERSION_HWREV \
 
-VERSION_NUMBER:=$(call qstrip,$(CONFIG_VERSION_NUMBER))
+qstrip_escape=$(subst ','\'',$(call qstrip,$(1)))
+#'
+
+VERSION_NUMBER:=$(call qstrip_escape,$(CONFIG_VERSION_NUMBER))
 VERSION_NUMBER:=$(if $(VERSION_NUMBER),$(VERSION_NUMBER),$(REVISION))
 
-VERSION_CODE:=$(call qstrip,$(CONFIG_VERSION_NUMBER))
+VERSION_CODE:=$(call qstrip_escape,$(CONFIG_VERSION_NUMBER))
 VERSION_CODE:=$(if $(VERSION_CODE),$(VERSION_CODE),Bleeding Edge)
 
-VERSION_NICK:=$(call qstrip,$(CONFIG_VERSION_NICK))
+VERSION_NICK:=$(call qstrip_escape,$(CONFIG_VERSION_NICK))
 VERSION_NICK:=$(if $(VERSION_NICK),$(VERSION_NICK),$(RELEASE))
 
-VERSION_REPO:=$(call qstrip,$(CONFIG_VERSION_REPO))
-VERSION_REPO:=$(if $(VERSION_REPO),$(VERSION_REPO),http://downloads.librecmc.org/snapshots/trunk/%T/packages)
+VERSION_REPO:=$(call qstrip_escape,$(CONFIG_VERSION_REPO))
+VERSION_REPO:=$(if $(VERSION_REPO),$(VERSION_REPO),http://downloads.openwrt.org/snapshots/trunk/%T/packages)
 
-VERSION_DIST:=$(call qstrip,$(CONFIG_VERSION_DIST))
+VERSION_DIST:=$(call qstrip_escape,$(CONFIG_VERSION_DIST))
 VERSION_DIST:=$(if $(VERSION_DIST),$(VERSION_DIST),libreCMC)
 
+VERSION_MANUFACTURER:=$(call qstrip_escape,$(CONFIG_VERSION_MANUFACTURER))
+VERSION_MANUFACTURER:=$(if $(VERSION_MANUFACTURER),$(VERSION_MANUFACTURER),libreCMC)
+
+VERSION_PRODUCT:=$(call qstrip_escape,$(CONFIG_VERSION_PRODUCT))
+VERSION_PRODUCT:=$(if $(VERSION_PRODUCT),$(VERSION_PRODUCT),Generic)
+
+VERSION_HWREV:=$(call qstrip_escape,$(CONFIG_VERSION_HWREV))
+VERSION_HWREV:=$(if $(VERSION_HWREV),$(VERSION_HWREV),v0)
 
 define taint2sym
 $(CONFIG_$(firstword $(subst :, ,$(subst +,,$(subst -,,$(1))))))
@@ -66,3 +80,8 @@ VERSION_SED:=$(SED) 's,%U,$(VERSION_REPO),g' \
 	-e 's,%T,$(BOARD),g' \
 	-e 's,%S,$(BOARD)/$(if $(SUBTARGET),$(SUBTARGET),generic),g' \
 	-e 's,%t,$(VERSION_TAINTS),g' \
+	-e 's,%M,$(VERSION_MANUFACTURER),g' \
+	-e 's,%P,$(VERSION_PRODUCT),g' \
+	-e 's,%h,$(VERSION_HWREV),g'
+
+VERSION_SED_SCRIPT:=$(subst '\'','\'\\\\\'\'',$(VERSION_SED))

+ 28 - 16
package/Makefile

@@ -7,20 +7,20 @@
 
 curdir:=package
 
+include $(INCLUDE_DIR)/feeds.mk
+
 -include $(TMP_DIR)/.packagedeps
 $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m))
 $(curdir)/builddirs-install:=.
-ifeq ($(SDK),1)
-else
-  $(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m))
-  $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
-endif
+$(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m))
+$(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
 ifneq ($(IGNORE_ERRORS),)
   package-y-filter := $(package-y)
   package-m-filter := $(filter-out $(package-y),$(package-m))
   package-n-filter := $(filter-out $(package-y) $(package-m),$(package-))
   package-ignore-errors := $(filter n m y,$(IGNORE_ERRORS))
   package-ignore-errors := $(if $(package-ignore-errors),$(package-ignore-errors),n m)
+  $(curdir)/builddirs-ignore-download := $(foreach m,$(package-ignore-errors),$(package-$(m)-filter))
   $(curdir)/builddirs-ignore-compile := $(foreach m,$(package-ignore-errors),$(package-$(m)-filter))
 endif
 
@@ -28,7 +28,7 @@ ifdef CONFIG_USE_MKLIBS
   define mklibs
 	rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
 	# first find all programs and add them to the mklibs list
-	find $(STAGING_DIR_ROOT) -type f -perm +100 -exec \
+	find $(STAGING_DIR_ROOT) -type f -perm /100 -exec \
 		file -r -N -F '' {} + | \
 		awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
 	# find all loadable objects that are not regular libraries and add them to the list as well
@@ -59,6 +59,7 @@ endif
 
 # where to build (and put) .ipk packages
 OPKG:= \
+  IPKG_NO_SCRIPT=1 \
   IPKG_TMP=$(TMP_DIR)/ipkg \
   IPKG_INSTROOT=$(TARGET_DIR) \
   IPKG_CONF_DIR=$(STAGING_DIR)/etc \
@@ -76,7 +77,7 @@ OPKG:= \
 PACKAGE_INSTALL_FILES:= \
 	$(foreach pkg,$(sort $(package-y)), \
 		$(foreach variant, \
-			$(if $(package/$(pkg)/variants), \
+			$(if $(strip $(package/$(pkg)/variants)), \
 				$(package/$(pkg)/variants), \
 				$(if $(package/$(pkg)/default-variant), \
 					$(package/$(pkg)/default-variant), \
@@ -94,7 +95,7 @@ $(curdir)/install: $(TMP_DIR)/.build
 	- find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
 	rm -rf $(TARGET_DIR)
 	[ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
-	@$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
+	@$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)$(if $(CONFIG_PER_FEED_REPO),/*)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
 	@for file in $(PACKAGE_INSTALL_FILES); do \
 		[ -s $$file.flags ] || continue; \
 		for flag in `cat $$file.flags`; do \
@@ -108,15 +109,15 @@ $(curdir)/install: $(TMP_DIR)/.build
 	@mkdir -p $(TARGET_DIR)/etc/rc.d
 	@( \
 		cd $(TARGET_DIR); \
-		for script in ./etc/init.d/*; do \
-			grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
-			IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) ./etc/rc.common $$script enable; \
+		for script in ./usr/lib/opkg/info/*.postinst; do \
+			IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
 		done || true \
 	)
 	@-find $(TARGET_DIR) -name CVS   | $(XARGS) rm -rf
 	@-find $(TARGET_DIR) -name .svn  | $(XARGS) rm -rf
 	@-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f
-	rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
+	rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst*
+	rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.prerm*
 	$(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
 	$(call mklibs)
 
@@ -129,11 +130,19 @@ ifndef CONFIG_OPKGSMIME_PASSPHRASE
   endif
 endif
 
+PACKAGE_SUBDIRS=.
+ifneq ($(CONFIG_PER_FEED_REPO),)
+  PACKAGE_SUBDIRS=base $(FEEDS_ENABLED)
+endif
+
 $(curdir)/index: FORCE
 	@echo Generating package index...
-	@(cd $(PACKAGE_DIR); \
+	@for d in $(PACKAGE_SUBDIRS); do ( \
+		[ -d $(PACKAGE_DIR)/$$d ] && \
+			cd $(PACKAGE_DIR)/$$d || continue; \
 		$(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
-		gzip -9c Packages > Packages.gz )
+			gzip -9c Packages > Packages.gz; \
+	); done
 ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_KEY)),)
 	@echo Signing key has not been configured
 else
@@ -141,12 +150,15 @@ ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_CERT)),)
 	@echo Certificate has not been configured
 else
 	@echo Signing package index...
-	@(cd $(PACKAGE_DIR); \
+	@for d in $(PACKAGE_SUBDIRS); do ( \
+		[ -d $(PACKAGE_DIR)/$$d ] && \
+			cd $(PACKAGE_DIR)/$$d || continue; \
 		openssl smime -binary -in Packages.gz \
 			-out Packages.sig -outform PEM -sign \
 			-signer $(CONFIG_OPKGSMIME_CERT) \
 			-inkey $(CONFIG_OPKGSMIME_KEY) \
-			$(PASSOPT) $(PASSARG) )
+			$(PASSOPT) $(PASSARG); \
+	); done
 endif
 endif
 

+ 13 - 9
package/base-files/Makefile

@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2007-2013 OpenWrt.org
+# Copyright (C) 2007-2014 OpenWrt.org
 # Copyright (C) 2010 Vertical Communications
 #
 # This is free software, licensed under the GNU General Public License v2.
@@ -11,10 +11,11 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/kernel.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=151
+PKG_RELEASE:=157
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
 PKG_BUILD_DEPENDS:=opkg/host
+PKG_LICENSE:=GPL-2.0
 
 include $(INCLUDE_DIR)/package.mk
 
@@ -28,9 +29,9 @@ endif
 define Package/base-files
   SECTION:=base
   CATEGORY:=Base system
-  DEPENDS:=+netifd +libc +procd
+  DEPENDS:=+netifd +libc +procd +jsonfilter
   TITLE:=Base filesystem for libreCMC
-  URL:=http://librecmc.org/
+  URL:=http://openwrt.org/
   VERSION:=$(PKG_RELEASE)-$(REVISION)
 endef
 
@@ -110,8 +111,11 @@ define Package/base-files/install
 
 	$(VERSION_SED) \
 		$(1)/etc/banner \
-		$(1)/etc/librecmc_version \
-		$(1)/etc/librecmc_release
+		$(1)/etc/librecmc_version
+
+	$(VERSION_SED_SCRIPT) \
+		$(1)/etc/librecmc_release \
+		$(1)/etc/device_info
 
 	mkdir -p $(1)/CONTROL
 	mkdir -p $(1)/dev
@@ -129,11 +133,11 @@ define Package/base-files/install
 	mkdir -p $(1)/sys
 	mkdir -p $(1)/www
 	mkdir -p $(1)/root
-	ln -sf /proc/mounts $(1)/etc/mtab
+	$(LN) /proc/mounts $(1)/etc/mtab
 	rm -f $(1)/var
-	ln -sf /tmp $(1)/var
+	$(LN) /tmp $(1)/var
 	mkdir -p $(1)/etc
-	ln -sf /tmp/resolv.conf /tmp/fstab /tmp/TZ $(1)/etc/
+	$(LN) /tmp/resolv.conf /tmp/fstab /tmp/TZ $(1)/etc/
 
 	chmod 0600 $(1)/etc/shadow
 	chmod 1777 $(1)/tmp

+ 14 - 0
package/base-files/files/bin/board_detect

@@ -0,0 +1,14 @@
+#!/bin/sh
+
+[ -d "/etc/board.d/" -a ! -f "/etc/board.json" ] && {
+	for a in `ls /etc/board.d/*`; do
+		[ -x $a ] || continue;
+		$(. $a)
+	done
+}
+
+[ -f "/etc/board.json" ] || return 1
+[ -f "/etc/config/network" ] || {
+	touch /etc/config/network
+	/bin/config_generate
+}

+ 172 - 0
package/base-files/files/bin/config_generate

@@ -0,0 +1,172 @@
+#!/bin/sh
+
+CFG=/etc/board.json
+
+. /usr/share/libubox/jshn.sh
+
+[ -f $CFG ] || exit 1
+
+generate_static_network() {
+	uci -q batch <<EOF
+delete network.loopback
+set network.loopback='interface'
+set network.loopback.ifname='lo'
+set network.loopback.proto='static'
+set network.loopback.ipaddr='127.0.0.1'
+set network.loopback.netmask='255.0.0.0'
+delete network.globals
+set network.globals='globals'
+set network.globals.ula_prefix='auto'
+EOF
+}
+
+next_vlan=3
+generate_network() {
+	local vlan
+
+	json_select network
+	json_select $1
+	json_get_vars ifname create_vlan macaddr
+	json_select ..
+	json_select ..
+
+	[ -n "$ifname" ] || return
+	[ "$create_vlan" -eq 1 ] && case $1 in
+	lan) vlan=1;;
+	wan) vlan=2;;
+	*)
+		vlan=$next_vlan
+		next_vlan=$((next_vlan + 1))
+		;;
+	esac
+	[ -n "$vlan" ] && ifname=${ifname}.${vlan}
+	uci -q batch <<EOF
+delete network.$1
+set network.$1='interface'
+set network.$1.ifname='$ifname'
+set network.$1.force_link=1
+set network.$1.proto='none'
+set network.$1.macaddr='$macaddr'
+EOF
+
+	case $1 in
+	lan) uci -q batch <<EOF
+set network.$1.type='bridge'
+set network.$1.proto='static'
+set network.$1.ipaddr='192.168.1.1'
+set network.$1.netmask='255.255.255.0'
+set network.$1.ip6assign='60'
+EOF
+		;;
+	wan) uci -q batch <<EOF
+set network.$1.proto='dhcp'
+delete network.wan6
+set network.wan6='interface'
+set network.wan6.ifname='$ifname'
+set network.wan6.proto='dhcpv6'
+EOF
+		;;
+	esac
+}
+
+generate_switch_vlan() {
+	local device=$1
+	local vlan=$2
+	local cpu_port=$3
+
+	case $vlan in
+	lan)	vlan=1;;
+	wan)	vlan=2;;
+	*)	vlan=${vlan##vlan};;
+	esac
+
+	json_select vlans
+	json_select $2
+	json_get_values ports
+	json_select ..
+	json_select ..
+
+	uci -q batch <<EOF
+add network switch_vlan
+set network.@switch_vlan[-1].device='$device'
+set network.@switch_vlan[-1].vlan='$vlan'
+set network.@switch_vlan[-1].ports='$ports ${cpu_port}t'
+EOF
+}
+
+generate_switch() {
+	local key=$1
+	local vlans
+
+	json_select switch
+	json_select $key
+	json_get_vars enable reset blinkrate cpu_port
+
+	uci -q batch <<EOF
+add network switch
+set network.@switch[-1].name='$key'
+set network.@switch[-1].reset='$reset'
+set network.@switch[-1].enable_vlan='$enable'
+set network.@switch[-1].blinkrate='$blinkrate'
+EOF
+	[ -n "$cpu_port" ] && {
+		json_get_keys vlans vlans
+		for vlan in $vlans; do generate_switch_vlan $1 $vlan $cpu_port; done
+	}
+	json_select ..
+	json_select ..
+}
+
+generate_led() {
+	local key=$1
+	local cfg="led_$key"
+
+	json_select led
+	json_select $key
+	json_get_vars name sysfs type trigger device interface default
+	json_select ..
+	json_select ..
+
+	uci -q batch <<EOF
+delete system.$cfg
+set system.$cfg='led'
+set system.$cfg.name='$name'
+set system.$cfg.sysfs='$sysfs'
+set system.$cfg.dev='$device'
+set system.$cfg.trigger='$trigger'
+set system.$cfg.port_mask='$port_mask'
+set system.$cfg.default='$default'
+EOF
+	case $type in
+	netdev)
+		uci -q batch <<EOF
+set system.$cfg.trigger='netdev'
+set system.$cfg.mode='link tx rx'
+EOF
+	;;
+
+	usb)
+		uci -q batch <<EOF
+set system.$cfg.trigger='usbdev'
+set system.$cfg.interval='50'
+EOF
+	;;
+
+	esac
+}
+
+json_init
+json_load "$(cat ${CFG})"
+
+generate_static_network
+
+json_get_keys keys network
+for key in $keys; do generate_network $key; done
+
+json_get_keys keys switch
+for key in $keys; do generate_switch $key; done
+
+json_get_keys keys led
+for key in $keys; do generate_led $key; done
+
+uci commit

+ 2 - 2
package/base-files/files/bin/login.sh

@@ -1,8 +1,8 @@
 #!/bin/sh
 # Copyright (C) 2006-2011 OpenWrt.org
 
-if ( ! grep -qs '^root:[!x]\?:' /etc/shadow || \
-     ! grep -qs '^root:[!x]\?:' /etc/passwd ) && \
+if ( ! grep -qsE '^root:[!x]?:' /etc/shadow || \
+     ! grep -qsE '^root:[!x]?:' /etc/passwd ) && \
    [ -z "$FAILSAFE" ]
 then
 	echo "Login failed."

+ 13 - 0
package/base-files/files/etc/banner.failsafe

@@ -0,0 +1,13 @@
+================= FAILSAFE MODE active ================
+special commands:
+* firstboot	     reset settings to factory defaults
+* mount_root	 mount root-partition with config files
+
+after mount_root:
+* passwd			 change root's password
+* /etc/config		    directory with config files
+
+for more help see:
+http://wiki.openwrt.org/doc/howto/generic.failsafe
+=======================================================
+

+ 0 - 4
package/base-files/files/etc/config/network

@@ -14,9 +14,5 @@ config interface lan
 	option netmask	255.255.255.0
 	option ip6assign 60
 
-config interface wan6
-	option ifname	@wan
-	option proto	dhcpv6
-
 config globals globals
 	option ula_prefix auto

+ 1 - 0
package/base-files/files/etc/config/system

@@ -7,4 +7,5 @@ config timeserver ntp
 	list server	1.librecmc.pool.ntp.org
 	list server	2.librecmc.pool.ntp.org
 	list server	3.librecmc.pool.ntp.org
+	option enabled 1
 	option enable_server 0

+ 3 - 0
package/base-files/files/etc/device_info

@@ -0,0 +1,3 @@
+DEVICE_MANUFACTURER='%M'
+DEVICE_PRODUCT='%P'
+DEVICE_REVISION='%h'

+ 15 - 3
package/base-files/files/etc/init.d/boot

@@ -4,6 +4,19 @@
 START=10
 STOP=98
 
+uci_apply_defaults() {
+	. /lib/functions/system.sh
+
+	cd /etc/uci-defaults || return 0
+	files="$(ls)"
+	[ -z "$files" ] && return 0
+	mkdir -p /tmp/.uci
+	for file in $files; do
+		( . "./$(basename $file)" ) && rm -f "$file"
+	done
+	uci commit
+}
+
 boot() {
 	[ -f /proc/mounts ] || /sbin/mount_root
 	[ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
@@ -33,13 +46,12 @@ boot() {
 	}
 	rm -f /tmp/wireless.tmp
 
-	sh -c '. /lib/functions.sh; include /lib/config; uci_apply_defaults'
+	/bin/board_detect
+	uci_apply_defaults
 	
 	# temporary hack until configd exists
 	/sbin/reload_config
 
-	start
-
 	# create /dev/root if it doesn't exist
 	[ -e /dev/root -o -h /dev/root ] || {
 		rootdev=$(awk 'BEGIN { RS=" "; FS="="; } $1 == "root" { print $2 }' < /proc/cmdline)

+ 1 - 5
package/base-files/files/etc/init.d/done

@@ -3,11 +3,7 @@
 
 START=95
 boot() {
-	[ -d /tmp/root ] && {
-		lock /tmp/.switch2jffs
-		switch2jffs
-		lock -u /tmp/.switch2jffs
-	}
+	[ -d /tmp/root ] && mount_root done
 
 	# process user commands
 	[ -f /etc/rc.local ] && {

+ 1 - 1
package/base-files/files/etc/init.d/led

@@ -1,5 +1,5 @@
 #!/bin/sh /etc/rc.common
-# (C) 2008 librecmc.org
+# Copyright (C) 2008 OpenWrt.org
 
 START=96
 

+ 2 - 4
package/base-files/files/etc/init.d/sysfixtime

@@ -5,9 +5,7 @@ START=00
 
 boot() {
 	local curtime="$(date +%s)"
-	local maxtime="$(find /etc -type f -exec date +%s -r {} \; | sort -nr | head -n1)"
-	[ $curtime -lt $maxtime ] && \
-		date -s @$maxtime && \
-		logger -t sysfixtime -p daemon.notice "Time fixed"
+	local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)"
+	[ $curtime -lt $maxtime ] && date -s @$maxtime
 }
 

+ 0 - 2
package/base-files/files/etc/init.d/system

@@ -12,8 +12,6 @@ validate_system_section()
 		'buffersize:uinteger' \
 		'timezone:string:UTC' \
 		'zonename:string'
-
-	return $?
 }
 
 system_config() {

+ 7 - 7
package/base-files/files/etc/librecmc_release

@@ -1,7 +1,7 @@
-DISTRIB_ID="%D"
-DISTRIB_RELEASE="%C"
-DISTRIB_REVISION="%R"
-DISTRIB_CODENAME="%n"
-DISTRIB_TARGET="%S"
-DISTRIB_DESCRIPTION="%D %N %V"
-DISTRIB_TAINTS="%t"
+DISTRIB_ID='%D'
+DISTRIB_RELEASE='%C'
+DISTRIB_REVISION='%R'
+DISTRIB_CODENAME='%n'
+DISTRIB_TARGET='%S'
+DISTRIB_DESCRIPTION='%D %N %V'
+DISTRIB_TAINTS='%t'

+ 2 - 0
package/base-files/files/etc/preinit

@@ -24,6 +24,8 @@ pi_init_path="/bin:/sbin:/usr/bin:/usr/sbin"
 pi_init_cmd="/sbin/init"
 
 . /lib/functions.sh
+. /lib/functions/preinit.sh
+. /lib/functions/system.sh
 
 boot_hook_init preinit_essential
 boot_hook_init preinit_main

+ 1 - 0
package/base-files/files/etc/profile

@@ -1,5 +1,6 @@
 #!/bin/sh
 [ -f /etc/banner ] && cat /etc/banner
+[ -e /tmp/.failsafe ] && cat /etc/banner.failsafe
 
 export PATH=/usr/bin:/usr/sbin:/bin:/sbin
 export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)

+ 5 - 0
package/base-files/files/etc/rc.button/power

@@ -0,0 +1,5 @@
+#!/bin/sh
+
+[ "${ACTION}" = "released" ] || exit 0
+
+exec /sbin/poweroff

+ 5 - 6
package/base-files/files/etc/rc.common

@@ -92,10 +92,6 @@ service_running() {
 	return 0
 }
 
-stop_service() {
-	return 0
-}
-
 ${INIT_TRACE:+set -x}
 
 . "$initscript"
@@ -113,18 +109,21 @@ ${INIT_TRACE:+set -x}
 
 	start() {
 		rc_procd start_service "$@"
+		if eval "type service_started" 2>/dev/null >/dev/null; then
+			service_started
+		fi
 	}
 
 	stop() {
-		procd_kill "$(basename ${basescript:-$initscript})" "$1"
 		stop_service "$@"
+		procd_kill "$(basename ${basescript:-$initscript})" "$1"
 	}
 
 	reload() {
 		if eval "type reload_service" 2>/dev/null >/dev/null; then
 			reload_service "$@"
 		else
-			restart
+			start
 		fi
 	}
 

+ 3 - 1
package/base-files/files/etc/sysctl.conf

@@ -4,6 +4,7 @@ net.ipv4.conf.all.arp_ignore=1
 net.ipv4.ip_forward=1
 net.ipv4.icmp_echo_ignore_broadcasts=1
 net.ipv4.icmp_ignore_bogus_error_responses=1
+net.ipv4.igmp_max_memberships=100
 net.ipv4.tcp_ecn=0
 net.ipv4.tcp_fin_timeout=30
 net.ipv4.tcp_keepalive_time=120
@@ -18,9 +19,10 @@ net.ipv6.conf.all.forwarding=1
 net.netfilter.nf_conntrack_acct=1
 net.netfilter.nf_conntrack_checksum=0
 net.netfilter.nf_conntrack_max=16384
-net.netfilter.nf_conntrack_tcp_timeout_established=3600
+net.netfilter.nf_conntrack_tcp_timeout_established=7440
 net.netfilter.nf_conntrack_udp_timeout=60
 net.netfilter.nf_conntrack_udp_timeout_stream=180
+net.netfilter.nf_conntrack_skip_filter=1
 
 # disable bridge firewalling by default
 net.bridge.bridge-nf-call-arptables=0

+ 1 - 1
package/base-files/files/etc/uci-defaults/12_network-generate-ula

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-[ "$(uci get network.globals.ula_prefix)" != "auto" ] && exit 0
+[ "$(uci -q get network.globals.ula_prefix)" != "auto" ] && exit 0
 
 r1=$(dd if=/dev/urandom bs=1 count=1 |hexdump -e '1/1 "%02x"')
 r2=$(dd if=/dev/urandom bs=2 count=1 |hexdump -e '2/1 "%02x"')

+ 100 - 388
package/base-files/files/lib/functions.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (C) 2006-2013 OpenWrt.org
+# Copyright (C) 2006-2014 OpenWrt.org
 # Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
 # Copyright (C) 2010 Vertical Communications
 
@@ -17,10 +17,6 @@ NO_EXPORT=1
 LOAD_STATE=1
 LIST_SEP=" "
 
-hotplug_dev() {
-	env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug-call net
-}
-
 append() {
 	local var="$1"
 	local value="$2"
@@ -38,21 +34,6 @@ list_contains() {
 	[ "${val%% $str *}" != "$val" ]
 }
 
-list_remove() {
-	local var="$1"
-	local remove="$2"
-	local val
-
-	eval "val=\" \${$var} \""
-	val1="${val%% $remove *}"
-	[ "$val1" = "$val" ] && return
-	val2="${val##* $remove }"
-	[ "$val2" = "$val" ] && return
-	val="${val1## } ${val2%% }"
-	val="${val%% }"
-	eval "export ${NO_EXPORT:+-n} -- \"$var=\$val\""
-}
-
 config_load() {
 	[ -n "$IPKG_INSTROOT" ] && return 0
 	uci_load "$@"
@@ -103,41 +84,10 @@ list() {
 	list_cb "$varname" "$*"
 }
 
-config_rename() {
-	local OLD="$1"
-	local NEW="$2"
-	local oldvar
-	local newvar
-
-	[ -n "$OLD" -a -n "$NEW" ] || return
-	for oldvar in `set | grep ^CONFIG_${OLD}_ | \
-		sed -e 's/\(.*\)=.*$/\1/'` ; do
-		newvar="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}"
-		eval "export ${NO_EXPORT:+-n} \"$newvar=\${$oldvar}\""
-		unset "$oldvar"
-	done
-	export ${NO_EXPORT:+-n} CONFIG_SECTIONS="$(echo " $CONFIG_SECTIONS " | sed -e "s, $OLD , $NEW ,")"
-
-	[ "$CONFIG_SECTION" = "$OLD" ] && export ${NO_EXPORT:+-n} CONFIG_SECTION="$NEW"
-}
-
 config_unset() {
 	config_set "$1" "$2" ""
 }
 
-config_clear() {
-	local SECTION="$1"
-	local oldvar
-
-	list_remove CONFIG_SECTIONS "$SECTION"
-	export ${NO_EXPORT:+-n} CONFIG_SECTIONS="${SECTION:+$CONFIG_SECTIONS}"
-
-	for oldvar in `set | grep ^CONFIG_${SECTION:+${SECTION}_} | \
-		sed -e 's/\(.*\)=.*$/\1/'` ; do
-		unset $oldvar
-	done
-}
-
 # config_get <variable> <section> <option> [<default>]
 # config_get <section> <option>
 config_get() {
@@ -152,8 +102,8 @@ config_get_bool() {
 	local _tmp
 	config_get _tmp "$2" "$3" "$4"
 	case "$_tmp" in
-		1|on|true|enabled) _tmp=1;;
-		0|off|false|disabled) _tmp=0;;
+		1|on|true|yes|enabled) _tmp=1;;
+		0|off|false|no|disabled) _tmp=0;;
 		*) _tmp="$4";;
 	esac
 	export ${NO_EXPORT:+-n} "$1=$_tmp"
@@ -210,6 +160,71 @@ insert_modules() {
 	}
 }
 
+default_prerm() {
+	local name
+	name=$(echo $(basename $1) | cut -d. -f1)
+	[ -f /usr/lib/opkg/info/${name}.prerm-pkg ] && . /usr/lib/opkg/info/${name}.prerm-pkg
+	for i in `cat /usr/lib/opkg/info/${name}.list | grep "^/etc/init.d/"`; do
+		$i disable
+		$i stop
+	done
+}
+
+default_postinst() {
+	local name rusers
+	name=$(echo $(basename $1) | cut -d. -f1)
+	rusers=$(grep "Require-User:" ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.control)
+	[ -n "$rusers" ] && {
+		local user group uid gid
+		for a in $(echo $rusers | sed "s/Require-User://g"); do
+			user=""
+			group=""
+			for b in $(echo $a | sed "s/:/ /g"); do
+				local name id
+
+				name=$(echo $b | cut -d= -f1)
+				id=$(echo $b | cut -d= -f2)
+
+				[ -z "$user" ] && {
+					user=$name
+					uid=$id
+					continue
+				}
+
+				gid=$id
+				[ -n "$gid" ] && {
+					group_exists $name || group_add $name $gid
+				}
+
+				[ -z "$gid" ] && {
+					group_add_next $name
+					gid=$?
+				}
+
+				[ -z "$group" ] && {
+					user_exists $user || user_add $user "$uid" $gid
+					group=$name
+					continue
+				}
+
+				group_add_user $name $user
+			done
+		done
+	}
+
+	[ -f ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.postinst-pkg ] && ( . ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.postinst-pkg )
+	[ -n "${IPKG_INSTROOT}" ] || rm -f /tmp/luci-indexcache 2>/dev/null
+
+	[ "$PKG_UPGRADE" = "1" ] || for i in `cat ${IPKG_INSTROOT}/usr/lib/opkg/info/${name}.list | grep "^/etc/init.d/"`; do
+		[ -n "${IPKG_INSTROOT}" ] && $(which bash) ${IPKG_INSTROOT}/etc/rc.common ${IPKG_INSTROOT}$i enable; \
+		[ -n "${IPKG_INSTROOT}" ] || {
+			$i enable
+			$i start
+		}
+	done
+	return 0
+}
+
 include() {
 	local file
 
@@ -233,182 +248,6 @@ find_mtd_part() {
 	echo "${INDEX:+$PREFIX$INDEX}"
 }
 
-find_mtd_chardev() {
-	local INDEX=$(find_mtd_index "$1")
-	local PREFIX=/dev/mtd
-
-	[ -d /dev/mtd ] && PREFIX=/dev/mtd/
-	echo "${INDEX:+$PREFIX$INDEX}"
-}
-
-mtd_get_mac_ascii()
-{
-	local mtdname="$1"
-	local key="$2"
-	local part
-	local mac_dirty
-
-	part=$(find_mtd_part "$mtdname")
-	if [ -z "$part" ]; then
-		echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
-		return
-	fi
-
-	mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
-
-	# "canonicalize" mac
-	[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
-}
-
-mtd_get_blob()
-{
-	local mtdname="$1"
-	local offset="$2"
-	local count="$3"
-	local firmware="$4"
-	local part
-
-	part=$(find_mtd_part "$mtdname")
-	if [ -z "$part" ]; then
-		echo "mtd_get_blob: partition $mtdname not found!" >&2
-		return 1
-	fi
-
-	dd if=$part of=$firmware bs=1 skip=$offset count=$count 2>/dev/null || {
-		echo "mtd_get_blob: failed to extract $firmware from $part" >&2
-		return 1
-	}
-}
-
-mtd_get_mac_binary() {
-	local mtdname="$1"
-	local offset="$2"
-	local part
-
-	part=$(find_mtd_part "$mtdname")
-	if [ -z "$part" ]; then
-		echo "mtd_get_mac_binary: partition $mtdname not found!" >&2
-		return
-	fi
-
-	dd bs=1 skip=$offset count=6 if=$part 2>/dev/null | hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"'
-}
-
-mtd_get_part_size() {
-	local part_name=$1
-	local first dev size erasesize name
-	while read dev size erasesize name; do
-		name=${name#'"'}; name=${name%'"'}
-		if [ "$name" = "$part_name" ]; then
-			echo $((0x$size))
-			break
-		fi
-	done < /proc/mtd
-}
-
-macaddr_add() {
-	local mac=$1
-	local val=$2
-	local oui=${mac%:*:*:*}
-	local nic=${mac#*:*:*:}
-
-	nic=$(printf "%06x" $((0x${nic//:/} + $val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
-	echo $oui:$nic
-}
-
-macaddr_setbit_la()
-{
-	local mac=$1
-
-	printf "%02x:%s" $((0x${mac%%:*} | 0x02)) ${mac#*:}
-}
-
-macaddr_2bin()
-{
-	local mac=$1
-
-	echo -ne \\x${mac//:/\\x}
-}
-
-macaddr_canonicalize()
-{
-	local mac="$1"
-	local canon=""
-
-	[ ${#mac} -gt 17 ] && return
-	[ -n "${mac//[a-fA-F0-9\.: -]/}" ] && return
-
-	for octet in ${mac//[\.:-]/ }; do
-		case "${#octet}" in
-		1)
-			octet="0${octet}"
-			;;
-		2)
-			;;
-		4)
-			octet="${octet:0:2} ${octet:2:2}"
-			;;
-		12)
-			octet="${octet:0:2} ${octet:2:2} ${octet:4:2} ${octet:6:2} ${octet:8:2} ${octet:10:2}"
-			;;
-		*)
-			return
-			;;
-		esac
-		canon=${canon}${canon:+ }${octet}
-	done
-
-	[ ${#canon} -ne 17 ] && return
-
-	printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${canon// / 0x} 2>/dev/null
-}
-
-strtok() { # <string> { <variable> [<separator>] ... }
-	local tmp
-	local val="$1"
-	local count=0
-
-	shift
-
-	while [ $# -gt 1 ]; do
-		tmp="${val%%$2*}"
-
-		[ "$tmp" = "$val" ] && break
-
-		val="${val#$tmp$2}"
-
-		export ${NO_EXPORT:+-n} "$1=$tmp"; count=$((count+1))
-		shift 2
-	done
-
-	if [ $# -gt 0 -a -n "$val" ]; then
-		export ${NO_EXPORT:+-n} "$1=$val"; count=$((count+1))
-	fi
-
-	return $count
-}
-
-
-jffs2_mark_erase() {
-	local part="$(find_mtd_part "$1")"
-	[ -z "$part" ] && {
-		echo Partition not found.
-		return 1
-	}
-	echo -e "\xde\xad\xc0\xde" | mtd -qq write - "$1"
-}
-
-uci_apply_defaults() {
-	cd /etc/uci-defaults || return 0
-	files="$(ls)"
-	[ -z "$files" ] && return 0
-	mkdir -p /tmp/.uci
-	for file in $files; do
-		( . "./$(basename $file)" ) && rm -f "$file"
-	done
-	uci commit
-}
-
 group_add() {
 	local name="$1"
 	local gid="$2"
@@ -425,14 +264,45 @@ group_exists() {
 	grep -qs "^${1}:" ${IPKG_INSTROOT}/etc/group
 }
 
+group_add_next() {
+	local gid gids
+	gid=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
+	[ -n "$gid" ] && return $gid
+	gids=$(cat ${IPKG_INSTROOT}/etc/group | cut -d: -f3)
+	gid=100
+	while [ -n "$(echo $gids | grep $gid)" ] ; do
+	        gid=$((gid + 1))
+	done
+	group_add $1 $gid
+	return $gid
+}
+
+group_add_user() {
+	local grp delim=","
+	grp=$(grep -s "^${1}:" ${IPKG_INSTROOT}/etc/group)
+	[ -z "$(echo $grp | cut -d: -f4 | grep $2)" ] || return
+	[ -n "$(echo $grp | grep ":$")" ] && delim=""
+	[ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd
+	sed -i "s/$grp/$grp$delim$2/g" ${IPKG_INSTROOT}/etc/group
+	[ -n "$IPKG_INSTROOT" ] || lock -u /var/lock/passwd
+}
+
 user_add() {
 	local name="${1}"
 	local uid="${2}"
-	local gid="${3:-$2}"
+	local gid="${3}"
 	local desc="${4:-$1}"
 	local home="${5:-/var/run/$1}"
 	local shell="${6:-/bin/false}"
 	local rc
+	[ -z "$uid" ] && {
+		uids=$(cat ${IPKG_INSTROOT}/etc/passwd | cut -d: -f3)
+		uid=100
+		while [ -n "$(echo $uids | grep $uid)" ] ; do
+		        uid=$((uid + 1))
+		done
+	}
+	[ -z "$gid" ] && gid=$uid
 	[ -f "${IPKG_INSTROOT}/etc/passwd" ] || return 1
 	[ -n "$IPKG_INSTROOT" ] || lock /var/lock/passwd
 	echo "${name}:x:${uid}:${gid}:${desc}:${home}:${shell}" >> ${IPKG_INSTROOT}/etc/passwd
@@ -446,162 +316,4 @@ user_exists() {
 	grep -qs "^${1}:" ${IPKG_INSTROOT}/etc/passwd
 }
 
-
-pi_include() {
-	if [ -f "/tmp/overlay/$1" ]; then
-		. "/tmp/overlay/$1"
-	elif [ -f "$1" ]; then
-		. "$1"
-	elif [ -d "/tmp/overlay/$1" ]; then
-		if [ -n "$(ls /tmp/overlay/$1/*.sh 2>/dev/null)" ]; then
-			for src_script in /tmp/overlay/$1/*.sh; do
-				. "$src_script"
-			done
-		fi
-	elif [ -d "$1" ]; then
-		if [ -n "$(ls $1/*.sh 2>/dev/null)" ]; then
-			for src_script in $1/*.sh; do
-				. "$src_script"
-			done
-		fi
-	else
-		echo "WARNING: $1 not found"
-		return 1
-	fi
-	return 0
-}
-
-boot_hook_splice_start() {
-	export -n PI_HOOK_SPLICE=1
-}
-
-boot_hook_splice_finish() {
-	local hook
-	for hook in $PI_STACK_LIST; do
-		local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook"
-		export -n "${hook}=${v% }"
-		export -n "${hook}_splice="
-	done
-	export -n PI_HOOK_SPLICE=
-}
-
-boot_hook_init() {
-	local hook="${1}_hook"
-	export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook"
-	export -n "$hook="
-}
-
-boot_hook_add() {
-	local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}"
-	local func="${2}"
-
-	[ -n "$func" ] && {
-		local v; eval "v=\$$hook"
-		export -n "$hook=${v:+$v }$func"
-	}
-}
-
-boot_hook_shift() {
-	local hook="${1}_hook"
-	local rvar="${2}"
-
-	local v; eval "v=\$$hook"
-	[ -n "$v" ] && {
-		local first="${v%% *}"
-
-		[ "$v" != "${v#* }" ] && \
-			export -n "$hook=${v#* }" || \
-			export -n "$hook="
-
-		export -n "$rvar=$first"
-		return 0
-	}
-
-	return 1
-}
-
-boot_run_hook() {
-	local hook="$1"
-	local func
-
-	while boot_hook_shift "$hook" func; do
-		local ran; eval "ran=\$PI_RAN_$func"
-		[ -n "$ran" ] || {
-			export -n "PI_RAN_$func=1"
-			$func "$1" "$2"
-		}
-	done
-}
-
-jffs2_ready() {
-	mtdpart="$(find_mtd_part rootfs_data)"
-	[ -z "$mtdpart" ] && return 1
-	magic=$(hexdump $mtdpart -n 4 -e '4/1 "%02x"')
-	[ "$magic" != "deadc0de" ]
-}
-
-dupe() { # <new_root> <old_root>
-	cd $1
-	echo -n "creating directories... "
-	{
-		cd $2
-		find . -xdev -type d
-		echo "./dev ./overlay ./mnt ./proc ./tmp"
-		# xdev skips mounted directories
-		cd $1
-	} | xargs mkdir -p
-	echo "done"
-
-	echo -n "setting up symlinks... "
-	for file in $(cd $2; find . -xdev -type f;); do
-		case "$file" in
-		./rom/note) ;; #nothing
-		./etc/config*|\
-		./usr/lib/opkg/info/*) cp -af $2/$file $file;;
-		*) ln -sf /rom/${file#./*} $file;;
-		esac
-	done
-	for file in $(cd $2; find . -xdev -type l;); do
-		cp -af $2/${file#./*} $file
-	done
-	echo "done"
-}
-
-pivot() { # <new_root> <old_root>
-	/bin/mount -o noatime,move /proc $1/proc && \
-	pivot_root $1 $1$2 && {
-		/bin/mount -o noatime,move $2/dev /dev
-		/bin/mount -o noatime,move $2/tmp /tmp
-		/bin/mount -o noatime,move $2/sys /sys 2>&-
-		/bin/mount -o noatime,move $2/overlay /overlay 2>&-
-		return 0
-	}
-}
-
-fopivot() { # <rw_root> <ro_root> <dupe?>
-	root=$1
-	{
-		if grep -q overlay /proc/filesystems; then
-			/bin/mount -o noatime,lowerdir=/,upperdir=$1 -t overlayfs "overlayfs:$1" /mnt && root=/mnt
-		elif grep -q mini_fo /proc/filesystems; then
-			/bin/mount -t mini_fo -o noatime,base=/,sto=$1 "mini_fo:$1" /mnt 2>&- && root=/mnt
-		else
-			/bin/mount --bind -o noatime / /mnt
-			/bin/mount --bind -o noatime,union "$1" /mnt && root=/mnt
-		fi
-	} || {
-		[ "$3" = "1" ] && {
-		/bin/mount | grep "on $1 type" 2>&- 1>&- || /bin/mount -o noatime,bind $1 $1
-		dupe $1 $rom
-		}
-	}
-	pivot $root $2
-}
-
-ramoverlay() {
-	mkdir -p /tmp/root
-	/bin/mount -t tmpfs -o noatime,mode=0755 root /tmp/root
-	fopivot /tmp/root /rom 1
-}
-
 [ -z "$IPKG_INSTROOT" -a -f /lib/config/uci.sh ] && . /lib/config/uci.sh

+ 159 - 318
package/base-files/files/lib/functions/network.sh

@@ -1,427 +1,268 @@
-. /usr/share/libubox/jshn.sh
-
-__network_set_cache()
-{
-	if [ -n "$3" ]; then
-		eval "export -- __NETWORK_CV_$1='$3'"
-		__NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1"
-	elif json_get_var "__NETWORK_CV_$1" "$2"; then
-		__NETWORK_CACHE="${__NETWORK_CACHE:+$__NETWORK_CACHE }__NETWORK_CV_$1"
-	fi
-}
-
-__network_export()
-{
-	local __v="__NETWORK_CV_$2"
-	eval "export -- \"$1=\${$__v:+\${$__v$4}$3}\"; [ -n \"\${$__v+x}\" ]"
-}
-
-__network_parse_ifstatus()
-{
-	local __iface="$1"
-	local __key="${__iface}"
+# 1: destination variable
+# 2: interface
+# 3: path
+# 4: separator
+# 5: limit
+__network_ifstatus() {
 	local __tmp
-	local __idx
-	local __list
-	local __old_ns
-
-	case "$__iface" in
-		*[^a-zA-Z0-9_]*) return 1 ;;
-	esac
-
-	__network_export __tmp "${__key}__parsed" && return 0
-	__tmp="$(ubus call network.interface."$__iface" status 2>/dev/null)"
-	[ -n "$__tmp" ] || return 1
-
-	json_set_namespace "network" __old_ns
-	json_load "$__tmp"
-
-	__network_set_cache "${__key}__parsed" "" "1"
-
-	for __tmp in "" "_inactive"; do
-
-		__key="${__key}${__tmp}"
-
-		# parse addresses
-		local __family
-		for __family in 4 6; do
-
-			__list=""
-
-			if json_is_a "ipv${__family}_address" array; then
-
-				json_select "ipv${__family}_address"
-
-				__idx=1
-
-				while json_is_a "$__idx" object; do
-
-					json_select "$((__idx++))"
-					json_get_var __tmp "address" && __list="${__list:+$__list }$__tmp"
-					json_get_var __tmp "mask"    && __list="${__list:+$__list/}$__tmp"
-					json_select ".."
-
-				done
-
-				json_select ".."
-
-			fi
-
-			if json_is_a "ipv${__family}_prefix_assignment" array; then
-
-				json_select "ipv${__family}_prefix_assignment"
-
-				__idx=1
-
-				while json_is_a "$__idx" object; do
-
-					json_select "$((__idx++))"
-					json_get_var __tmp "address" && __list="${__list:+$__list }${__tmp}1"
-					json_get_var __tmp "mask"    && __list="${__list:+$__list/}$__tmp"
-					json_select ".."
-
-				done
-
-				json_select ".."
-
-			fi
-
-			if [ -n "$__list" ]; then
-				__network_set_cache "${__key}_address${__family}" "" "$__list"
-			fi
-
-		done
-
-		# parse prefixes
-		if json_is_a "ipv6_prefix" array; then
-			json_select "ipv6_prefix"
-
-			__idx=1
-			__list=""
-
-			while json_is_a "$__idx" object; do
-
-				json_select "$((__idx++))"
-				json_get_var __tmp "address" && __list="${__list:+$__list }$__tmp"
-				json_get_var __tmp "mask"    && __list="${__list:+$__list/}$__tmp"
-				json_select ".."
-
-			done
-
-			json_select ".."
-
-
-			if [ -n "$__list" ]; then
-				__network_set_cache "${__key}_prefix6" "" "$__list"
-			fi
-
-		fi
-
-		# parse routes
-		if json_is_a route array; then
-
-			json_select "route"
-
-			local __idx=1
-			while json_is_a "$__idx" object; do
-
-				json_select "$((__idx++))"
-				json_get_var __tmp table
-
-				if [ -z "$__tmp" ]; then
-					json_get_var __tmp target
-
-					case "${__tmp}" in
-						0.0.0.0)
-							__network_set_cache "${__key}_gateway4" nexthop
-						;;
-						::)
-							__network_set_cache "${__key}_gateway6" nexthop
-						;;
-					esac
-				fi
-
-				json_select ".."
-
-			done
-
-			json_select ".."
-
-		fi
-
-		# parse dns info
-		local __field
-		for __field in "dns_server" "dns_search"; do
-			if json_is_a "$__field" array; then
-
-				json_select "$__field"
-
-				__idx=1
-				__list=""
-
-				while json_is_a "$__idx" string; do
-
-					json_get_var __tmp "$((__idx++))"
-					__list="${__list:+$__list }$__tmp"
-
-				done
-
-				json_select ".."
-
-				if [ -n "$__list" ]; then
-					__network_set_cache "${__key}_${__field}" "" "$__list"
-				fi
-			fi
-		done
-
-		# parse up state, proto, device and physdev
-		for __field in "up" "proto" "l3_device" "device"; do
-			if json_get_type __tmp "$__field"; then
-				__network_set_cache "${__key}_${__field}" "$__field"
-			fi
-		done
-
-		# descend into inactive table
-		json_is_a "inactive" object && json_select "inactive"
-
-	done
-
-	json_cleanup
-	json_set_namespace "$__old_ns"
-
-	return 0
-}
-
-
-__network_ipaddr()
-{
-	local __var="$1"
-	local __iface="$2"
-	local __field="$3"
-	local __subst="$4"
-	local __list="$5"
-	local __tmp=""
 
-	__network_parse_ifstatus "$__iface" || return 1
+	[ -z "$__NETWORK_CACHE" ] && \
+		export __NETWORK_CACHE="$(ubus call network.interface dump)"
 
-	if [ $__list = 1 ] && [ -n "$__subst" ]; then
-		__network_export "__list" "${__iface}_${__field}"
+	__tmp="$(jsonfilter ${4:+-F "$4"} ${5:+-l "$5"} -s "$__NETWORK_CACHE" -e "$1=@.interface${2:+[@.interface='$2']}$3")"
 
-		for __list in $__list; do
-			eval "__tmp=\"${__tmp:+$__tmp }\${__list$__subst}\""
-		done
-
-		export -- "$__var=$__tmp"; [ -n "$__tmp" ]
-		return $?
-	fi
+	[ -z "$__tmp" ] && \
+		unset "$1" && \
+		return 1
 
-	__network_export "$__var" "${__iface}_${__field}" "" "$__subst"
-	return $?
+	eval "$__tmp"
 }
 
 # determine first IPv4 address of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_ipaddr() { __network_ipaddr "$1" "$2" "address4" "%%/*" 0; }
+network_get_ipaddr() {
+	__network_ifstatus "$1" "$2" "['ipv4-address'][0].address";
+}
 
 # determine first IPv6 address of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_ipaddr6() { __network_ipaddr "$1" "$2" "address6" "%%/*" 0; }
+network_get_ipaddr6() {
+	local __addr
+
+	if __network_ifstatus "__addr" "$2" "['ipv6-address','ipv6-prefix-assignment'][0].address"; then
+		case "$__addr" in
+			*:)	export "$1=${__addr}1" ;;
+			*)	export "$1=${__addr}" ;;
+		esac
+		return 0
+	fi
+
+	unset $1
+	return 1
+}
 
 # determine first IPv4 subnet of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_subnet() { __network_ipaddr "$1" "$2" "address4" "%% *" 0; }
+network_get_subnet() {
+	__network_ifstatus "$1" "$2" "['ipv4-address'][0]['address','mask']" "/"
+}
 
 # determine first IPv6 subnet of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_subnet6() { __network_ipaddr "$1" "$2" "address6" "%% *" 0; }
+network_get_subnet6() {
+	__network_ifstatus "$1" "$2" "['ipv6-address'][0]['address','mask']" "/"
+}
 
 # determine first IPv6 prefix of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_prefix6() { __network_ipaddr "$1" "$2" "prefix6" "%% *" 0; }
+network_get_prefix6() {
+	__network_ifstatus "$1" "$2" "['ipv6-prefix'][0]['address','mask']" "/"
+}
 
 # determine all IPv4 addresses of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_ipaddrs() { __network_ipaddr "$1" "$2" "address4" "%%/*" 1; }
+network_get_ipaddrs() {
+	__network_ifstatus "$1" "$2" "['ipv4-address'][*].address"
+}
 
 # determine all IPv6 addresses of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_ipaddrs6() { __network_ipaddr "$1" "$2" "address6" "%%/*" 1; }
+network_get_ipaddrs6() {
+	local __addr
+	local __list=""
+
+	if __network_ifstatus "__addr" "$2" "['ipv6-address','ipv6-prefix-assignment'][*].address"; then
+		for __addr in $__addr; do
+			case "$__addr" in
+				*:) __list="${__list:+$__list }${__addr}1" ;;
+				*)  __list="${__list:+$__list }${__addr}"  ;;
+			esac
+		done
 
-# determine all IPv4 subnets of given logical interface
+		export "$1=$__list"
+		return 0
+	fi
+
+	unset "$1"
+	return 1
+}
+
+# determine all IP addresses of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_subnets() { __network_ipaddr "$1" "$2" "address4" "" 1; }
+network_get_ipaddrs_all() {
+	local __addr
+	local __list=""
+
+	if __network_ifstatus "__addr" "$2" "['ipv4-address','ipv6-address','ipv6-prefix-assignment'][*].address"; then
+		for __addr in $__addr; do
+			case "$__addr" in
+				*:) __list="${__list:+$__list }${__addr}1" ;;
+				*)  __list="${__list:+$__list }${__addr}"  ;;
+			esac
+		done
 
-# determine all IPv6 subnets of given logical interface
+		export "$1=$__list"
+		return 0
+	fi
+
+	unset "$1"
+	return 1
+}
+
+# determine all IPv4 subnets of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_subnets6() { __network_ipaddr "$1" "$2" "address6" "" 1; }
+network_get_subnets() {
+	__network_ifstatus "$1" "$2" "['ipv4-address'][*]['address','mask']" "/ "
+}
 
-# determine all IPv6 prefixes of given logical interface
+# determine all IPv6 subnets of given logical interface
 # 1: destination variable
 # 2: interface
-network_get_prefixes6() { __network_ipaddr "$1" "$2" "prefix6" "" 1; }
-
-
-__network_gateway()
-{
-	local __var="$1"
-	local __iface="$2"
-	local __family="$3"
-	local __inactive="$4"
-
-	__network_parse_ifstatus "$__iface" || return 1
+network_get_subnets6() {
+	local __addr
+	local __list=""
+
+	if __network_ifstatus "__addr" "$2" "['ipv6-address','ipv6-prefix-assignment'][*]['address','mask']" "/ "; then
+		for __addr in $__addr; do
+			case "$__addr" in
+				*:/*) __list="${__list:+$__list }${__addr%/*}1/${__addr##*/}" ;;
+				*)    __list="${__list:+$__list }${__addr}"                   ;;
+			esac
+		done
 
-	if [ "$__inactive" = 1 -o "$__inactive" = "true" ]; then
-		__network_export "$__var" "${__iface}_inactive_gateway${__family}" && \
-			return 0
+		export "$1=$__list"
+		return 0
 	fi
 
-	__network_export "$__var" "${__iface}_gateway${__family}"
-	return $?
+	unset "$1"
+	return 1
+}
+
+# determine all IPv6 prefixes of given logical interface
+# 1: destination variable
+# 2: interface
+network_get_prefixes6() {
+	__network_ifstatus "$1" "$2" "['ipv6-prefix'][*]['address','mask']" "/ "
 }
 
 # determine IPv4 gateway of given logical interface
 # 1: destination variable
 # 2: interface
 # 3: consider inactive gateway if "true" (optional)
-network_get_gateway() { __network_gateway "$1" "$2" 4 "${3:-0}"; }
+network_get_gateway() {
+	__network_ifstatus "$1" "$2" ".route[@.target='0.0.0.0' && !@.table].nexthop" "" 1 && \
+		return 0
+
+	[ "$3" = 1 -o "$3" = "true" ] && \
+		__network_ifstatus "$1" "$2" ".inactive.route[@.target='0.0.0.0' && !@.table].nexthop" "" 1
+}
 
 # determine IPv6 gateway of given logical interface
 # 1: destination variable
 # 2: interface
 # 3: consider inactive gateway if "true" (optional)
-network_get_gateway6() { __network_gateway "$1" "$2" 6 "${3:-0}"; }
-
-
-__network_dns() {
-	local __var="$1"
-	local __iface="$2"
-	local __field="$3"
-	local __inactive="$4"
+network_get_gateway6() {
+	__network_ifstatus "$1" "$2" ".route[@.target='::' && !@.table].nexthop" "" 1 && \
+		return 0
 
-	__network_parse_ifstatus "$__iface" || return 1
-
-	if [ "$__inactive" = 1 -o "$__inactive" = "true" ]; then
-		__network_export "$__var" "${__iface}_inactive_${__field}" && \
-			return 0
-	fi
-
-	__network_export "$__var" "${__iface}_${__field}"
-	return $?
+	[ "$3" = 1 -o "$3" = "true" ] && \
+		__network_ifstatus "$1" "$2" ".inactive.route[@.target='::' && !@.table].nexthop" "" 1
 }
 
 # determine the DNS servers of the given logical interface
 # 1: destination variable
 # 2: interface
 # 3: consider inactive servers if "true" (optional)
-network_get_dnsserver() { __network_dns "$1" "$2" dns_server "${3:-0}"; }
+network_get_dnsserver() {
+	__network_ifstatus "$1" "$2" "['dns-server'][*]" && return 0
+
+	[ "$3" = 1 -o "$3" = "true" ] && \
+		__network_ifstatus "$1" "$2" ".inactive['dns-server'][*]"
+}
 
 # determine the domains of the given logical interface
 # 1: destination variable
 # 2: interface
 # 3: consider inactive domains if "true" (optional)
-network_get_dnssearch() { __network_dns "$1" "$2" dns_search "${3:-0}"; }
+network_get_dnssearch() {
+	__network_ifstatus "$1" "$2" "['dns-search'][*]" && return 0
 
+	[ "$3" = 1 -o "$3" = "true" ] && \
+		__network_ifstatus "$1" "$2" ".inactive['dns-search'][*]"
+}
 
+
+# 1: destination variable
+# 2: addr
+# 3: inactive
 __network_wan()
 {
-	local __var="$1"
-	local __family="$2"
-	local __inactive="$3"
-	local __iface
-
-	for __iface in $(ubus list | sed -ne 's/^network\.interface\.//p'); do
-		if [ "$__iface" != loopback ]; then
-			if __network_gateway "$__var" "$__iface" "$__family" "$__inactive"; then
-				eval "export -- \"$__var=$__iface\""
-				return 0
-			fi
-		fi
-	done
-
-	eval "export -- \"$__var=\""
-	return 1
+	__network_ifstatus "$1" "" \
+		"[@.route[@.target='$2' && !@.table]].interface" "" 1 && \
+			return 0
+
+	[ "$3" = 1 -o "$3" = "true" ] && \
+		__network_ifstatus "$1" "" \
+			"[@.inactive.route[@.target='$2' && !@.table]].interface" "" 1
 }
 
 # find the logical interface which holds the current IPv4 default route
 # 1: destination variable
 # 2: consider inactive default routes if "true" (optional)
-network_find_wan() { __network_wan "$1" 4 "${2:-0}"; }
+network_find_wan() { __network_wan "$1" "0.0.0.0" "$2"; }
 
 # find the logical interface which holds the current IPv6 default route
 # 1: destination variable
 # 2: consider inactive dafault routes if "true" (optional)
-network_find_wan6() { __network_wan "$1" 6 "${2:-0}"; }
-
-
-__network_device()
-{
-	local __var="$1"
-	local __iface="$2"
-	local __field="$3"
-
-	__network_parse_ifstatus "$__iface" || return 1
-	__network_export "$__var" "${__iface}_${__field}"
-	return $?
-}
+network_find_wan6() { __network_wan "$1" "::" "$2"; }
 
 # test whether the given logical interface is running
 # 1: interface
 network_is_up()
 {
 	local __up
-	__network_device __up "$1" up && [ $__up -eq 1 ]
+	__network_ifstatus "__up" "$1" ".up" && [ "$__up" = 1 ]
 }
 
 # determine the protocol of the given logical interface
 # 1: destination variable
 # 2: interface
-network_get_protocol() { __network_device "$1" "$2" proto; }
+network_get_protocol() { __network_ifstatus "$1" "$2" ".proto"; }
 
 # determine the layer 3 linux network device of the given logical interface
 # 1: destination variable
 # 2: interface
-network_get_device() { __network_device "$1" "$2" l3_device; }
+network_get_device() { __network_ifstatus "$1" "$2" ".l3_device"; }
 
 # determine the layer 2 linux network device of the given logical interface
 # 1: destination variable
 # 2: interface
-network_get_physdev() { __network_device "$1" "$2" device; }
-
-
-__network_defer()
-{
-	local __device="$1"
-	local __defer="$2"
-
-	json_init
-	json_add_string name "$__device"
-	json_add_boolean defer "$__defer"
-
-	ubus call network.device set_state "$(json_dump)" 2>/dev/null
-}
+network_get_physdev() { __network_ifstatus "$1" "$2" ".device"; }
 
 # defer netifd actions on the given linux network device
 # 1: device name
-network_defer_device() { __network_defer "$1" 1; }
+network_defer_device()
+{
+	ubus call network.device set_state \
+		"$(printf '{ "name": "%s", "defer": true }' "$1")" 2>/dev/null
+}
 
 # continue netifd actions on the given linux network device
 # 1: device name
-network_ready_device() { __network_defer "$1" 0; }
-
-# flush the internal value cache to force re-reading values from ubus
-network_flush_cache()
+network_ready_device()
 {
-	local __tmp
-	for __tmp in $__NETWORK_CACHE __NETWORK_CACHE; do
-		unset "$__tmp"
-	done
+	ubus call network.device set_state \
+		"$(printf '{ "name": "%s", "defer": false }' "$1")" 2>/dev/null
 }
+
+# flush the internal value cache to force re-reading values from ubus
+network_flush_cache() { unset __NETWORK_CACHE; }

+ 87 - 0
package/base-files/files/lib/functions/preinit.sh

@@ -0,0 +1,87 @@
+#!/bin/sh
+# Copyright (C) 2006-2013 OpenWrt.org
+# Copyright (C) 2010 Vertical Communications
+
+boot_hook_splice_start() {
+	export -n PI_HOOK_SPLICE=1
+}
+
+boot_hook_splice_finish() {
+	local hook
+	for hook in $PI_STACK_LIST; do
+		local v; eval "v=\${${hook}_splice:+\$${hook}_splice }$hook"
+		export -n "${hook}=${v% }"
+		export -n "${hook}_splice="
+	done
+	export -n PI_HOOK_SPLICE=
+}
+
+boot_hook_init() {
+	local hook="${1}_hook"
+	export -n "PI_STACK_LIST=${PI_STACK_LIST:+$PI_STACK_LIST }$hook"
+	export -n "$hook="
+}
+
+boot_hook_add() {
+	local hook="${1}_hook${PI_HOOK_SPLICE:+_splice}"
+	local func="${2}"
+
+	[ -n "$func" ] && {
+		local v; eval "v=\$$hook"
+		export -n "$hook=${v:+$v }$func"
+	}
+}
+
+boot_hook_shift() {
+	local hook="${1}_hook"
+	local rvar="${2}"
+
+	local v; eval "v=\$$hook"
+	[ -n "$v" ] && {
+		local first="${v%% *}"
+
+		[ "$v" != "${v#* }" ] && \
+			export -n "$hook=${v#* }" || \
+			export -n "$hook="
+
+		export -n "$rvar=$first"
+		return 0
+	}
+
+	return 1
+}
+
+boot_run_hook() {
+	local hook="$1"
+	local func
+
+	while boot_hook_shift "$hook" func; do
+		local ran; eval "ran=\$PI_RAN_$func"
+		[ -n "$ran" ] || {
+			export -n "PI_RAN_$func=1"
+			$func "$1" "$2"
+		}
+	done
+}
+
+pivot() { # <new_root> <old_root>
+	/bin/mount -o noatime,move /proc $1/proc && \
+	pivot_root $1 $1$2 && {
+		/bin/mount -o noatime,move $2/dev /dev
+		/bin/mount -o noatime,move $2/tmp /tmp
+		/bin/mount -o noatime,move $2/sys /sys 2>&-
+		/bin/mount -o noatime,move $2/overlay /overlay 2>&-
+		return 0
+	}
+}
+
+fopivot() { # <rw_root> <ro_root> <dupe?>
+	/bin/mount -o noatime,lowerdir=/,upperdir=$1 -t overlayfs "overlayfs:$1" /mnt
+	pivot /mnt $2
+}
+
+ramoverlay() {
+	mkdir -p /tmp/root
+	/bin/mount -t tmpfs -o noatime,mode=0755 root /tmp/root
+	fopivot /tmp/root /rom 1
+}

+ 0 - 23
package/base-files/files/lib/functions/service.sh

@@ -101,26 +101,3 @@ service_stop() {
 service_reload() {
 	SERVICE_SIG="${SERVICE_SIG:-$SERVICE_SIG_RELOAD}" service -K "$@"
 }
-
-service_kill() {
-	cat 1>&2 << __END_OF_WARNING__
-#
-# WARNING: the 'service_kill' function is now deprecated and might be
-# removed soon. Consider using the other new service_* wrappers instead.
-#
-__END_OF_WARNING__
-	local name="${1}"
-	local pid="${2:-$(pidof "$name")}"
-	local grace="${3:-5}"
-
-	[ -f "$pid" ] && pid="$(head -n1 "$pid" 2>/dev/null)"
-
-	for pid in $pid; do
-		[ -d "/proc/$pid" ] || continue
-		local try=0
-		kill -TERM $pid 2>/dev/null && \
-			while grep -qs "$name" "/proc/$pid/cmdline" && [ $((try++)) -lt $grace ]; do sleep 1; done
-		kill -KILL $pid 2>/dev/null && \
-			while grep -qs "$name" "/proc/$pid/cmdline"; do sleep 1; done
-	done
-}

+ 112 - 0
package/base-files/files/lib/functions/system.sh

@@ -0,0 +1,112 @@
+# Copyright (C) 2006-2013 OpenWrt.org
+
+find_mtd_chardev() {
+	local INDEX=$(find_mtd_index "$1")
+	local PREFIX=/dev/mtd
+
+	[ -d /dev/mtd ] && PREFIX=/dev/mtd/
+	echo "${INDEX:+$PREFIX$INDEX}"
+}
+
+mtd_get_mac_ascii()
+{
+	local mtdname="$1"
+	local key="$2"
+	local part
+	local mac_dirty
+
+	part=$(find_mtd_part "$mtdname")
+	if [ -z "$part" ]; then
+		echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2
+		return
+	fi
+
+	mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p')
+
+	# "canonicalize" mac
+	[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty"
+}
+
+mtd_get_mac_binary() {
+	local mtdname="$1"
+	local offset="$2"
+	local part
+
+	part=$(find_mtd_part "$mtdname")
+	if [ -z "$part" ]; then
+		echo "mtd_get_mac_binary: partition $mtdname not found!" >&2
+		return
+	fi
+
+	dd bs=1 skip=$offset count=6 if=$part 2>/dev/null | hexdump -v -n 6 -e '5/1 "%02x:" 1/1 "%02x"'
+}
+
+mtd_get_part_size() {
+	local part_name=$1
+	local first dev size erasesize name
+	while read dev size erasesize name; do
+		name=${name#'"'}; name=${name%'"'}
+		if [ "$name" = "$part_name" ]; then
+			echo $((0x$size))
+			break
+		fi
+	done < /proc/mtd
+}
+
+macaddr_add() {
+	local mac=$1
+	local val=$2
+	local oui=${mac%:*:*:*}
+	local nic=${mac#*:*:*:}
+
+	nic=$(printf "%06x" $((0x${nic//:/} + $val & 0xffffff)) | sed 's/^\(.\{2\}\)\(.\{2\}\)\(.\{2\}\)/\1:\2:\3/')
+	echo $oui:$nic
+}
+
+macaddr_setbit_la()
+{
+	local mac=$1
+
+	printf "%02x:%s" $((0x${mac%%:*} | 0x02)) ${mac#*:}
+}
+
+macaddr_2bin()
+{
+	local mac=$1
+
+	echo -ne \\x${mac//:/\\x}
+}
+
+macaddr_canonicalize()
+{
+	local mac="$1"
+	local canon=""
+
+	mac=$(echo -n $mac | tr -d \")
+	[ ${#mac} -gt 17 ] && return
+	[ -n "${mac//[a-fA-F0-9\.: -]/}" ] && return
+
+	for octet in ${mac//[\.:-]/ }; do
+		case "${#octet}" in
+		1)
+			octet="0${octet}"
+			;;
+		2)
+			;;
+		4)
+			octet="${octet:0:2} ${octet:2:2}"
+			;;
+		12)
+			octet="${octet:0:2} ${octet:2:2} ${octet:4:2} ${octet:6:2} ${octet:8:2} ${octet:10:2}"
+			;;
+		*)
+			return
+			;;
+		esac
+		canon=${canon}${canon:+ }${octet}
+	done
+
+	[ ${#canon} -ne 17 ] && return
+
+	printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${canon// / 0x} 2>/dev/null
+}

+ 302 - 0
package/base-files/files/lib/functions/uci-defaults-new.sh

@@ -0,0 +1,302 @@
+#!/bin/ash
+
+CFG=/etc/board.json
+
+. /usr/share/libubox/jshn.sh
+
+json_select_array() {
+	local _json_no_warning=1
+
+	json_select "$1"
+	[ $? = 0 ] && return
+
+	json_add_array $1
+	json_close_array
+
+	json_select "$1"
+}
+
+json_select_object() {
+	local _json_no_warning=1
+
+	json_select "$1"
+	[ $? = 0 ] && return
+
+	json_add_object $1
+	json_close_object
+
+	json_select "$1"
+}
+
+_ucidef_set_interface() {
+	local name=$1
+	local iface=$2
+
+	json_select_object $name
+	json_add_string ifname "${iface%%.*}"
+	[ "$iface" = "${iface%%.*}" ] || json_add_boolean create_vlan 1
+	json_select ..
+}
+
+ucidef_set_interface_loopback()
+{
+	# stub
+	local a=$1
+}
+
+ucidef_set_interface_lan() {
+	local lan_if=$1
+
+	json_select_object network
+	_ucidef_set_interface lan $lan_if
+	json_select ..
+}
+
+ucidef_set_interfaces_lan_wan() {
+	local lan_if=$1
+	local wan_if=$2
+
+	json_select_object network
+	_ucidef_set_interface lan $lan_if
+	_ucidef_set_interface wan $wan_if
+	json_select ..
+}
+
+ucidef_add_switch() {
+	local name=$1
+	local reset=$2
+	local enable=$3
+
+	json_select_object switch
+
+	json_select_object $name
+	[ "$enable" -eq 1 ] && json_add_boolean enable 1
+	[ "$reset" -eq 1 ] && json_add_boolean reset 1
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_add_switch_attr() {
+	local name=$1
+	local key=$2
+	local val=$3
+
+	json_select_object switch
+
+	json_select_object $name
+	json_add_string $key $val
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_add_switch_vlan() {
+	local name=$1
+	local vlan=$2
+	local ports=$3
+	local cpu_port=''
+
+	case $vlan in
+	1)	vlan=lan;;
+	2)	vlan=wan;;
+	*)	vlan=vlan$vlan;;
+	esac
+
+	json_select_object switch
+	json_select_object $name
+	json_select_object vlans
+
+	json_add_array $vlan
+	for p in $ports; do
+		if [ ${p%t} != $p ]; then
+			cpu_port=$p
+		else
+			json_add_int "" $p
+		fi
+	done
+	json_close_array
+
+	json_select ..
+	[ -n "$cpu_port" ] && json_add_int cpu_port $cpu_port
+	json_select ..
+	json_select ..
+}
+
+ucidef_set_interface_macaddr() {
+	local network=$1
+	local macaddr=$2
+
+	json_select_object network
+
+	json_select $network
+	[ $? -eq 0 ] || {
+		json_select ..
+		return
+	}
+
+	json_add_string macaddr $macaddr
+	json_select ..
+	
+	json_select ..
+}
+
+ucidef_set_led_netdev() {
+	local cfg="led_$1"
+	local name=$2
+	local sysfs=$3
+	local dev=$4
+
+	json_select_object led
+	
+	json_select_object $1
+	json_add_string name $name
+	json_add_string type netdev
+	json_add_string sysfs $sysfs
+	json_add_string device $dev
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_set_led_interface() {
+	local name=$1
+	local sysfs=$2
+
+	json_select_object led
+	
+	json_select_object $1
+	json_add_string name $name
+	json_add_string type interface
+	json_add_string sysfs $sysfs
+	json_add_string interface $name
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_set_led_usbdev() {
+	local cfg="led_$1"
+	local name=$2
+	local sysfs=$3
+	local dev=$4
+
+	json_select_object led
+	
+	json_select_object $1
+	json_add_string name $name	
+	json_add_string type usb
+	json_add_string sysfs $sysfs
+	json_add_string device $dev
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_set_led_wlan() {
+	local cfg="led_$1"
+	local name=$2
+	local sysfs=$3
+	local trigger=$4
+
+	json_select_object led
+	
+	json_select_object $1
+	json_add_string name $name
+	json_add_string type trigger
+	json_add_string sysfs $sysfs
+	json_add_string trigger $trigger
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_set_led_switch() {
+	local cfg="led_$1"
+	local name=$2
+	local sysfs=$3
+	local trigger=$4
+	local port_mask=$5
+
+	json_select_object led
+	
+	json_select_object $1
+	json_add_string name $name
+	json_add_string type switch
+	json_add_string sysfs $sysfs
+	json_add_string trigger $trigger
+	json_add_string port_mask $port_mask
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_set_led_default() {
+	local cfg="led_$1"
+	local name=$2
+	local sysfs=$3
+	local default=$4
+
+	json_select_object led
+	
+	json_select_object $1
+	json_add_string name $name
+	json_add_string sysfs $sysfs
+	json_add_string default $default
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_set_led_rssi() {
+	local cfg="led_$1"
+	local name=$2
+	local sysfs=$3
+	local iface=$4
+	local minq=$5
+	local maxq=$6
+	local offset=$7
+	local factor=$8
+
+	json_select_object led
+	
+	json_select_object rssi
+	json_select_object $1
+	json_add_string name $name
+	json_add_string sysfs $sysfs
+	json_add_string minq $minq
+	json_add_string maxq $maxq
+	json_add_string offset $offset
+	json_add_string factor $factor
+	json_select ..
+	json_select ..
+
+	json_select ..
+}
+
+ucidef_set_rssimon() {
+	local dev="$1"
+	local refresh="$2"
+	local threshold="$3"
+
+	json_select_object led
+	
+	json_select_object rssi
+	json_add_string type rssi
+	json_add_string dev $dev
+	json_add_string threshold $threshold
+	json_select ..
+
+	json_select ..
+	
+}
+
+board_config_update() {
+	json_init
+	[ -f ${CFG} ] && json_load "$(cat ${CFG})"
+}
+
+board_config_flush() {
+	json_dump -i > /tmp/.board.json
+	mv /tmp/.board.json ${CFG}
+}

+ 5 - 3
package/base-files/files/lib/functions/uci-defaults.sh

@@ -140,7 +140,7 @@ EOF
 
 ucidef_commit_leds()
 {
-	[ "$UCIDEF_LEDS_CHANGED" == "1" ] && uci commit system
+	[ "$UCIDEF_LEDS_CHANGED" = "1" ] && uci commit system
 }
 
 ucidef_set_interface_loopback() {
@@ -158,11 +158,12 @@ EOF
 ucidef_set_interface_raw() {
 	local cfg=$1
 	local ifname=$2
+	local proto=${3:-"none"}
 
 	uci batch <<EOF
 set network.$cfg='interface'
 set network.$cfg.ifname='$ifname'
-set network.$cfg.proto='none'
+set network.$cfg.proto='$proto'
 EOF
 }
 
@@ -172,6 +173,7 @@ ucidef_set_interface_lan() {
 	uci batch <<EOF
 set network.lan='interface'
 set network.lan.ifname='$ifname'
+set network.lan.force_link=1
 set network.lan.type='bridge'
 set network.lan.proto='static'
 set network.lan.ipaddr='192.168.1.1'
@@ -188,7 +190,7 @@ set network.wan='interface'
 set network.wan.ifname='$ifname'
 set network.wan.proto='dhcp'
 set network.wan6='interface'
-set network.wan6.ifname='@wan'
+set network.wan6.ifname='$ifname'
 set network.wan6.proto='dhcpv6'
 EOF
 }

+ 51 - 23
package/base-files/files/lib/upgrade/common.sh

@@ -2,8 +2,8 @@
 
 RAM_ROOT=/tmp/root
 
-ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
-libs() { ldd $* | awk '{print $3}'; }
+[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
+libs() { ldd $* 2>/dev/null | sed -r 's/(.* => )?(.*) .*/\2/'; }
 
 install_file() { # <file> [ <file> ... ]
 	for file in "$@"; do
@@ -21,9 +21,6 @@ install_bin() { # <file> [ <symlink> ... ]
 	files=$1
 	[ -x "$src" ] && files="$src $(libs $src)"
 	install_file $files
-	[ -e /lib/ld.so.1 ] && {
-		install_file /lib/ld.so.1
-	}
 	shift
 	for link in "$@"; do {
 		dest="$RAM_ROOT/$link"
@@ -53,14 +50,30 @@ run_ramfs() { # <command> [...]
 	install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount	\
 		/sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd	\
 		/bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/["	\
-		/bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump		\
-		/bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc
+		/bin/dd /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump	\
+		/bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc \
+		/bin/cut /usr/bin/printf /bin/sync /bin/mkdir /bin/rmdir	\
+		/bin/rm /usr/bin/basename /bin/kill /bin/chmod
 
 	install_bin /sbin/mtd
+	install_bin /sbin/ubi
+	install_bin /sbin/mount_root
+	install_bin /sbin/snapshot
+	install_bin /sbin/snapshot_tool
+	install_bin /usr/sbin/ubiupdatevol
+	install_bin /usr/sbin/ubiattach
+	install_bin /usr/sbin/ubiblock
+	install_bin /usr/sbin/ubiformat
+	install_bin /usr/sbin/ubidetach
+	install_bin /usr/sbin/ubirsvol
+	install_bin /usr/sbin/ubirmvol
+	install_bin /usr/sbin/ubimkvol
 	for file in $RAMFS_COPY_BIN; do
-		install_bin $file
+		install_bin ${file//:/ }
 	done
-	install_file /etc/resolv.conf /lib/functions.sh /lib/functions.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
+	install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
+
+	[ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
 
 	supivot $RAM_ROOT /mnt || {
 		echo "Failed to switch over to ramfs. Please reboot."
@@ -83,6 +96,13 @@ kill_remaining() { # [ <signal> ]
 	local sig="${1:-TERM}"
 	echo -n "Sending $sig to remaining processes ... "
 
+	local my_pid=$$
+	local my_ppid=$(cut -d' ' -f4  /proc/$my_pid/stat)
+	local my_ppisupgraded=
+	grep -q upgraded /proc/$my_ppid/cmdline >/dev/null && {
+		local my_ppisupgraded=1
+	}
+	
 	local stat
 	for stat in /proc/[0-9]*/stat; do
 		[ -f "$stat" ] || continue
@@ -97,18 +117,26 @@ kill_remaining() { # [ <signal> ]
 		# Skip kernel threads
 		[ -n "$cmdline" ] || continue
 
-		case "$name" in
-			# Skip essential services
-			*procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*) : ;;
-
-			# Killable process
-			*)
-				if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then
-					echo -n "$name "
-					kill -$sig $pid 2>/dev/null
-				fi
-			;;
-		esac
+		if [ $$ -eq 1 ] || [ $my_ppid -eq 1 ] && [ -n "$my_ppisupgraded" ]; then
+			# Running as init process, kill everything except me
+			if [ $pid -ne $$ ] && [ $pid -ne $my_ppid ]; then
+				echo -n "$name "
+				kill -$sig $pid 2>/dev/null
+			fi
+		else 
+			case "$name" in
+				# Skip essential services
+				*procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*) : ;;
+
+				# Killable process
+				*)
+					if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then
+						echo -n "$name "
+						kill -$sig $pid 2>/dev/null
+					fi
+				;;
+			esac
+		fi
 	done
 	echo ""
 }
@@ -168,11 +196,11 @@ get_image() { # <source> [ <command> ]
 }
 
 get_magic_word() {
-	get_image "$@" | dd bs=2 count=1 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"'
+	(get_image "$@" | dd bs=2 count=1 | hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev/null
 }
 
 get_magic_long() {
-	get_image "$@" | dd bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"'
+	(get_image "$@" | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
 }
 
 jffs2_copy_config() {

+ 1 - 0
package/base-files/files/lib/upgrade/keep.d/base-files-essential

@@ -4,6 +4,7 @@
 /etc/group
 /etc/passwd
 /etc/profile
+/etc/shadow
 /etc/shells
 /etc/sysctl.conf
 /etc/rc.local

+ 4 - 4
package/base-files/files/sbin/led.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
-# (C) 2008 librecmc.org
+# (C) 2008 openwrt.org
 
 . /lib/functions.sh
 ACTION=$1
@@ -9,15 +9,15 @@ do_led() {
 	local sysfs
 	config_get name $1 name
 	config_get sysfs $1 sysfs
-	[ "$name" == "$NAME" -o "$sysfs" = "$NAME" -a -e "/sys/class/leds/${sysfs}" ] && {
-		[ "$ACTION" == "set" ] &&
+	[ "$name" = "$NAME" -o "$sysfs" = "$NAME" -a -e "/sys/class/leds/${sysfs}" ] && {
+		[ "$ACTION" = "set" ] &&
 			echo 1 >/sys/class/leds/${sysfs}/brightness \
 			|| echo 0 >/sys/class/leds/${sysfs}/brightness
 		exit 0
 	}
 }
 
-[ "$1" == "clear" -o "$1" == "set" ] &&
+[ "$1" = "clear" -o "$1" = "set" ] &&
 	[ -n "$2" ] &&{
 		config_load system
 		config_foreach do_led

+ 10 - 2
package/base-files/files/sbin/sysupgrade

@@ -1,5 +1,6 @@
 #!/bin/sh
 . /lib/functions.sh
+. /lib/functions/system.sh
 
 # initialize defaults
 RAMFS_COPY_BIN=""	# extra programs for temporary ramfs root
@@ -101,14 +102,19 @@ add_uci_conffiles() {
 	local file="$1"
 	( find $(sed -ne '/^[[:space:]]*$/d; /^#/d; p' \
 		/etc/sysupgrade.conf /lib/upgrade/keep.d/* 2>/dev/null) \
-		-type f 2>/dev/null;
+		-type f -o -type l 2>/dev/null;
 	  opkg list-changed-conffiles ) | sort -u > "$file"
 	return 0
 }
 
 add_overlayfiles() {
 	local file="$1"
-	find /overlay/etc/ -type f | sed \
+	if [ -d /overlay/upper ]; then
+		local overlaydir="/overlay/upper"
+	else
+		local overlaydir="/overlay"
+	fi
+	find $overlaydir/etc/ -type f -o -type l | sed \
 		-e 's,^/overlay/,/,' \
 		-e '\,/META_[a-zA-Z0-9]*$,d' \
 		-e '\,/functions.sh$,d' \
@@ -125,6 +131,8 @@ sysupgrade_image_check="platform_check_image"
 
 include /lib/upgrade
 
+[ "$1" = "nand" ] && nand_upgrade_stage2 $@
+
 do_save_conffiles() {
 	local conf_tar="${1:-$CONF_TAR}"
 

+ 1 - 1
package/base-files/files/sbin/wifi

@@ -108,7 +108,7 @@ wifi_fixup_hwmode() {
 _wifi_updown() {
 	for device in ${2:-$DEVICES}; do (
 		config_get disabled "$device" disabled
-		[ 1 == "$disabled" ] && {
+		[ "$disabled" = "1" ] && {
 			echo "'$device' is disabled"
 			set disable
 		}

+ 55 - 6
package/base-files/image-config.in

@@ -142,24 +142,26 @@ menuconfig VERSIONOPT
 		they're useful for release builds or custom libreCMC redistributions
 		that should carry custom version tags.
 
+if VERSIONOPT
+
 	config VERSION_DIST
 		string
-		prompt "Release distribution" if VERSIONOPT
-		default "libreCMC" if VERSIONOPT
+		prompt "Release distribution"
+		default "libreCMC"
 		help
 			This is the name of the release distribution.
 			If unspecified, it defaults to libreCMC.
 
 	config VERSION_NICK
 		string
-		prompt "Release version nickname" if VERSIONOPT
+		prompt "Release version nickname"
 		help
 			This is the release codename embedded in the image.
 			If unspecified, it defaults to the name of source branch.
 
 	config VERSION_NUMBER
 		string
-		prompt "Release version number" if VERSIONOPT
+		prompt "Release version number"
 		help
 			This is the release version number embedded in the image.
 			If unspecified, it defaults to the svn or git-svn revision
@@ -167,8 +169,8 @@ menuconfig VERSIONOPT
 
 	config VERSION_REPO
 		string
-		prompt "Release repository" if VERSIONOPT
-		default "http://downloads.librecmc.org/snapshots/trunk/%T/packages" if VERSIONOPT
+		prompt "Release repository"
+		default "http://downloads.openwrt.org/snapshots/trunk/%T/packages"
 		help
 			This is the repository address embedded in the image, it defaults
 			to the trunk snapshot repo; the url may contain the following placeholders:
@@ -184,6 +186,53 @@ menuconfig VERSIONOPT
 			 %T .. Target name
 			 %S .. Target/Subtarget name
 
+	config VERSION_MANUFACTURER
+		string
+		prompt "Manufacturer name"
+		help
+			This is the manufacturer name embedded in /etc/device_info
+			Useful for OEMs building libreCMC based firmware
+
+	config VERSION_PRODUCT
+		string
+		prompt "Product name"
+		help
+			This is the product name embedded in /etc/device_info
+			Useful for OEMs building libreCMC based firmware
+
+	config VERSION_HWREV
+		string
+		prompt "Hardware revision"
+		help
+			This is the hardware revision string embedded in /etc/device_info
+			Useful for OEMs building libreCMC based firmware
+endif
+
+
+menuconfig PER_FEED_REPO
+	bool "Separate feed repositories" if IMAGEOPT
+	default y
+	help
+		If set, a separate repository is generated within bin/*/packages/
+		for the core packages and each enabled feed.
+
+	config PER_FEED_REPO_ADD_DISABLED
+		bool "Add available but not enabled feeds to opkg.conf"
+		default y
+		depends on PER_FEED_REPO
+		help
+		  Add not installed or disabled feeds from feeds.conf to opkg.conf.
+
+	config PER_FEED_REPO_ADD_COMMENTED
+		bool "Comment out not enabled feeds"
+		default y
+		depends on PER_FEED_REPO && PER_FEED_REPO_ADD_DISABLED
+		help
+		  Add not enabled feeds as commented out source lines to opkg.conf.
+
+source "tmp/.config-feeds.in"
+
+
 menuconfig SMIMEOPT
 	bool "Package signing options" if IMAGEOPT
         default n

+ 9 - 0
package/boot/uboot-envtools/Config.in

@@ -0,0 +1,9 @@
+config UBOOT_ENVTOOLS_UBI
+	bool "Support environment in UBI volume"
+	depends on PACKAGE_uboot-envtools
+	default n
+	help
+		Add support for reading and writing U-Boot environment
+		stored in UBI volume(s).
+
+		Increases binary size by about 8 kB

Some files were not shown because too many files changed in this diff