From d9be6e62d501a621e4bf6b858ca8d473258a4614 Mon Sep 17 00:00:00 2001 From: CN_SZTL Date: Sat, 26 Oct 2019 10:01:37 +0800 Subject: [PATCH] tools: update --- tools/b43-tools/files/b43-fwsquash.py | 6 +- tools/bison/Makefile | 6 +- .../bison/patches/010-intl-stub-compat.patch | 15 - .../bison/patches/100-fix-gets-removal.patch | 2 +- tools/cbootimage-configs/Makefile | 32 + tools/cbootimage/Makefile | 31 + tools/cmake/Makefile | 22 +- .../cmake/patches/100-disable_qt_tests.patch | 4 +- .../120-curl-fix-libressl-linking.patch | 2 +- .../130-bootstrap_parallel_make_flag.patch | 2 +- tools/coreutils/Makefile | 2 +- tools/firmware-utils/Makefile | 19 +- tools/firmware-utils/src/fw.h | 11 +- tools/firmware-utils/src/jcgimage.c | 114 ++- tools/firmware-utils/src/mkdcs932.c | 39 - tools/firmware-utils/src/mkdlinkfw-lib.c | 63 +- tools/firmware-utils/src/mkdlinkfw-lib.h | 7 +- tools/firmware-utils/src/mkdlinkfw.c | 15 +- tools/firmware-utils/src/mkedimaximg.c | 43 +- tools/firmware-utils/src/mkfwimage.c | 213 ++-- tools/firmware-utils/src/mkrasimage.c | 459 +++++++++ tools/firmware-utils/src/mksenaofw.c | 206 +++- tools/firmware-utils/src/mksercommfw.c | 261 +++++ tools/firmware-utils/src/mktplinkfw.c | 11 +- tools/firmware-utils/src/mktplinkfw2.c | 18 + tools/firmware-utils/src/nec-enc.c | 129 +++ tools/firmware-utils/src/ptgen.c | 11 +- tools/firmware-utils/src/tplink-safeloader.c | 685 +++++++++++-- tools/firmware-utils/src/uimage_padhdr.c | 157 +++ tools/firmware-utils/src/xorimage.c | 39 +- tools/gengetopt/Makefile | 10 +- .../patches/100-dependency_fix.patch | 11 - .../gengetopt/patches/100-no-tests-docs.patch | 33 + .../gengetopt/patches/200-no_docs_tests.patch | 13 - tools/gptfdisk/Makefile | 29 - tools/isl/Makefile | 4 +- tools/libelf/Makefile | 9 +- .../900-fix-undefined-macro-access.patch | 198 ++++ tools/libressl/Makefile | 4 +- .../patches/001-dont-build-tests-man.patch | 11 + tools/libressl/patches/010-avoid-glibc.patch | 23 + tools/make-ext4fs/Makefile | 6 +- .../patches/060-remove_kernel_includes.patch | 2 +- tools/mklibs/Makefile | 7 +- .../patches/002-disable_symbol_checks.patch | 4 +- tools/mklibs/patches/003-no_copy.patch | 8 +- .../mklibs/patches/004-libpthread_link.patch | 2 +- tools/mklibs/patches/005-duplicate_syms.patch | 6 +- tools/mklibs/patches/006-uclibc_init.patch | 2 +- tools/mklibs/patches/007-gc_sections.patch | 2 +- .../patches/008-uclibc_libgcc_link.patch | 4 +- .../009-uclibc_libpthread_symbols.patch | 8 +- .../mklibs/patches/011-remove_multiarch.patch | 2 +- tools/mklibs/patches/100-apply-2to3.patch | 327 ++++++ tools/mpfr/Makefile | 8 +- tools/mpfr/patches/100-freebsd-compat.patch | 2 +- tools/mtd-utils/Makefile | 6 +- tools/mtd-utils/patches/110-portability.patch | 22 +- .../201-ubinize-add-terminator-support.patch | 2 +- tools/popt/Makefile | 21 - tools/popt/patches/900-autoconf-compat.patch | 25 - tools/scons/Makefile | 35 - tools/scons/files/pywrap.sh | 15 - tools/scons/patches/001-platform_env.patch | 11 - tools/sed/Makefile | 5 +- tools/squashfs4/Makefile | 43 - tools/squashfs4/patches/100-portability.patch | 40 - .../patches/110-allow_static_liblzma.patch | 30 - .../squashfs4/patches/120-cygwin_fixes.patch | 153 --- .../patches/130-include_sysmacros.patch | 20 - .../squashfs4/patches/150-freebsd_fixes.patch | 10 - .../patches/160-expose_lzma_xz_options.patch | 929 ------------------ ..._support_for_LZMA_MAGIC_to_unsqashfs.patch | 72 -- .../patches/180-openbsd_compat.patch | 24 - .../patches/190-no_nonstatic_inline.patch | 36 - .../200-add-fixed-timestamp-option.patch | 82 -- tools/tar/Makefile | 8 +- .../patches/100-symlink-force-root-name.patch | 2 +- .../110-symlink-force-permissions.patch | 2 +- tools/upslug2/Makefile | 25 +- .../patches/110-wrt350nv2_support.patch | 279 ------ tools/xz/Makefile | 5 +- tools/zip/Makefile | 36 + ...e-borrow-the-LFS-test-from-autotools.patch | 89 ++ .../004-do-not-set-unwanted-cflags.patch | 15 + ...k-markings-to-avoid-executable-stack.patch | 21 + .../007-fclose-in-file-not-fclose-x.patch | 16 + .../patches/008-hardening-build-fix-1.patch | 25 + .../patches/009-hardening-build-fix-2.patch | 16 + tools/zip/patches/010-remove-build-date.patch | 15 + ...add-option-for-reproducible-archives.patch | 145 +++ 91 files changed, 3289 insertions(+), 2350 deletions(-) delete mode 100644 tools/bison/patches/010-intl-stub-compat.patch create mode 100644 tools/cbootimage-configs/Makefile create mode 100644 tools/cbootimage/Makefile delete mode 100644 tools/firmware-utils/src/mkdcs932.c create mode 100644 tools/firmware-utils/src/mkrasimage.c create mode 100644 tools/firmware-utils/src/mksercommfw.c create mode 100644 tools/firmware-utils/src/nec-enc.c create mode 100644 tools/firmware-utils/src/uimage_padhdr.c delete mode 100644 tools/gengetopt/patches/100-dependency_fix.patch create mode 100644 tools/gengetopt/patches/100-no-tests-docs.patch delete mode 100644 tools/gengetopt/patches/200-no_docs_tests.patch delete mode 100644 tools/gptfdisk/Makefile create mode 100644 tools/libelf/patches/900-fix-undefined-macro-access.patch create mode 100644 tools/libressl/patches/001-dont-build-tests-man.patch create mode 100644 tools/libressl/patches/010-avoid-glibc.patch create mode 100644 tools/mklibs/patches/100-apply-2to3.patch delete mode 100644 tools/popt/Makefile delete mode 100644 tools/popt/patches/900-autoconf-compat.patch delete mode 100644 tools/scons/Makefile delete mode 100755 tools/scons/files/pywrap.sh delete mode 100644 tools/scons/patches/001-platform_env.patch delete mode 100644 tools/squashfs4/Makefile delete mode 100644 tools/squashfs4/patches/100-portability.patch delete mode 100644 tools/squashfs4/patches/110-allow_static_liblzma.patch delete mode 100644 tools/squashfs4/patches/120-cygwin_fixes.patch delete mode 100644 tools/squashfs4/patches/130-include_sysmacros.patch delete mode 100644 tools/squashfs4/patches/150-freebsd_fixes.patch delete mode 100644 tools/squashfs4/patches/160-expose_lzma_xz_options.patch delete mode 100644 tools/squashfs4/patches/170-add_support_for_LZMA_MAGIC_to_unsqashfs.patch delete mode 100644 tools/squashfs4/patches/180-openbsd_compat.patch delete mode 100644 tools/squashfs4/patches/190-no_nonstatic_inline.patch delete mode 100644 tools/squashfs4/patches/200-add-fixed-timestamp-option.patch delete mode 100644 tools/upslug2/patches/110-wrt350nv2_support.patch create mode 100644 tools/zip/Makefile create mode 100644 tools/zip/patches/001-unix-configure-borrow-the-LFS-test-from-autotools.patch create mode 100644 tools/zip/patches/004-do-not-set-unwanted-cflags.patch create mode 100644 tools/zip/patches/006-stack-markings-to-avoid-executable-stack.patch create mode 100644 tools/zip/patches/007-fclose-in-file-not-fclose-x.patch create mode 100644 tools/zip/patches/008-hardening-build-fix-1.patch create mode 100644 tools/zip/patches/009-hardening-build-fix-2.patch create mode 100644 tools/zip/patches/010-remove-build-date.patch create mode 100644 tools/zip/patches/011-add-option-for-reproducible-archives.patch diff --git a/tools/b43-tools/files/b43-fwsquash.py b/tools/b43-tools/files/b43-fwsquash.py index 2946d7c3c3..6b4952cbc1 100755 --- a/tools/b43-tools/files/b43-fwsquash.py +++ b/tools/b43-tools/files/b43-fwsquash.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # # b43 firmware file squasher # Removes unnecessary firmware files @@ -37,7 +37,7 @@ fwpath = sys.argv[3] phytypes = phytypes.split(',') try: - corerevs = map(lambda r: int(r), corerevs.split(',')) + corerevs = [int(r) for r in corerevs.split(',')] except ValueError: print("ERROR: \"%s\" is not a valid COREREVS string\n" % corerevs) usage() @@ -45,7 +45,7 @@ except ValueError: fwfiles = os.listdir(fwpath) -fwfiles = filter(lambda str: str.endswith(".fw"), fwfiles) +fwfiles = [str for str in fwfiles if str.endswith(".fw")] if not fwfiles: print("ERROR: No firmware files found in %s" % fwpath) sys.exit(1) diff --git a/tools/bison/Makefile b/tools/bison/Makefile index d00e7240d6..45255da4fb 100644 --- a/tools/bison/Makefile +++ b/tools/bison/Makefile @@ -7,16 +7,18 @@ include $(TOPDIR)/rules.mk PKG_NAME:=bison -PKG_VERSION:=3.2.2 +PKG_VERSION:=3.4.1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=@GNU/$(PKG_NAME) -PKG_HASH:=6f950f24e4d0745c7cc870e36d04f4057133ce0f31d6b4564e6f510a7d3ffafa +PKG_HASH:=27159ac5ebf736dffd5636fd2cd625767c9e437de65baa63cb0de83570bd820d HOST_BUILD_PARALLEL:=1 include $(INCLUDE_DIR)/host-build.mk +HOST_CONFIGURE_ARGS += --enable-threads=pth + define Host/Clean -$(MAKE) -C $(HOST_BUILD_DIR) uninstall $(call Host/Clean/Default) diff --git a/tools/bison/patches/010-intl-stub-compat.patch b/tools/bison/patches/010-intl-stub-compat.patch deleted file mode 100644 index d2dfcadbab..0000000000 --- a/tools/bison/patches/010-intl-stub-compat.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- a/src/main.c -+++ b/src/main.c -@@ -60,9 +60,9 @@ main (int argc, char *argv[]) - { - set_program_name (argv[0]); - setlocale (LC_ALL, ""); -- (void) bindtextdomain (PACKAGE, LOCALEDIR); -- (void) bindtextdomain ("bison-runtime", LOCALEDIR); -- (void) textdomain (PACKAGE); -+ bindtextdomain (PACKAGE, LOCALEDIR); -+ bindtextdomain ("bison-runtime", LOCALEDIR); -+ textdomain (PACKAGE); - - { - char const *cp = getenv ("LC_CTYPE"); diff --git a/tools/bison/patches/100-fix-gets-removal.patch b/tools/bison/patches/100-fix-gets-removal.patch index 6f4abe58c7..8650b8226f 100644 --- a/tools/bison/patches/100-fix-gets-removal.patch +++ b/tools/bison/patches/100-fix-gets-removal.patch @@ -1,6 +1,6 @@ --- a/lib/stdio.in.h +++ b/lib/stdio.in.h -@@ -739,14 +739,6 @@ _GL_WARN_ON_USE (getline, "getline is un +@@ -746,14 +746,6 @@ _GL_WARN_ON_USE (getline, "getline is un # endif #endif diff --git a/tools/cbootimage-configs/Makefile b/tools/cbootimage-configs/Makefile new file mode 100644 index 0000000000..5a1fc568cb --- /dev/null +++ b/tools/cbootimage-configs/Makefile @@ -0,0 +1,32 @@ +# +# Copyright (c) 2017-2019 Tomasz Maciej Nowak +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +include $(TOPDIR)/rules.mk + +PKG_NAME := cbootimage-configs + +PKG_SOURCE_DATE := 2017-04-13 +PKG_SOURCE_PROTO := git +PKG_SOURCE_URL := https://github.com/NVIDIA/cbootimage-configs.git +PKG_SOURCE_VERSION := 7c3b458b93ed6947cd083623f543e93f9103cc0f +PKG_MIRROR_HASH := 1d24421af8cf74ec2d625e237aa8121b1273774c4380ad333e2954e052a5a4fe + +include $(INCLUDE_DIR)/host-build.mk + +define Host/Compile +endef + +define Host/Install + $(INSTALL_DIR) $(STAGING_DIR_HOST)/share/$(PKG_NAME) + $(CP) $(HOST_BUILD_DIR)/* \ + $(STAGING_DIR_HOST)/share/$(PKG_NAME) +endef + +define Host/Clean + rm -fR $(STAGING_DIR_HOST)/share/$(PKG_NAME) +endef + +$(eval $(call HostBuild)) diff --git a/tools/cbootimage/Makefile b/tools/cbootimage/Makefile new file mode 100644 index 0000000000..42640eab36 --- /dev/null +++ b/tools/cbootimage/Makefile @@ -0,0 +1,31 @@ +# +# Copyright (c) 2017-2019 Tomasz Maciej Nowak +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +include $(TOPDIR)/rules.mk + +PKG_NAME := cbootimage +PKG_VERSION := 1.8 + +PKG_SOURCE_PROTO := git +PKG_SOURCE_URL := https://github.com/NVIDIA/cbootimage.git +PKG_SOURCE_VERSION := 7c9db585d06cce9efffa2a82245f233233680060 +PKG_MIRROR_HASH := 84d9abaaa3eddde05f506dc16effe1c9e18eb94727ed59c5e0a879baeb04e0b2 + +HOST_BUILD_PARALLEL := 1 + +include $(INCLUDE_DIR)/host-build.mk + +define Host/Configure + (cd $(HOST_BUILD_DIR); autoreconf --install --symlink) + $(call Host/Configure/Default) +endef + +define Host/Clean + rm -f $(STAGING_DIR_HOST)/bin/$(PKG_NAME) \ + $(STAGING_DIR_HOST)/share/man/man1/$(PKG_NAME).1 +endef + +$(eval $(call HostBuild)) diff --git a/tools/cmake/Makefile b/tools/cmake/Makefile index 888cf7de8e..33d6d4944f 100644 --- a/tools/cmake/Makefile +++ b/tools/cmake/Makefile @@ -7,19 +7,33 @@ include $(TOPDIR)/rules.mk PKG_NAME:=cmake -PKG_VERSION:=3.13.2 +PKG_VERSION:=3.15.1 PKG_CPE_ID:=cpe:/a:kitware:cmake PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://cmake.org/files/v3.13/ \ - https://fossies.org/linux/misc/ -PKG_HASH:=c925e7d2c5ba511a69f43543ed7b4182a7d446c274c7480d0e42cd933076ae25 +PKG_SOURCE_URL:=https://github.com/Kitware/CMake/releases/download/v$(PKG_VERSION)/ \ + https://cmake.org/files/v3.15/ +PKG_HASH:=18dec548d8f8b04d53c60f9cedcebaa6762f8425339d1e2c889c383d3ccdd7f7 HOST_BUILD_PARALLEL:=1 HOST_CONFIGURE_PARALLEL:=1 include $(INCLUDE_DIR)/host-build.mk +# Workaround for GCC versions below 6.X and ccache +# Reference: https://github.com/openwrt/openwrt/pull/1929 +GCC_DMPVER_GREPCMD := grep -E '^(4\.[8-9]|[5]\.?)' +GCC_DMPVER_STRING := $(shell $(HOSTCC_NOCACHE) -dumpversion | $(GCC_DMPVER_GREPCMD)) +ifneq ($(GCC_DMPVER_STRING),) + ifeq ($(CONFIG_CCACHE),y) + $(info GCC version less than 6.0 detected, disabling CCACHE) + HOST_CONFIGURE_VARS:=$(filter-out CC=% gcc%",$(HOST_CONFIGURE_VARS)) CC="$(HOSTCC_NOCACHE)" + HOST_CONFIGURE_VARS:=$(filter-out CXX=% g++%",$(HOST_CONFIGURE_VARS)) CXX="$(HOSTCXX_NOCACHE)" + else + $(info GCC version greater or equal to 6.0 detected, no workaround set for CCACHE) + endif +endif + HOST_CONFIGURE_VARS += \ MAKEFLAGS="$(HOST_JOBS)" \ CXXFLAGS="$(HOST_CFLAGS)" diff --git a/tools/cmake/patches/100-disable_qt_tests.patch b/tools/cmake/patches/100-disable_qt_tests.patch index af04bf7c41..7f83e279f7 100644 --- a/tools/cmake/patches/100-disable_qt_tests.patch +++ b/tools/cmake/patches/100-disable_qt_tests.patch @@ -1,6 +1,6 @@ --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt -@@ -301,15 +301,6 @@ add_RunCMake_test(no_install_prefix) +@@ -325,15 +325,6 @@ add_RunCMake_test(no_install_prefix) add_RunCMake_test(configure_file) add_RunCMake_test(CTestTimeoutAfterMatch) @@ -18,7 +18,7 @@ add_RunCMake_test(FindPkgConfig) --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt -@@ -437,13 +437,6 @@ if(BUILD_TESTING) +@@ -483,13 +483,6 @@ if(BUILD_TESTING) list(APPEND TEST_BUILD_DIRS ${CMake_TEST_INSTALL_PREFIX}) diff --git a/tools/cmake/patches/120-curl-fix-libressl-linking.patch b/tools/cmake/patches/120-curl-fix-libressl-linking.patch index e217979ee4..e7d9c5ddda 100644 --- a/tools/cmake/patches/120-curl-fix-libressl-linking.patch +++ b/tools/cmake/patches/120-curl-fix-libressl-linking.patch @@ -20,7 +20,7 @@ Signed-off-by: Jo-Philipp Wich --- --- a/Utilities/cmcurl/CMakeLists.txt +++ b/Utilities/cmcurl/CMakeLists.txt -@@ -454,6 +454,14 @@ if(CMAKE_USE_OPENSSL) +@@ -453,6 +453,14 @@ if(CMAKE_USE_OPENSSL) set(USE_OPENSSL ON) set(HAVE_LIBCRYPTO ON) set(HAVE_LIBSSL ON) diff --git a/tools/cmake/patches/130-bootstrap_parallel_make_flag.patch b/tools/cmake/patches/130-bootstrap_parallel_make_flag.patch index 535417d55a..124cf6d9d4 100644 --- a/tools/cmake/patches/130-bootstrap_parallel_make_flag.patch +++ b/tools/cmake/patches/130-bootstrap_parallel_make_flag.patch @@ -1,6 +1,6 @@ --- a/bootstrap +++ b/bootstrap -@@ -1164,7 +1164,10 @@ int main(){ printf("1%c", (char)0x0a); r +@@ -1168,7 +1168,10 @@ int main(){ printf("1%c", (char)0x0a); r ' > "test.c" cmake_original_make_flags="${cmake_make_flags}" if [ "x${cmake_parallel_make}" != "x" ]; then diff --git a/tools/coreutils/Makefile b/tools/coreutils/Makefile index 4109fd77b3..e338796053 100644 --- a/tools/coreutils/Makefile +++ b/tools/coreutils/Makefile @@ -16,7 +16,7 @@ PKG_HASH:=8891d349ee87b9ff7870f52b6d9312a9db672d2439d289bc57084771ca21656b HOST_BUILD_PARALLEL := 1 -BUILD_PROGRAMS = date readlink +BUILD_PROGRAMS = date readlink touch include $(INCLUDE_DIR)/host-build.mk diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile index 4b4af99908..2d2c96ce0a 100644 --- a/tools/firmware-utils/Makefile +++ b/tools/firmware-utils/Makefile @@ -12,7 +12,13 @@ include $(INCLUDE_DIR)/host-build.mk include $(INCLUDE_DIR)/kernel.mk define cc - $(HOSTCC) $(HOST_CFLAGS) -include endian.h $(HOST_LDFLAGS) -o $(HOST_BUILD_DIR)/bin/$(firstword $(1)) $(foreach src,$(1),src/$(src).c) $(2) + $(HOSTCC) \ + $(HOST_CFLAGS) \ + -Wno-unused-parameter \ + -include endian.h $(HOST_LDFLAGS) \ + -o $(HOST_BUILD_DIR)/bin/$(firstword $(1)) \ + $(foreach src,$(1),src/$(src).c) \ + $(2) endef define Host/Compile @@ -23,7 +29,7 @@ define Host/Compile $(call cc,otrx) $(call cc,motorola-bin) $(call cc,dgfirmware) - $(call cc,mksenaofw md5) + $(call cc,mksenaofw md5, -Wall --std=gnu99) $(call cc,trx2usr) $(call cc,ptgen) $(call cc,srec2bin) @@ -32,7 +38,7 @@ define Host/Compile $(call cc,mkzynfw) $(call cc,lzma2eva,-lz) $(call cc,mkcasfw) - $(call cc,mkfwimage,-lz -Wall) + $(call cc,mkfwimage,-lz -Wall -Werror -Wextra -D_FILE_OFFSET_BITS=64) $(call cc,mkfwimage2,-lz) $(call cc,imagetag imagetag_cmdline cyg_crc32) $(call cc,add_header) @@ -70,8 +76,8 @@ define Host/Compile $(call cc,fix-u-media-header cyg_crc32,-Wall) $(call cc,hcsmakeimage bcmalgo) $(call cc,mkporayfw, -Wall) + $(call cc,mkrasimage, --std=gnu99) $(call cc,mkhilinkfw, -lcrypto) - $(call cc,mkdcs932, -Wall) $(call cc,mkheader_gemtek,-lz) $(call cc,mkrtn56uimg, -lz) $(call cc,dgn3500sum, -Wall) @@ -82,8 +88,11 @@ define Host/Compile $(call cc,mkbuffaloimg, -Wall) $(call cc,zyimage, -Wall) $(call cc,mkdhpimg buffalo-lib, -Wall) - $(call cc,mkdlinkfw mkdlinkfw-lib, -lz -Wall --std=gnu99) + $(call cc,mkdlinkfw mkdlinkfw-lib, -lz -Wall --std=c99) $(call cc,dns313-header, -Wall) + $(call cc,mksercommfw, -Wall) + $(call cc,nec-enc, -Wall --std=gnu99) + $(call cc,uimage_padhdr, -Wall -lz) endef define Host/Install diff --git a/tools/firmware-utils/src/fw.h b/tools/firmware-utils/src/fw.h index e37859c52d..53a92a573c 100644 --- a/tools/firmware-utils/src/fw.h +++ b/tools/firmware-utils/src/fw.h @@ -24,8 +24,10 @@ #define MAGIC_HEADER "OPEN" #define MAGIC_PART "PART" #define MAGIC_END "END." +#define MAGIC_ENDS "ENDS" #define MAGIC_LENGTH 4 +#define PART_NAME_LENGTH 16 typedef struct header { char magic[MAGIC_LENGTH]; @@ -36,7 +38,7 @@ typedef struct header { typedef struct part { char magic[MAGIC_LENGTH]; - char name[16]; + char name[PART_NAME_LENGTH]; char pad[12]; u_int32_t memaddr; u_int32_t index; @@ -57,6 +59,13 @@ typedef struct signature { u_int32_t pad; } __attribute__ ((packed)) signature_t; +typedef struct signature_rsa { + char magic[MAGIC_LENGTH]; +// u_int32_t crc; + unsigned char rsa_signature[256]; + u_int32_t pad; +} __attribute__ ((packed)) signature_rsa_t; + #define VERSION "1.2" #define INFO(...) fprintf(stdout, __VA_ARGS__) diff --git a/tools/firmware-utils/src/jcgimage.c b/tools/firmware-utils/src/jcgimage.c index 354c26be19..81d9f79f52 100644 --- a/tools/firmware-utils/src/jcgimage.c +++ b/tools/firmware-utils/src/jcgimage.c @@ -2,6 +2,7 @@ * jcgimage - Create a JCG firmware image * * Copyright (C) 2015 Reinhard Max + * Copyright (C) 2019 Davide Fioravanti * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -45,6 +46,11 @@ * requiring JTAG to revive the board. To prevent such bricking from * happening, this tool refuses to build such overlong images. * + * Using -m is possible to set the maximum size of the payload. + * Otherwise the default MAXSIZE will be used. + * For an 8Mb flash, the corresponding maxsize is: + * 8 * 1024 * 1024 - 5 * 64 * 1024 = 8388608 - 327680 = 8060928 + * * Two more conditions have to be met for a JCG image to be accepted * as a valid update by the web interface of the stock firware: * @@ -92,6 +98,7 @@ #include #include #include +#include /* * JCG Firmware image header @@ -148,12 +155,12 @@ opensize(char *name, size_t *size) { struct stat s; int fd = open(name, O_RDONLY); - if (fd < 0) { + if (fd < 0) err(1, "cannot open \"%s\"", name); - } - if (fstat(fd, &s) == -1) { + + if (fstat(fd, &s) == -1) err(1, "cannot stat \"%s\"", name); - } + *size = s.st_size; return fd; } @@ -183,17 +190,15 @@ mkjcgheader(struct jcg_header *h, size_t psize, char *version) void *payload = (void *)h + sizeof(*h); time_t t; - if (source_date_epoch != -1) { + if (source_date_epoch != -1) t = source_date_epoch; - } else if ((time(&t) == (time_t)(-1))) { + else if ((time(&t) == (time_t)(-1))) err(1, "time call failed"); - } - if (version != NULL) { - if (sscanf(version, "%hu.%hu", &major, &minor) != 2) { + + if (version != NULL) + if (sscanf(version, "%hu.%hu", &major, &minor) != 2) err(1, "cannot parse version \"%s\"", version); - } - } memset(h, 0, sizeof(*h)); h->jh_magic = htonl(JH_MAGIC); @@ -267,14 +272,14 @@ craftcrc(uint32_t dcrc, uint8_t *buf, size_t len) a = ~dcrc; for (i = 0; i < 32; i++) { - if (patch & 1) { + if (patch & 1) patch = (patch >> 1) ^ 0xedb88320L; - } else { + else patch >>= 1; - } - if (a & 1) { + + if (a & 1) patch ^= 0x5b358fd3L; - } + a >>= 1; } patch ^= ~crc32(crc, buf, len - 4); @@ -285,17 +290,17 @@ craftcrc(uint32_t dcrc, uint8_t *buf, size_t len) /* Verify that we actually get the desired result */ crc = crc32(0L, Z_NULL, 0); crc = crc32(crc, buf, len); - if (crc != dcrc) { + if (crc != dcrc) errx(1, "CRC patching is broken: wanted %08x, but got %08x.", dcrc, crc); - } + } void usage() { fprintf(stderr, "Usage:\n" - "jcgimage -o outfile -u uImage [-v version]\n" - "jcgimage -o outfile -k kernel -f rootfs [-v version]\n"); + "jcgimage -o outfile -u uImage [-m maxsize] [-v version]\n" + "jcgimage -o outfile -k kernel -f rootfs [-m maxsize] [-v version]\n"); exit(1); } @@ -316,6 +321,8 @@ main(int argc, char **argv) char *file1 = NULL; char *file2 = NULL; char *version = NULL; + size_t maxsize = MAXSIZE; + char *endptr; int mode = MODE_UNKNOWN; int fdo, fd1, fd2; size_t size1, size2, sizeu, sizeo, off1, off2; @@ -326,31 +333,36 @@ main(int argc, char **argv) assert(sizeof(struct uimage_header) == 64); set_source_date_epoch(); - while ((c = getopt(argc, argv, "o:k:f:u:v:h")) != -1) { + while ((c = getopt(argc, argv, "o:k:f:u:v:m:h")) != -1) { switch (c) { case 'o': imagefile = optarg; break; case 'k': - if (mode == MODE_UIMAGE) { + if (mode == MODE_UIMAGE) errx(1,"-k cannot be combined with -u"); - } + mode = MODE_KR; file1 = optarg; break; case 'f': - if (mode == MODE_UIMAGE) { + if (mode == MODE_UIMAGE) errx(1,"-f cannot be combined with -u"); - } + mode = MODE_KR; file2 = optarg; break; case 'u': - if (mode == MODE_KR) { + if (mode == MODE_KR) errx(1,"-u cannot be combined with -k and -r"); - } + mode = MODE_UIMAGE; file1 = optarg; + break; + case 'm': + if (optarg != NULL) + maxsize = strtoimax(optarg, &endptr, 10); + break; case 'v': version = optarg; @@ -360,19 +372,19 @@ main(int argc, char **argv) usage(); } } - if (optind != argc) { + if (optind != argc) errx(1, "illegal arg \"%s\"", argv[optind]); - } - if (imagefile == NULL) { + + if (imagefile == NULL) errx(1, "no output file specified"); - } - if (mode == MODE_UNKNOWN) { + + if (mode == MODE_UNKNOWN) errx(1, "specify either -u or -k and -r"); - } + if (mode == MODE_KR) { - if (file1 == NULL || file2 == NULL) { - errx(1,"need -k and -r"); - } + if (file1 == NULL || file2 == NULL) + errx(1, "need -k and -r"); + fd2 = opensize(file2, &size2); } fd1 = opensize(file1, &size1); @@ -387,37 +399,37 @@ main(int argc, char **argv) sizeo = sizeof(*jh) + sizeu; } - if (sizeo > MAXSIZE) { - errx(1,"payload too large: %zd > %zd\n", sizeo, MAXSIZE); - } + if (sizeo > maxsize) + errx(1, "payload too large: %zd > %zd\n", sizeo, maxsize); + fdo = open(imagefile, O_RDWR | O_CREAT | O_TRUNC, 00644); - if (fdo < 0) { + if (fdo < 0) err(1, "cannot open \"%s\"", imagefile); - } - if (ftruncate(fdo, sizeo) == -1) { + + if (ftruncate(fdo, sizeo) == -1) err(1, "cannot grow \"%s\" to %zd bytes", imagefile, sizeo); - } + map = mmap(NULL, sizeo, PROT_READ|PROT_WRITE, MAP_SHARED, fdo, 0); uh = map + sizeof(*jh); - if (map == MAP_FAILED) { + if (map == MAP_FAILED) err(1, "cannot mmap \"%s\"", imagefile); - } - if (read(fd1, map + off1, size1) != size1) { + + if (read(fd1, map + off1, size1) != size1) err(1, "cannot copy %s", file1); - } + if (mode == MODE_KR) { - if (read(fd2, map+off2, size2) != size2) { + if (read(fd2, map+off2, size2) != size2) err(1, "cannot copy %s", file2); - } + mkuheader(uh, size1, size2); - } else if (mode == MODE_UIMAGE) { + } else if (mode == MODE_UIMAGE) craftcrc(ntohl(uh->ih_dcrc), (void*)uh + sizeof(*uh), sizeu - sizeof(*uh)); - } + mkjcgheader(map, sizeu, version); munmap(map, sizeo); close(fdo); diff --git a/tools/firmware-utils/src/mkdcs932.c b/tools/firmware-utils/src/mkdcs932.c deleted file mode 100644 index 28c67aa3b3..0000000000 --- a/tools/firmware-utils/src/mkdcs932.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License, - * version 2 as published by the Free Software Foundation. - * - * (C) John Crispin - */ - -#include -#include -#include -#include -#include -#include -#include - -int main(int argc, char **argv) -{ - uint32_t t = 0, sum = 0x55aa55aa; - int fd; - - if ((argc != 2) || ((fd = open(argv[1], O_RDWR)) == -1)) { - fprintf(stderr, "Usage: %s input_file\n", *argv); - return -EINVAL; - } - - lseek(fd, -4, SEEK_END); - write(fd, &t, 4); - lseek(fd, 0, SEEK_SET); - - while (read(fd, &t, 4) > 0) - sum -= t; - - lseek(fd, -4, SEEK_END); - write(fd, &sum, 4); - close(fd); - - return 0; -} diff --git a/tools/firmware-utils/src/mkdlinkfw-lib.c b/tools/firmware-utils/src/mkdlinkfw-lib.c index fcab856231..b3f3f41348 100644 --- a/tools/firmware-utils/src/mkdlinkfw-lib.c +++ b/tools/firmware-utils/src/mkdlinkfw-lib.c @@ -32,13 +32,26 @@ extern char *progname; -static unsigned char jffs2_eof_mark[4] = { 0xde, 0xad, 0xc0, 0xde }; - uint32_t jboot_timestamp(void) { - time_t rawtime; - time(&rawtime); - return (((uint32_t) rawtime) - TIMESTAMP_MAGIC) >> 2; + char *env = getenv("SOURCE_DATE_EPOCH"); + char *endptr = env; + time_t fixed_timestamp = -1; + errno = 0; + + if (env && *env) { + fixed_timestamp = strtoull(env, &endptr, 10); + + if (errno || (endptr && *endptr != '\0')) { + fprintf(stderr, "Invalid SOURCE_DATE_EPOCH"); + fixed_timestamp = -1; + } + } + + if (fixed_timestamp == -1) + time(&fixed_timestamp); + + return (((uint32_t) fixed_timestamp) - TIMESTAMP_MAGIC) >> 2; } uint16_t jboot_checksum(uint16_t start_val, uint16_t *data, int size) @@ -84,6 +97,7 @@ int read_to_buf(const struct file_info *fdata, char *buf) { FILE *f; int ret = EXIT_FAILURE; + size_t read; f = fopen(fdata->file_name, "r"); if (f == NULL) { @@ -91,9 +105,8 @@ int read_to_buf(const struct file_info *fdata, char *buf) goto out; } - errno = 0; - fread(buf, fdata->file_size, 1, f); - if (errno != 0) { + read = fread(buf, fdata->file_size, 1, f); + if (ferror(f) || read != 1) { ERRS("unable to read from file \"%s\"", fdata->file_name); goto out_close; } @@ -106,40 +119,6 @@ int read_to_buf(const struct file_info *fdata, char *buf) return ret; } -int pad_jffs2(char *buf, int currlen, int maxlen) -{ - int len; - uint32_t pad_mask; - - len = currlen; - pad_mask = (4 * 1024) | (64 * 1024); /* EOF at 4KB and at 64KB */ - while ((len < maxlen) && (pad_mask != 0)) { - uint32_t mask; - int i; - - for (i = 10; i < 32; i++) { - mask = 1 << i; - if (pad_mask & mask) - break; - } - - len = ALIGN(len, mask); - - for (i = 10; i < 32; i++) { - mask = 1 << i; - if ((len & (mask - 1)) == 0) - pad_mask &= ~mask; - } - - for (i = 0; i < sizeof(jffs2_eof_mark); i++) - buf[len + i] = jffs2_eof_mark[i]; - - len += sizeof(jffs2_eof_mark); - } - - return len; -} - int write_fw(const char *ofname, const char *data, int len) { FILE *f; diff --git a/tools/firmware-utils/src/mkdlinkfw-lib.h b/tools/firmware-utils/src/mkdlinkfw-lib.h index d61124cb63..da4ecf010c 100644 --- a/tools/firmware-utils/src/mkdlinkfw-lib.h +++ b/tools/firmware-utils/src/mkdlinkfw-lib.h @@ -33,6 +33,10 @@ #define SCH2_MAGIC 0x2124 #define SCH2_VER 0x02 +/* + * compression type values in the header + * so far onlysupport for LZMA is added + */ #define FLAT 0 #define JZ 1 #define GZIP 2 @@ -49,8 +53,6 @@ #define FACTORY 0 #define SYSUPGRADE 1 -#define ALIGN(x, a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); }) - #define ERR(fmt, ...) do { \ fflush(0); \ fprintf(stderr, "[%s] *** error: " fmt "\n", \ @@ -77,7 +79,6 @@ uint32_t jboot_timestamp(void); uint16_t jboot_checksum(uint16_t start_val, uint16_t *data, int size); int get_file_stat(struct file_info *fdata); int read_to_buf(const struct file_info *fdata, char *buf); -int pad_jffs2(char *buf, int currlen, int maxlen); int write_fw(const char *ofname, const char *data, int len); #endif /* mkdlinkfw_lib_h */ diff --git a/tools/firmware-utils/src/mkdlinkfw.c b/tools/firmware-utils/src/mkdlinkfw.c index 87605004fe..3b59a5d2df 100644 --- a/tools/firmware-utils/src/mkdlinkfw.c +++ b/tools/firmware-utils/src/mkdlinkfw.c @@ -99,11 +99,10 @@ struct file_info image_info; char *ofname; char *progname; uint32_t firmware_size; +uint32_t image_offset; uint16_t family_member; char *rom_id[12] = { 0 }; - char image_type; -int add_jffs2_eof; static void usage(int status) { @@ -405,7 +404,7 @@ int fill_sch2(struct sch2_header *header, char *kernel_ptr, char *rootfs_ptr) header->image_crc32 = crc32(0, (uint8_t *) kernel_ptr, kernel_info.file_size); header->start_addr = RAM_ENTRY_ADDR; header->rootfs_addr = - JBOOT_SIZE + STAG_SIZE + SCH2_SIZE + kernel_info.file_size; + image_offset + STAG_SIZE + SCH2_SIZE + kernel_info.file_size; header->rootfs_len = rootfs_info.file_size; header->rootfs_crc32 = crc32(0, (uint8_t *) rootfs_ptr, rootfs_info.file_size); header->header_crc32 = 0; @@ -448,9 +447,9 @@ int fill_auh(struct auh_header *header, uint32_t length) header->lpvs = AUH_LVPS; header->mbz = 0; header->time_stamp = jboot_timestamp(); - header->erase_start = JBOOT_SIZE; + header->erase_start = image_offset; header->erase_length = firmware_size; - header->data_offset = JBOOT_SIZE; + header->data_offset = image_offset; header->data_length = length; header->space4 = 0; header->space5 = 0; @@ -605,11 +604,12 @@ int main(int argc, char *argv[]) image_type = SYSUPGRADE; family_member = 0; firmware_size = 0; + image_offset = JBOOT_SIZE; while (1) { int c; - c = getopt(argc, argv, "f:F:i:hk:m:o:r:s:"); + c = getopt(argc, argv, "f:F:i:hk:m:o:O:r:s:"); if (c == -1) break; @@ -634,6 +634,9 @@ int main(int argc, char *argv[]) case 'r': rootfs_info.file_name = optarg; break; + case 'O': + sscanf(optarg, "0x%x", &image_offset); + break; case 'o': ofname = optarg; break; diff --git a/tools/firmware-utils/src/mkedimaximg.c b/tools/firmware-utils/src/mkedimaximg.c index d8a017e6a8..541eaaaa3f 100644 --- a/tools/firmware-utils/src/mkedimaximg.c +++ b/tools/firmware-utils/src/mkedimaximg.c @@ -17,12 +17,19 @@ #include #include /* for __BYTE_ORDER */ +#define FALSE 0 +#define TRUE 1 + #if (__BYTE_ORDER == __LITTLE_ENDIAN) # define HOST_TO_LE16(x) (x) # define HOST_TO_LE32(x) (x) +# define HOST_TO_BE16(x) bswap_16(x) +# define HOST_TO_BE32(x) bswap_32(x) #else # define HOST_TO_LE16(x) bswap_16(x) # define HOST_TO_LE32(x) bswap_32(x) +# define HOST_TO_BE16(x) (x) +# define HOST_TO_BE32(x) (x) #endif struct header @@ -47,6 +54,7 @@ struct buf }; static char *progname; +static int force_be = FALSE; static void usage(int status) { @@ -61,7 +69,8 @@ static void usage(int status) " -i read input from file \n" " -o write output to file \n" " -f set flash address to \n" - " -S set start address to \n"); + " -S set start address to \n" + " -b big-endianness mode\n"); exit(status); } @@ -83,8 +92,12 @@ static unsigned short fwcsum (struct buf *buf) { int i; unsigned short ret = 0; - for (i = 0; i < buf->size / 2; i++) - ret -= ((unsigned short *) buf->start)[i]; + for (i = 0; i < buf->size / 2; i++) { + if (force_be == FALSE) + ret -= ((unsigned short *) buf->start)[i]; + else + ret -= HOST_TO_BE16(((unsigned short *) buf->start)[i]); + } return ret; } @@ -144,7 +157,7 @@ int main(int argc, char **argv) header.flash = header.size = header.start = 0; progname = basename(argv[0]); - while((c = getopt(argc, argv, "i:o:m:s:f:S:h")) != -1) { + while((c = getopt(argc, argv, "i:o:m:s:f:S:h:b")) != -1) { switch (c) { case 'i': ifinfo.name = optarg; @@ -181,6 +194,9 @@ int main(int argc, char **argv) usage(EXIT_FAILURE); } break; + case 'b': + force_be = TRUE; + break; default: usage(EXIT_FAILURE); break; @@ -241,12 +257,23 @@ int main(int argc, char **argv) if (fwread(&ifinfo, &ibuf)) usage(EXIT_FAILURE); - header.flash = HOST_TO_LE32(header.flash); - header.size = HOST_TO_LE32(obuf.size - sizeof(struct header)); - header.start = HOST_TO_LE32(header.start); + if (force_be == FALSE) { + header.flash = HOST_TO_LE32(header.flash); + header.size = HOST_TO_LE32(obuf.size - sizeof(struct header)); + header.start = HOST_TO_LE32(header.start); + } else { + header.flash = HOST_TO_BE32(header.flash); + header.size = HOST_TO_BE32(obuf.size - sizeof(struct header)); + header.start = HOST_TO_BE32(header.start); + } + memcpy (obuf.start, &header, sizeof(struct header)); - csum = HOST_TO_LE16(fwcsum(&ibuf)); + if (force_be == FALSE) + csum = HOST_TO_LE16(fwcsum(&ibuf)); + else + csum = HOST_TO_BE16(fwcsum(&ibuf)); + memcpy(obuf.start + obuf.size - sizeof(unsigned short), &csum, sizeof(unsigned short)); diff --git a/tools/firmware-utils/src/mkfwimage.c b/tools/firmware-utils/src/mkfwimage.c index d8d5239cc5..c8737386a2 100644 --- a/tools/firmware-utils/src/mkfwimage.c +++ b/tools/firmware-utils/src/mkfwimage.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -29,65 +30,106 @@ #include #include #include +#include #include "fw.h" typedef struct fw_layout_data { - char name[PATH_MAX]; u_int32_t kern_start; u_int32_t kern_entry; u_int32_t firmware_max_length; } fw_layout_t; -fw_layout_t fw_layout_data[] = { +struct fw_info { + char name[PATH_MAX]; + struct fw_layout_data fw_layout; + bool sign; +}; + +struct fw_info fw_info[] = { { - .name = "XS2", - .kern_start = 0xbfc30000, - .kern_entry = 0x80041000, - .firmware_max_length= 0x00390000, + .name = "XS2", + .fw_layout = { + .kern_start = 0xbfc30000, + .kern_entry = 0x80041000, + .firmware_max_length= 0x00390000, + }, + .sign = false, }, { - .name = "XS5", - .kern_start = 0xbe030000, - .kern_entry = 0x80041000, - .firmware_max_length= 0x00390000, + .name = "XS5", + .fw_layout = { + .kern_start = 0xbe030000, + .kern_entry = 0x80041000, + .firmware_max_length= 0x00390000, + }, + .sign = false, }, { - .name = "RS", - .kern_start = 0xbf030000, - .kern_entry = 0x80060000, - .firmware_max_length= 0x00B00000, + .name = "RS", + .fw_layout = { + .kern_start = 0xbf030000, + .kern_entry = 0x80060000, + .firmware_max_length= 0x00B00000, + }, + .sign = false, }, { - .name = "RSPRO", - .kern_start = 0xbf030000, - .kern_entry = 0x80060000, - .firmware_max_length= 0x00F00000, + .name = "RSPRO", + .fw_layout = { + .kern_start = 0xbf030000, + .kern_entry = 0x80060000, + .firmware_max_length= 0x00F00000, + }, + .sign = false, }, { - .name = "LS-SR71", - .kern_start = 0xbf030000, - .kern_entry = 0x80060000, - .firmware_max_length= 0x00640000, + .name = "LS-SR71", + .fw_layout = { + .kern_start = 0xbf030000, + .kern_entry = 0x80060000, + .firmware_max_length= 0x00640000, + }, + .sign = false, }, { - .name = "XS2-8", - .kern_start = 0xa8030000, - .kern_entry = 0x80041000, - .firmware_max_length= 0x006C0000, + .name = "XS2-8", + .fw_layout = { + .kern_start = 0xa8030000, + .kern_entry = 0x80041000, + .firmware_max_length= 0x006C0000, + }, + .sign = false, + }, { - .name = "XM", - .kern_start = 0x9f050000, - .kern_entry = 0x80002000, - .firmware_max_length= 0x00760000, + .name = "XM", + .fw_layout = { + .kern_start = 0x9f050000, + .kern_entry = 0x80002000, + .firmware_max_length= 0x00760000, + }, + .sign = false, }, { - .name = "UBDEV01", - .kern_start = 0x9f050000, - .kern_entry = 0x80002000, - .firmware_max_length= 0x006A0000, + .name = "UBDEV01", + .fw_layout = { + .kern_start = 0x9f050000, + .kern_entry = 0x80002000, + .firmware_max_length= 0x006A0000, + }, + .sign = false, }, - { .name = "", + { + .name = "WA", + .fw_layout = { + .kern_start = 0x9f050000, + .kern_entry = 0x80002000, + .firmware_max_length= 0x00F60000, + }, + .sign = true, + }, + { + .name = "", }, }; @@ -116,8 +158,20 @@ typedef struct image_info { char outputfile[PATH_MAX]; u_int32_t part_count; part_data_t parts[MAX_SECTIONS]; + struct fw_info* fwinfo; } image_info_t; +static struct fw_info* get_fwinfo(char* board_name) { + struct fw_info *fwinfo = fw_info; + while(strlen(fwinfo->name)) { + if(strcmp(fwinfo->name, board_name) == 0) { + return fwinfo; + } + fwinfo++; + } + return NULL; +} + static void write_header(void* mem, const char *magic, const char* version) { header_t* header = mem; @@ -142,6 +196,17 @@ static void write_signature(void* mem, u_int32_t sig_offset) sign->pad = 0L; } +static void write_signature_rsa(void* mem, u_int32_t sig_offset) +{ + /* write signature */ + signature_rsa_t* sign = (signature_rsa_t*)(mem + sig_offset); + memset(sign, 0, sizeof(signature_rsa_t)); + + memcpy(sign->magic, MAGIC_ENDS, MAGIC_LENGTH); +// sign->crc = htonl(crc32(0L,(unsigned char *)mem, sig_offset)); + sign->pad = 0L; +} + static int write_part(void* mem, part_data_t* d) { char* addr; @@ -166,9 +231,10 @@ static int write_part(void* mem, part_data_t* d) memcpy(mem + sizeof(part_t), addr, d->stats.st_size); munmap(addr, d->stats.st_size); - memset(p->name, 0, sizeof(p->name)); - strncpy(p->magic, MAGIC_PART, MAGIC_LENGTH); - strncpy(p->name, d->partition_name, sizeof(p->name)); + memset(p->name, 0, PART_NAME_LENGTH); + memcpy(p->magic, MAGIC_PART, MAGIC_LENGTH); + memcpy(p->name, d->partition_name, PART_NAME_LENGTH); + p->index = htonl(d->partition_index); p->data_size = htonl(d->stats.st_size); p->part_size = htonl(d->partition_length); @@ -198,7 +264,8 @@ static void usage(const char* progname) static void print_image_info(const image_info_t* im) { - int i = 0; + unsigned int i = 0; + INFO("Firmware version: '%s'\n" "Output file: '%s'\n" "Part count: %u\n", @@ -208,15 +275,13 @@ static void print_image_info(const image_info_t* im) for (i = 0; i < im->part_count; ++i) { const part_data_t* d = &im->parts[i]; - INFO(" %10s: %8ld bytes (free: %8ld)\n", + INFO(" %10s: %8" PRId64 " bytes (free: %8" PRId64 ")\n", d->partition_name, d->stats.st_size, d->partition_length - d->stats.st_size); } } - - static u_int32_t filelength(const char* file) { FILE *p; @@ -232,22 +297,15 @@ static u_int32_t filelength(const char* file) return (ret); } -static int create_image_layout(const char* kernelfile, const char* rootfsfile, char* board_name, image_info_t* im) +static int create_image_layout(const char* kernelfile, const char* rootfsfile, image_info_t* im) { + uint32_t rootfs_len = 0; part_data_t* kernel = &im->parts[0]; part_data_t* rootfs = &im->parts[1]; - fw_layout_t* p; + fw_layout_t* p = &im->fwinfo->fw_layout; - p = &fw_layout_data[0]; - while (*p->name && (strcmp(p->name, board_name) != 0)) - p++; - if (!*p->name) { - printf("BUG! Unable to find default fw layout!\n"); - exit(-1); - } - - printf("board = %s\n", p->name); + printf("board = %s\n", im->fwinfo->name); strcpy(kernel->partition_name, "kernel"); kernel->partition_index = 1; kernel->partition_baseaddr = p->kern_start; @@ -256,8 +314,13 @@ static int create_image_layout(const char* kernelfile, const char* rootfsfile, c kernel->partition_entryaddr = p->kern_entry; strncpy(kernel->filename, kernelfile, sizeof(kernel->filename)); - if (filelength(rootfsfile) + kernel->partition_length > p->firmware_max_length) + rootfs_len = filelength(rootfsfile); + if (rootfs_len + kernel->partition_length > p->firmware_max_length) { + ERROR("File '%s' too big (0x%08X) - max size: 0x%08X (exceeds %u bytes)\n", + rootfsfile, rootfs_len, p->firmware_max_length, + (rootfs_len + kernel->partition_length) - p->firmware_max_length); return (-2); + } strcpy(rootfs->partition_name, "rootfs"); rootfs->partition_index = 2; @@ -280,7 +343,7 @@ static int create_image_layout(const char* kernelfile, const char* rootfsfile, c */ static int validate_image_layout(image_info_t* im) { - int i; + unsigned int i; if (im->part_count == 0 || im->part_count > MAX_SECTIONS) { @@ -311,7 +374,7 @@ static int validate_image_layout(image_info_t* im) return -3; } if (d->stats.st_size > d->partition_length) { - ERROR("File '%s' too big (%d) - max size: 0x%08X (exceeds %lu bytes)\n", + ERROR("File '%s' too big (%d) - max size: 0x%08X (exceeds %" PRId64 " bytes)\n", d->filename, i, d->partition_length, d->stats.st_size - d->partition_length); return -4; @@ -327,10 +390,15 @@ static int build_image(image_info_t* im) char* ptr; u_int32_t mem_size; FILE* f; - int i; + unsigned int i; // build in-memory buffer - mem_size = sizeof(header_t) + sizeof(signature_t); + mem_size = sizeof(header_t); + if(im->fwinfo->sign) { + mem_size += sizeof(signature_rsa_t); + } else { + mem_size += sizeof(signature_t); + } for (i = 0; i < im->part_count; ++i) { part_data_t* d = &im->parts[i]; @@ -359,7 +427,11 @@ static int build_image(image_info_t* im) ptr += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t); } // write signature - write_signature(mem, mem_size - sizeof(signature_t)); + if(im->fwinfo->sign) { + write_signature_rsa(mem, mem_size - sizeof(signature_rsa_t)); + } else { + write_signature(mem, mem_size - sizeof(signature_t)); + } // write in-memory buffer into file if ((f = fopen(im->outputfile, "w")) == NULL) @@ -388,6 +460,7 @@ int main(int argc, char* argv[]) char board_name[PATH_MAX]; int o, rc; image_info_t im; + struct fw_info *fwinfo; memset(&im, 0, sizeof(im)); memset(kernelfile, 0, sizeof(kernelfile)); @@ -403,30 +476,30 @@ int main(int argc, char* argv[]) switch (o) { case 'v': if (optarg) - strncpy(im.version, optarg, sizeof(im.version)); + strncpy(im.version, optarg, sizeof(im.version) - 1); break; case 'o': if (optarg) - strncpy(im.outputfile, optarg, sizeof(im.outputfile)); + strncpy(im.outputfile, optarg, sizeof(im.outputfile) - 1); break; case 'm': if (optarg) - strncpy(im.magic, optarg, sizeof(im.magic)); + strncpy(im.magic, optarg, sizeof(im.magic) - 1); break; case 'h': usage(argv[0]); return -1; case 'k': if (optarg) - strncpy(kernelfile, optarg, sizeof(kernelfile)); + strncpy(kernelfile, optarg, sizeof(kernelfile) - 1); break; case 'r': if (optarg) - strncpy(rootfsfile, optarg, sizeof(rootfsfile)); + strncpy(rootfsfile, optarg, sizeof(rootfsfile) - 1); break; case 'B': if (optarg) - strncpy(board_name, optarg, sizeof(board_name)); + strncpy(board_name, optarg, sizeof(board_name) - 1); break; } } @@ -447,7 +520,15 @@ int main(int argc, char* argv[]) return -2; } - if ((rc = create_image_layout(kernelfile, rootfsfile, board_name, &im)) != 0) + if ((fwinfo = get_fwinfo(board_name)) == NULL) { + ERROR("Invalid baord name '%s'\n", board_name); + usage(argv[0]); + return -2; + } + + im.fwinfo = fwinfo; + + if ((rc = create_image_layout(kernelfile, rootfsfile, &im)) != 0) { ERROR("Failed creating firmware layout description - error code: %d\n", rc); return -3; diff --git a/tools/firmware-utils/src/mkrasimage.c b/tools/firmware-utils/src/mkrasimage.c new file mode 100644 index 0000000000..8eee29cc08 --- /dev/null +++ b/tools/firmware-utils/src/mkrasimage.c @@ -0,0 +1,459 @@ +/* + * --- ZyXEL header format --- + * Original Version by Benjamin Berg + * C implementation based on generation-script by Christian Lamparter + * + * The firmware image prefixed with a header (which is written into the MTD device). + * The header is one erase block (~64KiB) in size, but the checksum only convers the + * first 2KiB. Padding is 0xff. All integers are in big-endian. + * + * The checksum is always a 16-Bit System V checksum (sum -s) stored in a 32-Bit integer. + * + * 4 bytes: checksum of the rootfs image + * 4 bytes: length of the contained rootfs image file (big endian) + * 32 bytes: Firmware Version string (NUL terminated, 0xff padded) + * 4 bytes: checksum over the header partition (big endian - see below) + * 64 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) + * 4 bytes: checksum of the kernel partition + * 4 bytes: length of the contained kernel image file (big endian) + * rest: 0xff padding (To erase block size) + * + * The kernel partition checksum and length is not used for every device. + * If it's notused, pad those 8 bytes with 0xFF. + * + * The checksums are calculated by adding up all bytes and if a 16bit + * overflow occurs, one is added and the sum is masked to 16 bit: + * csum = csum + databyte; if (csum > 0xffff) { csum += 1; csum &= 0xffff }; + * Should the file have an odd number of bytes then the byte len-0x800 is + * used additionally. + * + * The checksum for the header is calculated over the first 2048 bytes with + * the rootfs image checksum as the placeholder during calculation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +#define VERSION_STRING_LEN 31 +#define ROOTFS_HEADER_LEN 40 + +#define KERNEL_HEADER_LEN 8 + +#define BOARD_NAME_LEN 64 +#define BOARD_HEADER_LEN 68 + +#define HEADER_PARTITION_CALC_LENGTH 2048 +#define HEADER_PARTITION_LENGTH 0x10000 + +struct file_info { + char *name; /* name of the file */ + char *data; /* file content */ + size_t size; /* length of the file */ +}; + +static char *progname; + +static char *board_name = 0; +static char *version_name = 0; +static unsigned int rootfs_size = 0; + +static struct file_info kernel = { NULL, NULL, 0 }; +static struct file_info rootfs = { NULL, NULL, 0 }; +static struct file_info rootfs_out = { NULL, NULL, 0 }; +static struct file_info out = { NULL, NULL, 0 }; + +#define ERR(fmt, ...) do { \ + fprintf(stderr, "[%s] *** error: " fmt "\n", \ + progname, ## __VA_ARGS__ ); \ +} while (0) + +void map_file(struct file_info *finfo) +{ + struct stat file_stat = {0}; + int fd; + + fd = open(finfo->name, O_RDONLY, (mode_t)0600); + if (fd == -1) { + ERR("Error while opening file %s.", finfo->name); + exit(EXIT_FAILURE); + } + + if (fstat(fd, &file_stat) == -1) { + ERR("Error getting file size for %s.", finfo->name); + exit(EXIT_FAILURE); + } + + finfo->size = file_stat.st_size; + finfo->data = mmap(0, finfo->size, PROT_READ, MAP_SHARED, fd, 0); + + if (finfo->data == MAP_FAILED) { + ERR("Error mapping file %s.", finfo->name); + exit(EXIT_FAILURE); + } + + close(fd); +} + +void unmap_file(struct file_info *finfo) +{ + if(munmap(finfo->data, finfo->size) == -1) { + ERR("Error unmapping file %s.", finfo->name); + exit(EXIT_FAILURE); + } +} + +void write_file(struct file_info *finfo) +{ + FILE *fout = fopen(finfo->name, "w"); + + fwrite(finfo->data, finfo->size, 1, fout); + + if (ferror(fout)) { + ERR("Wanted to write, but something went wrong."); + exit(EXIT_FAILURE); + } + + fclose(fout); +} + +void usage(int status) +{ + FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout; + + fprintf(stream, "Usage: %s [OPTIONS...]\n", progname); + fprintf(stream, + "\n" + "Options:\n" + " -k path for kernel image\n" + " -r path for rootfs image\n" + " -s size of output rootfs\n" + " -v version string\n" + " -b name of board to generate image for\n" + " -o name of output image\n" + " -h show this screen\n" + ); + + exit(status); +} + +static int sysv_chksm(const unsigned char *data, int size) +{ + int r; + int checksum; + unsigned int s = 0; /* The sum of all the input bytes, modulo (UINT_MAX + 1). */ + + + for (int i = 0; i < size; i++) { + s += data[i]; + } + + r = (s & 0xffff) + ((s & 0xffffffff) >> 16); + checksum = (r & 0xffff) + (r >> 16); + + return checksum; +} + +static int zyxel_chksm(const unsigned char *data, int size) +{ + return htonl(sysv_chksm(data, size)); +} + +char *generate_rootfs_header(struct file_info filesystem, char *version) +{ + size_t version_string_length; + unsigned int chksm, size; + char *rootfs_header; + size_t ptr = 0; + + rootfs_header = malloc(ROOTFS_HEADER_LEN); + if (!rootfs_header) { + ERR("Couldn't allocate memory for rootfs header!"); + exit(EXIT_FAILURE); + } + + /* Prepare padding for firmware-version string here */ + memset(rootfs_header, 0xff, ROOTFS_HEADER_LEN); + + chksm = zyxel_chksm((const unsigned char *)filesystem.data, filesystem.size); + size = htonl(filesystem.size); + + /* 4 bytes: checksum of the rootfs image */ + memcpy(rootfs_header + ptr, &chksm, 4); + ptr += 4; + + /* 4 bytes: length of the contained rootfs image file (big endian) */ + memcpy(rootfs_header + ptr, &size, 4); + ptr += 4; + + /* 32 bytes: Firmware Version string (NUL terminated, 0xff padded) */ + version_string_length = strlen(version) <= VERSION_STRING_LEN ? strlen(version) : VERSION_STRING_LEN; + memcpy(rootfs_header + ptr, version, version_string_length); + ptr += version_string_length; + /* Add null-terminator */ + rootfs_header[ptr] = 0x0; + + return rootfs_header; +} + +char *generate_kernel_header(struct file_info kernel) +{ + unsigned int chksm, size; + char *kernel_header; + size_t ptr = 0; + + kernel_header = malloc(KERNEL_HEADER_LEN); + if (!kernel_header) { + ERR("Couldn't allocate memory for kernel header!"); + exit(EXIT_FAILURE); + } + + chksm = zyxel_chksm((const unsigned char *)kernel.data, kernel.size); + size = htonl(kernel.size); + + /* 4 bytes: checksum of the kernel image */ + memcpy(kernel_header + ptr, &chksm, 4); + ptr += 4; + + /* 4 bytes: length of the contained kernel image file (big endian) */ + memcpy(kernel_header + ptr, &size, 4); + + return kernel_header; +} + +unsigned int generate_board_header_checksum(char *kernel_hdr, char *rootfs_hdr, char *boardname) +{ + char *board_hdr_tmp; + unsigned int sum; + size_t ptr = 0; + + /* + * The checksum of the board header is calculated over the first 2048 bytes of + * the header partition with the rootfs checksum used as a placeholder for then + * board checksum we calculate in this step. The checksum gained from this step + * is then used for the final board header partition. + */ + + board_hdr_tmp = malloc(HEADER_PARTITION_CALC_LENGTH); + if (!board_hdr_tmp) { + ERR("Couldn't allocate memory for temporary board header!"); + exit(EXIT_FAILURE); + } + memset(board_hdr_tmp, 0xff, HEADER_PARTITION_CALC_LENGTH); + + /* 40 bytes: RootFS header */ + memcpy(board_hdr_tmp, rootfs_hdr, ROOTFS_HEADER_LEN); + ptr += ROOTFS_HEADER_LEN; + + /* 4 bytes: RootFS checksum (BE) as placeholder for board-header checksum */ + memcpy(board_hdr_tmp + ptr, rootfs_hdr, 4); + ptr += 4; + + /* 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) */ + memcpy(board_hdr_tmp + ptr, boardname, strlen(boardname)); + ptr += strlen(boardname); + /* Add null-terminator */ + board_hdr_tmp[ptr] = 0x0; + ptr = ROOTFS_HEADER_LEN + 4 + BOARD_NAME_LEN; + + /* 8 bytes: Kernel header */ + if (kernel_hdr) + memcpy(board_hdr_tmp + ptr, kernel_hdr, 8); + + /* Calculate the checksum over the first 2048 bytes */ + sum = zyxel_chksm((const unsigned char *)board_hdr_tmp, HEADER_PARTITION_CALC_LENGTH); + free(board_hdr_tmp); + return sum; +} + +char *generate_board_header(char *kernel_hdr, char *rootfs_hdr, char *boardname) +{ + unsigned int board_checksum; + char *board_hdr; + + board_hdr = malloc(BOARD_HEADER_LEN); + if (!board_hdr) { + ERR("Couldn't allocate memory for board header!"); + exit(EXIT_FAILURE); + } + memset(board_hdr, 0xff, BOARD_HEADER_LEN); + + /* 4 bytes: checksum over the header partition (big endian) */ + board_checksum = generate_board_header_checksum(kernel_hdr, rootfs_hdr, boardname); + memcpy(board_hdr, &board_checksum, 4); + + /* 32 bytes: Model (e.g. "NBG6617", NUL termiated, 0xff padded) */ + memcpy(board_hdr + 4, boardname, strlen(boardname)); + board_hdr[4 + strlen(boardname)] = 0x0; + + return board_hdr; +} + +int build_image() +{ + char *rootfs_header = NULL; + char *kernel_header = NULL; + char *board_header = NULL; + + size_t ptr; + + /* Load files */ + if (kernel.name) + map_file(&kernel); + map_file(&rootfs); + + /* + * Allocate memory and copy input rootfs for temporary output rootfs. + * This is important as we have to generate the rootfs checksum over the + * entire rootfs partition. As we might have to pad the partition to allow + * for flashing via ZyXEL's Web-GUI, we prepare the rootfs partition for the + * output image here (and also use it for calculating the rootfs checksum). + * + * The roofs padding has to be done with 0x00. + */ + rootfs_out.data = calloc(rootfs_out.size, sizeof(char)); + memcpy(rootfs_out.data, rootfs.data, rootfs.size); + + /* Prepare headers */ + rootfs_header = generate_rootfs_header(rootfs_out, version_name); + if (kernel.name) + kernel_header = generate_kernel_header(kernel); + board_header = generate_board_header(kernel_header, rootfs_header, board_name); + + /* Prepare output file */ + out.size = HEADER_PARTITION_LENGTH + rootfs_out.size; + if (kernel.name) + out.size += kernel.size; + out.data = malloc(out.size); + memset(out.data, 0xFF, out.size); + + /* Build output image */ + memcpy(out.data, rootfs_header, ROOTFS_HEADER_LEN); + memcpy(out.data + ROOTFS_HEADER_LEN, board_header, BOARD_HEADER_LEN); + if (kernel.name) + memcpy(out.data + ROOTFS_HEADER_LEN + BOARD_HEADER_LEN, kernel_header, KERNEL_HEADER_LEN); + ptr = HEADER_PARTITION_LENGTH; + memcpy(out.data + ptr, rootfs_out.data, rootfs_out.size); + ptr += rootfs_out.size; + if (kernel.name) + memcpy(out.data + ptr, kernel.data, kernel.size); + + /* Write back output image */ + write_file(&out); + + /* Free allocated memory */ + if (kernel.name) + unmap_file(&kernel); + unmap_file(&rootfs); + free(out.data); + free(rootfs_out.data); + + free(rootfs_header); + if (kernel.name) + free(kernel_header); + free(board_header); + + return 0; +} + +int check_options() +{ + if (!rootfs.name) { + ERR("No rootfs filename supplied"); + return -2; + } + + if (!out.name) { + ERR("No output filename supplied"); + return -3; + } + + if (!board_name) { + ERR("No board-name supplied"); + return -4; + } + + if (!version_name) { + ERR("No version supplied"); + return -5; + } + + if (rootfs_size <= 0) { + ERR("Invalid rootfs size supplied"); + return -6; + } + + if (strlen(board_name) > 31) { + ERR("Board name is to long"); + return -7; + } + return 0; +} + +int main(int argc, char *argv[]) +{ + int ret; + progname = basename(argv[0]); + while (1) { + int c; + + c = getopt(argc, argv, "b:k:o:r:s:v:h"); + if (c == -1) + break; + + switch (c) { + case 'b': + board_name = optarg; + break; + case 'h': + usage(EXIT_SUCCESS); + break; + case 'k': + kernel.name = optarg; + break; + case 'o': + out.name = optarg; + break; + case 'r': + rootfs.name = optarg; + break; + case 's': + sscanf(optarg, "%u", &rootfs_size); + break; + case 'v': + version_name = optarg; + break; + default: + usage(EXIT_FAILURE); + break; + } + } + + ret = check_options(); + if (ret) + usage(EXIT_FAILURE); + + /* As ZyXEL Web-GUI only accept images with a rootfs equal or larger than the first firmware shipped + * for the device, we need to pad rootfs partition to this size. To perform further calculations, we + * decide the size of this part here. In case the rootfs we want to integrate in our image is larger, + * take it's size, otherwise the supplied size. + * + * Be careful! We rely on assertion of correct size to be performed beforehand. It is unknown if images + * with a to large rootfs are accepted or not. + */ + rootfs_out.size = rootfs_size < rootfs.size ? rootfs.size : rootfs_size; + return build_image(); +} diff --git a/tools/firmware-utils/src/mksenaofw.c b/tools/firmware-utils/src/mksenaofw.c index 0f10ebdfbe..b0fb7203c3 100644 --- a/tools/firmware-utils/src/mksenaofw.c +++ b/tools/firmware-utils/src/mksenaofw.c @@ -55,6 +55,7 @@ typedef enum { } op_mode; static firmware_type FIRMWARE_TYPES[] = { + { 0x00, "combo" }, /* Used for new capwap-included style header */ { 0x01, "bootloader" }, { 0x02, "kernel" }, { 0x03, "kernelapp" }, @@ -70,6 +71,21 @@ static firmware_type FIRMWARE_TYPES[] = { { 0x0c, "langpack (D-Link)" } }; +#define MOD_DEFAULT 0x616C6C00 +#define SKU_DEFAULT 0x0 +#define DATECODE_NONE 0xFFFFFFFF +#define FIRMWARE_TYPE_NONE 0xFF + +struct capwap_header { + uint32_t mod; + uint32_t sku; + uint32_t firmware_ver[3]; + uint32_t datecode; + uint32_t capwap_ver[3]; + uint32_t model_size; + uint8_t model[]; +}; + static long get_file_size(const char *filename) { FILE *fp_file; @@ -84,15 +100,14 @@ static long get_file_size(const char *filename) return result; } -static int header_checksum(void *data, int len) +static int header_checksum(void *data, size_t len) { - int i; - int sum; + int sum = 0; /* shouldn't this be unsigned ? */ + size_t i; - sum = 0; - if (data != NULL && len >= 0) { + if (data != NULL && len > 0) { for (i = 0; i < len; ++i) - sum += *(unsigned char *) (data + i); + sum += ((unsigned char *)data)[i]; return sum; } @@ -124,18 +139,20 @@ static int md5_file(const char *filename, uint8_t *dst) } static int encode_image(const char *input_file_name, - const char *output_file_name, img_header *header, int block_size) + const char *output_file_name, img_header *header, + struct capwap_header *cw_header, int block_size) { char buf[BUF_SIZE]; - size_t bytes_read; size_t pad_len = 0; size_t bytes_avail; + size_t bytes_read; - FILE *fp_input; FILE *fp_output; + FILE *fp_input; - int i; + int model_size; long magic; + size_t i; fp_input = fopen(input_file_name, "r+b"); if (!fp_input) { @@ -172,6 +189,11 @@ static int encode_image(const char *input_file_name, } header->zero = 0; header->chksum = header_checksum(header, HDR_LEN); + if (cw_header) { + header->chksum += header_checksum(cw_header, + sizeof(struct capwap_header) + cw_header->model_size); + } + header->head = htonl(header->head); header->vendor_id = htonl(header->vendor_id); header->product_id = htonl(header->product_id); @@ -183,6 +205,22 @@ static int encode_image(const char *input_file_name, fwrite(header, HDR_LEN, 1, fp_output); + if (cw_header) { + model_size = cw_header->model_size; + cw_header->mod = htonl(cw_header->mod); + cw_header->sku = htonl(cw_header->sku); + cw_header->firmware_ver[0] = htonl(cw_header->firmware_ver[0]); + cw_header->firmware_ver[1] = htonl(cw_header->firmware_ver[1]); + cw_header->firmware_ver[2] = htonl(cw_header->firmware_ver[2]); + cw_header->datecode = htonl(cw_header->datecode); + cw_header->capwap_ver[0] = htonl(cw_header->capwap_ver[0]); + cw_header->capwap_ver[1] = htonl(cw_header->capwap_ver[1]); + cw_header->capwap_ver[2] = htonl(cw_header->capwap_ver[2]); + cw_header->model_size = htonl(cw_header->model_size); + fwrite(cw_header, sizeof(struct capwap_header) + model_size, 1, + fp_output); + } + while (!feof(fp_input) || pad_len > 0) { if (!feof(fp_input)) @@ -212,32 +250,33 @@ static int encode_image(const char *input_file_name, int decode_image(const char *input_file_name, const char *output_file_name) { - img_header header; + struct capwap_header cw_header; char buf[BUF_SIZE]; + img_header header; + char *pmodel = NULL; FILE *fp_input; FILE *fp_output; - unsigned int i; size_t bytes_read; size_t bytes_written; + unsigned int i; fp_input = fopen(input_file_name, "r+b"); if (!fp_input) { fprintf(stderr, "Cannot open %s !!\n", input_file_name); - fclose(fp_input); return -1; } fp_output = fopen(output_file_name, "w+b"); if (!fp_output) { fprintf(stderr, "Cannot open %s !!\n", output_file_name); - fclose(fp_output); + fclose(fp_input); return -1; } if (fread(&header, 1, HDR_LEN, fp_input) != HDR_LEN) { - fprintf(stderr, "Incorrect header size!!"); + fprintf(stderr, "Incorrect header size reading base header!!"); fclose(fp_input); fclose(fp_output); return -1; @@ -251,6 +290,44 @@ int decode_image(const char *input_file_name, const char *output_file_name) header.chksum = ntohl(header.chksum); header.magic = ntohl(header.magic); + /* read capwap header if firmware_type is zero */ + if (header.firmware_type == 0) { + if (fread(&cw_header, 1, sizeof(struct capwap_header), + fp_input) != sizeof(struct capwap_header)) { + fprintf(stderr, "Incorrect header size reading capwap_header!!"); + fclose(fp_input); + fclose(fp_output); + return -1; + } + cw_header.mod = ntohl(cw_header.mod); + cw_header.sku = ntohl(cw_header.sku); + cw_header.firmware_ver[0] = ntohl(cw_header.firmware_ver[0]); + cw_header.firmware_ver[1] = ntohl(cw_header.firmware_ver[1]); + cw_header.firmware_ver[2] = ntohl(cw_header.firmware_ver[2]); + cw_header.datecode = ntohl(cw_header.datecode); + cw_header.capwap_ver[0] = ntohl(cw_header.capwap_ver[0]); + cw_header.capwap_ver[1] = ntohl(cw_header.capwap_ver[1]); + cw_header.capwap_ver[2] = ntohl(cw_header.capwap_ver[2]); + cw_header.model_size = ntohl(cw_header.model_size); + + pmodel = malloc(cw_header.model_size + 1); + if (pmodel) { + pmodel[cw_header.model_size] = '\0'; + if (fread(pmodel, 1, cw_header.model_size, fp_input) != + cw_header.model_size) { + fprintf(stderr, "Incorrect header size reading model name!!"); + fclose(fp_input); + fclose(fp_output); + return -1; + } + } else { + fprintf(stderr, "Incorrect header size reading model name!!"); + fclose(fp_input); + fclose(fp_output); + return -1; + } + } + bytes_written = 0; while (!feof(fp_input)) { @@ -281,7 +358,7 @@ int decode_image(const char *input_file_name, const char *output_file_name) static void usage(const char *progname, int status) { FILE *stream = (status != EXIT_SUCCESS) ? stderr : stdout; - int i; + size_t i; fprintf(stream, "Usage: %s [OPTIONS...]\n", progname); fprintf(stream, "\n" @@ -301,28 +378,47 @@ static void usage(const char *progname, int status) " -m set encoding magic \n" " -z enable image padding to \n" " -b set image , defaults to %u\n" + " -c add capwap header with (e.g. 171101)\n" + " -w firmware version for capwap header (e.g. 3.0.1)\n" + " -x capwap firmware version for capwap header (e.g. 1.8.53)\n" + " -n model name for capwap header (e.g. ENS620EXT)\n" " -h show this screen\n", DEFAULT_BLOCK_SIZE); exit(status); } int main(int argc, char *argv[]) { - int opt; - char *input_file, *output_file, *progname = NULL; - op_mode mode = NONE; - int tmp, i, pad = 0; - int block_size; + static const char period[2] = "."; + struct capwap_header cw_header; img_header header; + struct capwap_header *pcw_header = NULL; + char *output_file = NULL; + char *input_file = NULL; + char *progname = NULL; + char *mod_name = NULL; + char *token; + + op_mode mode = NONE; + int tmp, pad = 0; + int block_size; + size_t i; + int opt; + block_size = DEFAULT_BLOCK_SIZE; progname = basename(argv[0]); - memset(&header, 0, sizeof( img_header )); + memset(&header, 0, sizeof(img_header)); header.magic = DEFAULT_MAGIC; header.head = DEFAULT_HEAD_VALUE; + header.firmware_type = FIRMWARE_TYPE_NONE; + memset(&cw_header, 0, sizeof(struct capwap_header)); + cw_header.mod = MOD_DEFAULT; + cw_header.sku = SKU_DEFAULT; + cw_header.datecode = DATECODE_NONE; strncpy( (char*)&header.version, DEFAULT_VERSION, VERSION_SIZE - 1); - while ((opt = getopt(argc, argv, ":o:e:d:t:v:r:p:m:b:h?z")) != -1) { + while ((opt = getopt(argc, argv, ":o:e:d:t:v:r:p:m:b:c:w:x:n:h?z")) != -1) { switch (opt) { case 'e': input_file = optarg; @@ -344,7 +440,7 @@ int main(int argc, char *argv[]) break; } } - if (header.firmware_type == 0) { + if (header.firmware_type == FIRMWARE_TYPE_NONE) { fprintf(stderr, "Invalid firmware type \"0\"!\n"); usage(progname, EXIT_FAILURE); } @@ -368,6 +464,31 @@ int main(int argc, char *argv[]) case 'b': block_size = strtol(optarg, 0, 10); break; + case 'c': + cw_header.datecode = strtoul(optarg, 0, 10); + break; + case 'w': + token = strtok(optarg, period); + i = 0; + while (token && (i < 3)) { + cw_header.firmware_ver[i++] = + strtoul(token, 0, 10); + token = strtok(NULL, period); + } + break; + case 'x': + token = strtok(optarg, period); + i = 0; + while (token && (i < 3)) { + cw_header.capwap_ver[i++] = + strtoul(token, 0, 10); + token = strtok(NULL, period); + } + break; + case 'n': + mod_name = optarg; + cw_header.model_size = strlen(mod_name); + break; case 'h': usage(progname, EXIT_SUCCESS); break; @@ -403,17 +524,46 @@ int main(int argc, char *argv[]) return EXIT_SUCCESS; } - if (header.firmware_type == 0) { - fprintf(stderr, "Firmware type must be defined\n"); + if ((header.firmware_type == 0) && + (cw_header.datecode == DATECODE_NONE)) { + fprintf(stderr, "Firmware type must be non-zero for non-capwap images\n"); usage(progname, EXIT_FAILURE); } if (header.vendor_id == 0 || header.product_id == 0) { - fprintf(stderr, "Vendor ID and Product ID must be defined and non-zero\n"); + fprintf(stderr, "Vendor ID and Product ID must be defined and non-zero\n"); usage(progname, EXIT_FAILURE); } - if (encode_image(input_file, output_file, &header, pad ? block_size : 0) < 0) + /* Check capwap header specific arguments */ + if (cw_header.datecode != DATECODE_NONE) { + if (!mod_name) { + fprintf(stderr, "Capwap header specified: model name must be specified\n"); + usage(progname, EXIT_FAILURE); + } + if (!cw_header.firmware_ver[0] && !cw_header.firmware_ver[1] && + !cw_header.firmware_ver[2]) { + fprintf(stderr, "Capwap header specified, fw_ver must be non-zero\n"); + } + if (!cw_header.capwap_ver[0] && !cw_header.capwap_ver[1] && + !cw_header.capwap_ver[2]) { + fprintf(stderr, "Capwap header specified, cw_ver must be non-zero\n"); + } + pcw_header = malloc(sizeof(struct capwap_header) + + cw_header.model_size); + if (pcw_header) { + memcpy(pcw_header, &cw_header, + sizeof(struct capwap_header)); + memcpy(&(pcw_header->model), mod_name, + cw_header.model_size); + } else { + fprintf(stderr, "Failed to allocate memory\n"); + return EXIT_FAILURE; + } + } + + if (encode_image(input_file, output_file, &header, pcw_header, + pad ? block_size : 0) < 0) return EXIT_FAILURE; return EXIT_SUCCESS; diff --git a/tools/firmware-utils/src/mksercommfw.c b/tools/firmware-utils/src/mksercommfw.c new file mode 100644 index 0000000000..f6f1d93f37 --- /dev/null +++ b/tools/firmware-utils/src/mksercommfw.c @@ -0,0 +1,261 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#if !defined(__BYTE_ORDER) +#error "Unknown byte order" +#endif + +#if __BYTE_ORDER == __BIG_ENDIAN +#define cpu_to_be32(x) (x) +#elif __BYTE_ORDER == __LITTLE_ENDIAN +#define cpu_to_be32(x) bswap_32(x) +#else +#error "Unsupported endianness" +#endif + +/* #define DEBUG 1 */ + +#ifdef DEBUG +#define DBG(...) {printf(__VA_ARGS__); } +#else +#define DBG(...) {} +#endif + +#define ERR(...) {printf(__VA_ARGS__); } + +/* + * Fw Header Layout for Netgear / Sercomm devices (bytes) + * + * Size : 512 bytes + zipped image size + * + * Locations: + * magic : 0-6 ASCII + * version: 7-11 fixed + * hwID : 11-44 ASCII + * hwVer : 45-54 ASCII + * swVer : 55-62 uint32_t in BE + * magic : 63-69 ASCII + * ChkSum : 511 Inverse value of the full image checksum while this location is 0x00 + */ +static const char* magic = "sErCoMm"; /* 7 */ +static const unsigned char version[4] = { 0x00, 0x01, 0x00, 0x00 }; +static const int header_sz = 512; +static const int footer_sz = 71; + +static int is_header = 1; + +struct file_info { + char* file_name; /* name of the file */ + char* file_data; /* data of the file in memory */ + u_int32_t file_size; /* length of the file */ +}; + +static u_int8_t getCheckSum(char* data, int len) { + u_int8_t new = 0; + int i; + + if (!data) { + ERR("Invalid pointer provided!\n"); + return 0; + } + + for (i = 0; i < len; i++) { + new += data[i]; + } + + return new; +} + +/* + * read file into buffer + * add space for header/footer + */ +static int copyToOutputBuf(struct file_info* finfo) { + FILE* fp = NULL; + + int file_sz = 0; + int extra_sz; + int hdr_pos; + int img_pos; + + if (!finfo || !finfo->file_name) { + ERR("Invalid pointer provided!\n"); + return -1; + } + + DBG("Opening file: %s\n", finfo->file_name); + + if (!(fp = fopen(finfo->file_name, "rb"))) { + ERR("Error opening file: %s\n", finfo->file_name); + return -1; + } + + /* Get filesize */ + rewind(fp); + fseek(fp, 0L, SEEK_END); + file_sz = ftell(fp); + rewind(fp); + + if (file_sz < 1) { + ERR("Error getting filesize: %s\n", finfo->file_name); + fclose(fp); + return -1; + } + + if (is_header) { + extra_sz = header_sz; + hdr_pos = 0; + img_pos = header_sz; + } else { + extra_sz = footer_sz; + hdr_pos = file_sz; + img_pos = 0; + } + + DBG("Filesize: %i\n", file_sz); + finfo->file_size = file_sz + extra_sz; + + if (!(finfo->file_data = malloc(finfo->file_size))) { + ERR("Out of memory!\n"); + fclose(fp); + return -1; + } + + /* init header/footer bytes */ + memset(finfo->file_data + hdr_pos, 0, extra_sz); + + /* read file and take care of leading header if exists */ + if (fread(finfo->file_data + img_pos, 1, file_sz, fp) != file_sz) { + ERR("Error reading file %s\n", finfo->file_name); + fclose(fp); + return -1; + } + + DBG("File: read successful\n"); + fclose(fp); + + return hdr_pos; +} + +static int writeFile(struct file_info* finfo) { + FILE* fp; + + if (!finfo || !finfo->file_name) { + ERR("Invalid pointer provided!\n"); + return -1; + } + + DBG("Opening file: %s\n", finfo->file_name); + + if (!(fp = fopen(finfo->file_name, "w"))) { + ERR("Error opening file: %s\n", finfo->file_name); + return -1; + } + + DBG("Writing file: %s\n", finfo->file_name); + + if (fwrite(finfo->file_data, 1, finfo->file_size, fp) != finfo->file_size) { + ERR("Wanted to write, but something went wrong!\n"); + fclose(fp); + return -1; + } + + fclose(fp); + return 0; +} + +static void usage(char* argv[]) { + printf("Usage: %s [OPTIONS...]\n" + "\n" + "Options:\n" + " -f add sercom footer (if absent, header)\n" + " -b use hardware id specified with (ASCII)\n" + " -r use hardware revision specified with (ASCII)\n" + " -v set image version to (decimal, hex or octal notation)\n" + " -i input file\n" + , argv[0]); +} + +int main(int argc, char* argv[]) { + struct file_info image = { 0 }; + + char* hwID = NULL; + char* hwVer = NULL; + u_int32_t swVer = 0; + u_int8_t chkSum; + int hdr_offset; + + while ( 1 ) { + int c; + + c = getopt(argc, argv, "b:i:r:v:f"); + if (c == -1) + break; + + switch (c) { + case 'b': + hwID = optarg; + break; + case 'f': + is_header = 0; + break; + case 'i': + image.file_name = optarg; + break; + case 'r': + hwVer = optarg; + break; + case 'v': + swVer = (u_int32_t) strtol(optarg, NULL, 0); + swVer = cpu_to_be32(swVer); + break; + default: + usage(argv); + return EXIT_FAILURE; + } + } + + if (!hwID || !hwVer || !image.file_name) { + usage(argv); + return EXIT_FAILURE; + } + + /* + * copy input to buffer, add extra space for header/footer and return + * header position + */ + hdr_offset = copyToOutputBuf(&image); + if (hdr_offset < 0) + return EXIT_FAILURE; + + DBG("Filling header: %s %s %2X %s\n", hwID, hwVer, swVer, magic); + + strncpy(image.file_data + hdr_offset + 0, magic, 7); + memcpy(image.file_data + hdr_offset + 7, version, sizeof(version)); + strncpy(image.file_data + hdr_offset + 11, hwID, 34); + strncpy(image.file_data + hdr_offset + 45, hwVer, 10); + memcpy(image.file_data + hdr_offset + 55, &swVer, sizeof(swVer)); + strncpy(image.file_data + hdr_offset + 63, magic, 7); + + /* calculate checksum and invert checksum */ + if (is_header) { + chkSum = getCheckSum(image.file_data, image.file_size); + chkSum = (chkSum ^ 0xFF) + 1; + DBG("Checksum for Image: %hhX\n", chkSum); + + /* write checksum to header */ + image.file_data[511] = (char) chkSum; + } + + /* overwrite input file */ + if (writeFile(&image)) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} diff --git a/tools/firmware-utils/src/mktplinkfw.c b/tools/firmware-utils/src/mktplinkfw.c index ab5fd6d58b..ce2acc20c9 100644 --- a/tools/firmware-utils/src/mktplinkfw.c +++ b/tools/firmware-utils/src/mktplinkfw.c @@ -107,6 +107,7 @@ static uint32_t reserved_space; static struct file_info inspect_info; static int extract = 0; static bool endian_swap = false; +static bool rootfs_ofs_calc = false; static const char md5salt_normal[MD5SUM_LEN] = { 0xdc, 0xd7, 0x3a, 0xa5, 0xc3, 0x95, 0x98, 0xfb, @@ -202,6 +203,7 @@ static void usage(int status) " -r read rootfs image from the file \n" " -a align the rootfs start on an bytes boundary\n" " -R overwrite rootfs offset with (hexval prefixed with 0x)\n" +" -O calculate rootfs offset for combined images\n" " -o write output to the file \n" " -s strip padding from the end of the image\n" " -j add jffs2 end-of-filesystem markers\n" @@ -384,6 +386,10 @@ void fill_header(char *buf, int len) hdr->rootfs_len = htonl(rootfs_info.file_size); } + if (combined && rootfs_ofs_calc) { + hdr->rootfs_ofs = htonl(sizeof(struct fw_header) + kernel_len); + } + hdr->ver_hi = htons(fw_ver_hi); hdr->ver_mid = htons(fw_ver_mid); hdr->ver_lo = htons(fw_ver_lo); @@ -539,7 +545,7 @@ int main(int argc, char *argv[]) while ( 1 ) { int c; - c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:xX:ehsjv:"); + c = getopt(argc, argv, "a:H:E:F:L:m:V:N:W:C:ci:k:r:R:o:OxX:ehsjv:"); if (c == -1) break; @@ -592,6 +598,9 @@ int main(int argc, char *argv[]) case 'o': ofname = optarg; break; + case 'O': + rootfs_ofs_calc = 1; + break; case 's': strip_padding = 1; break; diff --git a/tools/firmware-utils/src/mktplinkfw2.c b/tools/firmware-utils/src/mktplinkfw2.c index dead49e7af..102d72b1cc 100644 --- a/tools/firmware-utils/src/mktplinkfw2.c +++ b/tools/firmware-utils/src/mktplinkfw2.c @@ -146,12 +146,30 @@ static struct flash_layout layouts[] = { .kernel_la = 0x80000000, .kernel_ep = 0x80000000, .rootfs_ofs = 0x140000, + }, { + .id = "8MSUmtk", /* Split U-Boot OS */ + .fw_max_len = 0x770000, + .kernel_la = 0x80000000, + .kernel_ep = 0x80000000, + .rootfs_ofs = 0x140000, }, { .id = "8MLmtk", .fw_max_len = 0x7b0000, .kernel_la = 0x80000000, .kernel_ep = 0x80000000, .rootfs_ofs = 0x140000, + }, { + .id = "8Mqca", + .fw_max_len = 0x7a0000, + .kernel_la = 0x80060000, + .kernel_ep = 0x80060000, + .rootfs_ofs = 0x140000, + }, { + .id = "16Mqca", + .fw_max_len = 0xf90000, + .kernel_la = 0x80060000, + .kernel_ep = 0x80060000, + .rootfs_ofs = 0x140000, }, { /* terminating entry */ } diff --git a/tools/firmware-utils/src/nec-enc.c b/tools/firmware-utils/src/nec-enc.c new file mode 100644 index 0000000000..3c4e38721e --- /dev/null +++ b/tools/firmware-utils/src/nec-enc.c @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * nec-enc.c - encode/decode nec firmware with key + * + * based on xorimage.c in OpenWrt + * + */ + +#include +#include +#include +#include +#include + +#define KEY_LEN 16 +#define PATTERN_LEN 251 + +static int +xor_pattern(uint8_t *data, size_t len, const char *key, int k_len, int k_off) +{ + int offset = k_off; + + while (len--) { + *data ^= key[offset]; + data++; + offset = (offset + 1) % k_len; + } + + return offset; +} + +static void xor_data(uint8_t *data, size_t len, const uint8_t *pattern) +{ + for (int i = 0; i < len; i++) { + *data ^= pattern[i]; + data++; + } +} + +static void __attribute__((noreturn)) usage(void) +{ + fprintf(stderr, "Usage: nec-enc -i infile -o outfile -k \n"); + exit(EXIT_FAILURE); +} + +static unsigned char buf_pattern[4096], buf[4096]; + +int main(int argc, char **argv) +{ + int k_off = 0, ptn = 0, c, ret = EXIT_SUCCESS; + char *ifn = NULL, *ofn = NULL, *key = NULL; + size_t n, k_len; + FILE *out, *in; + + while ((c = getopt(argc, argv, "i:o:k:h")) != -1) { + switch (c) { + case 'i': + ifn = optarg; + break; + case 'o': + ofn = optarg; + break; + case 'k': + key = optarg; + break; + case 'h': + default: + usage(); + } + } + + if (optind != argc || optind == 1) { + fprintf(stderr, "illegal arg \"%s\"\n", argv[optind]); + usage(); + } + + in = fopen(ifn, "r"); + if (!in) { + perror("can not open input file"); + usage(); + } + + out = fopen(ofn, "w"); + if (!out) { + perror("can not open output file"); + usage(); + } + + if (!key) { + fprintf(stderr, "key is not specified\n"); + usage(); + } + + k_len = strnlen(key, KEY_LEN + 1); + if (k_len == 0 || k_len > KEY_LEN) { + fprintf(stderr, "key length is not in range (0,%d)\n", KEY_LEN); + usage(); + } + + while ((n = fread(buf, 1, sizeof(buf), in)) > 0) { + for (int i = 0; i < n; i++) { + buf_pattern[i] = ptn + 1; + ptn++; + + if (ptn > 250) + ptn = 0; + } + + k_off = xor_pattern(buf_pattern, n, key, k_len, k_off); + xor_data(buf, n, buf_pattern); + + if (fwrite(buf, 1, n, out) != n) { + perror("failed to write"); + ret = EXIT_FAILURE; + goto out; + } + } + + if (ferror(in)) { + perror("failed to read"); + ret = EXIT_FAILURE; + goto out; + } + +out: + fclose(in); + fclose(out); + return ret; +} diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c index 13e0eda622..0192bb65e5 100644 --- a/tools/firmware-utils/src/ptgen.c +++ b/tools/firmware-utils/src/ptgen.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -59,6 +60,7 @@ int active = 1; int heads = -1; int sectors = -1; int kb_align = 0; +bool ignore_null_sized_partition = false; struct partinfo parts[4]; char *filename = NULL; @@ -140,6 +142,8 @@ static int gen_ptable(uint32_t signature, int nr) memset(pte, 0, sizeof(struct pte) * 4); for (i = 0; i < nr; i++) { if (!parts[i].size) { + if (ignore_null_sized_partition) + continue; fprintf(stderr, "Invalid size in partition %d!\n", i); return -1; } @@ -196,7 +200,7 @@ fail: static void usage(char *prog) { - fprintf(stderr, "Usage: %s [-v] -h -s -o [-a 0..4] [-l ] [[-t ] -p ...] \n", prog); + fprintf(stderr, "Usage: %s [-v] [-n] -h -s -o [-a 0..4] [-l ] [[-t ] -p ...] \n", prog); exit(EXIT_FAILURE); } @@ -207,7 +211,7 @@ int main (int argc, char **argv) int part = 0; uint32_t signature = 0x5452574F; /* 'OWRT' */ - while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vl:S:")) != -1) { + while ((ch = getopt(argc, argv, "h:s:p:a:t:o:vnl:S:")) != -1) { switch (ch) { case 'o': filename = optarg; @@ -215,6 +219,9 @@ int main (int argc, char **argv) case 'v': verbose++; break; + case 'n': + ignore_null_sized_partition = true; + break; case 'h': heads = (int)strtoul(optarg, NULL, 0); break; diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c index 4b227e1c97..ce3a039e7e 100644 --- a/tools/firmware-utils/src/tplink-safeloader.c +++ b/tools/firmware-utils/src/tplink-safeloader.c @@ -65,7 +65,7 @@ struct image_partition_entry { /** A flash partition table entry */ struct flash_partition_entry { - const char *name; + char *name; uint32_t base; uint32_t size; }; @@ -77,7 +77,7 @@ struct device_info { const char *support_list; char support_trail; const char *soft_ver; - const struct flash_partition_entry partitions[MAX_PARTITIONS+1]; + struct flash_partition_entry partitions[MAX_PARTITIONS+1]; const char *first_sysupgrade_partition; const char *last_sysupgrade_partition; }; @@ -118,7 +118,7 @@ static const uint8_t md5_salt[16] = { /** Firmware layout table */ static struct device_info boards[] = { - /** Firmware layout for the CPE210/220 */ + /** Firmware layout for the CPE210/220 V1 */ { .id = "CPE210", .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n", @@ -140,8 +140,8 @@ static struct device_info boards[] = { {"default-mac", 0x30000, 0x00020}, {"product-info", 0x31100, 0x00100}, {"signature", 0x32000, 0x00400}, - {"os-image", 0x40000, 0x1c0000}, - {"file-system", 0x200000, 0x5b0000}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, {"soft-version", 0x7b0000, 0x00100}, {"support-list", 0x7b1000, 0x00400}, {"user-config", 0x7c0000, 0x10000}, @@ -182,8 +182,7 @@ static struct device_info boards[] = { {"device-info", 0x31400, 0x00400}, {"signature", 0x32000, 0x00400}, {"device-id", 0x33000, 0x00100}, - {"os-image", 0x40000, 0x1c0000}, - {"file-system", 0x200000, 0x5b0000}, + {"firmware", 0x40000, 0x770000}, {"soft-version", 0x7b0000, 0x00100}, {"support-list", 0x7b1000, 0x01000}, {"user-config", 0x7c0000, 0x10000}, @@ -197,7 +196,82 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "support-list", }, - /** Firmware layout for the CPE510/520 */ + /** Firmware layout for the CPE210 V3 */ + { + .id = "CPE210V3", + .vendor = "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n", + .support_list = + "SupportList:\r\n" + "CPE210(TP-LINK|EU|N300-2|45550000):3.0\r\n" + "CPE210(TP-LINK|UN|N300-2|00000000):3.0\r\n" + "CPE210(TP-LINK|UN|N300-2):3.0\r\n" + "CPE210(TP-LINK|EU|N300-2):3.0\r\n", + .support_trail = '\xff', + .soft_ver = NULL, + + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"partition-table", 0x20000, 0x01000}, + {"default-mac", 0x30000, 0x00020}, + {"product-info", 0x31100, 0x00100}, + {"device-info", 0x31400, 0x00400}, + {"signature", 0x32000, 0x00400}, + {"device-id", 0x33000, 0x00100}, + {"firmware", 0x40000, 0x770000}, + {"soft-version", 0x7b0000, 0x00100}, + {"support-list", 0x7b1000, 0x01000}, + {"user-config", 0x7c0000, 0x10000}, + {"default-config", 0x7d0000, 0x10000}, + {"log", 0x7e0000, 0x10000}, + {"radio", 0x7f0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "support-list", + }, + + /** Firmware layout for the CPE220 V2 */ + { + .id = "CPE220V2", + .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n", + .support_list = + "SupportList:\r\n" + "CPE220(TP-LINK|EU|N300-2|00000000):2.0\r\n" + "CPE220(TP-LINK|EU|N300-2|45550000):2.0\r\n" + "CPE220(TP-LINK|EU|N300-2|55530000):2.0\r\n" + "CPE220(TP-LINK|UN|N300-2|00000000):2.0\r\n" + "CPE220(TP-LINK|UN|N300-2|45550000):2.0\r\n" + "CPE220(TP-LINK|UN|N300-2|55530000):2.0\r\n" + "CPE220(TP-LINK|US|N300-2|55530000):2.0\r\n" + "CPE220(TP-LINK|UN|N300-2):2.0\r\n" + "CPE220(TP-LINK|EU|N300-2):2.0\r\n" + "CPE220(TP-LINK|US|N300-2):2.0\r\n", + .support_trail = '\xff', + .soft_ver = NULL, + + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"partition-table", 0x20000, 0x02000}, + {"default-mac", 0x30000, 0x00020}, + {"product-info", 0x31100, 0x00100}, + {"signature", 0x32000, 0x00400}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, + {"soft-version", 0x7b0000, 0x00100}, + {"support-list", 0x7b1000, 0x00400}, + {"user-config", 0x7c0000, 0x10000}, + {"default-config", 0x7d0000, 0x10000}, + {"log", 0x7e0000, 0x10000}, + {"radio", 0x7f0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "support-list", + }, + + /** Firmware layout for the CPE510/520 V1 */ { .id = "CPE510", .vendor = "CPE510(TP-LINK|UN|N300-5):1.0\r\n", @@ -220,8 +294,132 @@ static struct device_info boards[] = { {"default-mac", 0x30000, 0x00020}, {"product-info", 0x31100, 0x00100}, {"signature", 0x32000, 0x00400}, - {"os-image", 0x40000, 0x1c0000}, - {"file-system", 0x200000, 0x5b0000}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, + {"soft-version", 0x7b0000, 0x00100}, + {"support-list", 0x7b1000, 0x00400}, + {"user-config", 0x7c0000, 0x10000}, + {"default-config", 0x7d0000, 0x10000}, + {"log", 0x7e0000, 0x10000}, + {"radio", 0x7f0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "support-list", + }, + + /** Firmware layout for the CPE510 V2 */ + { + .id = "CPE510V2", + .vendor = "CPE510(TP-LINK|UN|N300-5):2.0\r\n", + .support_list = + "SupportList:\r\n" + "CPE510(TP-LINK|EU|N300-5|00000000):2.0\r\n" + "CPE510(TP-LINK|EU|N300-5|45550000):2.0\r\n" + "CPE510(TP-LINK|EU|N300-5|55530000):2.0\r\n" + "CPE510(TP-LINK|UN|N300-5|00000000):2.0\r\n" + "CPE510(TP-LINK|UN|N300-5|45550000):2.0\r\n" + "CPE510(TP-LINK|UN|N300-5|55530000):2.0\r\n" + "CPE510(TP-LINK|US|N300-5|00000000):2.0\r\n" + "CPE510(TP-LINK|US|N300-5|45550000):2.0\r\n" + "CPE510(TP-LINK|US|N300-5|55530000):2.0\r\n" + "CPE510(TP-LINK|UN|N300-5):2.0\r\n" + "CPE510(TP-LINK|EU|N300-5):2.0\r\n" + "CPE510(TP-LINK|US|N300-5):2.0\r\n", + .support_trail = '\xff', + .soft_ver = NULL, + + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"partition-table", 0x20000, 0x02000}, + {"default-mac", 0x30000, 0x00020}, + {"product-info", 0x31100, 0x00100}, + {"signature", 0x32000, 0x00400}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, + {"soft-version", 0x7b0000, 0x00100}, + {"support-list", 0x7b1000, 0x00400}, + {"user-config", 0x7c0000, 0x10000}, + {"default-config", 0x7d0000, 0x10000}, + {"log", 0x7e0000, 0x10000}, + {"radio", 0x7f0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "support-list", + }, + + /** Firmware layout for the CPE510 V3 */ + { + .id = "CPE510V3", + .vendor = "CPE510(TP-LINK|UN|N300-5):3.0\r\n", + .support_list = + "SupportList:\r\n" + "CPE510(TP-LINK|EU|N300-5|00000000):3.0\r\n" + "CPE510(TP-LINK|EU|N300-5|45550000):3.0\r\n" + "CPE510(TP-LINK|EU|N300-5|55530000):3.0\r\n" + "CPE510(TP-LINK|UN|N300-5|00000000):3.0\r\n" + "CPE510(TP-LINK|UN|N300-5|45550000):3.0\r\n" + "CPE510(TP-LINK|UN|N300-5|55530000):3.0\r\n" + "CPE510(TP-LINK|US|N300-5|00000000):3.0\r\n" + "CPE510(TP-LINK|US|N300-5|45550000):3.0\r\n" + "CPE510(TP-LINK|US|N300-5|55530000):3.0\r\n" + "CPE510(TP-LINK|UN|N300-5):3.0\r\n" + "CPE510(TP-LINK|EU|N300-5):3.0\r\n" + "CPE510(TP-LINK|US|N300-5):3.0\r\n", + .support_trail = '\xff', + .soft_ver = NULL, + + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"partition-table", 0x20000, 0x02000}, + {"default-mac", 0x30000, 0x00020}, + {"product-info", 0x31100, 0x00100}, + {"signature", 0x32000, 0x00400}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, + {"soft-version", 0x7b0000, 0x00100}, + {"support-list", 0x7b1000, 0x00400}, + {"user-config", 0x7c0000, 0x10000}, + {"default-config", 0x7d0000, 0x10000}, + {"log", 0x7e0000, 0x10000}, + {"radio", 0x7f0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "support-list", + }, + + /** Firmware layout for the CPE610V1 */ + { + .id = "CPE610V1", + .vendor = "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n", + .support_list = + "SupportList:\r\n" + "CPE610(TP-LINK|EU|N300-5|00000000):1.0\r\n" + "CPE610(TP-LINK|EU|N300-5|45550000):1.0\r\n" + "CPE610(TP-LINK|EU|N300-5|55530000):1.0\r\n" + "CPE610(TP-LINK|UN|N300-5|00000000):1.0\r\n" + "CPE610(TP-LINK|UN|N300-5|45550000):1.0\r\n" + "CPE610(TP-LINK|UN|N300-5|55530000):1.0\r\n" + "CPE610(TP-LINK|US|N300-5|55530000):1.0\r\n" + "CPE610(TP-LINK|UN|N300-5):1.0\r\n" + "CPE610(TP-LINK|EU|N300-5):1.0\r\n" + "CPE610(TP-LINK|US|N300-5):1.0\r\n", + .support_trail = '\xff', + .soft_ver = NULL, + + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"partition-table", 0x20000, 0x02000}, + {"default-mac", 0x30000, 0x00020}, + {"product-info", 0x31100, 0x00100}, + {"signature", 0x32000, 0x00400}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, {"soft-version", 0x7b0000, 0x00100}, {"support-list", 0x7b1000, 0x00400}, {"user-config", 0x7c0000, 0x10000}, @@ -252,8 +450,8 @@ static struct device_info boards[] = { {"default-mac", 0x30000, 0x00020}, {"product-info", 0x31100, 0x00100}, {"signature", 0x32000, 0x00400}, - {"os-image", 0x40000, 0x1c0000}, - {"file-system", 0x200000, 0x5b0000}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, {"soft-version", 0x7b0000, 0x00100}, {"support-list", 0x7b1000, 0x00400}, {"user-config", 0x7c0000, 0x10000}, @@ -284,8 +482,8 @@ static struct device_info boards[] = { {"default-mac", 0x30000, 0x00020}, {"product-info", 0x31100, 0x00100}, {"signature", 0x32000, 0x00400}, - {"os-image", 0x40000, 0x1c0000}, - {"file-system", 0x200000, 0x5b0000}, + {"os-image", 0x40000, 0x200000}, + {"file-system", 0x240000, 0x570000}, {"soft-version", 0x7b0000, 0x00100}, {"support-list", 0x7b1000, 0x00400}, {"user-config", 0x7c0000, 0x10000}, @@ -347,6 +545,84 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "file-system" }, + /** Firmware layout for the A7-V5 */ + { + .id = "ARCHER-A7-V5", + .support_list = + "SupportList:\n" + "{product_name:Archer A7,product_ver:5.0.0,special_id:45550000}\n" + "{product_name:Archer A7,product_ver:5.0.0,special_id:55530000}\n" + "{product_name:Archer A7,product_ver:5.0.0,special_id:43410000}\n" + "{product_name:Archer A7,product_ver:5.0.0,special_id:4A500000}\n" + "{product_name:Archer A7,product_ver:5.0.0,special_id:54570000}\n", + .support_trail = '\x00', + .soft_ver = "soft_ver:1.0.0\n", + + /* We're using a dynamic kernel/rootfs split here */ + .partitions = { + {"factory-boot", 0x00000, 0x20000}, + {"fs-uboot", 0x20000, 0x20000}, + {"firmware", 0x40000, 0xec0000}, /* Stock: name os-image base 0x40000 size 0x120000 */ + /* Stock: name file-system base 0x160000 size 0xda0000 */ + {"default-mac", 0xf40000, 0x00200}, + {"pin", 0xf40200, 0x00200}, + {"device-id", 0xf40400, 0x00100}, + {"product-info", 0xf40500, 0x0fb00}, + {"soft-version", 0xf50000, 0x00100}, + {"extra-para", 0xf51000, 0x01000}, + {"support-list", 0xf52000, 0x0a000}, + {"profile", 0xf5c000, 0x04000}, + {"default-config", 0xf60000, 0x10000}, + {"user-config", 0xf70000, 0x40000}, + {"certificate", 0xfb0000, 0x10000}, + {"partition-table", 0xfc0000, 0x10000}, + {"log", 0xfd0000, 0x20000}, + {"radio", 0xff0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "file-system", + }, + + /** Firmware layout for the C2v3 */ + { + .id = "ARCHER-C2-V3", + .support_list = + "SupportList:\n" + "{product_name:ArcherC2,product_ver:3.0.0,special_id:00000000}\n" + "{product_name:ArcherC2,product_ver:3.0.0,special_id:55530000}\n" + "{product_name:ArcherC2,product_ver:3.0.0,special_id:45550000}\n", + .support_trail = '\x00', + .soft_ver = "soft_ver:3.0.1\n", + + /** We're using a dynamic kernel/rootfs split here */ + + .partitions = { + {"factory-boot", 0x00000, 0x20000}, + {"fs-uboot", 0x20000, 0x10000}, + {"firmware", 0x30000, 0x7a0000}, + {"user-config", 0x7d0000, 0x04000}, + {"default-mac", 0x7e0000, 0x00100}, + {"device-id", 0x7e0100, 0x00100}, + {"extra-para", 0x7e0200, 0x00100}, + {"pin", 0x7e0300, 0x00100}, + {"support-list", 0x7e0400, 0x00400}, + {"soft-version", 0x7e0800, 0x00400}, + {"product-info", 0x7e0c00, 0x01400}, + {"partition-table", 0x7e2000, 0x01000}, + {"profile", 0x7e3000, 0x01000}, + {"default-config", 0x7e4000, 0x04000}, + {"merge-config", 0x7ec000, 0x02000}, + {"qos-db", 0x7ee000, 0x02000}, + {"radio", 0x7f0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "file-system", + }, + /** Firmware layout for the C25v1 */ { .id = "ARCHER-C25-V1", @@ -358,16 +634,12 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", - /** - We use a bigger os-image partition than the stock images (and thus - smaller file-system), as our kernel doesn't fit in the stock firmware's - 1MB os-image. - */ + /* We're using a dynamic kernel/rootfs split here */ .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x10000}, - {"os-image", 0x30000, 0x180000}, /* Stock: base 0x30000 size 0x100000 */ - {"file-system", 0x1b0000, 0x620000}, /* Stock: base 0x130000 size 0x6a0000 */ + {"firmware", 0x30000, 0x7a0000}, /* Stock: name os-image base 0x30000 size 0x100000 */ + /* Stock: name file-system base 0x130000 size 0x6a0000 */ {"user-config", 0x7d0000, 0x04000}, {"default-mac", 0x7e0000, 0x00100}, {"device-id", 0x7e0100, 0x00100}, @@ -413,8 +685,7 @@ static struct device_info boards[] = { {"profile", 0x11700, 0x03900}, {"default-config", 0x15000, 0x04000}, {"user-config", 0x19000, 0x04000}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0x648000}, + {"firmware", 0x20000, 0x7c8000}, {"certyficate", 0x7e8000, 0x08000}, {"radio", 0x7f0000, 0x10000}, {NULL, 0, 0} @@ -437,14 +708,14 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", + /* We're using a dynamic kernel/rootfs split here */ .partitions = { {"fs-uboot", 0x00000, 0x10000}, {"default-mac", 0x10000, 0x00200}, {"pin", 0x10200, 0x00200}, {"device-id", 0x10400, 0x00100}, {"product-info", 0x10500, 0x0fb00}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0xcb0000}, + {"firmware", 0x20000, 0xe30000}, {"partition-table", 0xe50000, 0x10000}, {"soft-version", 0xe60000, 0x10000}, {"support-list", 0xe70000, 0x10000}, @@ -463,6 +734,82 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "file-system", }, + /** Firmware layout for the C59v2 */ + { + .id = "ARCHER-C59-V2", + .vendor = "", + .support_list = + "SupportList:\r\n" + "{product_name:Archer C59,product_ver:2.0.0,special_id:00000000}\r\n" + "{product_name:Archer C59,product_ver:2.0.0,special_id:45550000}\r\n" + "{product_name:Archer C59,product_ver:2.0.0,special_id:55530000}\r\n", + .support_trail = '\x00', + .soft_ver = "soft_ver:2.0.0 Build 20161206 rel.7303\n", + + /** We're using a dynamic kernel/rootfs split here */ + .partitions = { + {"factory-boot", 0x00000, 0x20000}, + {"fs-uboot", 0x20000, 0x10000}, + {"default-mac", 0x30000, 0x00200}, + {"pin", 0x30200, 0x00200}, + {"device-id", 0x30400, 0x00100}, + {"product-info", 0x30500, 0x0fb00}, + {"firmware", 0x40000, 0xe10000}, + {"partition-table", 0xe50000, 0x10000}, + {"soft-version", 0xe60000, 0x10000}, + {"support-list", 0xe70000, 0x10000}, + {"profile", 0xe80000, 0x10000}, + {"default-config", 0xe90000, 0x10000}, + {"user-config", 0xea0000, 0x40000}, + {"usb-config", 0xee0000, 0x10000}, + {"certificate", 0xef0000, 0x10000}, + {"extra-para", 0xf00000, 0x10000}, + {"qos-db", 0xf10000, 0x30000}, + {"log", 0xfe0000, 0x10000}, + {"radio", 0xff0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "file-system", + }, + + /** Firmware layout for the C6v2 */ + { + .id = "ARCHER-C6-V2", + .vendor = "", + .support_list = + "SupportList:\r\n" + "{product_name:Archer C6,product_ver:2.0.0,special_id:45550000}\r\n" + "{product_name:Archer C6,product_ver:2.0.0,special_id:52550000}\r\n" + "{product_name:Archer C6,product_ver:2.0.0,special_id:4A500000}\r\n", + .support_trail = '\x00', + .soft_ver = "soft_ver:1.0.0\n", + + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"default-mac", 0x20000, 0x00200}, + {"pin", 0x20200, 0x00100}, + {"product-info", 0x20300, 0x00200}, + {"device-id", 0x20500, 0x0fb00}, + {"firmware", 0x30000, 0x7a9400}, + {"soft-version", 0x7d9400, 0x00100}, + {"extra-para", 0x7d9500, 0x00100}, + {"support-list", 0x7d9600, 0x00200}, + {"profile", 0x7d9800, 0x03000}, + {"default-config", 0x7dc800, 0x03000}, + {"partition-table", 0x7df800, 0x00800}, + {"user-config", 0x7e0000, 0x0c000}, + {"certificate", 0x7ec000, 0x04000}, + {"radio", 0x7f0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "file-system", + }, + + /** Firmware layout for the C60v1 */ { .id = "ARCHER-C60-V1", @@ -487,8 +834,7 @@ static struct device_info boards[] = { {"profile", 0x11700, 0x03900}, {"default-config", 0x15000, 0x04000}, {"user-config", 0x19000, 0x04000}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0x648000}, + {"firmware", 0x20000, 0x7c8000}, {"certyficate", 0x7e8000, 0x08000}, {"radio", 0x7f0000, 0x10000}, {NULL, 0, 0} @@ -517,8 +863,7 @@ static struct device_info boards[] = { {"product-info", 0x1fe00, 0x00100}, {"device-id", 0x1ff00, 0x00100}, {"fs-uboot", 0x20000, 0x10000}, - {"os-image", 0x30000, 0x180000}, - {"file-system", 0x1b0000, 0x620000}, + {"firmware", 0x30000, 0x7a0000}, {"soft-version", 0x7d9500, 0x00100}, {"support-list", 0x7d9600, 0x00100}, {"extra-para", 0x7d9700, 0x00100}, @@ -588,16 +933,12 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", - /** - We use a bigger os-image partition than the stock images (and thus - smaller file-system), as our kernel doesn't fit in the stock firmware's - 1MB os-image. - */ + /* We're using a dynamic kernel/rootfs split here */ .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x20000}, - {"os-image", 0x40000, 0x180000}, /* Stock: base 0x40000 size 0x120000 */ - {"file-system", 0x1c0000, 0xd40000}, /* Stock: base 0x160000 size 0xda0000 */ + {"firmware", 0x40000, 0xEC0000}, /* Stock: name os-image base 0x40000 size 0x120000 */ + /* Stock: name file-system base 0x160000 size 0xda0000 */ {"default-mac", 0xf00000, 0x00200}, {"pin", 0xf00200, 0x00200}, {"device-id", 0xf00400, 0x00100}, @@ -630,16 +971,14 @@ static struct device_info boards[] = { "{product_name:Archer C7,product_ver:5.0.0,special_id:55530000}\n" "{product_name:Archer C7,product_ver:5.0.0,special_id:43410000}\n" "{product_name:Archer C7,product_ver:5.0.0,special_id:4A500000}\n" - "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n", + "{product_name:Archer C7,product_ver:5.0.0,special_id:54570000}\n" + "{product_name:Archer C7,product_ver:5.0.0,special_id:52550000}\n" + "{product_name:Archer C7,product_ver:5.0.0,special_id:4B520000}\n", .support_trail = '\x00', .soft_ver = "soft_ver:1.0.0\n", - /** - We use a bigger os-image partition than the stock images (and thus - smaller file-system), as our kernel doesn't fit in the stock firmware's - 1MB os-image. - */ + /* We're using a dynamic kernel/rootfs split here */ .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x20000}, @@ -656,8 +995,8 @@ static struct device_info boards[] = { {"user-config", 0x80000, 0x40000}, - {"os-image", 0xc0000, 0x180000}, /* Stock: base 0xc0000 size 0x120000 */ - {"file-system", 0x240000, 0xd80000}, /* Stock: base 0x1e0000 size 0xde0000 */ + {"firmware", 0xc0000, 0xf00000}, /* Stock: name os-image base 0xc0000 size 0x120000 */ + /* Stock: name file-system base 0x1e0000 size 0xde0000 */ {"log", 0xfc0000, 0x20000}, {"certificate", 0xfe0000, 0x10000}, @@ -831,8 +1170,7 @@ static struct device_info boards[] = { .partitions = { {"factory-boot", 0x00000, 0x20000}, {"fs-uboot", 0x20000, 0x20000}, - {"os-image", 0x40000, 0x180000}, - {"file-system", 0x1c0000, 0xd40000}, + {"firmware", 0x40000, 0xec0000}, {"default-mac", 0xf00000, 0x00200}, {"pin", 0xf00200, 0x00200}, {"device-id", 0xf00400, 0x00100}, @@ -864,15 +1202,10 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /** - We use a bigger os-image partition than the stock images (and thus - smaller file-system), as our kernel doesn't fit in the stock firmware's - 1MB os-image. - */ + /* We're using a dynamic kernel/rootfs split here */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0xdb0000}, + {"firmware", 0x20000, 0xf30000}, {"default-mac", 0xf50000, 0x00200}, {"pin", 0xf50200, 0x00200}, {"product-info", 0xf50400, 0x0fc00}, @@ -908,8 +1241,7 @@ static struct device_info boards[] = { */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0x5b0000}, + {"firmware", 0x20000, 0x730000}, {"default-mac", 0x750000, 0x00200}, {"pin", 0x750200, 0x00200}, {"product-info", 0x750400, 0x0fc00}, @@ -941,8 +1273,7 @@ static struct device_info boards[] = { .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0xca0000}, + {"firmware", 0x20000, 0xe20000}, {"default-mac", 0xe40000, 0x00200}, {"pin", 0xe40200, 0x00200}, {"product-info", 0xe40400, 0x0fc00}, @@ -981,14 +1312,10 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /** - The original os-image partition is too small, - so we enlarge it to 1.75M - */ + /** We're using a dynamic kernel/rootfs split here */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"os-image", 0x20000, 0x1c0000}, - {"file-system", 0x1e0000, 0x420000}, + {"firmware", 0x20000, 0x5e0000}, {"partition-table", 0x600000, 0x02000}, {"default-mac", 0x610000, 0x00020}, {"pin", 0x610100, 0x00020}, @@ -1006,6 +1333,38 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "file-system" }, + /** Firmware layout for the RE350K v1 */ + { + .id = "RE350K-V1", + .vendor = "", + .support_list = + "SupportList:\n" + "{product_name:RE350K,product_ver:1.0.0,special_id:00000000,product_region:US}\n", + .support_trail = '\x00', + .soft_ver = NULL, + + /** We're using a dynamic kernel/rootfs split here */ + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"firmware", 0x20000, 0xd70000}, + {"partition-table", 0xd90000, 0x02000}, + {"default-mac", 0xda0000, 0x00020}, + {"pin", 0xda0100, 0x00020}, + {"product-info", 0xda1100, 0x01000}, + {"soft-version", 0xdb0000, 0x01000}, + {"support-list", 0xdb1000, 0x01000}, + {"profile", 0xdb2000, 0x08000}, + {"user-config", 0xdc0000, 0x10000}, + {"default-config", 0xdd0000, 0x10000}, + {"device-id", 0xde0000, 0x00108}, + {"radio", 0xff0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "file-system" + }, + /** Firmware layout for the RE355 */ { .id = "RE355", @@ -1023,15 +1382,10 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /** - The flash partition table for RE355; - it is almost the same as the one used by the stock images, - 576KB were moved from file-system to os-image. - */ + /* We're using a dynamic kernel/rootfs split here */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0x460000}, + {"firmware", 0x20000, 0x5e0000}, {"partition-table", 0x600000, 0x02000}, {"default-mac", 0x610000, 0x00020}, {"pin", 0x610100, 0x00020}, @@ -1066,15 +1420,10 @@ static struct device_info boards[] = { .support_trail = '\x00', .soft_ver = NULL, - /** - The flash partition table for RE450; - it is almost the same as the one used by the stock images, - 576KB were moved from file-system to os-image. - */ + /** We're using a dynamic kernel/rootfs split here */ .partitions = { {"fs-uboot", 0x00000, 0x20000}, - {"os-image", 0x20000, 0x180000}, - {"file-system", 0x1a0000, 0x460000}, + {"firmware", 0x20000, 0x5e0000}, {"partition-table", 0x600000, 0x02000}, {"default-mac", 0x610000, 0x00020}, {"pin", 0x610100, 0x00020}, @@ -1092,6 +1441,83 @@ static struct device_info boards[] = { .last_sysupgrade_partition = "file-system" }, + /** Firmware layout for the RE450 v2 */ + { + .id = "RE450-V2", + .vendor = "", + .support_list = + "SupportList:\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:00000000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:55530000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:45550000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:4A500000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:43410000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:41550000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:41530000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:4B520000}\r\n" + "{product_name:RE450,product_ver:2.0.0,special_id:42520000}\r\n", + .support_trail = '\x00', + .soft_ver = NULL, + + /* We're using a dynamic kernel/rootfs split here */ + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"firmware", 0x20000, 0x5e0000}, + {"partition-table", 0x600000, 0x02000}, + {"default-mac", 0x610000, 0x00020}, + {"pin", 0x610100, 0x00020}, + {"product-info", 0x611100, 0x01000}, + {"soft-version", 0x620000, 0x01000}, + {"support-list", 0x621000, 0x01000}, + {"profile", 0x622000, 0x08000}, + {"user-config", 0x630000, 0x10000}, + {"default-config", 0x640000, 0x10000}, + {"radio", 0x7f0000, 0x10000}, + + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "file-system" + }, + + /** Firmware layout for the RE650 */ + { + .id = "RE650-V1", + .vendor = "", + .support_list = + "SupportList:\r\n" + "{product_name:RE650,product_ver:1.0.0,special_id:00000000}\r\n" + "{product_name:RE650,product_ver:1.0.0,special_id:55530000}\r\n" + "{product_name:RE650,product_ver:1.0.0,special_id:45550000}\r\n" + "{product_name:RE650,product_ver:1.0.0,special_id:4A500000}\r\n" + "{product_name:RE650,product_ver:1.0.0,special_id:43410000}\r\n" + "{product_name:RE650,product_ver:1.0.0,special_id:41550000}\r\n" + "{product_name:RE650,product_ver:1.0.0,special_id:41530000}\r\n", + .support_trail = '\x00', + .soft_ver = NULL, + + /* We're using a dynamic kernel/rootfs split here */ + .partitions = { + {"fs-uboot", 0x00000, 0x20000}, + {"firmware", 0x20000, 0xde0000}, + {"partition-table", 0xe00000, 0x02000}, + {"default-mac", 0xe10000, 0x00020}, + {"pin", 0xe10100, 0x00020}, + {"product-info", 0xe11100, 0x01000}, + {"soft-version", 0xe20000, 0x01000}, + {"support-list", 0xe21000, 0x01000}, + {"profile", 0xe22000, 0x08000}, + {"user-config", 0xe30000, 0x10000}, + {"default-config", 0xe40000, 0x10000}, + {"radio", 0xff0000, 0x10000}, + {NULL, 0, 0} + }, + + .first_sysupgrade_partition = "os-image", + .last_sysupgrade_partition = "file-system" + }, + {} }; @@ -1227,7 +1653,7 @@ static struct image_partition_entry make_soft_version_from_string(const char *so } /** Generates the support-list partition */ -static struct image_partition_entry make_support_list(const struct device_info *info) { +static struct image_partition_entry make_support_list(struct device_info *info) { size_t len = strlen(info->support_list); struct image_partition_entry entry = alloc_image_partition("support-list", len + 9); @@ -1240,7 +1666,7 @@ static struct image_partition_entry make_support_list(const struct device_info * } /** Creates a new image partition with an arbitrary name from a file */ -static struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof) { +static struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof, struct flash_partition_entry *file_system_partition) { struct stat statbuf; if (stat(filename, &statbuf) < 0) @@ -1248,8 +1674,12 @@ static struct image_partition_entry read_file(const char *part_name, const char size_t len = statbuf.st_size; - if (add_jffs2_eof) - len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark); + if (add_jffs2_eof) { + if (file_system_partition) + len = ALIGN(len + file_system_partition->base, 0x10000) + sizeof(jffs2_eof_mark) - file_system_partition->base; + else + len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark); + } struct image_partition_entry entry = alloc_image_partition(part_name, len); @@ -1365,7 +1795,7 @@ static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) { 1014-1813 Image partition table (2048 bytes, padded with 0xff) 1814-xxxx Firmware partitions */ -static void * generate_factory_image(const struct device_info *info, const struct image_partition_entry *parts, size_t *len) { +static void * generate_factory_image(struct device_info *info, const struct image_partition_entry *parts, size_t *len) { *len = 0x1814; size_t i; @@ -1398,7 +1828,7 @@ static void * generate_factory_image(const struct device_info *info, const struc should be generalized when TP-LINK starts building its safeloader into hardware with different flash layouts. */ -static void * generate_sysupgrade_image(const struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) { +static void * generate_sysupgrade_image(struct device_info *info, const struct image_partition_entry *image_parts, size_t *len) { size_t i, j; size_t flash_first_partition_index = 0; size_t flash_last_partition_index = 0; @@ -1461,10 +1891,53 @@ static void build_image(const char *output, uint32_t rev, bool add_jffs2_eof, bool sysupgrade, - const struct device_info *info) { + struct device_info *info) { + + size_t i; struct image_partition_entry parts[7] = {}; + struct flash_partition_entry *firmware_partition = NULL; + struct flash_partition_entry *os_image_partition = NULL; + struct flash_partition_entry *file_system_partition = NULL; + size_t firmware_partition_index = 0; + + for (i = 0; info->partitions[i].name; i++) { + if (!strcmp(info->partitions[i].name, "firmware")) + { + firmware_partition = &info->partitions[i]; + firmware_partition_index = i; + } + } + + if (firmware_partition) + { + os_image_partition = &info->partitions[firmware_partition_index]; + file_system_partition = &info->partitions[firmware_partition_index + 1]; + + struct stat kernel; + if (stat(kernel_image, &kernel) < 0) + error(1, errno, "unable to stat file `%s'", kernel_image); + + if (kernel.st_size > firmware_partition->size) + error(1, 0, "kernel overflowed firmware partition\n"); + + for (i = MAX_PARTITIONS-1; i >= firmware_partition_index + 1; i--) + info->partitions[i+1] = info->partitions[i]; + + file_system_partition->name = "file-system"; + file_system_partition->base = firmware_partition->base + kernel.st_size; + + /* Align partition start to erase blocks for factory images only */ + if (!sysupgrade) + file_system_partition->base = ALIGN(firmware_partition->base + kernel.st_size, 0x10000); + + file_system_partition->size = firmware_partition->size - file_system_partition->base; + + os_image_partition->name = "os-image"; + os_image_partition->size = kernel.st_size; + } + parts[0] = make_partition_table(info->partitions); if (info->soft_ver) parts[1] = make_soft_version_from_string(info->soft_ver); @@ -1472,18 +1945,23 @@ static void build_image(const char *output, parts[1] = make_soft_version(rev); parts[2] = make_support_list(info); - parts[3] = read_file("os-image", kernel_image, false); - parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof); + parts[3] = read_file("os-image", kernel_image, false, NULL); + parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof, file_system_partition); /* Some devices need the extra-para partition to accept the firmware */ - if (strcasecmp(info->id, "ARCHER-C25-V1") == 0 || + if (strcasecmp(info->id, "ARCHER-C2-V3") == 0 || + strcasecmp(info->id, "ARCHER-C25-V1") == 0 || + strcasecmp(info->id, "ARCHER-C59-V2") == 0 || strcasecmp(info->id, "ARCHER-C60-V2") == 0 || strcasecmp(info->id, "TLWR1043NV5") == 0) { const char mdat[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; parts[5] = put_data("extra-para", mdat, 11); - } else if (strcasecmp(info->id, "ARCHER-C7-V4") == 0 || strcasecmp(info->id, "ARCHER-C7-V5") == 0) { + } else if (strcasecmp(info->id, "ARCHER-A7-V5") == 0 || strcasecmp(info->id, "ARCHER-C7-V4") == 0 || strcasecmp(info->id, "ARCHER-C7-V5") == 0) { const char mdat[11] = {0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0xca, 0x00, 0x01, 0x00, 0x00}; parts[5] = put_data("extra-para", mdat, 11); + } else if (strcasecmp(info->id, "ARCHER-C6-V2") == 0) { + const char mdat[11] = {0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}; + parts[5] = put_data("extra-para", mdat, 11); } size_t len; @@ -1504,7 +1982,6 @@ static void build_image(const char *output, free(image); - size_t i; for (i = 0; parts[i].name; i++) free_image_partition(parts[i]); } @@ -1534,7 +2011,7 @@ static void usage(const char *argv0) { }; -static const struct device_info *find_board(const char *id) +static struct device_info *find_board(const char *id) { struct device_info *board = NULL; @@ -1552,7 +2029,7 @@ static int add_flash_partition( unsigned long base, unsigned long size) { - int ptr; + size_t ptr; /* check if the list has a free entry */ for (ptr = 0; ptr < max_entries; ptr++, part_list++) { if (part_list->name == NULL && @@ -1566,6 +2043,10 @@ static int add_flash_partition( } part_list->name = calloc(1, strlen(name) + 1); + if (!part_list->name) { + error(1, 0, "Unable to allocate memory"); + } + memcpy((char *)part_list->name, name, strlen(name)); part_list->base = base; part_list->size = size; @@ -1601,7 +2082,7 @@ static int read_partition_table( if (fseek(file, offset, SEEK_SET) < 0) error(1, errno, "Can not seek in the firmware"); - if (fread(buf, 1, 2048, file) < 0) + if (fread(buf, 2048, 1, file) != 1) error(1, errno, "Can not read fwup-ptn from the firmware"); buf[2047] = '\0'; @@ -1692,18 +2173,18 @@ static void write_partition( fseek(input_file, entry->base + firmware_offset, SEEK_SET); for (offset = 0; sizeof(buf) + offset <= entry->size; offset += sizeof(buf)) { - if (fread(buf, sizeof(buf), 1, input_file) < 0) + if (fread(buf, sizeof(buf), 1, input_file) != 1) error(1, errno, "Can not read partition from input_file"); - if (fwrite(buf, sizeof(buf), 1, output_file) < 0) + if (fwrite(buf, sizeof(buf), 1, output_file) != 1) error(1, errno, "Can not write partition to output_file"); } /* write last chunk smaller than buffer */ if (offset < entry->size) { offset = entry->size - offset; - if (fread(buf, offset, 1, input_file) < 0) + if (fread(buf, offset, 1, input_file) != 1) error(1, errno, "Can not read partition from input_file"); - if (fwrite(buf, offset, 1, output_file) < 0) + if (fwrite(buf, offset, 1, output_file) != 1) error(1, errno, "Can not write partition to output_file"); } } @@ -1756,7 +2237,7 @@ static int extract_firmware(const char *input, const char *output_directory) error(1, 0, "Error can not read the partition table (fwup-ptn)"); } - for (int i = 0; i < max_entries; i++) { + for (size_t i = 0; i < max_entries; i++) { if (entries[i].name == NULL && entries[i].base == 0 && entries[i].size == 0) @@ -1772,7 +2253,7 @@ static struct flash_partition_entry *find_partition( struct flash_partition_entry *entries, size_t max_entries, const char *name, const char *error_msg) { - for (int i = 0; i < max_entries; i++, entries++) { + for (size_t i = 0; i < max_entries; i++, entries++) { if (strcmp(entries->name, name) == 0) return entries; } @@ -1784,19 +2265,19 @@ static struct flash_partition_entry *find_partition( static void write_ff(FILE *output_file, size_t size) { char buf[4096]; - int offset; + size_t offset; memset(buf, 0xff, sizeof(buf)); for (offset = 0; offset + sizeof(buf) < size ; offset += sizeof(buf)) { - if (fwrite(buf, sizeof(buf), 1, output_file) < 0) + if (fwrite(buf, sizeof(buf), 1, output_file) != 1) error(1, errno, "Can not write 0xff to output_file"); } /* write last chunk smaller than buffer */ if (offset < size) { offset = size - offset; - if (fwrite(buf, offset, 1, output_file) < 0) + if (fwrite(buf, offset, 1, output_file) != 1) error(1, errno, "Can not write partition to output_file"); } } @@ -1864,7 +2345,7 @@ int main(int argc, char *argv[]) { const char *extract_image = NULL, *output_directory = NULL, *convert_image = NULL; bool add_jffs2_eof = false, sysupgrade = false; unsigned rev = 0; - const struct device_info *info; + struct device_info *info; set_source_date_epoch(); while (true) { diff --git a/tools/firmware-utils/src/uimage_padhdr.c b/tools/firmware-utils/src/uimage_padhdr.c new file mode 100644 index 0000000000..d1a1efb575 --- /dev/null +++ b/tools/firmware-utils/src/uimage_padhdr.c @@ -0,0 +1,157 @@ +/* + * uimage_padhdr.c : add zero paddings after the tail of uimage header + * + * Copyright (C) 2019 NOGUCHI Hiroshi + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License, + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* from u-boot/include/image.h */ +#define IH_MAGIC 0x27051956 /* Image Magic Number */ +#define IH_NMLEN 32 /* Image Name Length */ + +/* + * Legacy format image header, + * all data in network byte order (aka natural aka bigendian). + */ +typedef struct image_header { + uint32_t ih_magic; /* Image Header Magic Number */ + uint32_t ih_hcrc; /* Image Header CRC Checksum */ + uint32_t ih_time; /* Image Creation Timestamp */ + uint32_t ih_size; /* Image Data Size */ + uint32_t ih_load; /* Data Load Address */ + uint32_t ih_ep; /* Entry Point Address */ + uint32_t ih_dcrc; /* Image Data CRC Checksum */ + uint8_t ih_os; /* Operating System */ + uint8_t ih_arch; /* CPU architecture */ + uint8_t ih_type; /* Image Type */ + uint8_t ih_comp; /* Compression Type */ + uint8_t ih_name[IH_NMLEN]; /* Image Name */ +} image_header_t; + + +/* default padding size */ +#define IH_PAD_BYTES (32) + + +static void usage(char *prog) +{ + fprintf(stderr, + "%s -i -o [-l ]\n", + prog); +} + +int main(int argc, char *argv[]) +{ + struct stat statbuf; + u_int8_t *filebuf; + int ifd; + int ofd; + ssize_t rsz; + u_int32_t crc_recalc; + image_header_t *imgh; + int opt; + char *infname = NULL; + char *outfname = NULL; + int padsz = IH_PAD_BYTES; + int ltmp; + + while ((opt = getopt(argc, argv, "i:o:l:")) != -1) { + switch (opt) { + case 'i': + infname = optarg; + break; + case 'o': + outfname = optarg; + break; + case 'l': + ltmp = strtol(optarg, NULL, 0); + if (ltmp > 0) + padsz = ltmp; + break; + default: + break; + } + } + + if (!infname || !outfname) { + usage(argv[0]); + exit(1); + } + + ifd = open(infname, O_RDONLY); + if (ifd < 0) { + fprintf(stderr, + "could not open input file. (errno = %d)\n", errno); + exit(1); + } + + ofd = open(outfname, O_WRONLY | O_CREAT, 0644); + if (ofd < 0) { + fprintf(stderr, + "could not open output file. (errno = %d)\n", errno); + exit(1); + } + + if (fstat(ifd, &statbuf) < 0) { + fprintf(stderr, + "could not fstat input file. (errno = %d)\n", errno); + exit(1); + } + + filebuf = malloc(statbuf.st_size + padsz); + if (!filebuf) { + fprintf(stderr, "buffer allocation failed\n"); + exit(1); + } + + rsz = read(ifd, filebuf, sizeof(*imgh)); + if (rsz != sizeof(*imgh)) { + fprintf(stderr, + "could not read input file (errno = %d).\n", errno); + exit(1); + } + + memset(&(filebuf[sizeof(*imgh)]), 0, padsz); + + rsz = read(ifd, &(filebuf[sizeof(*imgh) + padsz]), + statbuf.st_size - sizeof(*imgh)); + if (rsz != (int32_t)(statbuf.st_size - sizeof(*imgh))) { + fprintf(stderr, + "could not read input file (errno = %d).\n", errno); + exit(1); + } + + imgh = (image_header_t *)filebuf; + + imgh->ih_hcrc = 0; + crc_recalc = crc32(0, filebuf, sizeof(*imgh) + padsz); + imgh->ih_hcrc = htonl(crc_recalc); + + rsz = write(ofd, filebuf, statbuf.st_size + padsz); + if (rsz != (int32_t)statbuf.st_size + padsz) { + fprintf(stderr, + "could not write output file (errnor = %d).\n", errno); + exit(1); + } + + return 0; +} diff --git a/tools/firmware-utils/src/xorimage.c b/tools/firmware-utils/src/xorimage.c index ca6e43742a..2ca643faeb 100644 --- a/tools/firmware-utils/src/xorimage.c +++ b/tools/firmware-utils/src/xorimage.c @@ -20,11 +20,13 @@ #include #include #include +#include #include #include #include static char default_pattern[] = "12345678"; +static int is_hex_pattern; int xor_data(uint8_t *data, size_t len, const uint8_t *pattern, int p_len, int p_off) @@ -43,7 +45,7 @@ void usage(void) __attribute__ (( __noreturn__ )); void usage(void) { - fprintf(stderr, "Usage: xorimage [-i infile] [-o outfile] [-p ]\n"); + fprintf(stderr, "Usage: xorimage [-i infile] [-o outfile] [-p ] [-x]\n"); exit(EXIT_FAILURE); } @@ -56,12 +58,14 @@ int main(int argc, char **argv) char *ifn = NULL; char *ofn = NULL; const char *pattern = default_pattern; + char hex_pattern[128]; + unsigned int hex_buf; int c; int v0, v1, v2; size_t n; int p_len, p_off = 0; - while ((c = getopt(argc, argv, "i:o:p:h")) != -1) { + while ((c = getopt(argc, argv, "i:o:p:xh")) != -1) { switch (c) { case 'i': ifn = optarg; @@ -72,6 +76,9 @@ int main(int argc, char **argv) case 'p': pattern = optarg; break; + case 'x': + is_hex_pattern = true; + break; case 'h': default: usage(); @@ -100,6 +107,27 @@ int main(int argc, char **argv) usage(); } + if (is_hex_pattern) { + int i; + + if ((p_len / 2) > sizeof(hex_pattern)) { + fprintf(stderr, "provided hex pattern is too long\n"); + usage(); + } + + if (p_len % 2 != 0) { + fprintf(stderr, "the number of characters (hex) is incorrect\n"); + usage(); + } + + for (i = 0; i < (p_len / 2); i++) { + if (sscanf(pattern + (i * 2), "%2x", &hex_buf) < 0) { + fprintf(stderr, "invalid hex digit around %d\n", i * 2); + usage(); + } + hex_pattern[i] = (char)hex_buf; + } + } while ((n = fread(buf, 1, sizeof(buf), in)) > 0) { if (n < sizeof(buf)) { @@ -110,7 +138,12 @@ int main(int argc, char **argv) } } - p_off = xor_data(buf, n, pattern, p_len, p_off); + if (is_hex_pattern) { + p_off = xor_data(buf, n, hex_pattern, (p_len / 2), + p_off); + } else { + p_off = xor_data(buf, n, pattern, p_len, p_off); + } if (!fwrite(buf, n, 1, out)) { FWRITE_ERROR: diff --git a/tools/gengetopt/Makefile b/tools/gengetopt/Makefile index 6d2b85e658..563ecccf9d 100644 --- a/tools/gengetopt/Makefile +++ b/tools/gengetopt/Makefile @@ -1,19 +1,19 @@ # # Copyright (C) 2014 OpenWrt.org # -# This is free software, licengengetopt under the GNU General Public License v2. +# This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # include $(TOPDIR)/rules.mk PKG_NAME:=gengetopt -PKG_VERSION:=2.22.6 +PKG_VERSION:=2.23 -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=@GNU/$(PKG_NAME) -PKG_HASH:=30b05a88604d71ef2a42a2ef26cd26df242b41f5b011ad03083143a31d9b01f7 +PKG_HASH:=b941aec9011864978dd7fdeb052b1943535824169d2aa2b0e7eae9ab807584ac -HOST_FIXUP := autoreconf +HOST_FIXUP:=autoreconf HOST_BUILD_PARALLEL:=1 diff --git a/tools/gengetopt/patches/100-dependency_fix.patch b/tools/gengetopt/patches/100-dependency_fix.patch deleted file mode 100644 index 69cb598b7d..0000000000 --- a/tools/gengetopt/patches/100-dependency_fix.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/src/Makefile.am -+++ b/src/Makefile.am -@@ -51,7 +51,7 @@ libgengetopt_la_LIBADD = $(top_builddir) - @LTLIBOBJS@ \ - skels/libgen.la - --LDADD = $(top_builddir)/src/libgengetopt.la -+LDADD = libgengetopt.la - - EXTRA_DIST = parser.h argsdef.h gengetopt.h ggos.h gm.h gnugetopt.h \ - cmdline.c cmdline.h \ diff --git a/tools/gengetopt/patches/100-no-tests-docs.patch b/tools/gengetopt/patches/100-no-tests-docs.patch new file mode 100644 index 0000000000..d8c53af4fb --- /dev/null +++ b/tools/gengetopt/patches/100-no-tests-docs.patch @@ -0,0 +1,33 @@ +--- a/Makefile.am ++++ b/Makefile.am +@@ -18,7 +18,7 @@ + ACLOCAL_AMFLAGS = -I m4 -I gl/m4 + + EXTRA_DIST = configure TODO LICENSE gl/m4/gnulib-cache.m4 +-SUBDIRS = gl src doc tests ++SUBDIRS = gl src + + gengetoptdoc_DATA = ChangeLog COPYING NEWS THANKS INSTALL README LICENSE + +--- a/Makefile.in ++++ b/Makefile.in +@@ -593,7 +593,7 @@ top_builddir = @top_builddir@ + top_srcdir = @top_srcdir@ + ACLOCAL_AMFLAGS = -I m4 -I gl/m4 + EXTRA_DIST = configure TODO LICENSE gl/m4/gnulib-cache.m4 +-SUBDIRS = gl src doc tests ++SUBDIRS = gl src + gengetoptdoc_DATA = ChangeLog COPYING NEWS THANKS INSTALL README LICENSE + TARBALL = $(top_builddir)/gengetopt-$(PACKAGE_VERSION).tar.xz + all: config.h +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -16,7 +16,7 @@ + # with gengetopt; see the file COPYING. If not, write to the Free Software + # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +-SUBDIRS = skels tests ++SUBDIRS = skels + + bin_PROGRAMS = gengetopt + diff --git a/tools/gengetopt/patches/200-no_docs_tests.patch b/tools/gengetopt/patches/200-no_docs_tests.patch deleted file mode 100644 index d3930696ff..0000000000 --- a/tools/gengetopt/patches/200-no_docs_tests.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff -urN gengetopt-2.22.6/Makefile.am gengetopt-2.22.6.new/Makefile.am ---- gengetopt-2.22.6/Makefile.am 2012-11-02 06:26:54.000000000 -0700 -+++ gengetopt-2.22.6.new/Makefile.am 2015-05-21 17:43:15.183083542 -0700 -@@ -18,6 +18,6 @@ - ACLOCAL_AMFLAGS = -I m4 -I gl/m4 - - EXTRA_DIST = configure TODO LICENSE gl/m4/gnulib-cache.m4 --SUBDIRS = gl src doc tests -+SUBDIRS = gl src - --gengetoptdoc_DATA = ChangeLog COPYING NEWS THANKS INSTALL README LICENSE -\ No newline at end of file -+gengetoptdoc_DATA = ChangeLog COPYING NEWS THANKS INSTALL README LICENSE diff --git a/tools/gptfdisk/Makefile b/tools/gptfdisk/Makefile deleted file mode 100644 index 44315ed76a..0000000000 --- a/tools/gptfdisk/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -include $(TOPDIR)/rules.mk - -PKG_NAME:=gptfdisk -PKG_VERSION:=1.0.1 - -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=http://www.rodsbooks.com/gdisk/ -PKG_HASH:=864c8aee2efdda50346804d7e6230407d5f42a8ae754df70404dd8b2fdfaeac7 - -HOST_BUILD_PARALLEL := 1 - -include $(INCLUDE_DIR)/host-build.mk - -HOST_CPPFLAGS += \ - -I$(STAGING_DIR_HOST)/include/e2fsprogs - -define Host/Compile - $(call Host/Compile/Default,sgdisk) -endef - -define Host/Install - $(INSTALL_BIN) $(HOST_BUILD_DIR)/sgdisk $(STAGING_DIR_HOST)/bin/ -endef - -define Host/Clean - rm -f $(STAGING_DIR_HOST)/bin/sgdisk -endef - -$(eval $(call HostBuild)) diff --git a/tools/isl/Makefile b/tools/isl/Makefile index da37437119..c1000e1e31 100644 --- a/tools/isl/Makefile +++ b/tools/isl/Makefile @@ -7,11 +7,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=isl -PKG_VERSION:=0.18 +PKG_VERSION:=0.20 PKG_SOURCE_URL:=http://isl.gforge.inria.fr PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz -PKG_HASH:=0f35051cc030b87c673ac1f187de40e386a1482a0cfdf2c552dd6031b307ddc4 +PKG_HASH:=a5596a9fb8a5b365cb612e4b9628735d6e67e9178fae134a816ae195017e77aa HOST_BUILD_PARALLEL:=1 diff --git a/tools/libelf/Makefile b/tools/libelf/Makefile index 33cc7e8577..9fec8308b5 100644 --- a/tools/libelf/Makefile +++ b/tools/libelf/Makefile @@ -13,8 +13,9 @@ PKG_HASH:=591a9b4ec81c1f2042a97aa60564e0cb79d041c52faa7416acb38bc95bd2c76d PKG_RELEASE:=1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=https://fossies.org/linux/misc/old/ - +PKG_SOURCE_URL:= \ + http://distfiles.gentoo.org/distfiles/ \ + http://distcache.freebsd.org/ports-distfiles/ HOST_BUILD_PARALLEL:=1 include $(INCLUDE_DIR)/host-build.mk @@ -36,15 +37,17 @@ define Host/Compile endef define Host/Install - $(INSTALL_DIR) $(STAGING_DIR_HOST)/{lib,include/libelf} + $(INSTALL_DIR) $(STAGING_DIR_HOST)/{lib/pkgconfig,include/libelf} $(CP) $(HOST_BUILD_DIR)/lib/{elf_repl.h,gelf.h,libelf.h,nlist.h,sys_elf.h} \ $(STAGING_DIR_HOST)/include/libelf/ $(CP) $(HOST_BUILD_DIR)/lib/libelf.a $(STAGING_DIR_HOST)/lib/ + $(CP) $(HOST_BUILD_DIR)/libelf.pc $(STAGING_DIR_HOST)/lib/pkgconfig/ endef define Host/Clean rm -rf $(STAGING_DIR_HOST)/include/libelf rm -f $(STAGING_DIR_HOST)/lib/libelf.a + rm -f $(STAGING_DIR_HOST)/lib/pkgconfig/libelf.pc $(call Host/Clean/Default) endef diff --git a/tools/libelf/patches/900-fix-undefined-macro-access.patch b/tools/libelf/patches/900-fix-undefined-macro-access.patch new file mode 100644 index 0000000000..21e7d1ba8f --- /dev/null +++ b/tools/libelf/patches/900-fix-undefined-macro-access.patch @@ -0,0 +1,198 @@ +--- a/lib/elf_repl.h ++++ b/lib/elf_repl.h +@@ -45,7 +45,7 @@ typedef __libelf_u32_t Elf32_Word; + #define ELF32_FSZ_SWORD 4 + #define ELF32_FSZ_WORD 4 + +-#if __LIBELF64 ++#if defined(__LIBELF64) + + typedef __libelf_u64_t Elf64_Addr; + typedef __libelf_u16_t Elf64_Half; +@@ -93,7 +93,7 @@ typedef struct { + Elf32_Half e_shstrndx; + } Elf32_Ehdr; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + typedef struct { + unsigned char e_ident[EI_NIDENT]; + Elf64_Half e_type; +@@ -307,7 +307,7 @@ typedef struct { + Elf32_Word sh_entsize; + } Elf32_Shdr; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + typedef struct { + Elf64_Word sh_name; + Elf64_Word sh_type; +@@ -434,7 +434,7 @@ typedef struct { + Elf32_Half st_shndx; + } Elf32_Sym; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + typedef struct { + Elf64_Word st_name; + unsigned char st_info; +@@ -457,7 +457,7 @@ typedef struct { + #define ELF32_ST_TYPE(i) ((i)&0xf) + #define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) + +-#if __LIBELF64 ++#if defined(__LIBELF64) + #define ELF64_ST_BIND(i) ((i)>>4) + #define ELF64_ST_TYPE(i) ((i)&0xf) + #define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf)) +@@ -495,7 +495,7 @@ typedef struct { + * Macros for manipulating st_other + */ + #define ELF32_ST_VISIBILITY(o) ((o)&0x3) +-#if __LIBELF64 ++#if defined(__LIBELF64) + #define ELF64_ST_VISIBILITY(o) ((o)&0x3) + #endif /* __LIBELF64 */ + +@@ -521,7 +521,7 @@ typedef struct { + Elf32_Sword r_addend; + } Elf32_Rela; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + typedef struct { + Elf64_Addr r_offset; + Elf64_Xword r_info; +@@ -541,7 +541,7 @@ typedef struct { + #define ELF32_R_TYPE(i) ((unsigned char)(i)) + #define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t)) + +-#if __LIBELF64 ++#if defined(__LIBELF64) + #define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32) + #define ELF64_R_TYPE(i) ((i)&0xffffffffL) + #define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL)) +@@ -556,7 +556,7 @@ typedef struct { + Elf32_Word n_type; /* descriptor type */ + } Elf32_Nhdr; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + /* Solaris and GNU use this layout. Be compatible. */ + /* XXX: Latest ELF specs say it's 64-bit!!! */ + typedef struct { +@@ -587,7 +587,7 @@ typedef struct { + Elf32_Word p_align; + } Elf32_Phdr; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + typedef struct { + Elf64_Word p_type; + Elf64_Word p_flags; +@@ -654,7 +654,7 @@ typedef struct { + } d_un; + } Elf32_Dyn; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + typedef struct { + Elf64_Sxword d_tag; + union { +@@ -798,7 +798,7 @@ typedef struct { + Elf32_Half si_flags; + } Elf32_Syminfo; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + typedef struct { + Elf64_Half si_boundto; + Elf64_Half si_flags; +@@ -863,7 +863,7 @@ typedef struct { + + typedef Elf32_Half Elf32_Versym; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + + typedef struct { + Elf64_Half vd_version; +@@ -933,7 +933,7 @@ typedef Elf64_Half Elf64_Versym; + /* + * Move section + */ +-#if __LIBELF64 ++#if defined(__LIBELF64) + + typedef struct { + Elf32_Lword m_value; +@@ -973,7 +973,7 @@ typedef struct { + } c_un; + } Elf32_Cap; + +-#if __LIBELF64 ++#if defined(__LIBELF64) + + typedef struct { + Elf64_Xword c_tag; +--- a/lib/gelf.h ++++ b/lib/gelf.h +@@ -22,15 +22,15 @@ + #ifndef _GELF_H + #define _GELF_H + +-#if __LIBELF_INTERNAL__ ++#if defined(__LIBELF_INTERNAL__) + #include + #else /* __LIBELF_INTERNAL__ */ + #include + #endif /* __LIBELF_INTERNAL__ */ + +-#if __LIBELF_NEED_LINK_H ++#if defined(__LIBELF_NEED_LINK_H) + #include +-#elif __LIBELF_NEED_SYS_LINK_H ++#elif defined(__LIBELF_NEED_SYS_LINK_H) + #include + #endif /* __LIBELF_NEED_LINK_H */ + +@@ -71,7 +71,7 @@ typedef Elf64_Sym GElf_Sym; + /* + * Symbol versioning + */ +-#if __LIBELF_SYMBOL_VERSIONS ++#if defined(__LIBELF_SYMBOL_VERSIONS) + typedef Elf64_Verdef GElf_Verdef; + typedef Elf64_Verneed GElf_Verneed; + typedef Elf64_Verdaux GElf_Verdaux; +--- a/lib/libelf.h ++++ b/lib/libelf.h +@@ -25,7 +25,7 @@ + #include /* for size_t */ + #include + +-#if __LIBELF_INTERNAL__ ++#if defined(__LIBELF_INTERNAL__) + #include + #else /* __LIBELF_INTERNAL__ */ + #include +@@ -224,7 +224,7 @@ extern Elf_Data *elf32_xlatetom __P((Elf + */ + extern long elf32_checksum __P((Elf *__elf)); + +-#if __LIBELF64 ++#if defined(__LIBELF64) + /* + * 64-bit ELF functions + * Not available on all platforms +--- a/lib/sys_elf.h.in ++++ b/lib/sys_elf.h.in +@@ -116,7 +116,7 @@ Foundation, Inc., 51 Franklin Street, Fi + # define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL)) + # endif /* ELF64_R_SYM */ + +-# if __LIBELF64_LINUX ++# if defined(__LIBELF64_LINUX) + typedef __libelf_u64_t Elf64_Addr; + typedef __libelf_u16_t Elf64_Half; + typedef __libelf_u64_t Elf64_Off; diff --git a/tools/libressl/Makefile b/tools/libressl/Makefile index 8894a058e4..d029666611 100644 --- a/tools/libressl/Makefile +++ b/tools/libressl/Makefile @@ -8,8 +8,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=libressl -PKG_VERSION:=2.8.1 -PKG_HASH:=334bf7050f1db4087feebb30571ec13d9fa975bf05d6003ce3ab6d7d2452cf42 +PKG_VERSION:=2.9.2 +PKG_HASH:=c4c78167fae325b47aebd8beb54b6041d6f6a56b3743f4bd5d79b15642f9d5d4 PKG_RELEASE:=1 PKG_CPE_ID:=cpe:/a:openbsd:libressl diff --git a/tools/libressl/patches/001-dont-build-tests-man.patch b/tools/libressl/patches/001-dont-build-tests-man.patch new file mode 100644 index 0000000000..bd09818d43 --- /dev/null +++ b/tools/libressl/patches/001-dont-build-tests-man.patch @@ -0,0 +1,11 @@ +--- a/Makefile.in ++++ b/Makefile.in +@@ -361,7 +361,7 @@ target_alias = @target_alias@ + top_build_prefix = @top_build_prefix@ + top_builddir = @top_builddir@ + top_srcdir = @top_srcdir@ +-SUBDIRS = crypto ssl tls include apps tests man ++SUBDIRS = crypto ssl tls include apps + ACLOCAL_AMFLAGS = -I m4 + pkgconfigdir = $(libdir)/pkgconfig + pkgconfig_DATA = libcrypto.pc libssl.pc libtls.pc openssl.pc diff --git a/tools/libressl/patches/010-avoid-glibc.patch b/tools/libressl/patches/010-avoid-glibc.patch new file mode 100644 index 0000000000..e91899c7d7 --- /dev/null +++ b/tools/libressl/patches/010-avoid-glibc.patch @@ -0,0 +1,23 @@ +From a747aacc23607c993cc481378782b2c7dd5bc53b Mon Sep 17 00:00:00 2001 +From: Ishimoto Shinobu <47295761+protonesso@users.noreply.github.com> +Date: Tue, 21 May 2019 22:41:05 +0900 +Subject: [PATCH] avoid glibc + +cause problems on musl systems +--- + crypto/compat/getprogname_linux.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +--- a/crypto/compat/getprogname_linux.c ++++ b/crypto/compat/getprogname_linux.c +@@ -26,9 +26,7 @@ getprogname(void) + #if defined(__ANDROID_API__) && __ANDROID_API__ < 21 + extern const char *__progname; + return __progname; +-#elif defined(__GLIBC__) +- return program_invocation_short_name; + #else +-#error "Cannot emulate getprogname" ++ return program_invocation_short_name; + #endif + } diff --git a/tools/make-ext4fs/Makefile b/tools/make-ext4fs/Makefile index f67ab6e5b5..03db1917fc 100644 --- a/tools/make-ext4fs/Makefile +++ b/tools/make-ext4fs/Makefile @@ -11,9 +11,9 @@ PKG_NAME:=make-ext4fs PKG_SOURCE_URL=$(PROJECT_GIT)/project/make_ext4fs.git PKG_SOURCE_PROTO:=git -PKG_SOURCE_DATE:=2016-08-14 -PKG_SOURCE_VERSION:=484903e4332be6c317f531b008cb2a841a18c506 -PKG_MIRROR_HASH:=d7ccd5e426b1d15331ff000a37dc15161f6eef594453e970fd584fcde5a25075 +PKG_SOURCE_DATE:=2017-05-29 +PKG_SOURCE_VERSION:=eebda1d55d9701ace2700d7ae461697fadf52d1f +PKG_MIRROR_HASH:=c52e14101d7de89292a0c8b30506839aca3164603a20f8e491e42103083b9d8c include $(INCLUDE_DIR)/host-build.mk diff --git a/tools/mkimage/patches/060-remove_kernel_includes.patch b/tools/mkimage/patches/060-remove_kernel_includes.patch index 56d2a83197..8917ec0863 100644 --- a/tools/mkimage/patches/060-remove_kernel_includes.patch +++ b/tools/mkimage/patches/060-remove_kernel_includes.patch @@ -26,4 +26,4 @@ non Linux hosts. +#endif #define __packed __attribute__((packed)) - + diff --git a/tools/mklibs/Makefile b/tools/mklibs/Makefile index 507c2fd394..48b1eace40 100644 --- a/tools/mklibs/Makefile +++ b/tools/mklibs/Makefile @@ -7,17 +7,18 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mklibs -PKG_VERSION:=0.1.35 +PKG_VERSION:=0.1.44 -PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.gz +PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=http://ftp.de.debian.org/debian/pool/main/m/mklibs/ -PKG_HASH:=ccb1023dc1729c5a37ca6c3eca8e4bac3491116763c8820dfce8eea4845c8567 +PKG_HASH:=3af0b6bd35e5b6fc58d8b68827fbae2ff6b7e20dd2b238ccb9b49d84722066c2 HOST_FIXUP:=autoreconf include $(INCLUDE_DIR)/host-build.mk HOST_CFLAGS += -I$(CURDIR)/include +HOST_CPPFLAGS += -std=gnu++98 define Host/Install $(INSTALL_BIN) \ diff --git a/tools/mklibs/patches/002-disable_symbol_checks.patch b/tools/mklibs/patches/002-disable_symbol_checks.patch index 44be637609..e18dfa8e55 100644 --- a/tools/mklibs/patches/002-disable_symbol_checks.patch +++ b/tools/mklibs/patches/002-disable_symbol_checks.patch @@ -1,6 +1,6 @@ --- a/src/mklibs +++ b/src/mklibs -@@ -524,7 +524,7 @@ while 1: +@@ -533,7 +533,7 @@ while 1: # No progress in last pass. Verify all remaining symbols are weak. for name in unresolved: if not needed_symbols[name].weak: @@ -9,7 +9,7 @@ break previous_pass_unresolved = unresolved -@@ -559,7 +559,7 @@ while 1: +@@ -568,7 +568,7 @@ while 1: for name in needed_symbols: if not name in symbol_provider: if not needed_symbols[name].weak: diff --git a/tools/mklibs/patches/003-no_copy.patch b/tools/mklibs/patches/003-no_copy.patch index e0ab2ac88d..75beccf82e 100644 --- a/tools/mklibs/patches/003-no_copy.patch +++ b/tools/mklibs/patches/003-no_copy.patch @@ -1,6 +1,6 @@ --- a/src/mklibs +++ b/src/mklibs -@@ -463,7 +463,7 @@ while 1: +@@ -472,7 +472,7 @@ while 1: passnr = passnr + 1 # Gather all already reduced libraries and treat them as objects as well small_libs = [] @@ -9,7 +9,7 @@ obj = dest_path + "/" + lib small_libs.append(obj) inode = os.stat(obj)[ST_INO] -@@ -579,12 +579,7 @@ while 1: +@@ -588,12 +588,7 @@ while 1: if not so_file: sys.exit("File not found:" + library) pic_file = find_pic(library) @@ -23,7 +23,7 @@ # we have a pic file, recompile debug(DEBUG_SPAM, "extracting from:", pic_file, "so_file:", so_file) soname = extract_soname(so_file) -@@ -627,22 +622,14 @@ while 1: +@@ -636,22 +631,14 @@ while 1: cmd.append(library_depends_gcc_libnames(so_file)) command(target + "gcc", *cmd) @@ -47,4 +47,4 @@ + os.rename(dest_path + "/" + lib + "-so", dest_path + "/" + lib) # Canonicalize library names. - for lib in regexpfilter(os.listdir(dest_path), "(.*so[.\d]*)$"): + for lib in sorted(regexpfilter(os.listdir(dest_path), "(.*so[.\d]*)$")): diff --git a/tools/mklibs/patches/004-libpthread_link.patch b/tools/mklibs/patches/004-libpthread_link.patch index 657e232b0c..3a630ea288 100644 --- a/tools/mklibs/patches/004-libpthread_link.patch +++ b/tools/mklibs/patches/004-libpthread_link.patch @@ -17,7 +17,7 @@ if match.group('ld'): ret.append(find_lib(match.group(0))) elif match.group('lib'): -@@ -619,7 +619,7 @@ while 1: +@@ -628,7 +628,7 @@ while 1: cmd.extend(extra_flags) cmd.append("-lgcc") cmd.extend(["-L%s" % a for a in [dest_path] + [sysroot + b for b in lib_path if sysroot == "" or b not in ("/" + libdir + "/", "/usr/" + libdir + "/")]]) diff --git a/tools/mklibs/patches/005-duplicate_syms.patch b/tools/mklibs/patches/005-duplicate_syms.patch index 8428abfc9a..b0fdab7b10 100644 --- a/tools/mklibs/patches/005-duplicate_syms.patch +++ b/tools/mklibs/patches/005-duplicate_syms.patch @@ -1,6 +1,6 @@ --- a/src/mklibs +++ b/src/mklibs -@@ -531,7 +531,6 @@ while 1: +@@ -540,7 +540,6 @@ while 1: library_symbols = {} library_symbols_used = {} @@ -8,7 +8,7 @@ # WORKAROUND: Always add libgcc on old-abi arm header = elf_header(find_lib(libraries.copy().pop())) -@@ -549,20 +548,13 @@ while 1: +@@ -558,20 +557,13 @@ while 1: library_symbols_used[library] = set() for symbol in symbols: for name in symbol.base_names(): @@ -32,4 +32,4 @@ + library_symbols_used[lib].add(library_symbols[lib][name]) # reduce libraries - for library in libraries: + for library in sorted(libraries): diff --git a/tools/mklibs/patches/006-uclibc_init.patch b/tools/mklibs/patches/006-uclibc_init.patch index 2df7fe4355..da83340fe4 100644 --- a/tools/mklibs/patches/006-uclibc_init.patch +++ b/tools/mklibs/patches/006-uclibc_init.patch @@ -1,6 +1,6 @@ --- a/src/mklibs +++ b/src/mklibs -@@ -595,6 +595,11 @@ while 1: +@@ -604,6 +604,11 @@ while 1: extra_post_obj.append(sysroot + libc_extras_dir + "/sofini.o") symbols.add(ProvidedSymbol('__dso_handle', None, None, True)) diff --git a/tools/mklibs/patches/007-gc_sections.patch b/tools/mklibs/patches/007-gc_sections.patch index 068d88a532..2fdf4034da 100644 --- a/tools/mklibs/patches/007-gc_sections.patch +++ b/tools/mklibs/patches/007-gc_sections.patch @@ -1,6 +1,6 @@ --- a/src/mklibs +++ b/src/mklibs -@@ -607,7 +607,7 @@ while 1: +@@ -616,7 +616,7 @@ while 1: # compile in only used symbols cmd = [] cmd.extend(gcc_options) diff --git a/tools/mklibs/patches/008-uclibc_libgcc_link.patch b/tools/mklibs/patches/008-uclibc_libgcc_link.patch index 432a313b6c..34cd9d3ab3 100644 --- a/tools/mklibs/patches/008-uclibc_libgcc_link.patch +++ b/tools/mklibs/patches/008-uclibc_libgcc_link.patch @@ -14,7 +14,7 @@ return ' '.join(ret) class Symbol(object): -@@ -584,6 +581,7 @@ while 1: +@@ -593,6 +590,7 @@ while 1: extra_flags = [] extra_pre_obj = [] extra_post_obj = [] @@ -22,7 +22,7 @@ symbols.update(library_symbols_used[library]) -@@ -614,9 +612,10 @@ while 1: +@@ -623,9 +621,10 @@ while 1: cmd.append(pic_file) cmd.extend(extra_post_obj) cmd.extend(extra_flags) diff --git a/tools/mklibs/patches/009-uclibc_libpthread_symbols.patch b/tools/mklibs/patches/009-uclibc_libpthread_symbols.patch index 34866f7290..0d4d3e95aa 100644 --- a/tools/mklibs/patches/009-uclibc_libpthread_symbols.patch +++ b/tools/mklibs/patches/009-uclibc_libpthread_symbols.patch @@ -1,6 +1,6 @@ --- a/src/mklibs +++ b/src/mklibs -@@ -162,9 +162,10 @@ def undefined_symbols(obj): +@@ -173,9 +173,10 @@ def undefined_symbols(obj): return result class ProvidedSymbol(Symbol): @@ -12,7 +12,7 @@ def base_names(self): ret = [] -@@ -205,11 +206,15 @@ def provided_symbols(obj): +@@ -216,11 +217,15 @@ def provided_symbols(obj): if version_string.lower() not in ('base', 'none'): version = version_string @@ -29,7 +29,7 @@ return result -@@ -500,6 +505,9 @@ while 1: +@@ -509,6 +514,9 @@ while 1: debug(DEBUG_SPAM, "present_symbols adding %s" % symbol) names = symbol.base_names() for name in names: @@ -39,7 +39,7 @@ present_symbols[name] = symbol # are we finished? -@@ -591,12 +599,16 @@ while 1: +@@ -600,12 +608,16 @@ while 1: # may segfault in ptmalloc_init due to undefined weak reference extra_pre_obj.append(sysroot + libc_extras_dir + "/soinit.o") extra_post_obj.append(sysroot + libc_extras_dir + "/sofini.o") diff --git a/tools/mklibs/patches/011-remove_multiarch.patch b/tools/mklibs/patches/011-remove_multiarch.patch index a32d8ee17a..23e45cc12c 100644 --- a/tools/mklibs/patches/011-remove_multiarch.patch +++ b/tools/mklibs/patches/011-remove_multiarch.patch @@ -1,6 +1,6 @@ --- a/src/mklibs +++ b/src/mklibs -@@ -263,6 +263,7 @@ def extract_soname(so_file): +@@ -274,6 +274,7 @@ def extract_soname(so_file): return "" def multiarch(paths): diff --git a/tools/mklibs/patches/100-apply-2to3.patch b/tools/mklibs/patches/100-apply-2to3.patch new file mode 100644 index 0000000000..9f2ae6c438 --- /dev/null +++ b/tools/mklibs/patches/100-apply-2to3.patch @@ -0,0 +1,327 @@ +--- a/src/mklibs ++++ b/src/mklibs +@@ -57,18 +57,18 @@ debuglevel = DEBUG_NORMAL + + def debug(level, *msg): + if debuglevel >= level: +- print string.join(msg) ++ print(' '.join(msg)) + + # return a list of lines of output of the command + def command(command, *args): +- debug(DEBUG_SPAM, "calling", command, string.join(args)) ++ debug(DEBUG_SPAM, "calling", command, ' '.join(args)) + pipe = os.popen(command + ' ' + ' '.join(args), 'r') + output = pipe.read().strip() + status = pipe.close() + if status is not None and os.WEXITSTATUS(status) != 0: +- print "Command failed with status", os.WEXITSTATUS(status), ":", \ +- command, string.join(args) +- print "With output:", output ++ print("Command failed with status", os.WEXITSTATUS(status), ":", \ ++ command, ' '.join(args)) ++ print("With output:", output) + sys.exit(1) + return [i for i in output.split('\n') if i] + +@@ -204,7 +204,7 @@ class ProvidedSymbol(Symbol): + # Return a set of symbols provided by a library + def provided_symbols(obj): + if not os.access(obj, os.F_OK): +- raise Exception("Cannot find lib" + obj) ++ raise Exception("Cannot find lib " + obj) + library = extract_soname(obj) + + output = command("mklibs-readelf", "--print-symbols-provided", obj) +@@ -297,27 +297,27 @@ def usage(was_err): + outfd = sys.stderr + else: + outfd = sys.stdout +- print >> outfd, "Usage: mklibs [OPTION]... -d DEST FILE ..." +- print >> outfd, "Make a set of minimal libraries for FILE(s) in DEST." +- print >> outfd, "" +- print >> outfd, " -d, --dest-dir DIRECTORY create libraries in DIRECTORY" +- print >> outfd, " -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path), ")" +- print >> outfd, " -L DIRECTORY[:DIRECTORY]... add DIRECTORY(s) to the library search path" +- print >> outfd, " -l LIBRARY add LIBRARY always" +- print >> outfd, " --ldlib LDLIB use LDLIB for the dynamic linker" +- print >> outfd, " --libc-extras-dir DIRECTORY look for libc extra files in DIRECTORY" +- print >> outfd, " --target TARGET prepend TARGET- to the gcc and binutils calls" +- print >> outfd, " --root ROOT search in ROOT for library rpaths" +- print >> outfd, " --sysroot ROOT prepend ROOT to all paths for libraries" +- print >> outfd, " --gcc-options OPTIONS pass OPTIONS to gcc" +- print >> outfd, " --libdir DIR use DIR (e.g. lib64) in place of lib in default paths" +- print >> outfd, " -v, --verbose explain what is being done" +- print >> outfd, " -h, --help display this help and exit" ++ print("Usage: mklibs [OPTION]... -d DEST FILE ...", file=outfd) ++ print("Make a set of minimal libraries for FILE(s) in DEST.", file=outfd) ++ print("", file=outfd) ++ print(" -d, --dest-dir DIRECTORY create libraries in DIRECTORY", file=outfd) ++ print(" -D, --no-default-lib omit default libpath (", ':'.join(default_lib_path), ")", file=outfd) ++ print(" -L DIRECTORY[:DIRECTORY]... add DIRECTORY(s) to the library search path", file=outfd) ++ print(" -l LIBRARY add LIBRARY always", file=outfd) ++ print(" --ldlib LDLIB use LDLIB for the dynamic linker", file=outfd) ++ print(" --libc-extras-dir DIRECTORY look for libc extra files in DIRECTORY", file=outfd) ++ print(" --target TARGET prepend TARGET- to the gcc and binutils calls", file=outfd) ++ print(" --root ROOT search in ROOT for library rpaths", file=outfd) ++ print(" --sysroot ROOT prepend ROOT to all paths for libraries", file=outfd) ++ print(" --gcc-options OPTIONS pass OPTIONS to gcc", file=outfd) ++ print(" --libdir DIR use DIR (e.g. lib64) in place of lib in default paths", file=outfd) ++ print(" -v, --verbose explain what is being done", file=outfd) ++ print(" -h, --help display this help and exit", file=outfd) + sys.exit(was_err) + + def version(vers): +- print "mklibs: version ",vers +- print "" ++ print("mklibs: version ",vers) ++ print("") + + #################### main #################### + ## Usage: ./mklibs.py [OPTION]... -d DEST FILE ... +@@ -368,8 +368,8 @@ script_pattern = re.compile("^#!\s*/") + + try: + optlist, proglist = getopt.getopt(sys.argv[1:], opts, longopts) +-except getopt.GetoptError, msg: +- print >> sys.stderr, msg ++except getopt.GetoptError as msg: ++ print(msg, file=sys.stderr) + usage(1) + + for opt, arg in optlist: +@@ -377,7 +377,7 @@ for opt, arg in optlist: + if debuglevel < DEBUG_SPAM: + debuglevel = debuglevel + 1 + elif opt == "-L": +- lib_path.extend(string.split(arg, ":")) ++ lib_path.extend(arg.split(":")) + elif opt in ("-d", "--dest-dir"): + dest_path = arg + elif opt in ("-D", "--no-default-lib"): +@@ -396,17 +396,17 @@ for opt, arg in optlist: + elif opt in ("-l",): + force_libs.append(arg) + elif opt == "--gcc-options": +- gcc_options.extend(string.split(arg, " ")) ++ gcc_options.extend(arg.split(" ")) + elif opt == "--libdir": + libdir = arg + elif opt in ("--help", "-h"): +- usage(0) ++ usage(0) + sys.exit(0) + elif opt in ("--version", "-V"): + version(vers) + sys.exit(0) + else: +- print "WARNING: unknown option: " + opt + "\targ: " + arg ++ print("WARNING: unknown option: " + opt + "\targ: " + arg) + + if include_default_lib_path == "yes": + lib_path.extend([a.replace("/lib/", "/" + libdir + "/") for a in default_lib_path]) +@@ -424,22 +424,22 @@ if ldlib == "LDLIB": + objects = {} # map from inode to filename + for prog in proglist: + inode = os.stat(prog)[ST_INO] +- if objects.has_key(inode): ++ if inode in objects: + debug(DEBUG_SPAM, prog, "is a hardlink to", objects[inode]) + elif so_pattern.match(prog): + debug(DEBUG_SPAM, prog, "is a library") +- elif script_pattern.match(open(prog).read(256)): ++ elif script_pattern.match(open(prog, 'r', encoding='iso-8859-1').read(256)): + debug(DEBUG_SPAM, prog, "is a script") + else: + objects[inode] = prog + + if not ldlib: +- for obj in objects.values(): ++ for obj in list(objects.values()): + output = command("mklibs-readelf", "--print-interp", obj) + if output: + ldlib = output.pop() +- if ldlib: +- break ++ if ldlib: ++ break + + if not ldlib: + sys.exit("E: Dynamic linker not found, aborting.") +@@ -454,10 +454,10 @@ for obj in sorted(objects.values()): + for rpath_elem in rpath_val: + if not rpath_elem in lib_rpath: + if debuglevel >= DEBUG_VERBOSE: +- print "Adding rpath " + rpath_elem + " for " + obj ++ print("Adding rpath " + rpath_elem + " for " + obj) + lib_rpath.append(rpath_elem) + else: +- print "warning: " + obj + " may need rpath, but --root not specified" ++ print("warning: " + obj + " may need rpath, but --root not specified") + + lib_path.extend(lib_rpath) + +@@ -465,12 +465,12 @@ passnr = 1 + available_libs = [] + previous_pass_unresolved = set() + while 1: +- debug(DEBUG_NORMAL, "I: library reduction pass", `passnr`) ++ debug(DEBUG_NORMAL, "I: library reduction pass", repr(passnr)) + if debuglevel >= DEBUG_VERBOSE: +- print "Objects:", +- for obj in sorted([x[string.rfind(x, '/') + 1:] for x in objects.values()]): +- print obj, +- print ++ print("Objects:", end=' ') ++ for obj in sorted([x[x.rfind('/') + 1:] for x in list(objects.values())]): ++ print(obj, end=' ') ++ print() + + passnr = passnr + 1 + # Gather all already reduced libraries and treat them as objects as well +@@ -479,7 +479,7 @@ while 1: + obj = dest_path + "/" + lib + small_libs.append(obj) + inode = os.stat(obj)[ST_INO] +- if objects.has_key(inode): ++ if inode in objects: + debug(DEBUG_SPAM, obj, "is hardlink to", objects[inode]) + else: + objects[inode] = obj +@@ -509,7 +509,7 @@ while 1: + present_symbols = {} + checked_libs = small_libs + checked_libs.extend(available_libs) +- checked_libs.append(ldlib) ++ checked_libs.append(sysroot + "/" + ldlib) + for lib in checked_libs: + for symbol in provided_symbols(lib): + debug(DEBUG_SPAM, "present_symbols adding %s" % symbol) +@@ -529,8 +529,8 @@ while 1: + unresolved.add(name) + num_unresolved = num_unresolved + 1 + +- debug (DEBUG_NORMAL, `len(needed_symbols)`, "symbols,", +- `num_unresolved`, "unresolved") ++ debug (DEBUG_NORMAL, repr(len(needed_symbols)), "symbols,", ++ repr(num_unresolved), "unresolved") + + if num_unresolved == 0: + break +@@ -539,7 +539,7 @@ while 1: + # No progress in last pass. Verify all remaining symbols are weak. + for name in unresolved: + if not needed_symbols[name].weak: +- print "WARNING: Unresolvable symbol %s" % name ++ print("WARNING: Unresolvable symbol %s" % name) + break + + previous_pass_unresolved = unresolved +@@ -641,9 +641,9 @@ while 1: + command(target + "gcc", *cmd) + + ## DEBUG +- debug(DEBUG_VERBOSE, so_file, "\t", `os.stat(so_file)[ST_SIZE]`) ++ debug(DEBUG_VERBOSE, so_file, "\t", repr(os.stat(so_file)[ST_SIZE])) + debug(DEBUG_VERBOSE, dest_path + "/" + so_file_name + "-so", "\t", +- `os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE]`) ++ repr(os.stat(dest_path + "/" + so_file_name + "-so")[ST_SIZE])) + + # Finalising libs and cleaning up + for lib in regexpfilter(os.listdir(dest_path), "(.*)-so$"): +@@ -680,4 +680,4 @@ if not os.access(dest_path + "/" + ld_fu + command(target + "objcopy", "--strip-unneeded -R .note -R .comment", + ld_file, dest_path + "/" + ld_full_path) + +-os.chmod(dest_path + "/" + ld_full_path, 0755) ++os.chmod(dest_path + "/" + ld_full_path, 0o755) +--- a/src/mklibs-copy ++++ b/src/mklibs-copy +@@ -51,9 +51,9 @@ def command(command, *args): + output = pipe.read().strip() + status = pipe.close() + if status is not None and os.WEXITSTATUS(status) != 0: +- print "Command failed with status", os.WEXITSTATUS(status), ":", \ +- command, ' '.join(args) +- print "With output:", output ++ print("Command failed with status", os.WEXITSTATUS(status), ":", \ ++ command, ' '.join(args)) ++ print("With output:", output) + sys.exit(1) + return output.split('\n') + +@@ -134,8 +134,8 @@ def multiarch(paths): + return paths + + def version(vers): +- print "mklibs: version ",vers +- print "" ++ print("mklibs: version ",vers) ++ print("") + + # Clean the environment + vers="0.12" +@@ -159,7 +159,7 @@ if include_default_lib_path: + objects = {} # map from inode to filename + for prog in proglist: + inode = os.stat(prog)[ST_INO] +- if objects.has_key(inode): ++ if inode in objects: + logger.debug("%s is a hardlink to %s", prog, objects[inode]) + elif so_pattern.match(prog): + logger.debug("%s is a library", prog) +@@ -169,12 +169,12 @@ for prog in proglist: + logger.debug("%s is no ELF", prog) + + if not ldlib: +- for obj in objects.values(): ++ for obj in list(objects.values()): + output = command("mklibs-readelf", "-i", obj) +- for x in output: ++ for x in output: + ldlib = x +- if ldlib: +- break ++ if ldlib: ++ break + + if not ldlib: + sys.exit("E: Dynamic linker not found, aborting.") +@@ -182,7 +182,7 @@ if not ldlib: + logger.info('Using %s as dynamic linker', ldlib) + + # Check for rpaths +-for obj in objects.values(): ++for obj in list(objects.values()): + rpath_val = rpath(obj) + if rpath_val: + if root: +@@ -208,18 +208,18 @@ while 1: + obj = dest_path + "/" + lib + small_libs.append(obj) + inode = os.stat(obj)[ST_INO] +- if objects.has_key(inode): ++ if inode in objects: + logger.debug("%s is hardlink to %s", obj, objects[inode]) + else: + objects[inode] = obj + +- for obj in objects.values(): ++ for obj in list(objects.values()): + small_libs.append(obj) + +- logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.itervalues()])) ++ logger.verbose('Objects: %r', ' '.join([i[i.rfind('/') + 1:] for i in objects.values()])) + + libraries = set() +- for obj in objects.values(): ++ for obj in list(objects.values()): + libraries.update(library_depends(obj)) + + if libraries == previous_pass_libraries: +@@ -272,4 +272,4 @@ if not os.access(dest_path + "/" + ld_fu + command(target + "objcopy", "--strip-unneeded -R .note -R .comment", + ld_file, dest_path + "/" + ld_full_path) + +-os.chmod(dest_path + "/" + ld_full_path, 0755) ++os.chmod(dest_path + "/" + ld_full_path, 0o755) diff --git a/tools/mpfr/Makefile b/tools/mpfr/Makefile index dfff7964ce..fdb316efb9 100644 --- a/tools/mpfr/Makefile +++ b/tools/mpfr/Makefile @@ -7,13 +7,12 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mpfr -PKG_VERSION:=4.0.1 +PKG_VERSION:=4.0.2 PKG_CPE_ID:=cpe:/a:mpfr:gnu_mpfr -PKG_SOURCE_URL:=http://www.mpfr.org/mpfr-$(PKG_VERSION) \ - @GNU/mpfr +PKG_SOURCE_URL:=@GNU/mpfr http://www.mpfr.org/mpfr-$(PKG_VERSION) PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz -PKG_HASH:=67874a60826303ee2fb6affc6dc0ddd3e749e9bfcb4c8655e3953d0458a6e16e +PKG_HASH:=1d3be708604eae0e42d578ba93b390c2a145f17743a744d8f3f8c2ad5855a38a HOST_BUILD_PARALLEL:=1 HOST_FIXUP:=autoreconf @@ -23,6 +22,7 @@ include $(INCLUDE_DIR)/host-build.mk HOST_CONFIGURE_ARGS += \ --enable-static \ --disable-shared \ + --enable-thread-safe \ --with-gmp=$(STAGING_DIR_HOST) $(eval $(call HostBuild)) diff --git a/tools/mpfr/patches/100-freebsd-compat.patch b/tools/mpfr/patches/100-freebsd-compat.patch index c357b68736..8a7c6b098e 100644 --- a/tools/mpfr/patches/100-freebsd-compat.patch +++ b/tools/mpfr/patches/100-freebsd-compat.patch @@ -1,6 +1,6 @@ --- a/src/vasprintf.c +++ b/src/vasprintf.c -@@ -61,6 +61,7 @@ http://www.gnu.org/licenses/ or write to +@@ -72,6 +72,7 @@ https://www.gnu.org/licenses/ or write t #endif /* HAVE_VA_COPY */ #ifdef HAVE_WCHAR_H diff --git a/tools/mtd-utils/Makefile b/tools/mtd-utils/Makefile index ff000b99e3..e0e083d2b6 100644 --- a/tools/mtd-utils/Makefile +++ b/tools/mtd-utils/Makefile @@ -7,11 +7,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mtd-utils -PKG_VERSION:=2.0.2 +PKG_VERSION:=2.1.1 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 PKG_SOURCE_URL:=ftp://ftp.infradead.org/pub/mtd-utils/ -PKG_HASH:=fb3de61be8e932abb424e8ea3c30298f553d5f970ad158a737bb303bbf9660b8 +PKG_HASH:=8d15e8b70f036d6af1a66011f8ca0e048e9675fa7983d33bea92c24313a232d2 PKG_FIXUP:=autoreconf @@ -32,7 +32,9 @@ HOST_CONFIGURE_VARS+= \ HOST_CONFIGURE_ARGS+= \ --disable-tests \ + --without-crypto \ --without-xattr \ + --without-zstd \ --without-lzo HOST_MAKE_FLAGS += \ diff --git a/tools/mtd-utils/patches/110-portability.patch b/tools/mtd-utils/patches/110-portability.patch index a2942270d7..067526171a 100644 --- a/tools/mtd-utils/patches/110-portability.patch +++ b/tools/mtd-utils/patches/110-portability.patch @@ -70,7 +70,7 @@ #include --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c -@@ -1219,6 +1219,7 @@ static int add_inode(struct stat *st, in +@@ -1503,6 +1503,7 @@ static int add_inode(struct stat *st, in if (c->default_compr != UBIFS_COMPR_NONE) use_flags |= UBIFS_COMPR_FL; @@ -78,15 +78,15 @@ if (flags & FS_COMPR_FL) use_flags |= UBIFS_COMPR_FL; if (flags & FS_SYNC_FL) -@@ -1229,6 +1230,7 @@ static int add_inode(struct stat *st, in - use_flags |= UBIFS_APPEND_FL; - if (flags & FS_DIRSYNC_FL && S_ISDIR(st->st_mode)) +@@ -1515,6 +1516,7 @@ static int add_inode(struct stat *st, in use_flags |= UBIFS_DIRSYNC_FL; + if (fctx) + use_flags |= UBIFS_CRYPT_FL; +#endif - memset(ino, 0, UBIFS_INO_NODE_SZ); -@@ -1293,7 +1295,9 @@ static int add_dir_inode(const char *pat + ino_key_init(&key, inum); +@@ -1600,7 +1602,9 @@ static int add_dir_inode(const char *pat fd = dirfd(dir); if (fd == -1) return sys_err_msg("dirfd failed"); @@ -96,15 +96,15 @@ flags = 0; } -@@ -1476,6 +1480,7 @@ static int add_file(const char *path_nam +@@ -1811,6 +1815,7 @@ static int add_file(const char *path_nam + dn->ch.node_type = UBIFS_DATA_NODE; key_write(&key, &dn->key); - dn->size = cpu_to_le32(bytes_read); out_len = NODE_BUFFER_SIZE - UBIFS_DATA_NODE_SZ; +#ifndef NO_NATIVE_SUPPORT if (c->default_compr == UBIFS_COMPR_NONE && - (flags & FS_COMPR_FL)) + !c->encrypted && (flags & FS_COMPR_FL)) #ifdef WITHOUT_LZO -@@ -1484,6 +1489,7 @@ static int add_file(const char *path_nam +@@ -1819,6 +1824,7 @@ static int add_file(const char *path_nam use_compr = UBIFS_COMPR_LZO; #endif else @@ -112,7 +112,7 @@ use_compr = c->default_compr; compr_type = compress_data(buf, bytes_read, &dn->data, &out_len, use_compr); -@@ -1527,7 +1533,9 @@ static int add_non_dir(const char *path_ +@@ -1876,7 +1882,9 @@ static int add_non_dir(const char *path_ if (fd == -1) return sys_err_msg("failed to open file '%s'", path_name); diff --git a/tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch b/tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch index 0da28b71f2..d765cdc6cc 100644 --- a/tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch +++ b/tools/mtd-utils/patches/201-ubinize-add-terminator-support.patch @@ -47,7 +47,7 @@ case 'v': args.verbose = 1; break; -@@ -559,6 +569,18 @@ int main(int argc, char * const argv[]) +@@ -582,6 +592,18 @@ int main(int argc, char * const argv[]) printf("\n"); } diff --git a/tools/popt/Makefile b/tools/popt/Makefile deleted file mode 100644 index 50524b6eaf..0000000000 --- a/tools/popt/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -include $(TOPDIR)/rules.mk - -PKG_NAME:=popt -PKG_VERSION:=1.16 - -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=http://rpm5.org/files/popt -PKG_HASH:=e728ed296fe9f069a0e005003c3d6b2dde3d9cad453422a10d6558616d304cc8 - -HOST_FIXUP:=autoreconf - -include $(INCLUDE_DIR)/host-build.mk - -HOST_CONFIGURE_ARGS += \ - --disable-nls \ - --disable-rpath \ - --enable-shared=no \ - --without-libiconv-prefix \ - --without-libintl-prefix - -$(eval $(call HostBuild)) diff --git a/tools/popt/patches/900-autoconf-compat.patch b/tools/popt/patches/900-autoconf-compat.patch deleted file mode 100644 index 71a2cdab86..0000000000 --- a/tools/popt/patches/900-autoconf-compat.patch +++ /dev/null @@ -1,25 +0,0 @@ ---- a/configure.ac -+++ b/configure.ac -@@ -46,7 +46,7 @@ AC_GCC_TRADITIONAL - AC_SYS_LARGEFILE - - AC_ISC_POSIX --AM_C_PROTOTYPES -+AC_C_PROTOTYPES - - AC_CHECK_HEADERS(float.h fnmatch.h glob.h langinfo.h libintl.h mcheck.h unistd.h) - ---- a/Makefile.am -+++ b/Makefile.am -@@ -35,9 +35,10 @@ tdict_LDADD = $(usrlib_LTLIBRARIES) - noinst_SCRIPTS = testit.sh - - TESTS_ENVIRONMENT = \ -+TESTS_DIR="$(top_srcdir)" \ - test1="$(top_builddir)/test1" - --TESTS = $(top_srcdir)/testit.sh -+TESTS = testit.sh - - include_HEADERS = popt.h - diff --git a/tools/scons/Makefile b/tools/scons/Makefile deleted file mode 100644 index fc325bff02..0000000000 --- a/tools/scons/Makefile +++ /dev/null @@ -1,35 +0,0 @@ -# -# Copyright (C) 2011-2015 OpenWrt.org -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# - -include $(TOPDIR)/rules.mk - -PKG_NAME:=scons -PKG_VERSION:=3.0.1 - -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=@SF/scons \ - http://fossies.org/linux/misc/ -PKG_HASH:=24475e38d39c19683bc88054524df018fe6949d70fbd4c69e298d39a0269f173 - -include $(INCLUDE_DIR)/host-build.mk - -define Host/Configure -endef - -define Host/Compile -endef - -define Host/Install - ./files/pywrap.sh $(HOST_BUILD_DIR)/setup.py install --prefix=$(STAGING_DIR_HOST) - rm -f $(STAGING_DIR_HOST)/bin/scons*.py - for bin in $(STAGING_DIR_HOST)/bin/scons*; do \ - mv "$$$$bin" "$$$$bin.py"; \ - cp ./files/pywrap.sh "$$$$bin"; \ - done -endef - -$(eval $(call HostBuild)) diff --git a/tools/scons/files/pywrap.sh b/tools/scons/files/pywrap.sh deleted file mode 100755 index f62f590e0b..0000000000 --- a/tools/scons/files/pywrap.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -case "${0##*/}" in - pywrap.sh) arg1="";; - *) arg1="$0.py" ;; -esac - -for bin in python python2 python2.7 python2.6 python2.5 python2.4; do - case "$($bin -V 2>&1)" in - "Python 2"*) exec $bin $arg1 "$@" ;; - esac -done - -echo "Unable to find a Python 2.x interpreter for executing ${arg1:+$arg1 }$@ !" >&2 -exit 1 diff --git a/tools/scons/patches/001-platform_env.patch b/tools/scons/patches/001-platform_env.patch deleted file mode 100644 index 2be31470c2..0000000000 --- a/tools/scons/patches/001-platform_env.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- a/engine/SCons/Platform/__init__.py -+++ b/engine/SCons/Platform/__init__.py -@@ -65,6 +65,8 @@ def platform_default(): - care about the machine architecture. - """ - osname = os.name -+ if 'PLATFORM' in os.environ: -+ return os.environ['PLATFORM'] - if osname == 'java': - osname = os._osType - if osname == 'posix': diff --git a/tools/sed/Makefile b/tools/sed/Makefile index 834519b737..ddeb6c457f 100644 --- a/tools/sed/Makefile +++ b/tools/sed/Makefile @@ -7,11 +7,11 @@ include $(TOPDIR)/rules.mk PKG_NAME:=sed -PKG_VERSION:=4.5 +PKG_VERSION:=4.7 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=@GNU/$(PKG_NAME) -PKG_HASH:=7aad73c8839c2bdadca9476f884d2953cdace9567ecd0d90f9959f229d146b40 +PKG_HASH:=2885768cd0a29ff8d58a6280a270ff161f6a3deb5690b2be6c49f46d4c67bd6a export SED:= HOST_BUILD_PARALLEL:=1 @@ -24,6 +24,7 @@ include $(INCLUDE_DIR)/host-build.mk HOST_CONFIGURE_ARGS += \ --disable-acl \ --disable-nls \ + --enable-threads=pth HOST_CONFIGURE_VARS += \ ac_cv_search_setfilecon=no \ diff --git a/tools/squashfs4/Makefile b/tools/squashfs4/Makefile deleted file mode 100644 index 409b1b5a23..0000000000 --- a/tools/squashfs4/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (C) 2009-2012 OpenWrt.org -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# -include $(TOPDIR)/rules.mk - -PKG_NAME:=squashfs4 -PKG_CPE_ID:=cpe:/a:phillip_lougher:squashfs -PKG_VERSION:=4.2 - -PKG_SOURCE:=squashfs$(PKG_VERSION).tar.gz -PKG_SOURCE_URL:=@SF/squashfs -PKG_HASH:=d9e0195aa922dbb665ed322b9aaa96e04a476ee650f39bbeadb0d00b24022e96 -PKG_CAT:=zcat - -HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/squashfs$(PKG_VERSION) - -include $(INCLUDE_DIR)/host-build.mk - -define Host/Compile - +$(HOST_MAKE_VARS) \ - $(MAKE) -C $(HOST_BUILD_DIR)/squashfs-tools \ - XZ_SUPPORT=1 \ - LZMA_XZ_SUPPORT=1 \ - XATTR_SUPPORT= \ - LZMA_LIB="$(STAGING_DIR_HOST)/lib/liblzma.a" \ - EXTRA_CFLAGS="-I$(STAGING_DIR_HOST)/include" \ - mksquashfs unsquashfs -endef - -define Host/Install - $(INSTALL_BIN) $(HOST_BUILD_DIR)/squashfs-tools/mksquashfs $(STAGING_DIR_HOST)/bin/mksquashfs4 - $(INSTALL_BIN) $(HOST_BUILD_DIR)/squashfs-tools/unsquashfs $(STAGING_DIR_HOST)/bin/unsquashfs4 -endef - -define Host/Clean - rm -f $(STAGING_DIR_HOST)/bin/mksquashfs4 - rm -f $(STAGING_DIR_HOST)/bin/unsquashfs4 -endef - -$(eval $(call HostBuild)) diff --git a/tools/squashfs4/patches/100-portability.patch b/tools/squashfs4/patches/100-portability.patch deleted file mode 100644 index ac1349c7a3..0000000000 --- a/tools/squashfs4/patches/100-portability.patch +++ /dev/null @@ -1,40 +0,0 @@ ---- a/squashfs-tools/mksquashfs.c -+++ b/squashfs-tools/mksquashfs.c -@@ -60,6 +60,10 @@ - #include - #endif - -+#ifndef FNM_EXTMATCH -+#define FNM_EXTMATCH 0 -+#endif -+ - #ifdef SQUASHFS_TRACE - #define TRACE(s, args...) \ - do { \ ---- a/squashfs-tools/unsquashfs.h -+++ b/squashfs-tools/unsquashfs.h -@@ -49,8 +49,14 @@ - #define __BYTE_ORDER BYTE_ORDER - #define __BIG_ENDIAN BIG_ENDIAN - #define __LITTLE_ENDIAN LITTLE_ENDIAN -+#include - #else - #include -+#include -+#endif -+ -+#ifndef FNM_EXTMATCH -+#define FNM_EXTMATCH 0 - #endif - - #include "squashfs_fs.h" ---- a/squashfs-tools/unsquashfs.c -+++ b/squashfs-tools/unsquashfs.c -@@ -29,7 +29,6 @@ - #include "compressor.h" - #include "xattr.h" - --#include - #include - - struct cache *fragment_cache, *data_cache; diff --git a/tools/squashfs4/patches/110-allow_static_liblzma.patch b/tools/squashfs4/patches/110-allow_static_liblzma.patch deleted file mode 100644 index 9a3a744184..0000000000 --- a/tools/squashfs4/patches/110-allow_static_liblzma.patch +++ /dev/null @@ -1,30 +0,0 @@ ---- a/squashfs-tools/Makefile -+++ b/squashfs-tools/Makefile -@@ -129,7 +129,6 @@ ifeq ($(LZMA_XZ_SUPPORT),1) - CFLAGS += -DLZMA_SUPPORT - MKSQUASHFS_OBJS += lzma_xz_wrapper.o - UNSQUASHFS_OBJS += lzma_xz_wrapper.o --LIBS += -llzma - COMPRESSORS += lzma - endif - -@@ -137,10 +136,18 @@ ifeq ($(XZ_SUPPORT),1) - CFLAGS += -DXZ_SUPPORT - MKSQUASHFS_OBJS += xz_wrapper.o - UNSQUASHFS_OBJS += xz_wrapper.o --LIBS += -llzma - COMPRESSORS += xz - endif - -+ifneq ($(LZMA_XZ_SUPPORT)$(XZ_SUPPORT),) -+ifneq ($(LZMA_LIB),) -+MKSQUASHFS_OBJS += $(LZMA_LIB) -+UNSQUASHFS_OBJS += $(LZMA_LIB) -+else -+LIBS += -llzma -+endif -+endif -+ - ifeq ($(LZO_SUPPORT),1) - CFLAGS += -DLZO_SUPPORT - ifdef LZO_DIR diff --git a/tools/squashfs4/patches/120-cygwin_fixes.patch b/tools/squashfs4/patches/120-cygwin_fixes.patch deleted file mode 100644 index fa1dfba42d..0000000000 --- a/tools/squashfs4/patches/120-cygwin_fixes.patch +++ /dev/null @@ -1,153 +0,0 @@ ---- a/squashfs-tools/mksquashfs.c -+++ b/squashfs-tools/mksquashfs.c -@@ -51,15 +51,22 @@ - #include - - #ifndef linux -+#ifndef __CYGWIN__ - #define __BYTE_ORDER BYTE_ORDER - #define __BIG_ENDIAN BIG_ENDIAN - #define __LITTLE_ENDIAN LITTLE_ENDIAN - #include -+#endif /* __CYGWIN__ */ - #else - #include - #include - #endif - -+#ifdef __CYGWIN__ -+#include -+#define FNM_EXTMATCH (1 << 5) -+#endif -+ - #ifndef FNM_EXTMATCH - #define FNM_EXTMATCH 0 - #endif -@@ -844,6 +851,7 @@ void sigusr1_handler() - - void sigwinch_handler() - { -+#ifndef __CYGWIN__ - struct winsize winsize; - - if(ioctl(1, TIOCGWINSZ, &winsize) == -1) { -@@ -853,6 +861,9 @@ void sigwinch_handler() - columns = 80; - } else - columns = winsize.ws_col; -+#else -+ columns = 80; -+#endif - } - - -@@ -4066,6 +4077,9 @@ void initialise_threads(int readb_mbytes - - signal(SIGUSR1, sigusr1_handler); - -+#ifdef __CYGWIN__ -+ processors = atoi(getenv("NUMBER_OF_PROCESSORS")); -+#else - if(processors == -1) { - #ifndef linux - int mib[2]; -@@ -4087,6 +4101,7 @@ void initialise_threads(int readb_mbytes - processors = sysconf(_SC_NPROCESSORS_ONLN); - #endif - } -+#endif /* __CYGWIN__ */ - - thread = malloc((2 + processors * 2) * sizeof(pthread_t)); - if(thread == NULL) ---- a/squashfs-tools/read_fs.c -+++ b/squashfs-tools/read_fs.c -@@ -33,9 +33,11 @@ - #include - - #ifndef linux -+#ifndef __CYGWIN__ - #define __BYTE_ORDER BYTE_ORDER - #define __BIG_ENDIAN BIG_ENDIAN - #define __LITTLE_ENDIAN LITTLE_ENDIAN -+#endif - #else - #include - #endif ---- a/squashfs-tools/swap.c -+++ b/squashfs-tools/swap.c -@@ -20,9 +20,11 @@ - */ - - #ifndef linux -+#ifndef __CYGWIN__ - #define __BYTE_ORDER BYTE_ORDER - #define __BIG_ENDIAN BIG_ENDIAN - #define __LITTLE_ENDIAN LITTLE_ENDIAN -+#endif - #else - #include - #endif ---- a/squashfs-tools/unsquashfs.c -+++ b/squashfs-tools/unsquashfs.c -@@ -117,6 +117,7 @@ void update_progress_bar(); - - void sigwinch_handler() - { -+#ifndef __CYGWIN__ - struct winsize winsize; - - if(ioctl(1, TIOCGWINSZ, &winsize) == -1) { -@@ -126,6 +127,9 @@ void sigwinch_handler() - columns = 80; - } else - columns = winsize.ws_col; -+#else -+ columns = 80; -+#endif - } - - -@@ -1807,7 +1811,9 @@ void initialise_threads(int fragment_buf - if(sigprocmask(SIG_BLOCK, &sigmask, &old_mask) == -1) - EXIT_UNSQUASH("Failed to set signal mask in intialise_threads" - "\n"); -- -+#ifdef __CYGWIN__ -+ processors = atoi(getenv("NUMBER_OF_PROCESSORS")); -+#else - if(processors == -1) { - #ifndef linux - int mib[2]; -@@ -1829,6 +1835,7 @@ void initialise_threads(int fragment_buf - processors = sysconf(_SC_NPROCESSORS_ONLN); - #endif - } -+#endif /* __CYGWIN__ */ - - thread = malloc((3 + processors) * sizeof(pthread_t)); - if(thread == NULL) ---- a/squashfs-tools/unsquashfs.h -+++ b/squashfs-tools/unsquashfs.h -@@ -46,15 +46,22 @@ - #include - - #ifndef linux -+#ifndef __CYGWIN__ - #define __BYTE_ORDER BYTE_ORDER - #define __BIG_ENDIAN BIG_ENDIAN - #define __LITTLE_ENDIAN LITTLE_ENDIAN - #include -+#endif - #else - #include - #include - #endif - -+#ifdef __CYGWIN__ -+#include -+#define FNM_EXTMATCH (1 << 5) -+#endif -+ - #ifndef FNM_EXTMATCH - #define FNM_EXTMATCH 0 - #endif diff --git a/tools/squashfs4/patches/130-include_sysmacros.patch b/tools/squashfs4/patches/130-include_sysmacros.patch deleted file mode 100644 index e8845130ef..0000000000 --- a/tools/squashfs4/patches/130-include_sysmacros.patch +++ /dev/null @@ -1,20 +0,0 @@ ---- a/squashfs-tools/mksquashfs.c -+++ b/squashfs-tools/mksquashfs.c -@@ -33,6 +33,7 @@ - #include - #include - #include -+#include - #include - #include - #include ---- a/squashfs-tools/unsquashfs.c -+++ b/squashfs-tools/unsquashfs.c -@@ -30,6 +30,7 @@ - #include "xattr.h" - - #include -+#include - - struct cache *fragment_cache, *data_cache; - struct queue *to_reader, *to_deflate, *to_writer, *from_writer; diff --git a/tools/squashfs4/patches/150-freebsd_fixes.patch b/tools/squashfs4/patches/150-freebsd_fixes.patch deleted file mode 100644 index 44d40a7d1a..0000000000 --- a/tools/squashfs4/patches/150-freebsd_fixes.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- a/squashfs-tools/pseudo.c -+++ b/squashfs-tools/pseudo.c -@@ -32,6 +32,7 @@ - #include - #include - #include -+#include - - #include "pseudo.h" - diff --git a/tools/squashfs4/patches/160-expose_lzma_xz_options.patch b/tools/squashfs4/patches/160-expose_lzma_xz_options.patch deleted file mode 100644 index 9e1c1fbb1e..0000000000 --- a/tools/squashfs4/patches/160-expose_lzma_xz_options.patch +++ /dev/null @@ -1,929 +0,0 @@ ---- /dev/null -+++ b/squashfs-tools/lzma_xz_options.h -@@ -0,0 +1,115 @@ -+#ifndef LZMA_XZ_OPTIONS_H -+#define LZMA_XZ_OPTIONS_H -+/* -+ * Copyright (c) 2011 -+ * Jonas Gorski -+ * -+ * This program is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU General Public License -+ * as published by the Free Software Foundation; either version 2, -+ * or (at your option) any later version. -+ * -+ * This program is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with this program; if not, write to the Free Software -+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -+ * -+ * lzma_options.h -+ */ -+ -+#include -+ -+#ifndef linux -+#ifdef __FreeBSD__ -+#include -+#endif -+#define __BYTE_ORDER BYTE_ORDER -+#define __BIG_ENDIAN BIG_ENDIAN -+#define __LITTLE_ENDIAN LITTLE_ENDIAN -+#else -+#include -+#endif -+ -+ -+ -+struct lzma_opts { -+ uint32_t dict_size; -+ uint32_t flags; -+#define LZMA_OPT_FLT_MASK 0xffff -+#define LZMA_OPT_PRE_OFF 16 -+#define LZMA_OPT_PRE_MASK (0xf << LZMA_OPT_PRE_OFF) -+#define LZMA_OPT_EXTREME 20 -+ uint16_t bit_opts; -+#define LZMA_OPT_LC_OFF 0 -+#define LZMA_OPT_LC_MASK (0x7 << LZMA_OPT_LC_OFF) -+#define LZMA_OPT_LP_OFF 3 -+#define LZMA_OPT_LP_MASK (0x7 << LZMA_OPT_LP_OFF) -+#define LZMA_OPT_PB_OFF 6 -+#define LZMA_OPT_PB_MASK (0x7 << LZMA_OPT_PB_OFF) -+ uint16_t fb; -+}; -+ -+#if __BYTE_ORDER == __BIG_ENDIAN -+extern unsigned int inswap_le32(unsigned int); -+ -+#define SQUASHFS_INSWAP_LZMA_COMP_OPTS(s) { \ -+ (s)->flags = inswap_le32((s)->flags); \ -+ (s)->bit_opts = inswap_le16((s)->bit_opts); \ -+ (s)->fb = inswap_le16((s)->fb); \ -+ (s)->dict_size = inswap_le32((s)->dict_size); \ -+} -+#else -+#define SQUASHFS_INSWAP_LZMA_COMP_OPTS(s) -+#endif -+ -+#define MEMLIMIT (32 * 1024 * 1024) -+ -+#define LZMA_OPT_LC_MIN 0 -+#define LZMA_OPT_LC_MAX 4 -+#define LZMA_OPT_LC_DEFAULT 3 -+ -+#define LZMA_OPT_LP_MIN 0 -+#define LZMA_OPT_LP_MAX 4 -+#define LZMA_OPT_LP_DEFAULT 0 -+ -+#define LZMA_OPT_PB_MIN 0 -+#define LZMA_OPT_PB_MAX 4 -+#define LZMA_OPT_PB_DEFAULT 2 -+ -+#define LZMA_OPT_FB_MIN 5 -+#define LZMA_OPT_FB_MAX 273 -+#define LZMA_OPT_FB_DEFAULT 64 -+ -+enum { -+ LZMA_OPT_LZMA = 1, -+ LZMA_OPT_XZ -+}; -+ -+struct lzma_xz_options { -+ int preset; -+ int extreme; -+ int lc; -+ int lp; -+ int pb; -+ int fb; -+ int dict_size; -+ int flags; -+}; -+ -+struct lzma_xz_options *lzma_xz_get_options(void); -+ -+int lzma_xz_options(char *argv[], int argc, int lzmaver); -+ -+int lzma_xz_options_post(int block_size, int lzmaver); -+ -+void *lzma_xz_dump_options(int block_size, int *size, int flags); -+ -+int lzma_xz_extract_options(int block_size, void *buffer, int size, int lzmaver); -+ -+void lzma_xz_usage(int lzmaver); -+ -+#endif ---- /dev/null -+++ b/squashfs-tools/lzma_xz_options.c -@@ -0,0 +1,365 @@ -+/* -+ * Copyright (c) 2011 -+ * Jonas Gorski -+ * -+ * This program is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU General Public License -+ * as published by the Free Software Foundation; either version 2, -+ * or (at your option) any later version. -+ * -+ * This program is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -+ * GNU General Public License for more details. -+ * -+ * You should have received a copy of the GNU General Public License -+ * along with this program; if not, write to the Free Software -+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -+ * -+ * lzma_options.c -+ * -+ * Common options for LZMA1 and 2 compressors. Based on xz_wrapper.c -+ */ -+ -+#include -+#include -+#include -+ -+#include -+ -+#include "lzma_xz_options.h" -+ -+static const char const *lzmaver_str[] = { "", "lzma", "xz" }; -+ -+static struct lzma_xz_options options = { -+ .flags = 0, -+ .preset = 6, -+ .extreme = 0, -+ .lc = LZMA_OPT_LC_DEFAULT, -+ .lp = LZMA_OPT_LP_DEFAULT, -+ .pb = LZMA_OPT_PB_DEFAULT, -+ .fb = LZMA_OPT_FB_DEFAULT, -+ .dict_size = 0, -+}; -+ -+static float lzma_dict_percent = 0; -+ -+struct lzma_xz_options *lzma_xz_get_options(void) -+{ -+ return &options; -+} -+ -+ -+int lzma_xz_options(char *argv[], int argc, int lzmaver) -+{ -+ const char *comp_name = lzmaver_str[lzmaver]; -+ -+ if(strcmp(argv[0], "-Xpreset") == 0) { -+ int preset; -+ -+ if(argc < 2) { -+ fprintf(stderr, "%s: -Xpreset missing preset\n", comp_name); -+ goto failed; -+ } -+ -+ preset = atoi(argv[1]); -+ -+ if (preset < 0 || preset > 9) { -+ fprintf(stderr, "%s: -Xpreset invalid value\n", comp_name); -+ goto failed; -+ } -+ options.preset = preset; -+ return 1; -+ } else if(strcmp(argv[0], "-Xe") == 0) { -+ options.extreme = 1; -+ return 0; -+ } else if(strcmp(argv[0], "-Xlc") == 0) { -+ int lc; -+ -+ if(argc < 2) { -+ fprintf(stderr, "%s: -Xlc missing lc\n", comp_name); -+ goto failed; -+ } -+ -+ lc = atoi(argv[1]); -+ -+ if (lc < LZMA_OPT_LC_MIN || lc > LZMA_OPT_LC_MAX) { -+ fprintf(stderr, "%s: -Xlc invalid value\n", comp_name); -+ goto failed; -+ } -+ options.lc = lc; -+ return 1; -+ } else if(strcmp(argv[0], "-Xlp") == 0) { -+ int lp; -+ -+ if(argc < 2) { -+ fprintf(stderr, "%s: -Xlp missing lp\n", comp_name); -+ goto failed; -+ } -+ -+ lp = atoi(argv[1]); -+ -+ if (lp < LZMA_OPT_LP_MIN || lp > LZMA_OPT_LP_MAX) { -+ fprintf(stderr, "%s: -Xlp invalid value\n", comp_name); -+ goto failed; -+ } -+ options.lp = lp; -+ return 1; -+ } else if(strcmp(argv[0], "-Xpb") == 0) { -+ int pb; -+ -+ if(argc < 2) { -+ fprintf(stderr, "%s: -Xpb missing pb\n", comp_name); -+ goto failed; -+ } -+ -+ pb = atoi(argv[1]); -+ -+ if (pb < LZMA_OPT_PB_MIN || pb > LZMA_OPT_PB_MAX) { -+ fprintf(stderr, "%s: -Xbp invalid value\n", comp_name); -+ goto failed; -+ } -+ options.pb = pb; -+ return 1; -+ } else if(strcmp(argv[0], "-Xfb") == 0) { -+ int fb; -+ -+ if(argc < 2) { -+ fprintf(stderr, "%s: -Xfb missing fb\n", comp_name); -+ goto failed; -+ } -+ -+ fb = atoi(argv[1]); -+ -+ if (fb < LZMA_OPT_FB_MIN || fb > LZMA_OPT_FB_MAX) { -+ fprintf(stderr, "%s: -Xfb invalid value\n", comp_name); -+ goto failed; -+ } -+ options.fb = fb; -+ return 1; -+ } else if(strcmp(argv[0], "-Xdict-size") == 0) { -+ char *b; -+ float size; -+ -+ if(argc < 2) { -+ fprintf(stderr, "%s: -Xdict-size missing dict-size\n", comp_name); -+ goto failed; -+ } -+ -+ size = strtof(argv[1], &b); -+ if(*b == '%') { -+ if(size <= 0 || size > 100) { -+ fprintf(stderr, "%s: -Xdict-size percentage " -+ "should be 0 < dict-size <= 100\n", comp_name); -+ goto failed; -+ } -+ -+ lzma_dict_percent = size; -+ options.dict_size = 0; -+ } else { -+ if((float) ((int) size) != size) { -+ fprintf(stderr, "%s: -Xdict-size can't be " -+ "fractional unless a percentage of the" -+ " block size\n", comp_name); -+ goto failed; -+ } -+ -+ lzma_dict_percent = 0; -+ options.dict_size = (int) size; -+ -+ if(*b == 'k' || *b == 'K') -+ options.dict_size *= 1024; -+ else if(*b == 'm' || *b == 'M') -+ options.dict_size *= 1024 * 1024; -+ else if(*b != '\0') { -+ fprintf(stderr, "%s: -Xdict-size invalid " -+ "dict-size\n", comp_name); -+ goto failed; -+ } -+ } -+ -+ return 1; -+ } -+ -+ return -1; -+ -+failed: -+ return -2; -+ -+} -+ -+int lzma_xz_options_post(int block_size, int lzmaver) -+{ -+ const char *comp_name = lzmaver_str[lzmaver]; -+ /* -+ * if -Xdict-size has been specified use this to compute the datablock -+ * dictionary size -+ */ -+ if(options.dict_size || lzma_dict_percent) { -+ int dict_size_min = (lzmaver == 1 ? 4096 : 8192); -+ int n; -+ -+ if(options.dict_size) { -+ if(options.dict_size > block_size) { -+ fprintf(stderr, "%s: -Xdict-size is larger than" -+ " block_size\n", comp_name); -+ goto failed; -+ } -+ } else -+ options.dict_size = block_size * lzma_dict_percent / 100; -+ -+ if(options.dict_size < dict_size_min) { -+ fprintf(stderr, "%s: -Xdict-size should be %i bytes " -+ "or larger\n", comp_name, dict_size_min); -+ goto failed; -+ } -+ -+ /* -+ * dictionary_size must be storable in xz header as either -+ * 2^n or as 2^n+2^(n+1) -+ */ -+ n = ffs(options.dict_size) - 1; -+ if(options.dict_size != (1 << n) && -+ options.dict_size != ((1 << n) + (1 << (n + 1)))) { -+ fprintf(stderr, "%s: -Xdict-size is an unsupported " -+ "value, dict-size must be storable in %s " -+ "header\n", comp_name, comp_name); -+ fprintf(stderr, "as either 2^n or as 2^n+2^(n+1). " -+ "Example dict-sizes are 75%%, 50%%, 37.5%%, " -+ "25%%,\n"); -+ fprintf(stderr, "or 32K, 16K, 8K etc.\n"); -+ goto failed; -+ } -+ -+ } else -+ /* No -Xdict-size specified, use defaults */ -+ options.dict_size = block_size; -+ -+ return 0; -+ -+failed: -+ return -1; -+} -+ -+static struct lzma_opts lzma_comp_opts; -+ -+void *lzma_xz_dump_options(int block_size, int *size, int flags) -+{ -+ /* No need to store default options */ -+ if (options.preset == 6 && -+ options.extreme == 0 && -+ options.lc == LZMA_OPT_LC_DEFAULT && -+ options.lp == LZMA_OPT_LC_DEFAULT && -+ options.pb == LZMA_OPT_PB_DEFAULT && -+ options.fb == 0 && -+ options.dict_size == block_size && -+ flags == 0) -+ return NULL; -+ -+ *size = sizeof(struct lzma_opts); -+ -+ lzma_comp_opts.flags |= flags; -+ -+ if (options.extreme) -+ lzma_comp_opts.flags |= LZMA_OPT_EXTREME; -+ -+ lzma_comp_opts.flags |= ((options.preset << LZMA_OPT_PRE_OFF) & LZMA_OPT_PRE_MASK); -+ -+ lzma_comp_opts.bit_opts = -+ ((options.lc << LZMA_OPT_LC_OFF) & LZMA_OPT_LC_MASK) | -+ ((options.lp << LZMA_OPT_LP_OFF) & LZMA_OPT_LP_MASK) | -+ ((options.pb << LZMA_OPT_PB_OFF) & LZMA_OPT_PB_MASK); -+ lzma_comp_opts.fb = options.fb; -+ lzma_comp_opts.dict_size = options.dict_size; -+ -+ SQUASHFS_INSWAP_LZMA_COMP_OPTS(&lzma_comp_opts); -+ -+ return &lzma_comp_opts; -+} -+ -+int lzma_xz_extract_options(int block_size, void *buffer, int size, int lzmaver) -+{ -+ if (size == 0) { -+ /* default options */ -+ options.preset = 6; -+ options.extreme = 0; -+ options.lc = LZMA_OPT_LC_DEFAULT; -+ options.lp = LZMA_OPT_LC_DEFAULT; -+ options.pb = LZMA_OPT_PB_DEFAULT; -+ options.fb = LZMA_OPT_FB_DEFAULT; -+ options.dict_size = block_size; -+ options.flags = 0; -+ } else { -+ struct lzma_opts *comp_opts = buffer; -+ int n; -+ -+ if (size != sizeof(struct lzma_opts)) -+ goto failed; -+ -+ SQUASHFS_INSWAP_LZMA_COMP_OPTS(comp_opts); -+ -+ options.flags = comp_opts->flags & LZMA_OPT_FLT_MASK; -+ options.preset = (comp_opts->flags & LZMA_OPT_PRE_MASK) >> LZMA_OPT_PRE_OFF; -+ options.extreme = !!(comp_opts->flags & LZMA_OPT_EXTREME); -+ -+ options.lc = (comp_opts->bit_opts & LZMA_OPT_LC_MASK) >> LZMA_OPT_LC_OFF; -+ options.lp = (comp_opts->bit_opts & LZMA_OPT_LP_MASK) >> LZMA_OPT_LP_OFF; -+ options.pb = (comp_opts->bit_opts & LZMA_OPT_PB_MASK) >> LZMA_OPT_PB_OFF; -+ options.fb = comp_opts->fb; -+ options.dict_size = comp_opts->dict_size; -+ -+ /* check that the LZMA bit options are in range */ -+ if (options.lc < LZMA_OPT_LC_MIN || options.lc > LZMA_OPT_LC_MAX || -+ options.lp < LZMA_OPT_LP_MIN || options.lp > LZMA_OPT_LP_MAX || -+ options.pb < LZMA_OPT_PB_MIN || options.pb > LZMA_OPT_PB_MAX || -+ options.fb < LZMA_OPT_FB_MIN || options.fb > LZMA_OPT_FB_MAX) -+ goto failed; -+ -+ /* -+ * check that the dictionary size seems correct - the dictionary -+ * size should 2^n or 2^n+2^(n+1) -+ */ -+ n = ffs(options.dict_size) - 1; -+ if(options.dict_size != (1 << n) && -+ options.dict_size != ((1 << n) + (1 << (n + 1)))) -+ goto failed; -+ -+ } -+ -+ return 0; -+ -+failed: -+ fprintf(stderr, "%s: error reading stored compressor options from " -+ "filesystem!\n", lzmaver_str[lzmaver]); -+ return -1; -+} -+ -+void lzma_xz_usage(int lzmaver) -+{ -+ fprintf(stderr, "\t -Xpreset \n"); -+ fprintf(stderr, "\t\tcompression preset (0-9, default 6)\n"); -+ fprintf(stderr, "\t -Xe\n"); -+ fprintf(stderr, "\t\tTry to improve compression ratio by using more "); -+ fprintf(stderr, "CPU time.\n"); -+ fprintf(stderr, "\t -Xlc \n"); -+ fprintf(stderr, "\t\tNumber of literal context bits (0-4, default 3)\n"); -+ fprintf(stderr, "\t -Xlp \n"); -+ fprintf(stderr, "\t\tNumber of literal position bits (0-4, default 0)\n"); -+ fprintf(stderr, "\t -Xpb \n"); -+ fprintf(stderr, "\t\tNumber of position bits (0-4, default 2)\n"); -+ fprintf(stderr, "\t -Xnice \n"); -+ fprintf(stderr, "\t\tNice length of a match (5-273, default 64)\n"); -+ fprintf(stderr, "\t -Xdict-size \n"); -+ fprintf(stderr, "\t\tUse as the %s dictionary size. The", -+ lzmaver == LZMA_OPT_LZMA ? "LZMA" : "XZ"); -+ fprintf(stderr, " dictionary size\n\t\tcan be specified as a"); -+ fprintf(stderr, " percentage of the block size, or as an\n\t\t"); -+ fprintf(stderr, "absolute value. The dictionary size must be less"); -+ fprintf(stderr, " than or equal\n\t\tto the block size and %d bytes", -+ lzmaver == LZMA_OPT_LZMA ? 4096 : 8192); -+ fprintf(stderr, " or larger. It must also be\n\t\tstorable in the lzma"); -+ fprintf(stderr, " header as either 2^n or as 2^n+2^(n+1).\n\t\t"); -+ fprintf(stderr, "Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or"); -+ fprintf(stderr, " 32K, 16K, 8K\n\t\tetc.\n"); -+ -+} ---- a/squashfs-tools/lzma_xz_wrapper.c -+++ b/squashfs-tools/lzma_xz_wrapper.c -@@ -27,6 +27,7 @@ - - #include "squashfs_fs.h" - #include "compressor.h" -+#include "lzma_xz_options.h" - - #define LZMA_PROPS_SIZE 5 - #define LZMA_UNCOMP_SIZE 8 -@@ -38,13 +39,27 @@ - static int lzma_compress(void *dummy, void *dest, void *src, int size, - int block_size, int *error) - { -+ uint32_t preset; - unsigned char *d = (unsigned char *) dest; -+ struct lzma_xz_options *opts = lzma_xz_get_options(); -+ - lzma_options_lzma opt; - lzma_stream strm = LZMA_STREAM_INIT; - int res; - -- lzma_lzma_preset(&opt, LZMA_OPTIONS); -- opt.dict_size = block_size; -+ preset = opts->preset; -+ -+ if (opts->extreme) -+ preset |= LZMA_PRESET_EXTREME; -+ -+ lzma_lzma_preset(&opt, opts->preset); -+ opt.lc = opts->lc; -+ opt.lp = opts->lp; -+ opt.pb = opts->pb; -+ if (opts->fb) -+ opt.nice_len = opts->fb; -+ -+ opt.dict_size = opts->dict_size; - - res = lzma_alone_encoder(&strm, &opt); - if(res != LZMA_OK) { -@@ -143,13 +158,45 @@ failed: - return -1; - } - -+static int lzma_options(char *argv[], int argc) -+{ -+ return lzma_xz_options(argv, argc, LZMA_OPT_LZMA); -+} -+ -+ -+static int lzma_options_post(int block_size) -+{ -+ return lzma_xz_options_post(block_size, LZMA_OPT_LZMA); -+} -+ -+ -+static void *lzma_dump_options(int block_size, int *size) -+{ -+ return lzma_xz_dump_options(block_size, size, 0); -+} -+ -+ -+static int lzma_extract_options(int block_size, void *buffer, int size) -+{ -+ return lzma_xz_extract_options(block_size, buffer, size, LZMA_OPT_LZMA); -+} -+ -+ -+void lzma_usage() -+{ -+ lzma_xz_usage(LZMA_OPT_LZMA); -+} -+ - - struct compressor lzma_comp_ops = { - .init = NULL, - .compress = lzma_compress, - .uncompress = lzma_uncompress, -- .options = NULL, -- .usage = NULL, -+ .options = lzma_options, -+ .options_post = lzma_options_post, -+ .dump_options = lzma_dump_options, -+ .extract_options = lzma_extract_options, -+ .usage = lzma_usage, - .id = LZMA_COMPRESSION, - .name = "lzma", - .supported = 1 ---- a/squashfs-tools/xz_wrapper.h -+++ b/squashfs-tools/xz_wrapper.h -@@ -24,25 +24,6 @@ - * - */ - --#ifndef linux --#define __BYTE_ORDER BYTE_ORDER --#define __BIG_ENDIAN BIG_ENDIAN --#define __LITTLE_ENDIAN LITTLE_ENDIAN --#else --#include --#endif -- --#if __BYTE_ORDER == __BIG_ENDIAN --extern unsigned int inswap_le32(unsigned int); -- --#define SQUASHFS_INSWAP_COMP_OPTS(s) { \ -- (s)->dictionary_size = inswap_le32((s)->dictionary_size); \ -- (s)->flags = inswap_le32((s)->flags); \ --} --#else --#define SQUASHFS_INSWAP_COMP_OPTS(s) --#endif -- - #define MEMLIMIT (32 * 1024 * 1024) - - struct bcj { ---- a/squashfs-tools/xz_wrapper.c -+++ b/squashfs-tools/xz_wrapper.c -@@ -30,6 +30,7 @@ - #include "squashfs_fs.h" - #include "xz_wrapper.h" - #include "compressor.h" -+#include "lzma_xz_options.h" - - static struct bcj bcj[] = { - { "x86", LZMA_FILTER_X86, 0 }, -@@ -41,22 +42,18 @@ static struct bcj bcj[] = { - { NULL, LZMA_VLI_UNKNOWN, 0 } - }; - --static struct comp_opts comp_opts; -- - static int filter_count = 1; --static int dictionary_size = 0; --static float dictionary_percent = 0; - - - static int xz_options(char *argv[], int argc) - { -- int i; -- char *name; -- - if(strcmp(argv[0], "-Xbcj") == 0) { -+ int i; -+ char *name; -+ - if(argc < 2) { - fprintf(stderr, "xz: -Xbcj missing filter\n"); -- goto failed; -+ return -2; - } - - name = argv[1]; -@@ -76,190 +73,50 @@ static int xz_options(char *argv[], int - } - if(bcj[i].name == NULL) { - fprintf(stderr, "xz: -Xbcj unrecognised " -- "filter\n"); -- goto failed; -- } -- } -- -- return 1; -- } else if(strcmp(argv[0], "-Xdict-size") == 0) { -- char *b; -- float size; -- -- if(argc < 2) { -- fprintf(stderr, "xz: -Xdict-size missing dict-size\n"); -- goto failed; -- } -- -- size = strtof(argv[1], &b); -- if(*b == '%') { -- if(size <= 0 || size > 100) { -- fprintf(stderr, "xz: -Xdict-size percentage " -- "should be 0 < dict-size <= 100\n"); -- goto failed; -- } -- -- dictionary_percent = size; -- dictionary_size = 0; -- } else { -- if((float) ((int) size) != size) { -- fprintf(stderr, "xz: -Xdict-size can't be " -- "fractional unless a percentage of the" -- " block size\n"); -- goto failed; -- } -- -- dictionary_percent = 0; -- dictionary_size = (int) size; -- -- if(*b == 'k' || *b == 'K') -- dictionary_size *= 1024; -- else if(*b == 'm' || *b == 'M') -- dictionary_size *= 1024 * 1024; -- else if(*b != '\0') { -- fprintf(stderr, "xz: -Xdict-size invalid " -- "dict-size\n"); -- goto failed; -+ "filter\n"); -+ return -2; - } - } -- - return 1; -+ } else { -+ return lzma_xz_options(argv, argc, LZMA_OPT_XZ); - } -- -- return -1; -- --failed: -- return -2; - } - - - static int xz_options_post(int block_size) - { -- /* -- * if -Xdict-size has been specified use this to compute the datablock -- * dictionary size -- */ -- if(dictionary_size || dictionary_percent) { -- int n; -- -- if(dictionary_size) { -- if(dictionary_size > block_size) { -- fprintf(stderr, "xz: -Xdict-size is larger than" -- " block_size\n"); -- goto failed; -- } -- } else -- dictionary_size = block_size * dictionary_percent / 100; -- -- if(dictionary_size < 8192) { -- fprintf(stderr, "xz: -Xdict-size should be 8192 bytes " -- "or larger\n"); -- goto failed; -- } -- -- /* -- * dictionary_size must be storable in xz header as either -- * 2^n or as 2^n+2^(n+1) -- */ -- n = ffs(dictionary_size) - 1; -- if(dictionary_size != (1 << n) && -- dictionary_size != ((1 << n) + (1 << (n + 1)))) { -- fprintf(stderr, "xz: -Xdict-size is an unsupported " -- "value, dict-size must be storable in xz " -- "header\n"); -- fprintf(stderr, "as either 2^n or as 2^n+2^(n+1). " -- "Example dict-sizes are 75%%, 50%%, 37.5%%, " -- "25%%,\n"); -- fprintf(stderr, "or 32K, 16K, 8K etc.\n"); -- goto failed; -- } -- -- } else -- /* No -Xdict-size specified, use defaults */ -- dictionary_size = block_size; -- -- return 0; -- --failed: -- return -1; -+ return lzma_xz_options_post(block_size, LZMA_OPT_XZ); - } - - - static void *xz_dump_options(int block_size, int *size) - { -- int flags = 0, i; -- -- /* -- * don't store compressor specific options in file system if the -- * default options are being used - no compressor options in the -- * file system means the default options are always assumed -- * -- * Defaults are: -- * metadata dictionary size: SQUASHFS_METADATA_SIZE -- * datablock dictionary size: block_size -- * 1 filter -- */ -- if(dictionary_size == block_size && filter_count == 1) -- return NULL; -+ int i, flags = 0; - - for(i = 0; bcj[i].name; i++) - flags |= bcj[i].selected << i; - -- comp_opts.dictionary_size = dictionary_size; -- comp_opts.flags = flags; -- -- SQUASHFS_INSWAP_COMP_OPTS(&comp_opts); -- -- *size = sizeof(comp_opts); -- return &comp_opts; -+ return lzma_xz_dump_options(block_size, size, flags); - } - - - static int xz_extract_options(int block_size, void *buffer, int size) - { -- struct comp_opts *comp_opts = buffer; -- int flags, i, n; -- -- if(size == 0) { -- /* set defaults */ -- dictionary_size = block_size; -- flags = 0; -- } else { -- /* check passed comp opts struct is of the correct length */ -- if(size != sizeof(struct comp_opts)) -- goto failed; -- -- SQUASHFS_INSWAP_COMP_OPTS(comp_opts); -- -- dictionary_size = comp_opts->dictionary_size; -- flags = comp_opts->flags; -- -- /* -- * check that the dictionary size seems correct - the dictionary -- * size should 2^n or 2^n+2^(n+1) -- */ -- n = ffs(dictionary_size) - 1; -- if(dictionary_size != (1 << n) && -- dictionary_size != ((1 << n) + (1 << (n + 1)))) -- goto failed; -- } -+ int ret = lzma_xz_extract_options(block_size, buffer, size, LZMA_OPT_XZ); - -- filter_count = 1; -- for(i = 0; bcj[i].name; i++) { -- if((flags >> i) & 1) { -- bcj[i].selected = 1; -- filter_count ++; -- } else -- bcj[i].selected = 0; -+ if (!ret) { -+ int i; -+ struct lzma_xz_options *opts = lzma_xz_get_options(); -+ for(i = 0; bcj[i].name; i++) { -+ if((opts->flags >> i) & 1) { -+ bcj[i].selected = 1; -+ filter_count ++; -+ } else -+ bcj[i].selected = 0; -+ } - } -- -- return 0; -- --failed: -- fprintf(stderr, "xz: error reading stored compressor options from " -- "filesystem!\n"); -- -- return -1; -+ return ret; - } - - -@@ -268,6 +125,7 @@ static int xz_init(void **strm, int bloc - int i, j, filters = datablock ? filter_count : 1; - struct filter *filter = malloc(filters * sizeof(struct filter)); - struct xz_stream *stream; -+ struct lzma_xz_options *opts = lzma_xz_get_options(); - - if(filter == NULL) - goto failed; -@@ -281,7 +139,7 @@ static int xz_init(void **strm, int bloc - - memset(filter, 0, filters * sizeof(struct filter)); - -- stream->dictionary_size = datablock ? dictionary_size : -+ stream->dictionary_size = datablock ? opts->dict_size : - SQUASHFS_METADATA_SIZE; - - filter[0].filter[0].id = LZMA_FILTER_LZMA2; -@@ -323,14 +181,25 @@ static int xz_compress(void *strm, void - lzma_ret res = 0; - struct xz_stream *stream = strm; - struct filter *selected = NULL; -+ struct lzma_xz_options *opts = lzma_xz_get_options(); - - stream->filter[0].buffer = dest; - - for(i = 0; i < stream->filters; i++) { -+ uint32_t preset = opts->preset; - struct filter *filter = &stream->filter[i]; - -- if(lzma_lzma_preset(&stream->opt, LZMA_PRESET_DEFAULT)) -- goto failed; -+ if (opts->extreme) -+ preset |= LZMA_PRESET_EXTREME; -+ -+ if(lzma_lzma_preset(&stream->opt, preset)) -+ goto failed; -+ -+ stream->opt.lc = opts->lc; -+ stream->opt.lp = opts->lp; -+ stream->opt.pb = opts->pb; -+ if (opts->fb) -+ stream->opt.nice_len = opts->fb; - - stream->opt.dict_size = stream->dictionary_size; - -@@ -384,22 +253,13 @@ static int xz_uncompress(void *dest, voi - - void xz_usage() - { -+ lzma_xz_usage(LZMA_OPT_XZ); - fprintf(stderr, "\t -Xbcj filter1,filter2,...,filterN\n"); - fprintf(stderr, "\t\tCompress using filter1,filter2,...,filterN in"); - fprintf(stderr, " turn\n\t\t(in addition to no filter), and choose"); - fprintf(stderr, " the best compression.\n"); - fprintf(stderr, "\t\tAvailable filters: x86, arm, armthumb,"); - fprintf(stderr, " powerpc, sparc, ia64\n"); -- fprintf(stderr, "\t -Xdict-size \n"); -- fprintf(stderr, "\t\tUse as the XZ dictionary size. The"); -- fprintf(stderr, " dictionary size\n\t\tcan be specified as a"); -- fprintf(stderr, " percentage of the block size, or as an\n\t\t"); -- fprintf(stderr, "absolute value. The dictionary size must be less"); -- fprintf(stderr, " than or equal\n\t\tto the block size and 8192 bytes"); -- fprintf(stderr, " or larger. It must also be\n\t\tstorable in the xz"); -- fprintf(stderr, " header as either 2^n or as 2^n+2^(n+1).\n\t\t"); -- fprintf(stderr, "Example dict-sizes are 75%%, 50%%, 37.5%%, 25%%, or"); -- fprintf(stderr, " 32K, 16K, 8K\n\t\tetc.\n"); - } - - ---- a/squashfs-tools/Makefile -+++ b/squashfs-tools/Makefile -@@ -140,6 +140,8 @@ COMPRESSORS += xz - endif - - ifneq ($(LZMA_XZ_SUPPORT)$(XZ_SUPPORT),) -+MKSQUASHFS_OBJS += lzma_xz_options.o -+UNSQUASHFS_OBJS += lzma_xz_options.o - ifneq ($(LZMA_LIB),) - MKSQUASHFS_OBJS += $(LZMA_LIB) - UNSQUASHFS_OBJS += $(LZMA_LIB) diff --git a/tools/squashfs4/patches/170-add_support_for_LZMA_MAGIC_to_unsqashfs.patch b/tools/squashfs4/patches/170-add_support_for_LZMA_MAGIC_to_unsqashfs.patch deleted file mode 100644 index bc7d6c7a4a..0000000000 --- a/tools/squashfs4/patches/170-add_support_for_LZMA_MAGIC_to_unsqashfs.patch +++ /dev/null @@ -1,72 +0,0 @@ ---- a/squashfs-tools/squashfs_fs.h -+++ b/squashfs-tools/squashfs_fs.h -@@ -30,6 +30,13 @@ - #define SQUASHFS_MAGIC_SWAP 0x68737173 - #define SQUASHFS_START 0 - -+/* -+ * Squashfs + LZMA -+ */ -+ -+#define SQUASHFS_MAGIC_LZMA 0x71736873 -+#define SQUASHFS_MAGIC_LZMA_SWAP 0x73687371 -+ - /* size of metadata (inode and directory) blocks */ - #define SQUASHFS_METADATA_SIZE 8192 - #define SQUASHFS_METADATA_LOG 13 ---- a/squashfs-tools/unsquashfs.c -+++ b/squashfs-tools/unsquashfs.c -@@ -1464,10 +1464,12 @@ int read_super(char *source) - */ - read_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block), - &sBlk_4); -- swap = sBlk_4.s_magic != SQUASHFS_MAGIC; -+ swap = (sBlk_4.s_magic != SQUASHFS_MAGIC && -+ sBlk_4.s_magic != SQUASHFS_MAGIC_LZMA); - SQUASHFS_INSWAP_SUPER_BLOCK(&sBlk_4); - -- if(sBlk_4.s_magic == SQUASHFS_MAGIC && sBlk_4.s_major == 4 && -+ if((sBlk_4.s_magic == SQUASHFS_MAGIC || -+ sBlk_4.s_magic == SQUASHFS_MAGIC_LZMA) && sBlk_4.s_major == 4 && - sBlk_4.s_minor == 0) { - s_ops.squashfs_opendir = squashfs_opendir_4; - s_ops.read_fragment = read_fragment_4; -@@ -1480,7 +1482,11 @@ int read_super(char *source) - /* - * Check the compression type - */ -- comp = lookup_compressor_id(sBlk.s.compression); -+ if (sBlk_4.s_magic == SQUASHFS_MAGIC_LZMA) -+ comp = lookup_compressor("lzma"); -+ else -+ comp = lookup_compressor_id(sBlk.s.compression); -+ - return TRUE; - } - -@@ -1495,8 +1501,10 @@ int read_super(char *source) - * Check it is a SQUASHFS superblock - */ - swap = 0; -- if(sBlk_3.s_magic != SQUASHFS_MAGIC) { -- if(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP) { -+ if(sBlk_3.s_magic != SQUASHFS_MAGIC && -+ sBlk_3.s_magic != SQUASHFS_MAGIC_LZMA) { -+ if(sBlk_3.s_magic == SQUASHFS_MAGIC_SWAP || -+ sBlk_3.s_magic == SQUASHFS_MAGIC_LZMA_SWAP) { - squashfs_super_block_3 sblk; - ERROR("Reading a different endian SQUASHFS filesystem " - "on %s\n", source); -@@ -1574,7 +1582,11 @@ int read_super(char *source) - /* - * 1.x, 2.x and 3.x filesystems use gzip compression. - */ -- comp = lookup_compressor("gzip"); -+ if (sBlk.s.s_magic == SQUASHFS_MAGIC_LZMA) -+ comp = lookup_compressor("lzma"); -+ else -+ comp = lookup_compressor("gzip"); -+ - return TRUE; - - failed_mount: diff --git a/tools/squashfs4/patches/180-openbsd_compat.patch b/tools/squashfs4/patches/180-openbsd_compat.patch deleted file mode 100644 index 4f7afd89cc..0000000000 --- a/tools/squashfs4/patches/180-openbsd_compat.patch +++ /dev/null @@ -1,24 +0,0 @@ ---- a/squashfs-tools/mksquashfs.c -+++ b/squashfs-tools/mksquashfs.c -@@ -32,6 +32,9 @@ - #include - #include - #include -+#if defined(__OpenBSD__) -+#include -+#endif - #include - #include - #include ---- a/squashfs-tools/unsquashfs.h -+++ b/squashfs-tools/unsquashfs.h -@@ -25,6 +25,9 @@ - #define TRUE 1 - #define FALSE 0 - #include -+#if defined(__OpenBSD__) -+#include -+#endif - #include - #include - #include diff --git a/tools/squashfs4/patches/190-no_nonstatic_inline.patch b/tools/squashfs4/patches/190-no_nonstatic_inline.patch deleted file mode 100644 index 8cab120832..0000000000 --- a/tools/squashfs4/patches/190-no_nonstatic_inline.patch +++ /dev/null @@ -1,36 +0,0 @@ ---- a/squashfs-tools/mksquashfs.c -+++ b/squashfs-tools/mksquashfs.c -@@ -736,13 +736,13 @@ void cache_block_put(struct file_buffer - + (((char *)A) - data_cache))) - - --inline void inc_progress_bar() -+static inline void inc_progress_bar() - { - cur_uncompressed ++; - } - - --inline void update_progress_bar() -+static inline void update_progress_bar() - { - pthread_mutex_lock(&progress_mutex); - pthread_cond_signal(&progress_wait); -@@ -750,7 +750,7 @@ inline void update_progress_bar() - } - - --inline void waitforthread(int i) -+static inline void waitforthread(int i) - { - TRACE("Waiting for thread %d\n", i); - while(thread[i] != 0) -@@ -3359,7 +3359,7 @@ struct inode_info *lookup_inode(struct s - } - - --inline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, -+static inline void add_dir_entry(char *name, char *pathname, struct dir_info *sub_dir, - struct inode_info *inode_info, struct dir_info *dir) - { - if((dir->count % DIR_ENTRIES) == 0) { diff --git a/tools/squashfs4/patches/200-add-fixed-timestamp-option.patch b/tools/squashfs4/patches/200-add-fixed-timestamp-option.patch deleted file mode 100644 index 7411b97844..0000000000 --- a/tools/squashfs4/patches/200-add-fixed-timestamp-option.patch +++ /dev/null @@ -1,82 +0,0 @@ ---- a/squashfs-tools/mksquashfs.c -+++ b/squashfs-tools/mksquashfs.c -@@ -176,6 +176,9 @@ unsigned int cache_bytes = 0, cache_size - /* inode lookup table */ - squashfs_inode *inode_lookup_table = NULL; - -+/* override all timestamps */ -+time_t fixed_time = -1; -+ - /* in memory directory data */ - #define I_COUNT_SIZE 128 - #define DIR_ENTRIES 32 -@@ -2453,6 +2456,8 @@ again: - restat: - fstat(file, &buf2); - close(file); -+ if (fixed_time != -1) -+ buf2.st_mtime = fixed_time; - if(read_size != buf2.st_size) { - memcpy(buf, &buf2, sizeof(struct stat)); - file_buffer->error = 2; -@@ -3613,7 +3618,7 @@ void dir_scan(squashfs_inode *inode, cha - buf.st_mode = S_IRWXU | S_IRWXG | S_IRWXO | S_IFDIR; - buf.st_uid = getuid(); - buf.st_gid = getgid(); -- buf.st_mtime = time(NULL); -+ buf.st_mtime = fixed_time != -1 ? fixed_time : time(NULL); - buf.st_dev = 0; - buf.st_ino = 0; - dir_ent->inode = lookup_inode(&buf); -@@ -3624,6 +3629,8 @@ void dir_scan(squashfs_inode *inode, cha - pathname, strerror(errno)); - return; - } -+ if(fixed_time != -1) -+ buf.st_mtime = fixed_time; - dir_ent->inode = lookup_inode(&buf); - } - -@@ -3678,6 +3685,8 @@ struct dir_info *dir_scan1(char *pathnam - filename, strerror(errno)); - continue; - } -+ if(fixed_time != -1) -+ buf.st_mtime = fixed_time; - - if((buf.st_mode & S_IFMT) != S_IFREG && - (buf.st_mode & S_IFMT) != S_IFDIR && -@@ -3796,7 +3805,7 @@ struct dir_info *dir_scan2(struct dir_in - buf.st_gid = pseudo_ent->dev->gid; - buf.st_rdev = makedev(pseudo_ent->dev->major, - pseudo_ent->dev->minor); -- buf.st_mtime = time(NULL); -+ buf.st_mtime = fixed_time != -1 ? fixed_time : time(NULL); - buf.st_ino = pseudo_ino ++; - - if(pseudo_ent->dev->type == 'f') { -@@ -4675,6 +4684,15 @@ int main(int argc, char *argv[]) - progress = FALSE; - else if(strcmp(argv[i], "-no-exports") == 0) - exportable = FALSE; -+ else if(strcmp(argv[i], "-fixed-time") == 0) { -+ if((++i == argc) || (fixed_time = -+ strtoll(argv[i], &b, 10), *b != '\0')) { -+ ERROR("%s: -fixed-time missing or invalid " -+ "timestamp\n", argv[0]); -+ -+ exit(1); -+ } -+ } - else if(strcmp(argv[i], "-processors") == 0) { - if((++i == argc) || (processors = - strtol(argv[i], &b, 10), *b != '\0')) { -@@ -5315,7 +5333,7 @@ printOptions: - sBlk.flags = SQUASHFS_MKFLAGS(noI, noD, noF, noX, no_fragments, - always_use_fragments, duplicate_checking, exportable, - no_xattrs, comp_opts); -- sBlk.mkfs_time = time(NULL); -+ sBlk.mkfs_time = fixed_time != -1 ? fixed_time : time(NULL); - - restore_filesystem: - if(progress && estimated_uncompressed) { diff --git a/tools/tar/Makefile b/tools/tar/Makefile index baa431e2db..d69ee40f01 100644 --- a/tools/tar/Makefile +++ b/tools/tar/Makefile @@ -8,13 +8,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=tar PKG_CPE_ID:=cpe:/a:gnu:tar -PKG_VERSION:=1.30 +PKG_VERSION:=1.32 -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2 +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=@GNU/tar -PKG_HASH:=87592b86cb037c554375f5868bdd3cc57748aef38d6cb741c81065f0beac63b7 +PKG_HASH:=d0d3ae07f103323be809bc3eac0dcc386d52c5262499fe05511ac4788af1fdd8 -HOST_BUILD_PARALLEL := 1 +HOST_BUILD_PARALLEL:=1 include $(INCLUDE_DIR)/host-build.mk diff --git a/tools/tar/patches/100-symlink-force-root-name.patch b/tools/tar/patches/100-symlink-force-root-name.patch index 93f889761b..8a8ebc0c4c 100644 --- a/tools/tar/patches/100-symlink-force-root-name.patch +++ b/tools/tar/patches/100-symlink-force-root-name.patch @@ -5,7 +5,7 @@ Signed-off-by: Felix Fietkau --- --- a/src/create.c +++ b/src/create.c -@@ -544,17 +544,8 @@ write_gnu_long_link (struct tar_stat_inf +@@ -543,17 +543,8 @@ write_gnu_long_link (struct tar_stat_inf union block *header; header = start_private_header ("././@LongLink", size, 0); diff --git a/tools/tar/patches/110-symlink-force-permissions.patch b/tools/tar/patches/110-symlink-force-permissions.patch index 6fb799bc0a..e9a32f7d13 100644 --- a/tools/tar/patches/110-symlink-force-permissions.patch +++ b/tools/tar/patches/110-symlink-force-permissions.patch @@ -1,6 +1,6 @@ --- a/src/create.c +++ b/src/create.c -@@ -1853,6 +1853,7 @@ dump_file0 (struct tar_stat_info *st, ch +@@ -1852,6 +1852,7 @@ dump_file0 (struct tar_stat_info *st, ch #ifdef HAVE_READLINK else if (S_ISLNK (st->stat.st_mode)) { diff --git a/tools/upslug2/Makefile b/tools/upslug2/Makefile index 42448b0185..f270c9fbe9 100644 --- a/tools/upslug2/Makefile +++ b/tools/upslug2/Makefile @@ -7,28 +7,17 @@ include $(TOPDIR)/rules.mk PKG_NAME:=upslug2 -PKG_VERSION:=20071227 -PKG_SOURCE_URL:=http://svn.nslu2-linux.org/svnroot/upslug2/trunk -PKG_SOURCE_PROTO:=svn -PKG_SOURCE_SUBDIR:=upslug2-$(PKG_VERSION) -PKG_SOURCE_VERSION:=41 -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz -PKG_MIRROR_HASH:=5c69eae3a2affef8f4f7194cfedfdb9175b04ca433f9ae046c85309b42bdb21e +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/fretb/upslug2 +PKG_SOURCE_DATE:=2016-05-16 +PKG_SOURCE_VERSION:=35f0b18c56368f69eef590e7d9fb688fbe624b10 +PKG_MIRROR_HASH:=646856532e5fad240b1697eb94726aafa6712294f608e24892983e6db95fb65f + +HOST_FIXUP:=autoreconf include $(INCLUDE_DIR)/host-build.mk -unexport CFLAGS - -define Host/Configure - (cd $(HOST_BUILD_DIR); \ - aclocal && autoconf && \ - autoheader && \ - automake --add-missing; \ - ) - $(Host/Configure/Default) -endef - ifneq ($(HOST_OS),Linux) HOST_CONFIGURE_ARGS += --with-libpcap endif diff --git a/tools/upslug2/patches/110-wrt350nv2_support.patch b/tools/upslug2/patches/110-wrt350nv2_support.patch deleted file mode 100644 index eea7cc4d00..0000000000 --- a/tools/upslug2/patches/110-wrt350nv2_support.patch +++ /dev/null @@ -1,279 +0,0 @@ ---- a/nslu2_image.cc -+++ b/nslu2_image.cc -@@ -54,28 +54,44 @@ namespace NSLU2Image { - int &address, int &length) { - address = image.tellg(); - length = buffer_length; -- if (address+length > NSLU2Protocol::FlashSize) -- length = NSLU2Protocol::FlashSize-address; -+ if (address+length > EndAddress) -+ length = EndAddress-address; - if (length > 0) - SafeRead(&image, buffer, length, "image (read)"); - } - -+ virtual void GetBoundaries(int &start, int &end) -+ { -+ start = BaseAddress; -+ end = EndAddress; -+ } -+ - /* Rewind to the start of the image (or the Kernel if not - * doing a complete reprogram). - */ - virtual void Rewind(void) { -- SafeSeek(&image, reprogram ? 0 : NSLU2Protocol::BaseAddress, -+ SafeSeek(&image, reprogram ? 0 : BaseAddress, - "image (seek)"); - } - - private: -+ int BaseAddress; -+ int EndAddress; -+ - /* Validate that this really is an image file. */ - void Validate(const char *i) { - char signature[8]; - - SafeSeek(&image, -8, i, std::ios::end); - SafeRead(&image, signature, 8, i); -- if (memcmp(signature, "eRcOmM", 6) != 0) -+ -+ if (memcmp(signature, "eRcOmM", 6) == 0) { -+ BaseAddress = NSLU2Protocol::BaseAddress; -+ EndAddress = NSLU2Protocol::FlashSize; -+ } else if (memcmp(signature + 1, "sErCoMm", 7) == 0) { -+ BaseAddress = 0; -+ EndAddress = NSLU2Protocol::FlashSize - 0x40000; -+ } else - throw NSLU2Image::FileError(DataError, i, 0); - } - -@@ -93,6 +109,12 @@ namespace NSLU2Image { - virtual ~SynthesiseImage() { - } - -+ void GetBoundaries(int &start, int &end) -+ { -+ start = NSLU2Protocol::BaseAddress; -+ end = NSLU2Protocol::FlashSize; -+ } -+ - /* Get the next block of bytes, returns an address and length, false if - * there is a problem. - */ ---- a/nslu2_image.h -+++ b/nslu2_image.h -@@ -35,6 +35,8 @@ namespace NSLU2Image { - virtual ~Image() { - } - -+ virtual void GetBoundaries(int &start, int &end) = 0; -+ - /* Get the next block of bytes, returns an address and length. - */ - virtual void GetBytes(char *buffer, size_t buffer_length, ---- a/nslu2_upgrade.cc -+++ b/nslu2_upgrade.cc -@@ -95,7 +95,7 @@ namespace NSLU2Upgrade { - - class RealDoUpgrade : public DoUpgrade { - public: -- RealDoUpgrade(Wire *w, Progress *p, bool r) : -+ RealDoUpgrade(Wire *w, Progress *p, bool r, int start, int end) : - wire(w), progress(p), sequenceError(-1), reprogram(r), - lastType(NSLU2Protocol::InvalidType) { - if (reprogram) { -@@ -105,6 +105,8 @@ namespace NSLU2Upgrade { - NSLU2Protocol::UpgradeStartPacket packet(seq); - wire->Send(packet.PacketBuffer(), packet.PacketLength()); - } -+ BaseAddress = start; -+ EndAddress = end; - } - - virtual ~RealDoUpgrade() { -@@ -205,8 +207,8 @@ namespace NSLU2Upgrade { - - }; - -- DoUpgrade *DoUpgrade::MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram) { -- return new RealDoUpgrade(wire, progress, reprogram); -+ DoUpgrade *DoUpgrade::MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram, int start, int end) { -+ return new RealDoUpgrade(wire, progress, reprogram, start, end); - } - }; - -@@ -421,13 +423,18 @@ void NSLU2Upgrade::RealDoUpgrade::Upgrad - /* Simple upgrade programs only the addresses beyound BaseAddress, - * reprogram overwrites the whole flash. - */ -- if (!reprogram && address < NSLU2Protocol::BaseAddress) { -+ if (!reprogram && address < BaseAddress) { - length += address; -- if (length <= NSLU2Protocol::BaseAddress) -+ if (length <= BaseAddress) - return; /* nothing to do. */ -- address = NSLU2Protocol::BaseAddress; -+ address = BaseAddress; - length -= address; - } -+ if (!reprogram && address + length > EndAddress) { -+ if (address >= EndAddress) -+ return; /* nothing to do. */ -+ length -= EndAddress - address; -+ } - - #if 1 - /* Skip blocks of 255 valued bytes - the erase clears the flash to this -@@ -495,11 +502,11 @@ void NSLU2Upgrade::RealDoUpgrade::Verify - Finish(); - - /* Verify never verifies anything below BaseAddress. */ -- if (address < NSLU2Protocol::BaseAddress) { -+ if (address < BaseAddress) { - length += address; -- if (length <= NSLU2Protocol::BaseAddress) -+ if (length <= BaseAddress) - return; /* nothing to do. */ -- address = NSLU2Protocol::BaseAddress; -+ address = BaseAddress; - length -= address; - } - ---- a/nslu2_upgrade.h -+++ b/nslu2_upgrade.h -@@ -206,6 +206,8 @@ namespace NSLU2Upgrade { - - class DoUpgrade { - public: -+ int BaseAddress; -+ int EndAddress; - virtual ~DoUpgrade() { - } - -@@ -228,7 +230,7 @@ namespace NSLU2Upgrade { - virtual void Reboot(void) = 0; - /* Reboot the NSLU2. */ - -- static DoUpgrade *MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram); -+ static DoUpgrade *MakeDoUpgrade(Wire *wire, Progress *progress, bool reprogram, int start, int end); - /* Instantiate a real DoUpgrade, returns NULL if the object - * cannot be instantiated. - * ---- a/upslug2.cc -+++ b/upslug2.cc -@@ -21,8 +21,8 @@ - - class ProgressBar : public UpSlug2::CharacterProgressBar<80> { - public: -- ProgressBar(bool reprogram, const unsigned char *t) : -- UpSlug2::CharacterProgressBar<80>(reprogram, 64), -+ ProgressBar(bool reprogram, const unsigned char *t, int start, int end) : -+ UpSlug2::CharacterProgressBar<80>(reprogram, 64, start, end), - target(t), displayed(false), ticker(0) { - } - -@@ -95,7 +95,7 @@ private: - else if (seen == -1) { - seen = 0; - if (!reprogram) -- sent -= NSLU2Protocol::BaseAddress; -+ sent -= NSLU2Protocol::FlashSize - (EndAddress - BaseAddress); - } else - sent -= seen; - -@@ -423,7 +423,7 @@ int main(int argc, char **argv) { - { 0, 0, 0, 0 } - }; - -- do switch (getopt_long(argc, argv, "he:d:t:f:vUni:Ck:r:R:j:p:P:T:F:E:", options, 0)) { -+ do switch (getopt_long(argc, argv, "he:d:t:f:vUni:Ck:r:R:j:op:P:T:F:E:", options, 0)) { - case -1: if (optind < argc) { - std::fprintf(stderr, "%s: unrecognised option\n", argv[optind]); - std::exit(1); -@@ -523,16 +523,22 @@ done: - - if (mac && got_kernel) { - Pointer wire(NSLU2Upgrade::Wire::MakeWire(device, fromMac, mac, euid)); -- ProgressBar progress(reprogram, mac); -+ int BaseAddress = NSLU2Protocol::BaseAddress; -+ int EndAddress = NSLU2Protocol::FlashSize; - - if (full_image) { /* complete image. */ - /* The full image case allows a complete reprogram. */ -+ NSLU2Image::Image *image_p; - Pointer image( - NSLU2Image::Image::MakeImage( - reprogram, full_image)); -+ image_p = image.p; -+ image_p->GetBoundaries(BaseAddress, EndAddress); -+ ProgressBar progress(reprogram, mac, BaseAddress, EndAddress); - Pointer upgrade( - NSLU2Upgrade::DoUpgrade::MakeDoUpgrade( -- wire.p, &progress, reprogram)); -+ wire.p, &progress, reprogram, -+ BaseAddress, EndAddress)); - progress.FirstDisplay(); - Upgrade(upgrade.p, image.p, no_upgrade, no_verify); - progress.EndDisplay(); -@@ -551,9 +557,11 @@ done: - fis_payload, - product_id, protocol_id, - firmware_version, extra_version)); -+ ProgressBar progress(reprogram, mac, BaseAddress, EndAddress); - Pointer upgrade( - NSLU2Upgrade::DoUpgrade::MakeDoUpgrade( -- wire.p, &progress, false)); -+ wire.p, &progress, false, -+ BaseAddress, EndAddress)); - progress.FirstDisplay(); - Upgrade(upgrade.p, image.p, no_upgrade, no_verify); - progress.EndDisplay(); ---- a/upslug2_progress.h -+++ b/upslug2_progress.h -@@ -161,15 +161,19 @@ namespace UpSlug2 { - Timedout, /* *: timeout on a sent packet for this address. */ - NumberOfStates - } Status; -- -+ int BaseAddress; -+ int EndAddress; -+ - /* reprogram says whether this is a full reprogram (the entire - * flash will be erased) or not (the leading, RedBoot, SysConf - * partitions are not erased). - * resolution should be about 6 for a command line (character) - * progress bar and 8 for a GUI (pixel) progress bar. - */ -- ProgressBar(bool r) : -+ ProgressBar(bool r, int start, int end) : - reprogram(r), timeout(false), retransmit(false), status(Init) { -+ BaseAddress = start; -+ EndAddress = end; - } - - /* lowWaterMark..(highWaterMark-1) bytes are in state 'st', -@@ -179,8 +183,8 @@ namespace UpSlug2 { - /* These initial settings cover the majority of cases - * correctly. - */ -- lowWaterMark = reprogram ? 0 : NSLU2Protocol::BaseAddress; -- highWaterMark = status >= st ? NSLU2Protocol::FlashSize-1 : 0; -+ lowWaterMark = reprogram ? 0 : BaseAddress; -+ highWaterMark = status >= st ? EndAddress-1 : 0; - switch (st) { - case Init: - /* Everything has an initial value... */ -@@ -286,9 +290,9 @@ namespace UpSlug2 { - */ - template class CharacterProgressBar : public ProgressBar { - public: -- CharacterProgressBar(bool reprogram, int n, const char ind[NumberOfStates] = 0) : -+ CharacterProgressBar(bool reprogram, int n, int start, int end, const char ind[NumberOfStates] = 0) : - numberOfCharacters(n > characters || n < 1 ? characters : n), -- ProgressBar(reprogram) { -+ ProgressBar(reprogram, start, end) { - if (ind) - std::memcpy(indicators, ind, NumberOfStates); - else diff --git a/tools/xz/Makefile b/tools/xz/Makefile index 5d574892bb..21029a74aa 100644 --- a/tools/xz/Makefile +++ b/tools/xz/Makefile @@ -1,4 +1,4 @@ -# +# # Copyright (C) 2006-2015 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. @@ -25,7 +25,8 @@ HOSTCXX := $(HOSTCXX_NOCACHE) HOST_CONFIGURE_ARGS += \ --enable-static=yes \ --enable-shared=no \ - --disable-doc + --disable-doc \ + --with-pic define Host/Install +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) install xzlinks="unxz xzcat" diff --git a/tools/zip/Makefile b/tools/zip/Makefile new file mode 100644 index 0000000000..7dd81a1b8b --- /dev/null +++ b/tools/zip/Makefile @@ -0,0 +1,36 @@ +# +# Copyright (C) 2007-2016 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=zip +PKG_REV:=30 +PKG_VERSION:=3.0 + +PKG_SOURCE:=$(PKG_NAME)$(PKG_REV).tar.gz +PKG_SOURCE_URL:=@SF/infozip +PKG_HASH:=f0e8bb1f9b7eb0b01285495a2699df3a4b766784c1765a8f1aeedf63c0806369 + +PKG_LICENSE:=BSD-4-Clause +PKG_LICENSE_FILES:=LICENSE + +HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-$(PKG_VERSION)/zip$(PKG_REV) +HOST_BUILD_PARALLEL:=1 + +include $(INCLUDE_DIR)/host-build.mk + +define Host/Compile + +$(HOST_MAKE_VARS) $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) -I. -f unix/Makefile zip +endef + +define Host/Install + $(INSTALL_DIR) $(STAGING_DIR_HOST)/bin/ + $(INSTALL_BIN) $(HOST_BUILD_DIR)/zip $(STAGING_DIR_HOST)/bin/ +endef + +$(eval $(call HostBuild)) +#$(eval $(call BuildPackage,zip)) diff --git a/tools/zip/patches/001-unix-configure-borrow-the-LFS-test-from-autotools.patch b/tools/zip/patches/001-unix-configure-borrow-the-LFS-test-from-autotools.patch new file mode 100644 index 0000000000..ef0de6fd9b --- /dev/null +++ b/tools/zip/patches/001-unix-configure-borrow-the-LFS-test-from-autotools.patch @@ -0,0 +1,89 @@ +From fc392c939b9a18959482f588aff0afc29dd6d30a Mon Sep 17 00:00:00 2001 +From: Romain Naour +Date: Fri, 23 Jan 2015 22:20:18 +0100 +Subject: [PATCH 6/6] unix/configure: borrow the LFS test from autotools. + +Infozip's LFS check can't work for cross-compilation +since it try to run a target's binary on the host system. + +Instead, use to LFS test used by autotools which is a +compilation test. +(see autotools/lib/autoconf/specific.m4) + +Reported-by: Richard Genoud +Signed-off-by: Romain Naour +--- + configure | 46 +++++++++++++++------------------------------- + 1 file changed, 15 insertions(+), 31 deletions(-) + +--- a/unix/configure ++++ b/unix/configure +@@ -399,9 +399,8 @@ else + fi + + +-# Now we set the 64-bit file environment and check the size of off_t +-# Added 11/4/2003 EG +-# Revised 8/12/2004 EG ++# LFS check borrowed from autotools sources ++# lib/autoconf/specific.m4 + + echo Check for Large File Support + cat > conftest.c << _EOF_ +@@ -410,23 +409,19 @@ cat > conftest.c << _EOF_ + # define _FILE_OFFSET_BITS 64 /* select default interface as 64 bit */ + # define _LARGE_FILES /* some OSes need this for 64-bit off_t */ + #include +-#include +-#include +-#include ++ ++ /* Check that off_t can represent 2**63 - 1 correctly. ++ We can't simply define LARGE_OFF_T to be 9223372036854775807, ++ since some C++ compilers masquerading as C compilers ++ incorrectly reject 9223372036854775807. */ ++#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62)) ++ int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 ++ && LARGE_OFF_T % 2147483647 == 1) ++ ? 1 : -1]; ++ + int main() + { +- off_t offset; +- struct stat s; +- /* see if have 64-bit off_t */ +- if (sizeof(offset) < 8) +- return 1; +- printf(" off_t is %d bytes\n", sizeof(off_t)); +- /* see if have 64-bit stat */ +- if (sizeof(s.st_size) < 8) { +- printf(" s.st_size is %d bytes\n", sizeof(s.st_size)); +- return 2; +- } +- return 3; ++ return 0; + } + _EOF_ + # compile it +@@ -434,19 +429,8 @@ $CC -o conftest conftest.c >/dev/null 2> + if [ $? -ne 0 ]; then + echo -- no Large File Support + else +-# run it +- ./conftest +- r=$? +- if [ $r -eq 1 ]; then +- echo -- no Large File Support - no 64-bit off_t +- elif [ $r -eq 2 ]; then +- echo -- no Large File Support - no 64-bit stat +- elif [ $r -eq 3 ]; then +- echo -- yes we have Large File Support! +- CFLAGS="${CFLAGS} -DLARGE_FILE_SUPPORT" +- else +- echo -- no Large File Support - conftest returned $r +- fi ++ echo -- yes we have Large File Support! ++ CFLAGS="${CFLAGS} -DLARGE_FILE_SUPPORT" + fi + + diff --git a/tools/zip/patches/004-do-not-set-unwanted-cflags.patch b/tools/zip/patches/004-do-not-set-unwanted-cflags.patch new file mode 100644 index 0000000000..bfd226077a --- /dev/null +++ b/tools/zip/patches/004-do-not-set-unwanted-cflags.patch @@ -0,0 +1,15 @@ +From: Santiago Vila +Subject: Do not set unwanted CFLAGS, as it breaks DEB_BUILD_OPTIONS +X-Debian-version: 2.32-1 + +--- a/unix/configure ++++ b/unix/configure +@@ -98,7 +98,7 @@ int main() + _EOF_ + $CC $CFLAGS -c conftest.c > /dev/null 2>/dev/null + if test $? -eq 0; then +- CFLAGS_OPT='-O3' ++ # CFLAGS_OPT='-O3' + echo " GNU C ($CFLAGS_OPT)" + # Special Mac OS X shared library "ld" option? + if test ` uname -s 2> /dev/null ` = 'Darwin'; then diff --git a/tools/zip/patches/006-stack-markings-to-avoid-executable-stack.patch b/tools/zip/patches/006-stack-markings-to-avoid-executable-stack.patch new file mode 100644 index 0000000000..8b479faeda --- /dev/null +++ b/tools/zip/patches/006-stack-markings-to-avoid-executable-stack.patch @@ -0,0 +1,21 @@ +From: Kees Cook +Subject: put stack markings in i386 assembly to avoid executable stack +Bug-Debian: http://bugs.debian.org/528280 +X-Debian-version: 3.0-2 + +--- a/crc_i386.S ++++ b/crc_i386.S +@@ -302,3 +302,5 @@ _crc32: /* ulg c + #endif /* i386 || _i386 || _I386 || __i386 */ + + #endif /* !USE_ZLIB && !CRC_TABLE_ONLY */ ++.section .note.GNU-stack, "", @progbits ++.previous +--- a/match.S ++++ b/match.S +@@ -405,3 +405,5 @@ L__return: + #endif /* i386 || _I386 || _i386 || __i386 */ + + #endif /* !USE_ZLIB */ ++.section .note.GNU-stack, "", @progbits ++.previous diff --git a/tools/zip/patches/007-fclose-in-file-not-fclose-x.patch b/tools/zip/patches/007-fclose-in-file-not-fclose-x.patch new file mode 100644 index 0000000000..402f90a2d5 --- /dev/null +++ b/tools/zip/patches/007-fclose-in-file-not-fclose-x.patch @@ -0,0 +1,16 @@ +From: Christian Spieler +Subject: zipnote.c: Close in_file instead of undefined file x +Bug-Debian: http://bugs.debian.org/628594 +X-Debian-version: 3.0-4 + +--- a/zipnote.c ++++ b/zipnote.c +@@ -661,7 +661,7 @@ char **argv; /* command line + if ((r = zipcopy(z)) != ZE_OK) + ziperr(r, "was copying an entry"); + } +- fclose(x); ++ fclose(in_file); + + /* Write central directory and end of central directory with new comments */ + if ((c = zftello(y)) == (zoff_t)-1) /* get start of central */ diff --git a/tools/zip/patches/008-hardening-build-fix-1.patch b/tools/zip/patches/008-hardening-build-fix-1.patch new file mode 100644 index 0000000000..a0c3a91eee --- /dev/null +++ b/tools/zip/patches/008-hardening-build-fix-1.patch @@ -0,0 +1,25 @@ +From: Santiago Vila +Subject: Use format specifier %s to print strings, not the string itself +Bug-Debian: http://bugs.debian.org/673476 +X-Debian-version: 3.0-5 + +--- a/zip.c ++++ b/zip.c +@@ -1028,7 +1028,7 @@ local void help_extended() + + for (i = 0; i < sizeof(text)/sizeof(char *); i++) + { +- printf(text[i]); ++ printf("%s", text[i]); + putchar('\n'); + } + #ifdef DOS +@@ -1225,7 +1225,7 @@ local void version_info() + CR_MAJORVER, CR_MINORVER, CR_BETA_VER, CR_VERSION_DATE); + for (i = 0; i < sizeof(cryptnote)/sizeof(char *); i++) + { +- printf(cryptnote[i]); ++ printf("%s", cryptnote[i]); + putchar('\n'); + } + ++i; /* crypt support means there IS at least one compilation option */ diff --git a/tools/zip/patches/009-hardening-build-fix-2.patch b/tools/zip/patches/009-hardening-build-fix-2.patch new file mode 100644 index 0000000000..e295ffbc64 --- /dev/null +++ b/tools/zip/patches/009-hardening-build-fix-2.patch @@ -0,0 +1,16 @@ +From: Santiago Vila +Subject: unix/configure: Take linking flags from the environment +Bug-Debian: http://bugs.debian.org/673476 +X-Debian-version: 3.0-5 + +--- a/unix/configure ++++ b/unix/configure +@@ -18,7 +18,7 @@ trap "rm -f conftest* core a.out; exit 1 + + CC=${1-cc} + CFLAGS=${2-"-I. -DUNIX"} +-LFLAGS1='' ++LFLAGS1=${LDFLAGS} + LFLAGS2='' + LN="ln -s" + diff --git a/tools/zip/patches/010-remove-build-date.patch b/tools/zip/patches/010-remove-build-date.patch new file mode 100644 index 0000000000..5fc385228a --- /dev/null +++ b/tools/zip/patches/010-remove-build-date.patch @@ -0,0 +1,15 @@ +From: Santiago Vila +Subject: Remove (optional) build date to make the build reproducible +Bug-Debian: http://bugs.debian.org/779042 + +--- a/unix/unix.c ++++ b/unix/unix.c +@@ -1020,7 +1020,7 @@ void version_local() + + + /* Define the compile date string */ +-#ifdef __DATE__ ++#if 0 + # define COMPILE_DATE " on " __DATE__ + #else + # define COMPILE_DATE "" diff --git a/tools/zip/patches/011-add-option-for-reproducible-archives.patch b/tools/zip/patches/011-add-option-for-reproducible-archives.patch new file mode 100644 index 0000000000..45b9d67e15 --- /dev/null +++ b/tools/zip/patches/011-add-option-for-reproducible-archives.patch @@ -0,0 +1,145 @@ +From 6d659fc87451c02c8777dc33f750b16834e4c715 Mon Sep 17 00:00:00 2001 +From: Mathias Kresin +Date: Sat, 12 Jan 2019 19:33:33 +0100 +Subject: [PATCH] add option for reproducible archives + +Add the option -mt/--mtime to pass a timestamp which is used as filedate +for the containing files. + +So far, it isn't used for anything written to the extra fields, +therefore requires the -X (eXclude eXtra file attributes) parameter to +be effective. + +Signed-off-by: Mathias Kresin +--- + globals.c | 1 + + util.c | 22 ++++++++++++++++++++++ + zip.c | 6 ++++++ + zip.h | 1 + + zipup.c | 4 +++- + 5 files changed, 33 insertions(+), 1 deletion(-) + +--- a/globals.c ++++ b/globals.c +@@ -205,6 +205,7 @@ uzoff_t bytes_this_split = 0; /* byt + int read_split_archive = 0; /* 1=scanzipf_reg detected spanning signature */ + int split_method = 0; /* 0=no splits, 1=seekable, 2=data desc, -1=no */ + uzoff_t split_size = 0; /* how big each split should be */ ++time_t timestamp = -1; /* fixed timestamp for archive content filedate */ + int split_bell = 0; /* when pause for next split ring bell */ + uzoff_t bytes_prev_splits = 0; /* total bytes written to all splits before this */ + uzoff_t bytes_this_entry = 0; /* bytes written for this entry across all splits */ +--- a/util.c ++++ b/util.c +@@ -1217,6 +1217,7 @@ int DisplayNumString(file, i) + return 0; + } + ++ + /* Read numbers with trailing size multiplier (like 10M) and return number. + 10/30/04 EG */ + +@@ -1279,6 +1280,29 @@ uzoff_t ReadNumString( numstring ) + } + + ++uzoff_t ReadNumStringUL( numstring ) ++ char *numstring; ++{ ++ zoff_t num = 0; ++ ++ /* check if valid number (currently no negatives) */ ++ if (numstring == NULL) { ++ zipwarn("Unable to read empty number in ReadNumString", ""); ++ return (uzoff_t)-1; ++ } ++ if (numstring[0] < '0' || numstring[0] > '9') { ++ zipwarn("Unable to read number (must start with digit): ", numstring); ++ return (uzoff_t)-1; ++ } ++ if (strlen(numstring) > 10) { ++ zipwarn("Number too long to read (10 characters max): ", numstring); ++ return (uzoff_t)-1; ++ } ++ ++ return (uzoff_t)atoll(numstring); ++} ++ ++ + /* Write the number as a string with a multiplier (like 10M) to outstring. + Always writes no more than 3 digits followed maybe by a multiplier and + returns the characters written or -1 if error. +--- a/zip.c ++++ b/zip.c +@@ -1942,6 +1942,7 @@ int set_filetype(out_path) + #ifdef UNICODE_TEST + #define o_sC 0x146 + #endif ++#define o_mt 0x255 + + + /* the below is mainly from the old main command line +@@ -2036,6 +2037,7 @@ struct option_struct far options[] = { + {"m", "move", o_NO_VALUE, o_NOT_NEGATABLE, 'm', "add files to archive then delete files"}, + {"mm", "", o_NO_VALUE, o_NOT_NEGATABLE, o_mm, "not used"}, + {"MM", "must-match", o_NO_VALUE, o_NOT_NEGATABLE, o_MM, "error if in file not matched/not readable"}, ++ {"mt", "mtime", o_REQUIRED_VALUE, o_NOT_NEGATABLE, o_mt, "use fixed timestamp for archive content filedate"}, + {"n", "suffixes", o_REQUIRED_VALUE, o_NOT_NEGATABLE, 'n', "suffixes to not compress: .gz:.zip"}, + {"nw", "no-wild", o_NO_VALUE, o_NOT_NEGATABLE, o_nw, "no wildcards during add or update"}, + #if defined(AMIGA) || defined(MACOS) +@@ -2440,6 +2442,7 @@ char **argv; /* command line + split_method = 0; /* 0=no splits, 1=update LHs, 2=data descriptors */ + split_size = 0; /* how big each split should be */ + split_bell = 0; /* when pause for next split ring bell */ ++ timestamp = -1; /* fixed timestamp for archive content filedate */ + bytes_prev_splits = 0; /* total bytes written to all splits before this */ + bytes_this_entry = 0; /* bytes written for this entry across all splits */ + noisy_splits = 0; /* be verbose about creating splits */ +@@ -2897,6 +2900,9 @@ char **argv; /* command line + dispose = 1; break; + case o_MM: /* Exit with error if input file can't be read */ + bad_open_is_error = 1; break; ++ case o_mt: /* fixed timestamp for archive content filedate */ ++ timestamp = ReadNumStringUL(value); ++ break; + case 'n': /* Don't compress files with a special suffix */ + special = value; + /* special = NULL; */ /* will be set at next argument */ +--- a/zip.h ++++ b/zip.h +@@ -502,6 +502,7 @@ extern uzoff_t bytes_this_split; /* byte + extern int read_split_archive; /* 1=scanzipf_reg detected spanning signature */ + extern int split_method; /* 0=no splits, 1=seekable, 2=data descs, -1=no */ + extern uzoff_t split_size; /* how big each split should be */ ++extern time_t timestamp; /* fixed timestamp for archive content filedate */ + extern int split_bell; /* when pause for next split ring bell */ + extern uzoff_t bytes_prev_splits; /* total bytes written to all splits before this */ + extern uzoff_t bytes_this_entry; /* bytes written for this entry across all splits */ +@@ -789,6 +790,7 @@ char *zip_fzofft OF((zoff_t, char + int DisplayNumString OF ((FILE *file, uzoff_t i)); + int WriteNumString OF((uzoff_t num, char *outstring)); + uzoff_t ReadNumString OF((char *numstring)); ++uzoff_t ReadNumStringUL OF((char *numstring)); + + /* returns true if abbrev is abbreviation for string */ + int abbrevmatch OF((char *, char *, int, int)); +--- a/zipup.c ++++ b/zipup.c +@@ -415,7 +415,6 @@ struct zlist far *z; /* zip entry to + char *tempextra = NULL; + char *tempcextra = NULL; + +- + #ifdef WINDLL + # ifdef ZIP64_SUPPORT + extern _int64 filesize64; +@@ -441,6 +440,9 @@ struct zlist far *z; /* zip entry to + if (tim == 0 || q == (zoff_t) -3) + return ZE_OPEN; + ++ if (timestamp > 0) ++ tim = unix2dostime(×tamp); ++ + /* q is set to -1 if the input file is a device, -2 for a volume label */ + if (q == (zoff_t) -2) { + isdir = 1;