tools:fix xxd download not responding

This commit is contained in:
DHDAXCW 2022-11-01 14:35:34 +00:00
parent b30ad537e4
commit 446543a7e9
7 changed files with 90 additions and 26 deletions

View File

@ -58,6 +58,10 @@ menu "Global build settings"
bool "Enable signature checking in opkg"
default SIGNED_PACKAGES
config DOWNLOAD_CHECK_CERTIFICATE
bool "Enable TLS certificate verification during package download"
default y
comment "General build options"
config TESTING_KERNEL

View File

@ -192,7 +192,10 @@ $(STAGING_DIR_HOST)/bin/mkhash: $(SCRIPT_DIR)/mkhash.c
mkdir -p $(dir $@)
$(CC) -O2 -I$(TOPDIR)/tools/include -o $@ $<
prereq: $(STAGING_DIR_HOST)/bin/mkhash
$(STAGING_DIR_HOST)/bin/xxd: $(SCRIPT_DIR)/xxdi.pl
$(LN) $< $@
prereq: $(STAGING_DIR_HOST)/bin/mkhash $(STAGING_DIR_HOST)/bin/xxd
# Install ldconfig stub
$(eval $(call TestHostCommand,ldconfig-stub,Failed to install stub, \

View File

@ -265,7 +265,10 @@ TARGET_CC:=$(TARGET_CROSS)gcc
TARGET_CXX:=$(TARGET_CROSS)g++
KPATCH:=$(SCRIPT_DIR)/patch-kernel.sh
SED:=$(STAGING_DIR_HOST)/bin/sed -i -e
ESED:=$(STAGING_DIR_HOST)/bin/sed -E -i -e
ESED:=$(STAGING_DIR_HOST)/bin/sed -E -i -e.
# DOWNLOAD_CHECK_CERTIFICATE is used in /scripts, so we export it here.
DOWNLOAD_CHECK_CERTIFICATE:=$(CONFIG_DOWNLOAD_CHECK_CERTIFICATE)
export DOWNLOAD_CHECK_CERTIFICATE
CP:=cp -fpR
LN:=ln -sf
XARGS:=xargs -r

View File

@ -24,6 +24,8 @@ my $scriptdir = dirname($0);
my @mirrors;
my $ok;
my $check_certificate = $ENV{DOWNLOAD_CHECK_CERTIFICATE} eq "y";
$url_filename or $url_filename = $filename;
sub localmirrors {
@ -74,7 +76,7 @@ sub download_cmd($) {
my $url = shift;
my $have_curl = 0;
if (open CURL, '-|', 'curl', '--version') {
if (open CURL, "curl --version 2>/dev/null |") {
if (defined(my $line = readline CURL)) {
$have_curl = 1 if $line =~ /^curl /;
}
@ -82,8 +84,14 @@ sub download_cmd($) {
}
return $have_curl
? (qw(curl -f --connect-timeout 20 --retry 5 --location --insecure), shellwords($ENV{CURL_OPTIONS} || ''), $url)
: (qw(wget --tries=5 --timeout=20 --no-check-certificate --output-document=-), shellwords($ENV{WGET_OPTIONS} || ''), $url)
? (qw(curl -f --connect-timeout 20 --retry 5 --location),
$check_certificate ? () : '--insecure',
shellwords($ENV{CURL_OPTIONS} || ''),
$url)
: (qw(wget --tries=5 --timeout=20 --output-document=-),
$check_certificate ? () : '--no-check-certificate',
shellwords($ENV{WGET_OPTIONS} || ''),
$url)
;
}
@ -291,4 +299,3 @@ while (!-f "$target/$filename") {
}
$SIG{INT} = \&cleanup;

66
scripts/xxdi.pl Normal file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env perl
#
# xxdi.pl - perl implementation of 'xxd -i' mode
#
# Copyright 2013 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
# Copyright 2013 Linux Foundation
#
# Released under the GPLv2.
#
# Implements the "basic" functionality of 'xxd -i' in perl to keep build
# systems from having to build/install/rely on vim-core, which not all
# distros want to do. But everyone has perl, so use it instead.
#
use strict;
use warnings;
my $indata;
my $var_name = "stdin";
my $full_output = (@ARGV > 0 && $ARGV[0] eq '-i') ? shift @ARGV : undef;
{
local $/;
my $fh;
if (@ARGV) {
$var_name = $ARGV[0];
open($fh, '<:raw', $var_name) || die("xxdi.pl: Unable to open $var_name: $!\n");
} elsif (! -t STDIN) {
$fh = \*STDIN;
undef $full_output;
} else {
die "usage: xxdi.pl [-i] [infile]\n";
}
$indata = readline $fh;
close $fh;
}
my $len_data = length($indata);
my $num_digits_per_line = 12;
my $outdata = "";
# Use the variable name of the file we read from, converting '/' and '.
# to '_', or, if this is stdin, just use "stdin" as the name.
$var_name =~ s/\//_/g;
$var_name =~ s/\./_/g;
$var_name = "__$var_name" if $var_name =~ /^\d/;
$outdata = "unsigned char $var_name\[] = { " if $full_output;
for (my $key= 0; $key < $len_data; $key++) {
if ($key % $num_digits_per_line == 0) {
$outdata = substr($outdata, 0, -1)."\n ";
}
$outdata .= sprintf("0x%.2x, ", ord(substr($indata, $key, 1)));
}
$outdata = substr($outdata, 0, -2);
$outdata .= "\n";
$outdata .= "};\nunsigned int $var_name\_len = $len_data;\n" if $full_output;
binmode STDOUT;
print $outdata;

View File

@ -25,7 +25,7 @@ tools-y += autoconf autoconf-archive automake bc bison cmake dosfstools
tools-y += e2fsprogs fakeroot findutils firmware-utils flex gengetopt
tools-y += libressl libtool lzma m4 make-ext4fs missing-macros mkimage
tools-y += mklibs mm-macros mtd-utils mtools padjffs2 patch-image
tools-y += patchelf pkgconf quilt squashfskit4 sstrip xxd zip zlib zstd
tools-y += patchelf pkgconf quilt squashfskit4 sstrip zip zlib zstd
tools-$(BUILD_B43_TOOLS) += b43-tools
tools-$(BUILD_ISL) += isl
tools-$(BUILD_TOOLCHAIN) += expat gmp libelf mpc mpfr

View File

@ -1,19 +0,0 @@
# SPDX-License-Identifier: GPL-2.0-or-later
include $(TOPDIR)/rules.mk
PKG_NAME:=xxd
PKG_VERSION:=1.10
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://grail.cba.csuohio.edu/~somos/
PKG_HASH:=9bf05c19b9084973e3cc877696a7f9881a5c87fa5a9fa438d9962519726559f9
PKG_CPE_ID:=cpe:/a:vim:vim
include $(INCLUDE_DIR)/host-build.mk
define Host/Install
$(INSTALL_DIR) $(STAGING_DIR_HOST)/bin
$(INSTALL_BIN) $(HOST_BUILD_DIR)/xxd $(STAGING_DIR_HOST)/bin/
endef
$(eval $(call HostBuild))