Skip to content

Commit c8299ac

Browse files
Merge pull request #46198 from advaitjain:cmsis-download-script
PiperOrigin-RevId: 350661648 Change-Id: I010cddd3da50d9cd728d0c64a5eee33b856de32c
2 parents 4dde394 + e24b61c commit c8299ac

10 files changed

Lines changed: 152 additions & 32 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
17+
18+
# Compute the MD5 sum.
19+
#
20+
# Parameter(s):
21+
# ${1} - path to the file
22+
function compute_md5() {
23+
UNAME_S=`uname -s`
24+
if [ ${UNAME_S} == Linux ]; then
25+
tflm_md5sum=md5sum
26+
elif [ ${UNAME_S} == Darwin ]; then
27+
tflm_md5sum='md5 -r'
28+
fi
29+
${tflm_md5sum} ${1} | awk '{print $1}'
30+
}
31+
32+
# Check that MD5 sum matches expected value.
33+
#
34+
# Parameter(s):
35+
# ${1} - path to the file
36+
# ${2} - expected md5
37+
function check_md5() {
38+
MD5=`compute_md5 ${1}`
39+
40+
if [[ ${MD5} != ${2} ]]
41+
then
42+
echo "Bad checksum. Expected: ${2}, Got: ${MD5}"
43+
exit 1
44+
fi
45+
46+
}
47+
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
# ==============================================================================
16+
#
17+
# Called with following arguments:
18+
# 1 - Path to the downloads folder which is typically
19+
# tensorflow/lite/micro/tools/make/downloads
20+
#
21+
# This script is called from the Makefile and uses the following convention to
22+
# enable determination of sucess/failure:
23+
#
24+
# - If the script is successful, the only output on stdout should be SUCCESS.
25+
# The makefile checks for this particular string.
26+
#
27+
# - Any string on stdout that is not SUCCESS will be shown in the makefile as
28+
# the cause for the script to have failed.
29+
#
30+
# - Any other informational prints should be on stderr.
31+
32+
set -e
33+
34+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
35+
ROOT_DIR=${SCRIPT_DIR}/../../../../../..
36+
cd "${ROOT_DIR}"
37+
38+
source tensorflow/lite/micro/tools/make/bash_helpers.sh
39+
40+
DOWNLOADS_DIR=${1}
41+
if [ ! -d ${DOWNLOADS_DIR} ]; then
42+
echo "The top-level downloads directory: ${DOWNLOADS_DIR} does not exist."
43+
exit 1
44+
fi
45+
46+
DOWNLOADED_CMSIS_PATH=${DOWNLOADS_DIR}/cmsis
47+
48+
if [ -d ${DOWNLOADED_CMSIS_PATH} ]; then
49+
echo >&2 "${DOWNLOADED_CMSIS_PATH} already exists, skipping the download."
50+
else
51+
52+
ZIP_PREFIX="01f5b32badf7b78c85a24a7149b56400fa6a2999"
53+
CMSIS_URL="http://github.com/ARM-software/CMSIS_5/archive/${ZIP_PREFIX}.zip"
54+
CMSIS_MD5="823916c6f1749c65fd0bfdeec20b30ed"
55+
56+
# wget is much faster than git clone of the entire repo. So we wget a specific
57+
# version and can then apply a patch, as needed.
58+
wget ${CMSIS_URL} -O /tmp/${ZIP_PREFIX}.zip >&2
59+
check_md5 /tmp/${ZIP_PREFIX}.zip ${CMSIS_MD5}
60+
61+
unzip -qo /tmp/${ZIP_PREFIX}.zip -d /tmp >&2
62+
mv /tmp/CMSIS_5-${ZIP_PREFIX} ${DOWNLOADED_CMSIS_PATH}
63+
fi
64+
65+
echo "SUCCESS"

‎tensorflow/lite/micro/tools/make/ext_libs/cmsis_nn.inc‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ ifneq ($(filter cmsis-nn,$(ALL_TAGS)),)
55
endif
66

77
ifneq ($(DISABLE_DOWNLOADS), true)
8-
# Setup CMSIS-NN lib and add required header files to microlite lib INCLUDE.
9-
# Unless an external path is provided we force a download during the first phase of make so
10-
# that the files exist prior to the call to recursive_find below. add_third_party_download
11-
# prevents the use of wildcards and recursive_find in selecting which files to add to THIRD_PARTY_SRCS.
8+
# Unless an external path is provided we force a download during the first
9+
# phase of make.
1210
CMSIS_DEFAULT_DOWNLOAD_PATH := $(MAKEFILE_DIR)/downloads/cmsis
1311
CMSIS_PATH := $(CMSIS_DEFAULT_DOWNLOAD_PATH)
1412
ifeq ($(CMSIS_PATH), $(CMSIS_DEFAULT_DOWNLOAD_PATH))
15-
$(call $(or $(shell $(DOWNLOAD_SCRIPT) $(CMSIS_URL) $(CMSIS_MD5) $(CMSIS_PATH) >&2 && echo SUCCESS), $(error $(DOWNLOAD_SCRIPT) failed)))
13+
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/ext_libs/cmsis_download.sh ${MAKEFILE_DIR}/downloads)
14+
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
15+
$(error Something went wrong with the CMSIS download: $(DOWNLOAD_RESULT))
16+
endif
1617
endif
1718
endif
1819

