From c90d42dcc6aee53a0743e913d56a33ff9e1e14f3 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sun, 3 Apr 2016 22:14:11 +0100 Subject: [PATCH] jz4670_tools: add usbboot tool, tweak Makefile and packtool Although the jz4740 contains a similar tool to usbboot, its command-line interface is not very useful, also it does not compile by default because it relies on some external code, and it contains code specific to some JZ4740 devices. Change-Id: I22688238d147e21fb0fd524466b333b6003d4ff1 --- utils/jz4760_tools/Makefile | 4 +- utils/jz4760_tools/packtools.cpp | 9 +- utils/jz4760_tools/usbboot.c | 349 +++++++++++++++++++++++++++++++ 3 files changed, 357 insertions(+), 5 deletions(-) create mode 100644 utils/jz4760_tools/usbboot.c diff --git a/utils/jz4760_tools/Makefile b/utils/jz4760_tools/Makefile index 847539e38c..f181fa5c70 100644 --- a/utils/jz4760_tools/Makefile +++ b/utils/jz4760_tools/Makefile @@ -2,9 +2,9 @@ DEFINES= CC?=gcc CXX?=g++ LD?=g++ -CFLAGS=-g -std=c99 -Wall $(DEFINES) -Ilib +CFLAGS=-g -std=c99 -Wall $(DEFINES) `pkg-config --cflags libusb-1.0` CXXFLAGS=-g -Wall $(DEFINES) -LDFLAGS= +LDFLAGS=`pkg-config --libs libusb-1.0` SRC=$(wildcard *.c) SRCXX=$(wildcard *.cpp) EXEC=$(SRC:.c=) $(SRCXX:.cpp=) diff --git a/utils/jz4760_tools/packtools.cpp b/utils/jz4760_tools/packtools.cpp index 6bd5ec0330..b594525978 100644 --- a/utils/jz4760_tools/packtools.cpp +++ b/utils/jz4760_tools/packtools.cpp @@ -96,6 +96,9 @@ const uint32_t jz4760_crc_key[256] = 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, }; +/* This table is generated programmatically: it contains two copies of a 172-bytes + * table. This table contains the lower 8-bit of the first 172 prime numbers: + * 2, 3, 5, 7, ..., 251(=0xfb), 257(=0x101 -> 0x01), ... */ const unsigned JZ4760_XOR_KEY_SIZE = 344; uint8_t jz4760_xor_key[JZ4760_XOR_KEY_SIZE] = { @@ -530,7 +533,7 @@ int descramble(int argc, char **argv) void usage() { - printf("usage: [--pack|--unpack|--descramble] \n"); + printf("usage: [--pack|--unpack|--descramble|--scramble] \n"); printf(" unpack options:\n"); printf(" -i Input file\n"); printf(" -o Output directory\n"); @@ -541,7 +544,7 @@ void usage() printf(" -m Machine flags\n"); printf(" -v Verbose output\n"); printf(" -t