mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 04:04:31 +02:00
Tools: fix architecture armhf/armel detection
This commit is contained in:
committed by
Anton Maklakov
parent
7d010d36c8
commit
1edf376060
@@ -105,54 +105,84 @@ PLATFORM_LINUX_ARMHF = 'linux-armhf'
|
|||||||
PLATFORM_LINUX_ARM64 = 'linux-arm64'
|
PLATFORM_LINUX_ARM64 = 'linux-arm64'
|
||||||
|
|
||||||
|
|
||||||
# Mappings from various other names these platforms are known as, to the identifiers above.
|
class Platforms:
|
||||||
# This includes strings produced from "platform.system() + '-' + platform.machine()", see PYTHON_PLATFORM
|
# Mappings from various other names these platforms are known as, to the identifiers above.
|
||||||
# definition above.
|
# This includes strings produced from "platform.system() + '-' + platform.machine()", see PYTHON_PLATFORM
|
||||||
# This list also includes various strings used in release archives of xtensa-esp32-elf-gcc, OpenOCD, etc.
|
# definition above.
|
||||||
PLATFORM_FROM_NAME = {
|
# This list also includes various strings used in release archives of xtensa-esp32-elf-gcc, OpenOCD, etc.
|
||||||
# Windows
|
PLATFORM_FROM_NAME = {
|
||||||
PLATFORM_WIN32: PLATFORM_WIN32,
|
# Windows
|
||||||
'Windows-i686': PLATFORM_WIN32,
|
PLATFORM_WIN32: PLATFORM_WIN32,
|
||||||
'Windows-x86': PLATFORM_WIN32,
|
'Windows-i686': PLATFORM_WIN32,
|
||||||
'i686-w64-mingw32': PLATFORM_WIN32,
|
'Windows-x86': PLATFORM_WIN32,
|
||||||
PLATFORM_WIN64: PLATFORM_WIN64,
|
'i686-w64-mingw32': PLATFORM_WIN32,
|
||||||
'Windows-x86_64': PLATFORM_WIN64,
|
PLATFORM_WIN64: PLATFORM_WIN64,
|
||||||
'Windows-AMD64': PLATFORM_WIN64,
|
'Windows-x86_64': PLATFORM_WIN64,
|
||||||
'x86_64-w64-mingw32': PLATFORM_WIN64,
|
'Windows-AMD64': PLATFORM_WIN64,
|
||||||
# macOS
|
'x86_64-w64-mingw32': PLATFORM_WIN64,
|
||||||
PLATFORM_MACOS: PLATFORM_MACOS,
|
# macOS
|
||||||
'osx': PLATFORM_MACOS,
|
PLATFORM_MACOS: PLATFORM_MACOS,
|
||||||
'darwin': PLATFORM_MACOS,
|
'osx': PLATFORM_MACOS,
|
||||||
'Darwin-x86_64': PLATFORM_MACOS,
|
'darwin': PLATFORM_MACOS,
|
||||||
PLATFORM_MACOS_ARM64: PLATFORM_MACOS_ARM64,
|
'Darwin-x86_64': PLATFORM_MACOS,
|
||||||
'Darwin-arm64': PLATFORM_MACOS_ARM64,
|
PLATFORM_MACOS_ARM64: PLATFORM_MACOS_ARM64,
|
||||||
# Linux
|
'Darwin-arm64': PLATFORM_MACOS_ARM64,
|
||||||
PLATFORM_LINUX64: PLATFORM_LINUX64,
|
# Linux
|
||||||
'linux64': PLATFORM_LINUX64,
|
PLATFORM_LINUX64: PLATFORM_LINUX64,
|
||||||
'Linux-x86_64': PLATFORM_LINUX64,
|
'linux64': PLATFORM_LINUX64,
|
||||||
'FreeBSD-amd64': PLATFORM_LINUX64,
|
'Linux-x86_64': PLATFORM_LINUX64,
|
||||||
'x86_64-linux-gnu': PLATFORM_LINUX64,
|
'FreeBSD-amd64': PLATFORM_LINUX64,
|
||||||
PLATFORM_LINUX32: PLATFORM_LINUX32,
|
'x86_64-linux-gnu': PLATFORM_LINUX64,
|
||||||
'linux32': PLATFORM_LINUX32,
|
PLATFORM_LINUX32: PLATFORM_LINUX32,
|
||||||
'Linux-i686': PLATFORM_LINUX32,
|
'linux32': PLATFORM_LINUX32,
|
||||||
'FreeBSD-i386': PLATFORM_LINUX32,
|
'Linux-i686': PLATFORM_LINUX32,
|
||||||
'i586-linux-gnu': PLATFORM_LINUX32,
|
'FreeBSD-i386': PLATFORM_LINUX32,
|
||||||
# armhf must be before armel to avoid mismatching
|
'i586-linux-gnu': PLATFORM_LINUX32,
|
||||||
PLATFORM_LINUX_ARMHF: PLATFORM_LINUX_ARMHF,
|
PLATFORM_LINUX_ARM64: PLATFORM_LINUX_ARM64,
|
||||||
'arm-linux-gnueabihf': PLATFORM_LINUX_ARMHF,
|
'Linux-arm64': PLATFORM_LINUX_ARM64,
|
||||||
PLATFORM_LINUX_ARM32: PLATFORM_LINUX_ARM32,
|
'Linux-aarch64': PLATFORM_LINUX_ARM64,
|
||||||
'Linux-arm': PLATFORM_LINUX_ARM32,
|
'Linux-armv8l': PLATFORM_LINUX_ARM64,
|
||||||
'Linux-armv7l': PLATFORM_LINUX_ARM32,
|
'aarch64': PLATFORM_LINUX_ARM64,
|
||||||
'arm-linux-gnueabi': PLATFORM_LINUX_ARM32,
|
PLATFORM_LINUX_ARMHF: PLATFORM_LINUX_ARMHF,
|
||||||
PLATFORM_LINUX_ARM64: PLATFORM_LINUX_ARM64,
|
'arm-linux-gnueabihf': PLATFORM_LINUX_ARMHF,
|
||||||
'Linux-arm64': PLATFORM_LINUX_ARM64,
|
PLATFORM_LINUX_ARM32: PLATFORM_LINUX_ARM32,
|
||||||
'Linux-aarch64': PLATFORM_LINUX_ARM64,
|
'arm-linux-gnueabi': PLATFORM_LINUX_ARM32,
|
||||||
'Linux-armv8l': PLATFORM_LINUX_ARM64,
|
'Linux-armv7l': PLATFORM_LINUX_ARM32,
|
||||||
'aarch64': PLATFORM_LINUX_ARM64,
|
'Linux-arm': PLATFORM_LINUX_ARM32,
|
||||||
}
|
}
|
||||||
|
|
||||||
UNKNOWN_PLATFORM = 'unknown'
|
@staticmethod
|
||||||
CURRENT_PLATFORM = PLATFORM_FROM_NAME.get(PYTHON_PLATFORM, UNKNOWN_PLATFORM)
|
def get(platform_alias): # type: (Optional[str]) -> Optional[str]
|
||||||
|
if platform_alias is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
platform_name = Platforms.PLATFORM_FROM_NAME.get(platform_alias, None)
|
||||||
|
|
||||||
|
# ARM platform may run on armhf hardware but having armel installed packages.
|
||||||
|
# To avoid possible armel/armhf libraries mixing need to define user's
|
||||||
|
# packages architecture to use the same
|
||||||
|
# See note section in https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html#index-mfloat-abi
|
||||||
|
if platform_name in (PLATFORM_LINUX_ARM32, PLATFORM_LINUX_ARMHF) and 'arm' in platform.machine():
|
||||||
|
# suppose that installed python was built with a right ABI
|
||||||
|
with open(sys.executable, 'rb') as f:
|
||||||
|
if int.from_bytes(f.read(4), sys.byteorder) != int.from_bytes(b'\x7fELF', sys.byteorder):
|
||||||
|
return platform_name # ELF magic not found. Use default platform name from PLATFORM_FROM_NAME
|
||||||
|
f.seek(36) # seek to e_flags (https://man7.org/linux/man-pages/man5/elf.5.html)
|
||||||
|
e_flags = int.from_bytes(f.read(4), sys.byteorder)
|
||||||
|
platform_name = PLATFORM_LINUX_ARMHF if e_flags & 0x400 else PLATFORM_LINUX_ARM32
|
||||||
|
return platform_name
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_by_filename(file_name): # type: (str) -> Optional[str]
|
||||||
|
found_alias = ''
|
||||||
|
for platform_alias in Platforms.PLATFORM_FROM_NAME:
|
||||||
|
# Find the longest alias which matches with file name to avoid mismatching
|
||||||
|
if platform_alias in file_name and len(found_alias) < len(platform_alias):
|
||||||
|
found_alias = platform_alias
|
||||||
|
return Platforms.get(found_alias)
|
||||||
|
|
||||||
|
|
||||||
|
CURRENT_PLATFORM = Platforms.get(PYTHON_PLATFORM)
|
||||||
|
|
||||||
EXPORT_SHELL = 'shell'
|
EXPORT_SHELL = 'shell'
|
||||||
EXPORT_KEY_VALUE = 'key-value'
|
EXPORT_KEY_VALUE = 'key-value'
|
||||||
@@ -501,17 +531,16 @@ class IDFToolVersion(object):
|
|||||||
def add_download(self, platform_name, url, size, sha256): # type: (str, str, int, str) -> None
|
def add_download(self, platform_name, url, size, sha256): # type: (str, str, int, str) -> None
|
||||||
self.downloads[platform_name] = IDFToolDownload(platform_name, url, size, sha256)
|
self.downloads[platform_name] = IDFToolDownload(platform_name, url, size, sha256)
|
||||||
|
|
||||||
def get_download_for_platform(self, platform_name): # type: (str) -> Optional[IDFToolDownload]
|
def get_download_for_platform(self, platform_name): # type: (Optional[str]) -> Optional[IDFToolDownload]
|
||||||
if platform_name in PLATFORM_FROM_NAME.keys():
|
platform_name = Platforms.get(platform_name)
|
||||||
platform_name = PLATFORM_FROM_NAME[platform_name]
|
if platform_name and platform_name in self.downloads.keys():
|
||||||
if platform_name in self.downloads.keys():
|
|
||||||
return self.downloads[platform_name]
|
return self.downloads[platform_name]
|
||||||
if 'any' in self.downloads.keys():
|
if 'any' in self.downloads.keys():
|
||||||
return self.downloads['any']
|
return self.downloads['any']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def compatible_with_platform(self, platform_name=PYTHON_PLATFORM):
|
def compatible_with_platform(self, platform_name=PYTHON_PLATFORM):
|
||||||
# type: (str) -> bool
|
# type: (Optional[str]) -> bool
|
||||||
return self.get_download_for_platform(platform_name) is not None
|
return self.get_download_for_platform(platform_name) is not None
|
||||||
|
|
||||||
def get_supported_platforms(self): # type: () -> set[str]
|
def get_supported_platforms(self): # type: () -> set[str]
|
||||||
@@ -563,7 +592,7 @@ class IDFTool(object):
|
|||||||
def _update_current_options(self): # type: () -> None
|
def _update_current_options(self): # type: () -> None
|
||||||
self._current_options = IDFToolOptions(*self.options)
|
self._current_options = IDFToolOptions(*self.options)
|
||||||
for override in self.platform_overrides:
|
for override in self.platform_overrides:
|
||||||
if self._platform not in override['platforms']:
|
if self._platform and self._platform not in override['platforms']:
|
||||||
continue
|
continue
|
||||||
override_dict = override.copy()
|
override_dict = override.copy()
|
||||||
del override_dict['platforms']
|
del override_dict['platforms']
|
||||||
@@ -891,7 +920,7 @@ class IDFTool(object):
|
|||||||
for platform_id, platform_dict in version_dict.items(): # type: ignore
|
for platform_id, platform_dict in version_dict.items(): # type: ignore
|
||||||
if platform_id in ['name', 'status']:
|
if platform_id in ['name', 'status']:
|
||||||
continue
|
continue
|
||||||
if platform_id not in PLATFORM_FROM_NAME.keys():
|
if Platforms.get(platform_id) is None:
|
||||||
raise RuntimeError('invalid platform %s for tool %s version %s' %
|
raise RuntimeError('invalid platform %s for tool %s version %s' %
|
||||||
(platform_id, tool_name, version))
|
(platform_id, tool_name, version))
|
||||||
|
|
||||||
@@ -1379,10 +1408,10 @@ def action_download(args): # type: ignore
|
|||||||
if 'required' in tools_spec:
|
if 'required' in tools_spec:
|
||||||
targets = clean_targets(args.targets)
|
targets = clean_targets(args.targets)
|
||||||
|
|
||||||
if args.platform not in PLATFORM_FROM_NAME:
|
platform = Platforms.get(args.platform)
|
||||||
|
if platform is None:
|
||||||
fatal('unknown platform: {}' % args.platform)
|
fatal('unknown platform: {}' % args.platform)
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
platform = PLATFORM_FROM_NAME[args.platform]
|
|
||||||
|
|
||||||
tools_info_for_platform = OrderedDict()
|
tools_info_for_platform = OrderedDict()
|
||||||
for name, tool_obj in tools_info.items():
|
for name, tool_obj in tools_info.items():
|
||||||
@@ -1421,12 +1450,12 @@ def action_download(args): # type: ignore
|
|||||||
if tool_version is None:
|
if tool_version is None:
|
||||||
tool_version = tool_obj.get_recommended_version()
|
tool_version = tool_obj.get_recommended_version()
|
||||||
if tool_version is None:
|
if tool_version is None:
|
||||||
fatal('tool {} not found for {} platform'.format(tool_name, platform))
|
fatal('tool {} not found for {} platform'.format(tool_name, args.platform))
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
tool_spec = '{}@{}'.format(tool_name, tool_version)
|
tool_spec = '{}@{}'.format(tool_name, tool_version)
|
||||||
|
|
||||||
info('Downloading {}'.format(tool_spec))
|
info('Downloading {}'.format(tool_spec))
|
||||||
apply_url_mirrors(args, tool_obj.versions[tool_version].get_download_for_platform(platform))
|
apply_url_mirrors(args, tool_obj.versions[tool_version].get_download_for_platform(args.platform))
|
||||||
|
|
||||||
tool_obj.download(tool_version)
|
tool_obj.download(tool_version)
|
||||||
|
|
||||||
@@ -1688,11 +1717,7 @@ def action_add_version(args): # type: ignore
|
|||||||
checksum_info = ChecksumFileParser(tool_name, args.checksum_file) if args.checksum_file else ChecksumCalculator(args.artifact_file)
|
checksum_info = ChecksumFileParser(tool_name, args.checksum_file) if args.checksum_file else ChecksumCalculator(args.artifact_file)
|
||||||
for file_size, file_sha256, file_name in checksum_info:
|
for file_size, file_sha256, file_name in checksum_info:
|
||||||
# Guess which platform this file is for
|
# Guess which platform this file is for
|
||||||
found_platform = None
|
found_platform = Platforms.get_by_filename(file_name)
|
||||||
for platform_alias, platform_id in PLATFORM_FROM_NAME.items():
|
|
||||||
if platform_alias in file_name:
|
|
||||||
found_platform = platform_id
|
|
||||||
break
|
|
||||||
if found_platform is None:
|
if found_platform is None:
|
||||||
info('Could not guess platform for file {}'.format(file_name))
|
info('Could not guess platform for file {}'.format(file_name))
|
||||||
found_platform = TODO_MESSAGE
|
found_platform = TODO_MESSAGE
|
||||||
@@ -1933,7 +1958,7 @@ def main(argv): # type: (list[str]) -> None
|
|||||||
'Please set IDF_TOOLS_PATH to a directory with an ASCII name, or switch to Python 3.')
|
'Please set IDF_TOOLS_PATH to a directory with an ASCII name, or switch to Python 3.')
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
if CURRENT_PLATFORM == UNKNOWN_PLATFORM:
|
if CURRENT_PLATFORM is None:
|
||||||
fatal('Platform {} appears to be unsupported'.format(PYTHON_PLATFORM))
|
fatal('Platform {} appears to be unsupported'.format(PYTHON_PLATFORM))
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
@@ -391,6 +391,11 @@
|
|||||||
"size": 8033639,
|
"size": 8033639,
|
||||||
"url": "https://github.com/espressif/binutils-esp32ulp/releases/download/v2.28.51-esp-20191205/binutils-esp32ulp-linux-armel-2.28.51-esp-20191205.tar.gz"
|
"url": "https://github.com/espressif/binutils-esp32ulp/releases/download/v2.28.51-esp-20191205/binutils-esp32ulp-linux-armel-2.28.51-esp-20191205.tar.gz"
|
||||||
},
|
},
|
||||||
|
"linux-armhf": {
|
||||||
|
"sha256": "88967c086a6e71834282d9ae05841ee74dae1815f27807b25cdd3f7775a47101",
|
||||||
|
"size": 8033639,
|
||||||
|
"url": "https://github.com/espressif/binutils-esp32ulp/releases/download/v2.28.51-esp-20191205/binutils-esp32ulp-linux-armel-2.28.51-esp-20191205.tar.gz"
|
||||||
|
},
|
||||||
"macos": {
|
"macos": {
|
||||||
"sha256": "a35d9e7a0445247c7fc9dccd3fbc35682f0fafc28beeb10c94b59466317190c4",
|
"sha256": "a35d9e7a0445247c7fc9dccd3fbc35682f0fafc28beeb10c94b59466317190c4",
|
||||||
"size": 8872874,
|
"size": 8872874,
|
||||||
@@ -459,6 +464,11 @@
|
|||||||
"size": 8034624,
|
"size": 8034624,
|
||||||
"url": "https://github.com/espressif/binutils-esp32ulp/releases/download/v2.28.51-esp-20191205/binutils-esp32s2ulp-linux-armel-2.28.51-esp-20191205.tar.gz"
|
"url": "https://github.com/espressif/binutils-esp32ulp/releases/download/v2.28.51-esp-20191205/binutils-esp32s2ulp-linux-armel-2.28.51-esp-20191205.tar.gz"
|
||||||
},
|
},
|
||||||
|
"linux-armhf": {
|
||||||
|
"sha256": "893b213c8f716d455a6efb2b08b6cf1bc34d08b78ee19c31e82ac44b1b45417e",
|
||||||
|
"size": 8034624,
|
||||||
|
"url": "https://github.com/espressif/binutils-esp32ulp/releases/download/v2.28.51-esp-20191205/binutils-esp32s2ulp-linux-armel-2.28.51-esp-20191205.tar.gz"
|
||||||
|
},
|
||||||
"macos": {
|
"macos": {
|
||||||
"sha256": "5a9bb678a5246638cbda303f523d9bb8121a9a24dc01ecb22c21c46c41184155",
|
"sha256": "5a9bb678a5246638cbda303f523d9bb8121a9a24dc01ecb22c21c46c41184155",
|
||||||
"size": 8876194,
|
"size": 8876194,
|
||||||
@@ -544,6 +554,11 @@
|
|||||||
"size": 19330381,
|
"size": 19330381,
|
||||||
"url": "https://dl.espressif.com/dl/cmake/cmake-3.23.1-Linux-armv7l.tar.gz"
|
"url": "https://dl.espressif.com/dl/cmake/cmake-3.23.1-Linux-armv7l.tar.gz"
|
||||||
},
|
},
|
||||||
|
"linux-armhf": {
|
||||||
|
"sha256": "aa6079237e16cc3b389479b2f7279d07e57f6aedad520e2b3014ef97fb906466",
|
||||||
|
"size": 19330381,
|
||||||
|
"url": "https://dl.espressif.com/dl/cmake/cmake-3.23.1-Linux-armv7l.tar.gz"
|
||||||
|
},
|
||||||
"macos": {
|
"macos": {
|
||||||
"sha256": "f794ed92ccb4e9b6619a77328f313497d7decf8fb7e047ba35a348b838e0e1e2",
|
"sha256": "f794ed92ccb4e9b6619a77328f313497d7decf8fb7e047ba35a348b838e0e1e2",
|
||||||
"size": 70988516,
|
"size": 70988516,
|
||||||
|
Reference in New Issue
Block a user