Skip to content

Commit 89cd3db

Browse files
authored
Merge pull request #21813 from crasbe/pr/cryptocell_use_dlcache
pkg/{c25519,driver_cryptocell_310}: use dlcache for fetching zip archives, update `pkg/Makefile.http` example
2 parents f3a5da8 + a30ce22 commit 89cd3db

File tree

7 files changed

+65
-47
lines changed

7 files changed

+65
-47
lines changed

Makefile.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ ifeq (,$(and $(DOWNLOAD_TO_STDOUT),$(DOWNLOAD_TO_FILE)))
352352
DOWNLOAD_TO_STDOUT ?= $(if $(CURL),$(CURL) -s,$(WGET) -q -O-)
353353
endif
354354
ifeq (,$(DOWNLOAD_TO_FILE))
355-
DOWNLOAD_TO_FILE ?= $(if $(WGET),$(WGET) -nv -c -O,$(CURL) -s -o)
355+
DOWNLOAD_TO_FILE ?= $(DLCACHE)
356356
endif
357357
endif
358358

dist/tools/dlcache/README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
# Introduction
22

3-
This script aims to cache http(s)-downloads
3+
This script aims to cache http(s)-downloads of (mainly) zip archives.
44

55
## How it works
66

7-
- if a file with the right name and md5 exists, nothing happens
8-
- if a file with the right name and md5 is in cache, use that
9-
- if a file with the right name but wrong md5 is in cache, redownload
7+
- if a file with the right name and SHA512 exists, nothing happens
8+
- if a file with the right name and SHA512 is in cache, use that
9+
- if a file with the right name but wrong SHA512 is in cache, redownload
1010
download to cache
11-
- after download, check md5, then copy to target
11+
- after download, check SHA512, then copy to target
12+
- if no SHA512 checksum is given, always redownload
13+
14+
## Usage
15+
16+
In order to stay compatible with the `$(DOWNLOAD_TO_FILE)` command,
17+
the command usage was changed for Release 2025.10.
18+
19+
If no SHA512 checksum was given, the file will *always* be downloaded,
20+
regardless of whether it is in the cache or not.
21+
22+
```sh
23+
dist/tools/dlcache/dlcache.sh <output_folder> <URL> [SHA512 checksum]
24+
```

dist/tools/dlcache/dlcache.sh

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ if [ "$(uname)" = Darwin ]; then
1313
local lockfile="$1"
1414
shift
1515

16-
while ! shlock -p $$ -f $lockfile; do
16+
while ! shlock -p "$$" -f "$lockfile"; do
1717
sleep 0.2
1818
done
1919

20-
$*
20+
"$@"
2121

22-
rm $lockfile
22+
rm "$lockfile"
2323
}
2424
else
2525
_locked() {
@@ -28,58 +28,57 @@ else
2828

2929
(
3030
flock -w 600 9 || exit 1
31-
$*
31+
"$@"
3232
) 9>"$lockfile"
3333
}
3434
fi
3535

36-
if [ "$(uname)" = Darwin ]; then
37-
MD5="md5 -r"
38-
else
39-
MD5=md5sum
40-
fi
36+
# shasum is supported on Linux and Darwin
37+
SHA512="shasum -a 512"
4138