‎tensorflow/lite/micro/tools/make/ext_libs/ethosu.inc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ ifneq ($(filter ethos-u,$(ALL_TAGS)),)
3131
CMSIS_DEFAULT_DOWNLOAD_PATH := $(MAKEFILE_DIR)/downloads/cmsis
3232
CMSIS_PATH := $(CMSIS_DEFAULT_DOWNLOAD_PATH)
3333
ifeq ($(CMSIS_PATH), $(CMSIS_DEFAULT_DOWNLOAD_PATH))
34-
$(eval $(call add_third_party_download,$(CMSIS_URL),$(CMSIS_MD5),cmsis,))
34+
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/ext_libs/cmsis_download.sh ${MAKEFILE_DIR}/downloads)
35+
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
36+
$(error Something went wrong with the CMSIS download: $(DOWNLOAD_RESULT))
37+
endif
3538
endif
39+
3640
THIRD_PARTY_CC_HDRS += $(CMSIS_PATH)/CMSIS/Core/Include/cmsis_compiler.h
3741

3842
INCLUDES += -I$(ETHOSU_DRIVER_PATH)/include \

‎tensorflow/lite/micro/tools/make/flatbuffers_download.sh‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
set -e
3333

34+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
35+
ROOT_DIR=${SCRIPT_DIR}/../../../../..
36+
cd "${ROOT_DIR}"
37+
38+
source tensorflow/lite/micro/tools/make/bash_helpers.sh
39+
3440
DOWNLOADS_DIR=${1}
3541
if [ ! -d ${DOWNLOADS_DIR} ]; then
3642
echo "The top-level downloads directory: ${DOWNLOADS_DIR} does not exist."
@@ -88,26 +94,13 @@ else
8894
FLATBUFFERS_MD5="aa9adc93eb9b33fa1a2a90969e48baee"
8995

9096
wget ${FLATBUFFERS_URL} -O /tmp/${ZIP_PREFIX}.zip >&2
91-
92-
if ! command -v md5sum &> /dev/null
93-
then
94-
MD5=`md5 -r /tmp/${ZIP_PREFIX}.zip | awk '{print $1}'`
95-
else
96-
MD5=`md5sum /tmp/${ZIP_PREFIX}.zip | awk '{print $1}'`
97-
fi
98-
99-
if [[ ${MD5} != ${FLATBUFFERS_MD5} ]]
100-
then
101-
echo "Bad checksum. Expected: ${FLATBUFFERS_MD5}, Got: ${MD5}"
102-
exit 1
103-
fi
97+
check_md5 /tmp/${ZIP_PREFIX}.zip ${FLATBUFFERS_MD5}
10498

10599
unzip -qo /tmp/${ZIP_PREFIX}.zip -d /tmp >&2
106100
mv /tmp/flatbuffers-${ZIP_PREFIX} ${DOWNLOADED_FLATBUFFERS_PATH}
107101

108102
patch_to_avoid_strtod ${DOWNLOADED_FLATBUFFERS_PATH}/include/flatbuffers/flexbuffers.h
109103
delete_build_files ${DOWNLOADED_FLATBUFFERS_PATH}
110-
111104
fi
112105

113106
echo "SUCCESS"

‎tensorflow/lite/micro/tools/make/renode_download.sh‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131

3232
set -e
3333

34+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
35+
ROOT_DIR=${SCRIPT_DIR}/../../../../..
36+
cd "${ROOT_DIR}"
37+
38+
source tensorflow/lite/micro/tools/make/bash_helpers.sh
39+
3440
DOWNLOADS_DIR=${1}
3541
if [ ! -d ${DOWNLOADS_DIR} ]; then
3642
echo "The top-level downloads directory: ${DOWNLOADS_DIR} does not exist."
@@ -73,12 +79,7 @@ else
7379
wget ${LINUX_PORTABLE_URL} -O ${TEMP_ARCHIVE} >&2
7480

7581
EXPECTED_MD5="8415361f5caa843f1e31b59c50b2858f"
76-
MD5=`md5sum ${TEMP_ARCHIVE} | awk '{print $1}'`
77-
if [[ ${MD5} != ${EXPECTED_MD5} ]]
78-
then
79-
echo "Bad checksum. Expected: ${EXPECTED_MD5}, Got: ${MD5}"
80-
exit 1
81-
fi
82+
check_md5 ${TEMP_ARCHIVE} ${EXPECTED_MD5}
8283

8384
mkdir ${DOWNLOADED_RENODE_PATH}
8485
tar xzf ${TEMP_ARCHIVE} --strip-components=1 --directory "${DOWNLOADED_RENODE_PATH}" >&2

