From 98d1c7d83485ed2b024bf8ab5f8ff7e2a66ab85e Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Mon, 4 Nov 2019 10:55:23 -1000 Subject: [PATCH 1/5] build: image: add common and reproducible IMG_PART_SIGNATURE variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit x86, mvebu and tegra targets are currently using more or less same SIGNATURE variable which provides unique partition ID/signature, so it makes sense to refactor it out into common variable which could be reused by all targets. While at it, make the content of the variable reproducible. Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-March/016148.html Signed-off-by: Paul Spooren Suggested-by: Jo-Philipp Wich [renamed to IMG_PARTSIGNATURE, reworked with epoch+vermagic hash] Signed-off-by: Petr Štetiar --- include/image.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/include/image.mk b/include/image.mk index 77d4567197..8755c4832a 100644 --- a/include/image.mk +++ b/include/image.mk @@ -44,6 +44,7 @@ IMG_PREFIX_VERCODE:=$(if $(CONFIG_VERSION_CODE_FILENAMES),$(call sanitize,$(VERS IMG_PREFIX:=$(VERSION_DIST_SANITIZED)-$(IMG_PREFIX_VERNUM)$(IMG_PREFIX_VERCODE)$(IMG_PREFIX_EXTRA)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET)) IMG_ROOTFS:=$(IMG_PREFIX)-rootfs IMG_COMBINED:=$(IMG_PREFIX)-combined +IMG_PART_SIGNATURE:=$(shell echo $(SOURCE_DATE_EPOCH)$(LINUX_VERMAGIC) | mkhash md5 | head --bytes 8) MKFS_DEVTABLE_OPT := -D $(INCLUDE_DIR)/device_table.txt From e97113d5e18c31050bc06f7c6b7a5c663b5f31a4 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Mon, 4 Nov 2019 10:55:23 -1000 Subject: [PATCH 2/5] x86,tegra,mvebu: image: use common reproducible IMG_PART_SIGNATURE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These targets are currently using more or less same SIGNATURE variable which provides unique partition ID/signature, so it makes sense to refactor it out into common IMG_PART_SIGNATURE variable which could be reused by all targets. This is another step in the direction of reproducible OpenWrt images. Signed-off-by: Paul Spooren [split into separate commit, renamed to IMG_PART_SIGNATURE] Signed-off-by: Petr Štetiar --- target/linux/mvebu/image/Makefile | 8 +++----- target/linux/tegra/image/Makefile | 6 ++---- target/linux/x86/image/Makefile | 5 ++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/target/linux/mvebu/image/Makefile b/target/linux/mvebu/image/Makefile index 967a1e4ee1..ce1344a547 100644 --- a/target/linux/mvebu/image/Makefile +++ b/target/linux/mvebu/image/Makefile @@ -13,12 +13,10 @@ include $(INCLUDE_DIR)/image.mk KERNEL_LOADADDR := 0x00008000 -SIGNATURE:=$(shell printf "%.8s" $(SOURCE_DATE_EPOCH)) - define Build/boot-scr rm -f $@-boot.scr sed \ - -e 's#@ROOT@#$(SIGNATURE)#g' \ + -e 's#@ROOT@#$(IMG_PART_SIGNATURE)#g' \ -e 's#@DTB@#$(firstword $(DEVICE_DTS))#g' \ $(BOOT_SCRIPT).bootscript > $@-new.bootscript mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d $@-new.bootscript $@-boot.scr @@ -42,7 +40,7 @@ define Build/boot-img-ext4 endef define Build/sdcard-img - SIGNATURE="$(SIGNATURE)" \ + SIGNATURE="$(IMG_PART_SIGNATURE)" \ ./gen_mvebu_sdcard_img.sh $@ \ $(if $(UBOOT),$(STAGING_DIR_IMAGE)/$(UBOOT)) \ c $(CONFIG_TARGET_KERNEL_PARTSIZE) $@.boot \ @@ -50,7 +48,7 @@ define Build/sdcard-img endef define Build/sdcard-img-ext4 - SIGNATURE="$(SIGNATURE)" \ + SIGNATURE="$(IMG_PART_SIGNATURE)" \ ./gen_mvebu_sdcard_img.sh $@ \ $(if $(UBOOT),$(STAGING_DIR_IMAGE)/$(UBOOT)) \ 83 $(CONFIG_TARGET_KERNEL_PARTSIZE) $@.bootimg \ diff --git a/target/linux/tegra/image/Makefile b/target/linux/tegra/image/Makefile index 2ce8659995..10bada9c38 100644 --- a/target/linux/tegra/image/Makefile +++ b/target/linux/tegra/image/Makefile @@ -7,8 +7,6 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/image.mk -SIGNATURE:=$(shell printf "%.8s" $(SOURCE_DATE_EPOCH)) - define Build/tegra-sdcard rm -fR $@.boot mkdir -p $@.boot @@ -17,7 +15,7 @@ define Build/tegra-sdcard $(foreach dtb,$(DEVICE_DTS),$(CP) $(DTS_DIR)/$(dtb).dtb $@.boot), \ $(CP) $(DTS_DIR)/*.dtb $@.boot) sed \ - -e 's#@ROOT@#$(SIGNATURE)#g' \ + -e 's#@ROOT@#$(IMG_PART_SIGNATURE)#g' \ -e 's#@KERNEL@#$(KERNEL_NAME)#g' \ $(BOOT_SCRIPT) > $@-boot.scr mkimage -A arm -O linux -T script -C none -a 0 -e 0 \ @@ -25,7 +23,7 @@ define Build/tegra-sdcard -d $@-boot.scr \ $@.boot/boot.scr - SIGNATURE="$(SIGNATURE)" \ + SIGNATURE="$(IMG_PART_SIGNATURE)" \ $(SCRIPT_DIR)/gen_image_generic.sh \ $@ \ $(CONFIG_TARGET_KERNEL_PARTSIZE) $@.boot \ diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile index ac70e771c8..4383bcdcb2 100644 --- a/target/linux/x86/image/Makefile +++ b/target/linux/x86/image/Makefile @@ -40,9 +40,8 @@ ifneq ($(GRUB_TERMINALS),) GRUB_TERMINAL_CONFIG := terminal_input $(GRUB_TERMINALS); terminal_output $(GRUB_TERMINALS) endif -SIGNATURE:=$(shell perl -e 'printf("%08x", rand(0xFFFFFFFF))') ROOTPART:=$(call qstrip,$(CONFIG_TARGET_ROOTFS_PARTNAME)) -ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(SIGNATURE)-02) +ROOTPART:=$(if $(ROOTPART),$(ROOTPART),PARTUUID=$(IMG_PART_SIGNATURE)-02) GRUB_TIMEOUT:=$(call qstrip,$(CONFIG_GRUB_TIMEOUT)) GRUB_TITLE:=$(call qstrip,$(CONFIG_GRUB_TITLE)) @@ -80,7 +79,7 @@ ifneq ($(CONFIG_GRUB_IMAGES),) -e 's#@TITLE@#$(GRUB_TITLE)#g' \ ./grub.cfg > $(KDIR)/root.grub/boot/grub/grub.cfg -$(CP) $(STAGING_DIR_ROOT)/boot/. $(KDIR)/root.grub/boot/ - PADDING="1" SIGNATURE="$(SIGNATURE)" PATH="$(TARGET_PATH)" $(SCRIPT_DIR)/gen_image_generic.sh \ + PADDING="1" SIGNATURE="$(IMG_PART_SIGNATURE)" PATH="$(TARGET_PATH)" $(SCRIPT_DIR)/gen_image_generic.sh \ $(BIN_DIR)/$(IMG_COMBINED)-$(1).img \ $(CONFIG_TARGET_KERNEL_PARTSIZE) $(KDIR)/root.grub \ $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(KDIR)/root.$(1) \ From 4ba8f7b1ef1e4c0607185a41c06b51928c625d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Sat, 9 Nov 2019 14:33:13 +0100 Subject: [PATCH 3/5] fwtool: update to latest Git head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Includes following changes: 9d9d4c284786 fix possible garbage in unitialized char* struct members dbc1b1b71b24 fix possible copy of null buffer and validation of unitialized header 76d53deef8bb crc32: add missing stdint.h dependency e5666ed3b47c add cram based unit tests abe0cf7de053 add initial GitLab CI support e43042507b4f iron out extra compiler warnings 5df0cd6e1523 convert into CMake project a7dc0526f819 refactor into separate Git project adds missing PKG_LICENSE field and converts the package build to utilize CMake. Signed-off-by: Petr Štetiar --- package/system/fwtool/Makefile | 21 +- package/system/fwtool/src/crc32.h | 48 --- package/system/fwtool/src/fwimage.h | 39 --- package/system/fwtool/src/fwtool.c | 468 ---------------------------- package/system/fwtool/src/utils.h | 116 ------- 5 files changed, 11 insertions(+), 681 deletions(-) delete mode 100644 package/system/fwtool/src/crc32.h delete mode 100644 package/system/fwtool/src/fwimage.h delete mode 100644 package/system/fwtool/src/fwtool.c delete mode 100644 package/system/fwtool/src/utils.h diff --git a/package/system/fwtool/Makefile b/package/system/fwtool/Makefile index 283be8d77a..8397282392 100644 --- a/package/system/fwtool/Makefile +++ b/package/system/fwtool/Makefile @@ -8,15 +8,24 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fwtool -PKG_RELEASE:=2 +PKG_RELEASE:=1 + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL=$(PROJECT_GIT)/project/fwtool.git +PKG_SOURCE_DATE:=2019-11-09 +PKG_SOURCE_VERSION:=9d9d4c2847862adec2f474d4126213c17f98e024 +PKG_MIRROR_HASH:=4a72a48cbc7cda4c1860ec8328c049b4b84f7f00273d82ee98175937b63af1f8 +CMAKE_INSTALL:=1 PKG_FLAGS:=nonshared +PKG_LICENSE:=GPL-2.0 PKG_MAINTAINER := Felix Fietkau PKG_BUILD_DEPENDS := fwtool/host include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/host-build.mk +include $(INCLUDE_DIR)/cmake.mk HOST_BUILD_PREFIX:=$(STAGING_DIR_HOST) @@ -26,21 +35,13 @@ define Package/fwtool TITLE:=Utility for appending and extracting firmware metadata and signatures endef -define Host/Compile - $(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $(HOST_BUILD_DIR)/fwtool ./src/fwtool.c -endef - define Host/Install $(INSTALL_BIN) $(HOST_BUILD_DIR)/fwtool $(1)/bin/ endef -define Build/Compile - $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/fwtool ./src/fwtool.c -endef - define Package/fwtool/install $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/fwtool $(1)/usr/bin/ + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/fwtool $(1)/usr/bin/ endef $(eval $(call HostBuild)) diff --git a/package/system/fwtool/src/crc32.h b/package/system/fwtool/src/crc32.h deleted file mode 100644 index 022c69fc7f..0000000000 --- a/package/system/fwtool/src/crc32.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2016 Felix Fietkau - * - * Based on busybox code: - * CRC32 table fill function - * Copyright (C) 2006 by Rob Sullivan - * - * 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. - */ -#ifndef __BB_CRC32_H -#define __BB_CRC32_H - -static inline void -crc32_filltable(uint32_t *crc_table) -{ - uint32_t polynomial = 0xedb88320; - uint32_t c; - int i, j; - - for (i = 0; i < 256; i++) { - c = i; - for (j = 8; j; j--) - c = (c&1) ? ((c >> 1) ^ polynomial) : (c >> 1); - - *crc_table++ = c; - } -} - -static inline uint32_t -crc32_block(uint32_t val, const void *buf, unsigned len, uint32_t *crc_table) -{ - const void *end = (uint8_t*)buf + len; - - while (buf != end) { - val = crc_table[(uint8_t)val ^ *(uint8_t*)buf] ^ (val >> 8); - buf = (uint8_t*)buf + 1; - } - return val; -} - -#endif diff --git a/package/system/fwtool/src/fwimage.h b/package/system/fwtool/src/fwimage.h deleted file mode 100644 index 52dcfb1bac..0000000000 --- a/package/system/fwtool/src/fwimage.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2016 Felix Fietkau - * - * 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. - */ -#ifndef __FWIMAGE_H -#define __FWIMAGE_H - -#include - -#define FWIMAGE_MAGIC 0x46577830 /* FWx0 */ - -struct fwimage_header { - uint32_t version; - uint32_t flags; - char data[]; -}; - -struct fwimage_trailer { - uint32_t magic; - uint32_t crc32; - uint8_t type; - uint8_t __pad[3]; - uint32_t size; -}; - -enum fwimage_type { - FWIMAGE_SIGNATURE, - FWIMAGE_INFO, -}; - -#endif diff --git a/package/system/fwtool/src/fwtool.c b/package/system/fwtool/src/fwtool.c deleted file mode 100644 index 89e89514ad..0000000000 --- a/package/system/fwtool/src/fwtool.c +++ /dev/null @@ -1,468 +0,0 @@ -/* - * Copyright (C) 2016 Felix Fietkau - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ -#include -#include -#include -#include -#include -#include -#include - -#include "fwimage.h" -#include "utils.h" -#include "crc32.h" - -#define METADATA_MAXLEN 30 * 1024 -#define SIGNATURE_MAXLEN 1 * 1024 - -#define BUFLEN (METADATA_MAXLEN + SIGNATURE_MAXLEN + 1024) - -enum { - MODE_DEFAULT = -1, - MODE_EXTRACT = 0, - MODE_APPEND = 1, -}; - -struct data_buf { - char *cur; - char *prev; - int cur_len; - int file_len; -}; - -static FILE *signature_file, *metadata_file, *firmware_file; -static int file_mode = MODE_DEFAULT; -static bool truncate_file; -static bool write_truncated; -static bool quiet = false; - -static uint32_t crc_table[256]; - -#define msg(...) \ - do { \ - if (!quiet) \ - fprintf(stderr, __VA_ARGS__); \ - } while (0) - -static int -usage(const char *progname) -{ - fprintf(stderr, "Usage: %s \n" - "\n" - "Options:\n" - " -S : Append signature file to firmware image\n" - " -I : Append metadata file to firmware image\n" - " -s : Extract signature file from firmware image\n" - " -i : Extract metadata file from firmware image\n" - " -t: Remove extracted chunks from firmare image (using -s, -i)\n" - " -T: Output firmware image without extracted chunks to stdout (using -s, -i)\n" - " -q: Quiet (suppress error messages)\n" - "\n", progname); - return 1; -} - -static FILE * -open_file(const char *name, bool write) -{ - FILE *ret; - - if (!strcmp(name, "-")) - return write ? stdout : stdin; - - ret = fopen(name, write ? "w" : "r+"); - if (!ret && !write) - ret = fopen(name, "r"); - - return ret; -} - -static int -set_file(FILE **file, const char *name, int mode) -{ - if (file_mode < 0) - file_mode = mode; - else if (file_mode != mode) { - msg("Error: mixing appending and extracting data is not supported\n"); - return 1; - } - - if (*file) { - msg("Error: the same append/extract option cannot be used multiple times\n"); - return 1; - } - - *file = open_file(name, mode == MODE_EXTRACT); - return !*file; -} - -static void -trailer_update_crc(struct fwimage_trailer *tr, void *buf, int len) -{ - tr->crc32 = cpu_to_be32(crc32_block(be32_to_cpu(tr->crc32), buf, len, crc_table)); -} - -static int -append_data(FILE *in, FILE *out, struct fwimage_trailer *tr, int maxlen) -{ - while (1) { - char buf[512]; - int len; - - len = fread(buf, 1, sizeof(buf), in); - if (!len) - break; - - maxlen -= len; - if (maxlen < 0) - return 1; - - tr->size += len; - trailer_update_crc(tr, buf, len); - fwrite(buf, len, 1, out); - } - - return 0; -} - -static void -append_trailer(FILE *out, struct fwimage_trailer *tr) -{ - tr->size = cpu_to_be32(tr->size); - fwrite(tr, sizeof(*tr), 1, out); - trailer_update_crc(tr, tr, sizeof(*tr)); -} - -static int -add_metadata(struct fwimage_trailer *tr) -{ - struct fwimage_header hdr = {}; - - tr->type = FWIMAGE_INFO; - tr->size = sizeof(hdr) + sizeof(*tr); - - trailer_update_crc(tr, &hdr, sizeof(hdr)); - fwrite(&hdr, sizeof(hdr), 1, firmware_file); - - if (append_data(metadata_file, firmware_file, tr, METADATA_MAXLEN)) - return 1; - - append_trailer(firmware_file, tr); - - return 0; -} - -static int -add_signature(struct fwimage_trailer *tr) -{ - if (!signature_file) - return 0; - - tr->type = FWIMAGE_SIGNATURE; - tr->size = sizeof(*tr); - - if (append_data(signature_file, firmware_file, tr, SIGNATURE_MAXLEN)) - return 1; - - append_trailer(firmware_file, tr); - - return 0; -} - -static int -add_data(const char *name) -{ - struct fwimage_trailer tr = { - .magic = cpu_to_be32(FWIMAGE_MAGIC), - .crc32 = ~0, - }; - int file_len = 0; - int ret = 0; - - firmware_file = fopen(name, "r+"); - if (!firmware_file) { - msg("Failed to open firmware file\n"); - return 1; - } - - while (1) { - char buf[512]; - int len; - - len = fread(buf, 1, sizeof(buf), firmware_file); - if (!len) - break; - - file_len += len; - trailer_update_crc(&tr, buf, len); - } - - if (metadata_file) - ret = add_metadata(&tr); - else if (signature_file) - ret = add_signature(&tr); - - if (ret) { - fflush(firmware_file); - ftruncate(fileno(firmware_file), file_len); - } - - return ret; -} - -static void -remove_tail(struct data_buf *dbuf, int len) -{ - dbuf->cur_len -= len; - dbuf->file_len -= len; - - if (dbuf->cur_len) - return; - - free(dbuf->cur); - dbuf->cur = dbuf->prev; - dbuf->prev = NULL; - dbuf->cur_len = BUFLEN; -} - -static int -extract_tail(struct data_buf *dbuf, void *dest, int len) -{ - int cur_len = dbuf->cur_len; - - if (!dbuf->cur) - return 1; - - if (cur_len >= len) - cur_len = len; - - memcpy(dest + (len - cur_len), dbuf->cur + dbuf->cur_len - cur_len, cur_len); - remove_tail(dbuf, cur_len); - - cur_len = len - cur_len; - if (cur_len && !dbuf->cur) - return 1; - - memcpy(dest, dbuf->cur + dbuf->cur_len - cur_len, cur_len); - remove_tail(dbuf, cur_len); - - return 0; -} - -static uint32_t -tail_crc32(struct data_buf *dbuf, uint32_t crc32) -{ - if (dbuf->prev) - crc32 = crc32_block(crc32, dbuf->prev, BUFLEN, crc_table); - - return crc32_block(crc32, dbuf->cur, dbuf->cur_len, crc_table); -} - -static int -validate_metadata(struct fwimage_header *hdr, int data_len) -{ - if (hdr->version != 0) - return 1; - return 0; -} - -static int -extract_data(const char *name) -{ - struct fwimage_header *hdr; - struct fwimage_trailer tr; - struct data_buf dbuf = {}; - uint32_t crc32 = ~0; - int data_len = 0; - int ret = 1; - void *buf; - bool metadata_keep = false; - - firmware_file = open_file(name, false); - if (!firmware_file) { - msg("Failed to open firmware file\n"); - return 1; - } - - if (truncate_file && firmware_file == stdin) { - msg("Cannot truncate file when reading from stdin\n"); - return 1; - } - - buf = malloc(BUFLEN); - if (!buf) - return 1; - - do { - char *tmp = dbuf.cur; - - if (write_truncated && dbuf.prev) - fwrite(dbuf.prev, 1, BUFLEN, stdout); - - dbuf.cur = dbuf.prev; - dbuf.prev = tmp; - - if (dbuf.cur) - crc32 = crc32_block(crc32, dbuf.cur, BUFLEN, crc_table); - else - dbuf.cur = malloc(BUFLEN); - - if (!dbuf.cur) - goto out; - - dbuf.cur_len = fread(dbuf.cur, 1, BUFLEN, firmware_file); - dbuf.file_len += dbuf.cur_len; - } while (dbuf.cur_len == BUFLEN); - - while (1) { - - if (extract_tail(&dbuf, &tr, sizeof(tr))) - break; - - if (tr.magic != cpu_to_be32(FWIMAGE_MAGIC)) { - msg("Data not found\n"); - metadata_keep = true; - break; - } - - data_len = be32_to_cpu(tr.size) - sizeof(tr); - - if (be32_to_cpu(tr.crc32) != tail_crc32(&dbuf, crc32)) { - msg("CRC error\n"); - break; - } - - if (data_len > BUFLEN) { - msg("Size error\n"); - break; - } - - extract_tail(&dbuf, buf, data_len); - - if (tr.type == FWIMAGE_SIGNATURE) { - if (!signature_file) - continue; - fwrite(buf, data_len, 1, signature_file); - ret = 0; - break; - } else if (tr.type == FWIMAGE_INFO) { - if (!metadata_file) { - dbuf.file_len += data_len + sizeof(tr); - metadata_keep = true; - break; - } - - hdr = buf; - data_len -= sizeof(*hdr); - if (validate_metadata(hdr, data_len)) - continue; - - fwrite(hdr + 1, data_len, 1, metadata_file); - ret = 0; - break; - } else { - continue; - } - } - - if (!ret && truncate_file) - ftruncate(fileno(firmware_file), dbuf.file_len); - - if (write_truncated) { - if (dbuf.prev) - fwrite(dbuf.prev, 1, BUFLEN, stdout); - if (dbuf.cur) - fwrite(dbuf.cur, 1, dbuf.cur_len, stdout); - if (metadata_keep) { - fwrite(buf, data_len, 1, stdout); - fwrite(&tr, sizeof(tr), 1, stdout); - } - } - -out: - free(buf); - free(dbuf.cur); - free(dbuf.prev); - return ret; -} - -static void cleanup(void) -{ - if (signature_file) - fclose(signature_file); - if (metadata_file) - fclose(metadata_file); - if (firmware_file) - fclose(firmware_file); -} - -int main(int argc, char **argv) -{ - const char *progname = argv[0]; - int ret, ch; - - crc32_filltable(crc_table); - - while ((ch = getopt(argc, argv, "i:I:qs:S:tT")) != -1) { - ret = 0; - switch(ch) { - case 'S': - ret = set_file(&signature_file, optarg, MODE_APPEND); - break; - case 'I': - ret = set_file(&metadata_file, optarg, MODE_APPEND); - break; - case 's': - ret = set_file(&signature_file, optarg, MODE_EXTRACT); - break; - case 'i': - ret = set_file(&metadata_file, optarg, MODE_EXTRACT); - break; - case 't': - truncate_file = true; - break; - case 'T': - write_truncated = true; - break; - case 'q': - quiet = true; - break; - } - - if (ret) - goto out; - } - - if (optind >= argc) { - ret = usage(progname); - goto out; - } - - if (file_mode == MODE_DEFAULT) { - ret = usage(progname); - goto out; - } - - if (signature_file && metadata_file) { - msg("Cannot append/extract metadata and signature in one run\n"); - return 1; - } - - if (file_mode) - ret = add_data(argv[optind]); - else - ret = extract_data(argv[optind]); - -out: - cleanup(); - return ret; -} diff --git a/package/system/fwtool/src/utils.h b/package/system/fwtool/src/utils.h deleted file mode 100644 index c2e665e54a..0000000000 --- a/package/system/fwtool/src/utils.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * utils - misc libubox utility functions - * - * Copyright (C) 2012 Felix Fietkau - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef __LIBUBOX_UTILS_H -#define __LIBUBOX_UTILS_H - -#include -#include -#include - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) -#endif - -#ifdef __GNUC__ -#define _GNUC_MIN_VER(maj, min) (((__GNUC__ << 8) + __GNUC_MINOR__) >= (((maj) << 8) + (min))) -#else -#define _GNUC_MIN_VER(maj, min) 0 -#endif - -#if defined(__linux__) || defined(__CYGWIN__) -#include -#include - -#elif defined(__APPLE__) -#include -#include -#define bswap_32(x) OSSwapInt32(x) -#define bswap_64(x) OSSwapInt64(x) -#elif defined(__FreeBSD__) -#include -#define bswap_32(x) bswap32(x) -#define bswap_64(x) bswap64(x) -#else -#include -#define bswap_32(x) swap32(x) -#define bswap_64(x) swap64(x) -#endif - -#ifndef __BYTE_ORDER -#define __BYTE_ORDER BYTE_ORDER -#endif -#ifndef __BIG_ENDIAN -#define __BIG_ENDIAN BIG_ENDIAN -#endif -#ifndef __LITTLE_ENDIAN -#define __LITTLE_ENDIAN LITTLE_ENDIAN -#endif - -static inline uint16_t __u_bswap16(uint16_t val) -{ - return ((val >> 8) & 0xffu) | ((val & 0xffu) << 8); -} - -#if _GNUC_MIN_VER(4, 2) -#define __u_bswap32(x) __builtin_bswap32(x) -#define __u_bswap64(x) __builtin_bswap64(x) -#else -#define __u_bswap32(x) bswap_32(x) -#define __u_bswap64(x) bswap_64(x) -#endif - -#if __BYTE_ORDER == __LITTLE_ENDIAN - -#define cpu_to_be64(x) __u_bswap64(x) -#define cpu_to_be32(x) __u_bswap32(x) -#define cpu_to_be16(x) __u_bswap16((uint16_t) (x)) - -#define be64_to_cpu(x) __u_bswap64(x) -#define be32_to_cpu(x) __u_bswap32(x) -#define be16_to_cpu(x) __u_bswap16((uint16_t) (x)) - -#define cpu_to_le64(x) (x) -#define cpu_to_le32(x) (x) -#define cpu_to_le16(x) (x) - -#define le64_to_cpu(x) (x) -#define le32_to_cpu(x) (x) -#define le16_to_cpu(x) (x) - -#else /* __BYTE_ORDER == __LITTLE_ENDIAN */ - -#define cpu_to_le64(x) __u_bswap64(x) -#define cpu_to_le32(x) __u_bswap32(x) -#define cpu_to_le16(x) __u_bswap16((uint16_t) (x)) - -#define le64_to_cpu(x) __u_bswap64(x) -#define le32_to_cpu(x) __u_bswap32(x) -#define le16_to_cpu(x) __u_bswap16((uint16_t) (x)) - -#define cpu_to_be64(x) (x) -#define cpu_to_be32(x) (x) -#define cpu_to_be16(x) (x) - -#define be64_to_cpu(x) (x) -#define be32_to_cpu(x) (x) -#define be16_to_cpu(x) (x) - -#endif - -#endif From 509894cffb7ec24ac21a381bed3c035efce42aeb Mon Sep 17 00:00:00 2001 From: Manuel Kock Date: Mon, 11 Nov 2019 13:01:33 +0100 Subject: [PATCH 4/5] lantiq: remove redundant WiFi LED on FRITZ!Box 7320 The led wireless trigger is already set correctly to phy0tpt through the alias in the device tree. Signed-off-by: Manuel Kock [rephrased commit title] Signed-off-by: David Bauer --- target/linux/lantiq/base-files/etc/board.d/01_leds | 3 --- 1 file changed, 3 deletions(-) diff --git a/target/linux/lantiq/base-files/etc/board.d/01_leds b/target/linux/lantiq/base-files/etc/board.d/01_leds index 4476a7eb43..e89de97fbe 100755 --- a/target/linux/lantiq/base-files/etc/board.d/01_leds +++ b/target/linux/lantiq/base-files/etc/board.d/01_leds @@ -57,9 +57,6 @@ avm,fritz3370-rev2-hynix|\ avm,fritz3370-rev2-micron) ucidef_set_led_switch "lan" "LAN" "fritz3370:green:lan" "switch0" "0x17" ;; -avm,fritz7320) - ucidef_set_led_netdev "wifi" "wifi" "fritz7320:green:wlan" "wlan0" - ;; zyxel,p-2812hnu-f1|\ zyxel,p-2812hnu-f3) ucidef_set_led_wlan "wifi" "wifi" "p2812hnufx:green:wlan" "phy0radio" From b5791118ccd3039cc9ef6fd3b1c4efcad6ab154f Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Mon, 11 Nov 2019 19:03:20 +0100 Subject: [PATCH 5/5] ath79: fix SUPPORTED_DEVICES for TP-Link TL-WR1043ND v3 In ar71xx, the board name for the TL-WR1043ND v3 is equal to v2: tl-wr1043nd-v2 Fix SUPPORTED_DEVICES for v3 in ath79 accordingly. Signed-off-by: Adrian Schmutzler --- target/linux/ath79/image/generic-tp-link.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/linux/ath79/image/generic-tp-link.mk b/target/linux/ath79/image/generic-tp-link.mk index a2b112a5ec..114c20d3d5 100644 --- a/target/linux/ath79/image/generic-tp-link.mk +++ b/target/linux/ath79/image/generic-tp-link.mk @@ -424,7 +424,7 @@ define Device/tplink_tl-wr1043nd-v3 DEVICE_VARIANT := v3 DEVICE_PACKAGES := kmod-usb2 kmod-usb-ledtrig-usbport TPLINK_HWID := 0x10430003 - SUPPORTED_DEVICES += tl-wr1043nd-v3 + SUPPORTED_DEVICES += tl-wr1043nd-v2 endef TARGET_DEVICES += tplink_tl-wr1043nd-v3