sbtools: convert crypto to libtomcrypt.

Replace the use of crypto++ with tomcrypt, which is much smaller and C.
This gets rid of various build issues for systems that don't ship
crypo++ (i.e. everything except Linux.)

Change-Id: Ic0799e17b94935c71b14765cf9a2a7ea2b0adc7a
This commit is contained in:
Dominik Riebeling 2020-08-08 18:46:43 +02:00
parent 815b289cb3
commit 2037b837f8
6 changed files with 50 additions and 64 deletions

View file

@ -8,24 +8,18 @@
# We use the SB code available in the Rockbox utils/sbtools directory
IMXTOOLS_DIR=../../utils/imxtools/sbtools/
CFLAGS += -I$(IMXTOOLS_DIR) -Wall
COMPILEFLAGS := -Wall -g -O3 -I$(IMXTOOLS_DIR)
# std=gnu99 is required by MinGW on Windows (c99 is sufficient for Linux / MXE)
CFLAGS += -std=gnu99 -g -O3
CFLAGS += -std=gnu99 $(COMPILEFLAGS)
CXXFLAGS += $(COMPILEFLAGS)
# Location to pkg-config binary.
PKGCONFIG := pkg-config
TOMCRYPT_DIR := ../../utils/tomcrypt
# Distros could use different names for the crypto library. We try a list
# of candidate names, only one of them should be the valid one.
LIBCRYPTO_NAMES = libcryptopp libcrypto++ cryptopp crypto++
$(foreach l,$(LIBCRYPTO_NAMES),\
$(eval LDOPTS += $(shell $(PKGCONFIG) --silence-errors --libs $(l))))
$(foreach l,$(LIBCRYPTO_NAMES),\
$(eval CFLAGS += $(shell $(PKGCONFIG) --silence-errors --cflags $(l))))
$(foreach l,$(LIBCRYPTO_NAMES),\
$(eval CXXFLAGS += $(shell $(PKGCONFIG) --silence-errors --cflags $(l))))
LDOPTS += -lpthread
CXXFLAGS += -I$(TOMCRYPT_DIR)/src/headers
CFLAGS += -I$(TOMCRYPT_DIR)/src/headers
LDOPTS += -lpthread $(TOMCRYPT_DIR)/librbtomcrypt.a
OUTPUT = mkimxboot
@ -33,6 +27,10 @@ OUTPUT = mkimxboot
IMXTOOLS_SOURCES = misc.c sb.c crypto.cpp crc.c elf.c
LIBSOURCES := dualboot.c mkimxboot.c md5.c \
$(addprefix $(IMXTOOLS_DIR),$(IMXTOOLS_SOURCES))
# for now build tomcrypt as part of the lib.
LIBSOURCES += $(addprefix $(TOMCRYPT_DIR),$(TOMCRYPT_SOURCES))
# inputs for binary only
SOURCES := $(LIBSOURCES) main.c
# dependencies for binary
@ -43,3 +41,8 @@ include ../libtools.make
# explicit dependencies on dualboot.{c,h} and mkimxboot.h
$(OBJDIR)mkimxboot.o: dualboot.h dualboot.c mkimxboot.c mkimxboot.h
$(OBJDIR)main.o: dualboot.h dualboot.c main.c mkimxboot.h
$(BINARY): librbtomcrypt.a
librbtomcrypt.a:
$(MAKE) -C ../../utils/tomcrypt

View file

@ -33,12 +33,14 @@ export CC=$(EXTRALIBS_CC)
export CXX=$(EXTRALIBS_CXX)
export AR=$(EXTRALIBS_AR)
libs: librbspeex libucl libipodpatcher libsansapatcher libmkamsboot libmktccboot libmkmpioboot libchinachippatcher libmkimxboot libmks5lboot libbzip2 libbspatch
libs: librbspeex libucl libipodpatcher libsansapatcher libmkamsboot libmktccboot libmkmpioboot libchinachippatcher libmkimxboot libmks5lboot libbzip2 libbspatch librbtomcrypt
# To support cross compiles, we explicitly pass the CC flag below for
# all tools which override CC or CXX in their makefiles. CXX is only
# used by mkimxboot.
librbtomcrypt:
$(SILENT) $(MAKE) -C $(RBBASE_DIR)/utils/tomcrypt BUILD_DIR=$(BUILD_DIR)/tomcrypt librbtomcrypt.a
librbspeex:
$(SILENT) $(MAKE) -C $(RBBASE_DIR)/tools/rbspeex BUILD_DIR=$(BUILD_DIR)/libspeex librbspeex.a

View file

@ -85,7 +85,8 @@ extralibs.commands = $$SILENT \
# Note: order is important for RBLIBS! The libs are appended to the linker
# flags in this order, put libucl at the end.
RBLIBS = rbspeex ipodpatcher sansapatcher mkamsboot mktccboot \
mkmpioboot chinachippatcher mkimxboot mks5lboot bspatch ucl
mkmpioboot chinachippatcher mkimxboot mks5lboot bspatch ucl \
rbtomcrypt
# NOTE: Linking bzip2 causes problems on Windows (Qt seems to export those
# symbols as well, similar to what we have with zlib.) Only link that on
# non-Windows for now.
@ -139,9 +140,6 @@ for(rblib, RBLIBS) {
LIBS += -l$$rblib
}
# We need libcrypto++
LIBS += -lcryptopp
# on win32 libz is linked implicitly.
!win32 {
LIBS += -lz