‎tensorflow/lite/micro/tools/make/targets/apollo3evb_makefile.inc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ APOLLO3_SDK := $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST)
1010
GCC_ARM := $(MAKEFILE_DIR)/downloads/gcc_embedded/
1111

1212
$(eval $(call add_third_party_download,$(GCC_EMBEDDED_URL),$(GCC_EMBEDDED_MD5),gcc_embedded,))
13-
$(eval $(call add_third_party_download,$(CMSIS_URL),$(CMSIS_MD5),cmsis,))
1413
$(eval $(call add_third_party_download,$(AM_SDK_URL),$(AM_SDK_MD5),$(AM_SDK_DEST),patch_am_sdk))
1514

15+
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/ext_libs/cmsis_download.sh ${MAKEFILE_DIR}/downloads)
16+
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
17+
$(error Something went wrong with the CMSIS download: $(DOWNLOAD_RESULT))
18+
endif
19+
1620
ifeq ($(findstring sparkfun,$(TARGET)), sparkfun)
1721
$(eval $(call add_third_party_download,$(SF_BSPS_URL),$(SF_BSPS_MD5),$(AM_SDK_DEST)/$(SF_BSPS_DEST),))
1822
# Make sure that we download the full Ambiq SDK before the SparkFun BSPs.

‎tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ TARGET_ARCH := cortex-m3
33
TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
44

55
$(eval $(call add_third_party_download,$(GCC_EMBEDDED_URL),$(GCC_EMBEDDED_MD5),gcc_embedded,))
6-
$(eval $(call add_third_party_download,$(CMSIS_URL),$(CMSIS_MD5),cmsis,))
76
$(eval $(call add_third_party_download,$(STM32_BARE_LIB_URL),$(STM32_BARE_LIB_MD5),stm32_bare_lib,))
87

98
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/renode_download.sh ${MAKEFILE_DIR}/downloads)
109
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
1110
$(error Something went wrong with the renode download: $(DOWNLOAD_RESULT))
1211
endif
1312

13+
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/ext_libs/cmsis_download.sh ${MAKEFILE_DIR}/downloads)
14+
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
15+
$(error Something went wrong with the CMSIS download: $(DOWNLOAD_RESULT))
16+
endif
17+
1418
PLATFORM_FLAGS = \
1519
-DTF_LITE_MCU_DEBUG_LOG \
1620
-mcpu=cortex-m3 \

‎tensorflow/lite/micro/tools/make/targets/stm32f4_makefile.inc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
66
TARGET_TOOLCHAIN_ROOT := $(TENSORFLOW_ROOT)$(MAKEFILE_DIR)/downloads/gcc_embedded/bin/
77

88
$(eval $(call add_third_party_download,$(GCC_EMBEDDED_URL),$(GCC_EMBEDDED_MD5),gcc_embedded,))
9-
$(eval $(call add_third_party_download,$(CMSIS_URL),$(CMSIS_MD5),cmsis,))
109
$(eval $(call add_third_party_download,$(STM32_BARE_LIB_URL),$(STM32_BARE_LIB_MD5),stm32_bare_lib,))
1110

1211
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/renode_download.sh ${MAKEFILE_DIR}/downloads)
1312
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
1413
$(error Something went wrong with the renode download: $(DOWNLOAD_RESULT))
1514
endif
1615

16+
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/ext_libs/cmsis_download.sh ${MAKEFILE_DIR}/downloads)
17+
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
18+
$(error Something went wrong with the CMSIS download: $(DOWNLOAD_RESULT))
19+
endif
20+
1721
# TODO(b/161478030) : change - Wno - vla to - Wvla and remove - Wno-shadow once
1822
# we have a solution for fixing / avoiding being tripped up by these warnings.
1923
PLATFORM_FLAGS = \

‎tensorflow/lite/micro/tools/make/third_party_downloads.inc‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ LEON_BCC2_MD5 := "cdf78082be4882da2a92c9baa82fe765"
2525
TSIM_URL := "http://mirror.tensorflow.org/www.gaisler.com/anonftp/tsim/tsim-eval-2.0.63.tar.gz"
2626
TSIM_MD5 := "afa0095d3ed989a949e1467f94e41d2f"
2727
28-
CMSIS_URL := "http://github.com/ARM-software/CMSIS_5/archive/01f5b32badf7b78c85a24a7149b56400fa6a2999.zip"
29-
CMSIS_MD5 := "823916c6f1749c65fd0bfdeec20b30ed"
30-
3128
AM_SDK_URL := "http://mirror.tensorflow.org/s3.asia.ambiqmicro.com/downloads/AmbiqSuite-Rel2.2.0.zip"
3229
AM_SDK_MD5 := "7605fa2d4d97e6bb7a1190c92b66b597"
3330
AM_SDK_DEST := AmbiqSuite-Rel2.2.0

0 commit comments

Comments
 (0)