tools: update
This commit is contained in:
parent
07d52b5ebe
commit
d9be6e62d5
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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");
|
||||
@ -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
|
||||
|
||||
|
||||
32
tools/cbootimage-configs/Makefile
Normal file
32
tools/cbootimage-configs/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
#
|
||||
# Copyright (c) 2017-2019 Tomasz Maciej Nowak <tomek_n@o2.pl>
|
||||
#
|
||||
# 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))
|
||||
31
tools/cbootimage/Makefile
Normal file
31
tools/cbootimage/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
#
|
||||
# Copyright (c) 2017-2019 Tomasz Maciej Nowak <tomek_n@o2.pl>
|
||||
#
|
||||
# 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))
|
||||
@ -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)"
|
||||
|
||||
@ -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})
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ Signed-off-by: Jo-Philipp Wich <jo@mein.io>
|
||||
---
|
||||
--- 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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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__)
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
* jcgimage - Create a JCG firmware image
|
||||
*
|
||||
* Copyright (C) 2015 Reinhard Max <reinhard@m4x.de>
|
||||
* Copyright (C) 2019 Davide Fioravanti <pantanastyle@gmail.com>
|
||||
*
|
||||
* 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 <sys/mman.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
@ -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 <blogic@openwrt.org>
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
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;
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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 */
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -17,12 +17,19 @@
|
||||
#include <sys/stat.h>
|
||||
#include <endian.h> /* 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 <file> read input from file <file>\n"
|
||||
" -o <file> write output to file <file>\n"
|
||||
" -f <flash> set flash address to <flash>\n"
|
||||
" -S <start> set start address to <start>\n");
|
||||
" -S <start> set start address to <start>\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));
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <inttypes.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
@ -29,65 +30,106 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#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;
|
||||
|
||||
459
tools/firmware-utils/src/mkrasimage.c
Normal file
459
tools/firmware-utils/src/mkrasimage.c
Normal file
@ -0,0 +1,459 @@
|
||||
/*
|
||||
* --- ZyXEL header format ---
|
||||
* Original Version by Benjamin Berg <benjamin@sipsolutions.net>
|
||||
* C implementation based on generation-script by Christian Lamparter <chunkeey@gmail.com>
|
||||
*
|
||||
* 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 <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#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 <kernel> path for kernel image\n"
|
||||
" -r <rootfs> path for rootfs image\n"
|
||||
" -s <rfssize> size of output rootfs\n"
|
||||
" -v <version> version string\n"
|
||||
" -b <boardname> name of board to generate image for\n"
|
||||
" -o <out_name> 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();
|
||||
}
|
||||
@ -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 <magic> set encoding magic <magic>\n"
|
||||
" -z enable image padding to <blocksize>\n"
|
||||
" -b <blocksize> set image <blocksize>, defaults to %u\n"
|
||||
" -c <datecode> add capwap header with <datecode> (e.g. 171101)\n"
|
||||
" -w <fw_ver> firmware version for capwap header (e.g. 3.0.1)\n"
|
||||
" -x <cw_ver> capwap firmware version for capwap header (e.g. 1.8.53)\n"
|
||||
" -n <name> 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;
|
||||
|
||||
261
tools/firmware-utils/src/mksercommfw.c
Normal file
261
tools/firmware-utils/src/mksercommfw.c
Normal file
@ -0,0 +1,261 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <byteswap.h>
|
||||
#include <endian.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#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 <hwid> use hardware id specified with <hwid> (ASCII)\n"
|
||||
" -r <hwrev> use hardware revision specified with <hwrev> (ASCII)\n"
|
||||
" -v <version> set image version to <version> (decimal, hex or octal notation)\n"
|
||||
" -i <file> 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;
|
||||
}
|
||||
@ -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 <file> read rootfs image from the file <file>\n"
|
||||
" -a <align> align the rootfs start on an <align> bytes boundary\n"
|
||||
" -R <offset> overwrite rootfs offset with <offset> (hexval prefixed with 0x)\n"
|
||||
" -O calculate rootfs offset for combined images\n"
|
||||
" -o <file> write output to the file <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;
|
||||
|
||||
@ -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 */
|
||||
}
|
||||
|
||||
129
tools/firmware-utils/src/nec-enc.c
Normal file
129
tools/firmware-utils/src/nec-enc.c
Normal file
@ -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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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 <key>\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;
|
||||
}
|
||||
@ -27,6 +27,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
@ -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 <heads> -s <sectors> -o <outputfile> [-a 0..4] [-l <align kB>] [[-t <type>] -p <size>...] \n", prog);
|
||||
fprintf(stderr, "Usage: %s [-v] [-n] -h <heads> -s <sectors> -o <outputfile> [-a 0..4] [-l <align kB>] [[-t <type>] -p <size>...] \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;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
157
tools/firmware-utils/src/uimage_padhdr.c
Normal file
157
tools/firmware-utils/src/uimage_padhdr.c
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* uimage_padhdr.c : add zero paddings after the tail of uimage header
|
||||
*
|
||||
* Copyright (C) 2019 NOGUCHI Hiroshi <drvlabo@gmail.com>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
/* 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 <input_uimage_file> -o <output_file> [-l <padding bytes>]\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;
|
||||
}
|
||||
@ -20,11 +20,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
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 <pattern>]\n");
|
||||
fprintf(stderr, "Usage: xorimage [-i infile] [-o outfile] [-p <pattern>] [-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:
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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 \
|
||||
33
tools/gengetopt/patches/100-no-tests-docs.patch
Normal file
33
tools/gengetopt/patches/100-no-tests-docs.patch
Normal file
@ -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
|
||||
|
||||
@ -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
|
||||
@ -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))
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
198
tools/libelf/patches/900-fix-undefined-macro-access.patch
Normal file
198
tools/libelf/patches/900-fix-undefined-macro-access.patch
Normal file
@ -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 <libelf.h>
|
||||
#else /* __LIBELF_INTERNAL__ */
|
||||
#include <libelf/libelf.h>
|
||||
#endif /* __LIBELF_INTERNAL__ */
|
||||
|
||||
-#if __LIBELF_NEED_LINK_H
|
||||
+#if defined(__LIBELF_NEED_LINK_H)
|
||||
#include <link.h>
|
||||
-#elif __LIBELF_NEED_SYS_LINK_H
|
||||
+#elif defined(__LIBELF_NEED_SYS_LINK_H)
|
||||
#include <sys/link.h>
|
||||
#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 <stddef.h> /* for size_t */
|
||||
#include <sys/types.h>
|
||||
|
||||
-#if __LIBELF_INTERNAL__
|
||||
+#if defined(__LIBELF_INTERNAL__)
|
||||
#include <sys_elf.h>
|
||||
#else /* __LIBELF_INTERNAL__ */
|
||||
#include <libelf/sys_elf.h>
|
||||
@@ -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;
|
||||
@ -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
|
||||
|
||||
11
tools/libressl/patches/001-dont-build-tests-man.patch
Normal file
11
tools/libressl/patches/001-dont-build-tests-man.patch
Normal file
@ -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
|
||||
23
tools/libressl/patches/010-avoid-glibc.patch
Normal file
23
tools/libressl/patches/010-avoid-glibc.patch
Normal file
@ -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
|
||||
}
|
||||
@ -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
|
||||
|
||||
|
||||
@ -26,4 +26,4 @@ non Linux hosts.
|
||||
+#endif
|
||||
|
||||
#define __packed __attribute__((packed))
|
||||
|
||||
|
||||
|
||||
@ -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) \
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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]*)$")):
|
||||
|
||||
@ -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 + "/")]])
|
||||
|
||||
@ -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):
|
||||
|
||||
@ -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))
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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):
|
||||
|
||||
327
tools/mklibs/patches/100-apply-2to3.patch
Normal file
327
tools/mklibs/patches/100-apply-2to3.patch
Normal file
@ -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)
|
||||
@ -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))
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 += \
|
||||
|
||||
@ -70,7 +70,7 @@
|
||||
#include <sys/types.h>
|
||||
--- 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);
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
|
||||
@ -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))
|
||||
@ -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
|
||||
|
||||
@ -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))
|
||||
@ -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
|
||||
@ -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':
|
||||
@ -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 \
|
||||
|
||||
@ -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))
|
||||
@ -1,40 +0,0 @@
|
||||
--- a/squashfs-tools/mksquashfs.c
|
||||
+++ b/squashfs-tools/mksquashfs.c
|
||||
@@ -60,6 +60,10 @@
|
||||
#include <sys/sysinfo.h>
|
||||
#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 <sys/sysctl.h>
|
||||
#else
|
||||
#include <endian.h>
|
||||
+#include <sys/sysinfo.h>
|
||||
+#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 <sys/sysinfo.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
struct cache *fragment_cache, *data_cache;
|
||||
@ -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
|
||||
@ -1,153 +0,0 @@
|
||||
--- a/squashfs-tools/mksquashfs.c
|
||||
+++ b/squashfs-tools/mksquashfs.c
|
||||
@@ -51,15 +51,22 @@
|
||||
#include <sys/wait.h>
|
||||
|
||||
#ifndef linux
|
||||
+#ifndef __CYGWIN__
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#include <sys/sysctl.h>
|
||||
+#endif /* __CYGWIN__ */
|
||||
#else
|
||||
#include <endian.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
+#ifdef __CYGWIN__
|
||||
+#include <sys/termios.h>
|
||||
+#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 <sys/mman.h>
|
||||
|
||||
#ifndef linux
|
||||
+#ifndef __CYGWIN__
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
+#endif
|
||||
#else
|
||||
#include <endian.h>
|
||||
#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 <endian.h>
|
||||
#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 <sys/time.h>
|
||||
|
||||
#ifndef linux
|
||||
+#ifndef __CYGWIN__
|
||||
#define __BYTE_ORDER BYTE_ORDER
|
||||
#define __BIG_ENDIAN BIG_ENDIAN
|
||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
#include <sys/sysctl.h>
|
||||
+#endif
|
||||
#else
|
||||
#include <endian.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#endif
|
||||
|
||||
+#ifdef __CYGWIN__
|
||||
+#include <sys/termios.h>
|
||||
+#define FNM_EXTMATCH (1 << 5)
|
||||
+#endif
|
||||
+
|
||||
#ifndef FNM_EXTMATCH
|
||||
#define FNM_EXTMATCH 0
|
||||
#endif
|
||||
@ -1,20 +0,0 @@
|
||||
--- a/squashfs-tools/mksquashfs.c
|
||||
+++ b/squashfs-tools/mksquashfs.c
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <stddef.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
+#include <sys/sysmacros.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
--- a/squashfs-tools/unsquashfs.c
|
||||
+++ b/squashfs-tools/unsquashfs.c
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "xattr.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
+#include <sys/sysmacros.h>
|
||||
|
||||
struct cache *fragment_cache, *data_cache;
|
||||
struct queue *to_reader, *to_deflate, *to_writer, *from_writer;
|
||||
@ -1,10 +0,0 @@
|
||||
--- a/squashfs-tools/pseudo.c
|
||||
+++ b/squashfs-tools/pseudo.c
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
+#include <sys/stat.h>
|
||||
|
||||
#include "pseudo.h"
|
||||
|
||||
@ -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 <jonas.gorski@gmail.com>
|
||||
+ *
|
||||
+ * 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 <stdint.h>
|
||||
+
|
||||
+#ifndef linux
|
||||
+#ifdef __FreeBSD__
|
||||
+#include <machine/endian.h>
|
||||
+#endif
|
||||
+#define __BYTE_ORDER BYTE_ORDER
|
||||
+#define __BIG_ENDIAN BIG_ENDIAN
|
||||
+#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
||||
+#else
|
||||
+#include <endian.h>
|
||||
+#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 <jonas.gorski@gmail.com>
|
||||
+ *
|
||||
+ * 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 <stdio.h>
|
||||
+#include <string.h>
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
+#include <lzma.h>
|
||||
+
|
||||
+#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 <preset>\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 <lc>\n");
|
||||
+ fprintf(stderr, "\t\tNumber of literal context bits (0-4, default 3)\n");
|
||||
+ fprintf(stderr, "\t -Xlp <lp>\n");
|
||||
+ fprintf(stderr, "\t\tNumber of literal position bits (0-4, default 0)\n");
|
||||
+ fprintf(stderr, "\t -Xpb <pb>\n");
|
||||
+ fprintf(stderr, "\t\tNumber of position bits (0-4, default 2)\n");
|
||||
+ fprintf(stderr, "\t -Xnice <nice>\n");
|
||||
+ fprintf(stderr, "\t\tNice length of a match (5-273, default 64)\n");
|
||||
+ fprintf(stderr, "\t -Xdict-size <dict-size>\n");
|
||||
+ fprintf(stderr, "\t\tUse <dict-size> 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 <endian.h>
|
||||
-#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 <dict-size>\n");
|
||||
- fprintf(stderr, "\t\tUse <dict-size> 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)
|
||||
@ -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:
|
||||
@ -1,24 +0,0 @@
|
||||
--- a/squashfs-tools/mksquashfs.c
|
||||
+++ b/squashfs-tools/mksquashfs.c
|
||||
@@ -32,6 +32,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/time.h>
|
||||
+#if defined(__OpenBSD__)
|
||||
+#include <sys/param.h>
|
||||
+#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/stat.h>
|
||||
--- a/squashfs-tools/unsquashfs.h
|
||||
+++ b/squashfs-tools/unsquashfs.h
|
||||
@@ -25,6 +25,9 @@
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#include <stdio.h>
|
||||
+#if defined(__OpenBSD__)
|
||||
+#include <sys/param.h>
|
||||
+#endif
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
@ -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) {
|
||||
@ -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) {
|
||||
@ -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
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
||||
---
|
||||
--- 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);
|
||||
|
||||
@ -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))
|
||||
{
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<NSLU2Upgrade::Wire> 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<NSLU2Image::Image> image(
|
||||
NSLU2Image::Image::MakeImage(
|
||||
reprogram, full_image));
|
||||
+ image_p = image.p;
|
||||
+ image_p->GetBoundaries(BaseAddress, EndAddress);
|
||||
+ ProgressBar progress(reprogram, mac, BaseAddress, EndAddress);
|
||||
Pointer<NSLU2Upgrade::DoUpgrade> 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<NSLU2Upgrade::DoUpgrade> 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 <int characters> 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
|
||||
@ -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"
|
||||
|
||||
36
tools/zip/Makefile
Normal file
36
tools/zip/Makefile
Normal file
@ -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))
|
||||
@ -0,0 +1,89 @@
|
||||
From fc392c939b9a18959482f588aff0afc29dd6d30a Mon Sep 17 00:00:00 2001
|
||||
From: Romain Naour <romain.naour at openwide.fr>
|
||||
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 <richard.genoud at gmail.com>
|
||||
Signed-off-by: Romain Naour <romain.naour at openwide.fr>
|
||||
---
|
||||
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 <sys/types.h>
|
||||
-#include <sys/stat.h>
|
||||
-#include <unistd.h>
|
||||
-#include <stdio.h>
|
||||
+
|
||||
+ /* 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
|
||||
|
||||
|
||||
15
tools/zip/patches/004-do-not-set-unwanted-cflags.patch
Normal file
15
tools/zip/patches/004-do-not-set-unwanted-cflags.patch
Normal file
@ -0,0 +1,15 @@
|
||||
From: Santiago Vila <sanvila@debian.org>
|
||||
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
|
||||
@ -0,0 +1,21 @@
|
||||
From: Kees Cook <kees@debian.org>
|
||||
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
|
||||
16
tools/zip/patches/007-fclose-in-file-not-fclose-x.patch
Normal file
16
tools/zip/patches/007-fclose-in-file-not-fclose-x.patch
Normal file
@ -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 */
|
||||
25
tools/zip/patches/008-hardening-build-fix-1.patch
Normal file
25
tools/zip/patches/008-hardening-build-fix-1.patch
Normal file
@ -0,0 +1,25 @@
|
||||
From: Santiago Vila <sanvila@debian.org>
|
||||
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 */
|
||||
16
tools/zip/patches/009-hardening-build-fix-2.patch
Normal file
16
tools/zip/patches/009-hardening-build-fix-2.patch
Normal file
@ -0,0 +1,16 @@
|
||||
From: Santiago Vila <sanvila@debian.org>
|
||||
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"
|
||||
|
||||
15
tools/zip/patches/010-remove-build-date.patch
Normal file
15
tools/zip/patches/010-remove-build-date.patch
Normal file
@ -0,0 +1,15 @@
|
||||
From: Santiago Vila <sanvila@debian.org>
|
||||
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 ""
|
||||
145
tools/zip/patches/011-add-option-for-reproducible-archives.patch
Normal file
145
tools/zip/patches/011-add-option-for-reproducible-archives.patch
Normal file
@ -0,0 +1,145 @@
|
||||
From 6d659fc87451c02c8777dc33f750b16834e4c715 Mon Sep 17 00:00:00 2001
|
||||
From: Mathias Kresin <dev@kresin.me>
|
||||
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 <dev@kresin.me>
|
||||
---
|
||||
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;
|
||||
Loading…
Reference in New Issue
Block a user