42-
calcmd5() {
39+
calcsha512() {
4340
local file="$1"
44-
local md5="$2"
41+
local sha512="$2"
42+
local file_sha512
43+
file_sha512=$(${SHA512} "$file" | cut -d\ -f1)
4544

46-
local file_md5=$(${MD5} "$file" | cut -d\ -f1)
47-
48-
test "$md5" = "$file_md5"
45+
test "$sha512" = "$file_sha512"
4946
}
5047

5148
downloader() {
5249
if [ -n "$(command -v wget)" ]; then
53-
wget -nv "$1" -O $2
50+
wget -nv "$1" -O "$2"
5451
elif [ -n "$(command -v curl)" ]; then
55-
curl -L $1 -o $2
52+
curl -L "$1" -o "$2"
5653
else
5754
_echo "$0: neither wget nor curl available!"
5855
return 1
5956
fi
6057
}
6158

6259
download() {
63-
local url="$1"
64-
local _md5="$2"
65-
local basename_url=$(basename ${url})
66-
local target="${3:-${basename_url}}"
67-
68-
[ -f "$target" ] && {
69-
# if our target file exists, check it's md5.
70-
calcmd5 "$target" "$_md5" && {
71-
_echo "$0: target exists, md5 matches."
60+
local url="$2"
61+
local _sha512="$3"
62+
local basename_url
63+
basename_url="$(basename "${url}")"
64+
local target="${1:-"${basename_url}"}"
65+
66+
if [ -f "$target" ] && [ -n "$_sha512" ]; then
67+
# if our target file exists and an SHA512 sum was given, check it's SHA512
68+
calcsha512 "$target" "$_sha512" && {
69+
_echo "$0: target exists, SHA512 matches."
7270
exit 0
7371
}
74-
}
72+
fi
7573

76-
local filename="$(basename $url)"
74+
local filename
75+
filename="$(basename "$url")"
7776
[ -f "$DLCACHE_DIR/$filename" ] && {
78-
# if the file exists in cache, check it's md5 and possibly remove it.
79-
if calcmd5 "$DLCACHE_DIR/$filename" "$_md5"; then
77+
# if the file exists in cache, check it's SHA512 and possibly remove it.
78+
if calcsha512 "$DLCACHE_DIR/$filename" "$_sha512"; then
8079
_echo "$0: getting \"$url\" from cache"
8180
else
82-
_echo "$0: \"$DLCACHE_DIR/$filename\" has wrong checksum, re-downloading"
81+
_echo "$0: \"$DLCACHE_DIR/$filename\" has wrong or no checksum, re-downloading"
8382
rm "$DLCACHE_DIR/$filename"
8483
fi
8584
}
@@ -93,10 +92,13 @@ download() {
9392
_echo "$0: done downloading \"$url\""
9493
}
9594

96-
calcmd5 "$DLCACHE_DIR/$filename" "$_md5" || {
97-
_echo "$0: checksum mismatch!"
98-
exit 1
99-
}
95+
# only try to calculate the checksum if a checksum was given
96+
if [ -n "$_sha512" ]; then
97+
calcsha512 "$DLCACHE_DIR/$filename" "$_sha512" || {
98+
_echo "$0: checksum mismatch!"
99+
exit 1
100+
}
101+
fi
100102

101103
if [ "$target" = "-" ]; then
102104
cat "$DLCACHE_DIR/$filename"
@@ -105,4 +107,4 @@ download() {
105107
fi
106108
}
107109

108-
_locked "$DLCACHE_DIR/$(basename $1).locked" download "$@"
110+
_locked "$DLCACHE_DIR/$(basename "$1").locked" download "$@"

makefiles/mcuboot.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SIGN_BINFILE = $(BINDIR)/signed-$(APPLICATION).bin
88
MCUBOOT_KEYFILE ?= $(BINDIR)/key.pem
99
MCUBOOT_BIN ?= $(BINDIR)/mcuboot.bin
1010
MCUBOOT_BIN_URL ?= http://download.riot-os.org/mynewt.mcuboot.bin
11-
MCUBOOT_BIN_MD5 ?= 0c71a0589bd3709fc2d90f07a0035ce7
11+
MCUBOOT_BIN_SHA512 ?=
1212

1313
export IMAGE_HDR_SIZE ?= 512
1414

@@ -37,7 +37,7 @@ mcuboot: mcuboot-create-key link
3737
@$(COLOR_ECHO)
3838

3939
$(MCUBOOT_BIN):
40-
$(Q)$(DLCACHE) $(MCUBOOT_BIN_URL) $(MCUBOOT_BIN_MD5) $@
40+
$(Q)$(DLCACHE) $@ $(MCUBOOT_BIN_URL) $(MCUBOOT_BIN_SHA512)
4141

4242
.PHONY: mcuboot-flash-bootloader mcuboot-flash
4343

pkg/Makefile.http

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PKG_URL = http://example.com/downloads # source url of the package e.g. a gi
33
PKG_VERSION = v1.2.3 # version of the package to use e.g. a git commit/ref
44
PKG_EXT = zip # extension of this package
55
PKG_LICENSE = MIT # license of the package
6+
PKG_SHA512 = 5bcc4310f09ea247f5b65d63afae872fb92bb5c39029f336d94503fe04feccfcd22aa42b377b0927ab7f0a19111fd5a0a6842ecab147761c8f218f7f115e0da5 # SHA512 checksum of the package
67

78
ifneq ($(RIOTBASE),)
89
include $(RIOTBASE)/Makefile.base
@@ -30,7 +31,9 @@ $(CURDIR)/$(PKG_NAME)-$(PKG_VERSION)/: $(CURDIR)/$(PKG_NAME)-$(PKG_VERSION).$(PK
3031

3132
$(CURDIR)/$(PKG_NAME)-$(PKG_VERSION).$(PKG_EXT):
3233
# Get PKG_VERSION of package from PKG_URL
33-
$(Q)$(DOWNLOAD_TO_FILE) $@ $(PKG_URL)/$(PKG_NAME)-$(PKG_VERSION).$(PKG_EXT)
34+
$(Q)$(DOWNLOAD_TO_FILE) $@ $(PKG_URL)/$(PKG_NAME)-$(PKG_VERSION).$(PKG_EXT) $(PKG_SHA512)
35+
# Note: Since Release 2025.10, DOWNLOAD_TO_FILE uses dlcache and
36+
# requires an SHA512 checksum for caching!
3437

3538
clean::
3639
# Reset package to checkout state.

pkg/c25519/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $(PKG_SOURCE_DIR)/: $(PKG_ZIPFILE)
2626

2727
$(PKG_ZIPFILE):
2828
$(QQ)mkdir -p $(PKGDIRBASE)
29-
$(Q)$(DOWNLOAD_TO_FILE) $@ $(PKG_ZIP_URL)
29+
$(Q)$(DOWNLOAD_TO_FILE) $@ $(PKG_ZIP_URL) $(PKG_SHA512)
3030

3131
clean::
3232
# Reset package to checkout state.

pkg/driver_cryptocell_310/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ PKG_ZIP_URL = $(PKG_URL)/$(PKG_DIR_NAME)_$(PKG_VERSION).$(PKG_EXT)
1515
NRF_CC310_PATH = external/nrf_cc310
1616

1717
ifneq ($(RIOTBASE),)
18-
include $(RIOTBASE)/Makefile.base
18+
include $(RIOTBASE)/Makefile.base
1919
endif
2020

2121
.PHONY: all clean distclean
@@ -34,7 +34,7 @@ $(PKG_SOURCE_DIR)/: $(PKG_ZIPFILE)
3434

3535
$(PKG_ZIPFILE):
3636
$(QQ)mkdir -p $(PKGDIRBASE)
37-
$(Q)$(DOWNLOAD_TO_FILE) $@ $(PKG_ZIP_URL)
37+
$(Q)$(DOWNLOAD_TO_FILE) $@ $(PKG_ZIP_URL) $(PKG_SHA512)
3838

3939
clean::
4040
rm -rf $(PKG_SOURCE_DIR)

0 commit comments

Comments
 (0)