Import Mbed OS hard-float snapshot
This commit is contained in:
178
tools/arm_pack_manager/__init__.py
Normal file
178
tools/arm_pack_manager/__init__.py
Normal file
@@ -0,0 +1,178 @@
|
||||
"""
|
||||
Copyright (c) 2016-2019 ARM Limited. All rights reserved.
|
||||
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
from os.path import join, dirname
|
||||
from json import load, dump
|
||||
import warnings
|
||||
|
||||
try:
|
||||
from cmsis_pack_manager import Cache as _Cache
|
||||
_CPM_PRESENT = True
|
||||
except (ImportError, OSError):
|
||||
_CPM_PRESENT = False
|
||||
|
||||
from tools.flash_algo import PackFlashAlgo
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
RootPackURL = "http://www.keil.com/pack/index.idx"
|
||||
|
||||
LocalPackDir = dirname(__file__)
|
||||
LocalPackIndex = join(LocalPackDir, "index.json")
|
||||
LocalPackAliases = join(LocalPackDir, "aliases.json")
|
||||
LocalPackLegacyNames = join(LocalPackDir, "legacy-names.json")
|
||||
|
||||
|
||||
class _CacheLookup(object):
|
||||
def __init__(self, index, legacy_names):
|
||||
self.index = index
|
||||
self.legacy_names = legacy_names
|
||||
|
||||
def __getitem__(self, name):
|
||||
try:
|
||||
return self.index[name]
|
||||
except KeyError:
|
||||
return self.index[self.legacy_names[name]]
|
||||
|
||||
def __contains__(self, name):
|
||||
return name in self.index or name in self.legacy_names
|
||||
|
||||
|
||||
class Cache(object):
|
||||
""" The Cache object is the only relevant API object at the moment
|
||||
|
||||
Constructing the Cache object does not imply any caching.
|
||||
A user of the API must explicitly call caching functions.
|
||||
|
||||
:param silent: Not used
|
||||
:type silent: bool
|
||||
:param no_timeouts: Not used
|
||||
:type no_timeouts: bool
|
||||
"""
|
||||
def __init__(self, silent, no_timeouts):
|
||||
if _CPM_PRESENT:
|
||||
self._cache = _Cache(
|
||||
silent, no_timeouts,
|
||||
json_path=LocalPackDir, data_path=LocalPackDir
|
||||
)
|
||||
else:
|
||||
self._cache = None
|
||||
|
||||
try:
|
||||
self._legacy_names = load(open(LocalPackLegacyNames))
|
||||
except IOError:
|
||||
self._legacy_names = {}
|
||||
|
||||
def _get_sectors(self, device):
|
||||
"""Extract sector sizes from device FLM algorithm
|
||||
|
||||
Will return None if there is no algorithm, pdsc URL formatted in
|
||||
correctly
|
||||
|
||||
:return: A list tuples of sector start and size
|
||||
:rtype: [list]
|
||||
"""
|
||||
try:
|
||||
pack = self._cache.pack_from_cache(device)
|
||||
ret = []
|
||||
for algo in device['algorithms']:
|
||||
try:
|
||||
flm = pack.open(
|
||||
algo["file_name"]
|
||||
.replace("\\\\", "/")
|
||||
.replace("\\", "/")
|
||||
)
|
||||
flash_alg = PackFlashAlgo(flm.read())
|
||||
sectors = [(flash_alg.flash_start + offset, size)
|
||||
for offset, size in flash_alg.sector_sizes]
|
||||
ret.extend(sectors)
|
||||
except Exception:
|
||||
pass
|
||||
ret.sort(key=lambda sector: sector[0])
|
||||
return ret
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
@property
|
||||
def index(self):
|
||||
if _CPM_PRESENT:
|
||||
return _CacheLookup(self._cache.index, self._legacy_names)
|
||||
else:
|
||||
local_index = load(open(LocalPackIndex))
|
||||
return _CacheLookup(local_index, self._legacy_names)
|
||||
|
||||
def cache_descriptors(self):
|
||||
if _CPM_PRESENT:
|
||||
return self._cache.cache_descriptors()
|
||||
else:
|
||||
print(
|
||||
'The Python package "cmsis-pack-manager" is not installed. '
|
||||
'To cache CMSIS Pack descriptors, please install this '
|
||||
'package with "pip install cmsis-pack-manager".'
|
||||
)
|
||||
return []
|
||||
|
||||
def cache_everything(self):
|
||||
if _CPM_PRESENT:
|
||||
self._cache.cache_everything()
|
||||
for name, device in self._cache.index.items():
|
||||
if name != "version":
|
||||
device["sectors"] = self._get_sectors(device)
|
||||
self.generate_index()
|
||||
else:
|
||||
print(
|
||||
'The Python package "cmsis-pack-manager" is not installed. '
|
||||
'To update the cache, please install this package with '
|
||||
'"pip install cmsis-pack-manager".'
|
||||
)
|
||||
|
||||
def get_svd_file(self, device_name):
|
||||
"""Retrieve the flash algorithm file for a particular part.
|
||||
|
||||
Assumes that both the PDSC and the PACK file associated with that part
|
||||
are in the cache.
|
||||
|
||||
:param device_name: The exact name of a device
|
||||
:type device_name: str
|
||||
:return: A file-like object that, when read, is the ELF file that
|
||||
describes the flashing algorithm
|
||||
:rtype: ZipExtFile
|
||||
"""
|
||||
if _CPM_PRESENT:
|
||||
device = self.index[device_name]
|
||||
pack = self._cache.pack_from_cache(device)
|
||||
return pack.open(device['debug'])
|
||||
else:
|
||||
print(
|
||||
'The Python package "cmsis-pack-manager" is not installed. '
|
||||
'To use SVD files, please install this package with '
|
||||
'"pip install cmsis-pack-manager".'
|
||||
)
|
||||
return None
|
||||
|
||||
def generate_index(self):
|
||||
if _CPM_PRESENT:
|
||||
with open(LocalPackIndex, "w+") as out:
|
||||
self._cache.index["version"] = "0.2.0"
|
||||
dump(self._cache.index, out, indent=4, sort_keys=True)
|
||||
else:
|
||||
print(
|
||||
'The Python package "cmsis-pack-manager" is not installed. '
|
||||
'To generate a CMSIS Pack index, please install this package with '
|
||||
'"pip install cmsis-pack-manager".'
|
||||
)
|
||||
1781
tools/arm_pack_manager/aliases.json
Normal file
1781
tools/arm_pack_manager/aliases.json
Normal file
File diff suppressed because it is too large
Load Diff
517369
tools/arm_pack_manager/index.json
Normal file
517369
tools/arm_pack_manager/index.json
Normal file
File diff suppressed because it is too large
Load Diff
69
tools/arm_pack_manager/legacy-names.json
Normal file
69
tools/arm_pack_manager/legacy-names.json
Normal file
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"MK22DN512xxx5": "MK22DN512VLH5",
|
||||
"MK24FN1M0xxx12": "MK24FN1M0VLL12",
|
||||
"MKL26Z128xxx4": "MKL26Z128VLH4",
|
||||
"MKL27Z64xxx4": "MKL27Z64VLH4",
|
||||
"MKL43Z256xxx4": "MKL43Z256VLH4",
|
||||
"MKL46Z256xxx4": "MKL46Z256VLL4",
|
||||
"MKL82Z128xxx7": "MKL82Z128VLK7",
|
||||
"R7S72103": "R7S72100",
|
||||
"STM32F030R8": "STM32F030R8Tx",
|
||||
"STM32F031K6": "STM32F031K6Tx",
|
||||
"STM32F042K6": "STM32F042K6Tx",
|
||||
"STM32F051R8": "STM32F051R8Tx",
|
||||
"STM32F070RB": "STM32F070RBTx",
|
||||
"STM32F072RB": "STM32F072RBTx",
|
||||
"STM32F091RC": "STM32F091RCTx",
|
||||
"STM32F207ZG": "STM32F207ZGTx",
|
||||
"STM32F302R8": "STM32F302R8Tx",
|
||||
"STM32F303K8": "STM32F303K8Tx",
|
||||
"STM32F303RE": "STM32F303RETx",
|
||||
"STM32F303VC": "STM32F303VCTx",
|
||||
"STM32F303ZE": "STM32F303ZETx",
|
||||
"STM32F334C8": "STM32F334C8Tx",
|
||||
"STM32F334R8": "STM32F334R8Tx",
|
||||
"STM32F401RE": "STM32F401RETx",
|
||||
"STM32F401VC": "STM32F401VCTx",
|
||||
"STM32F401VE": "STM32F401VETx",
|
||||
"STM32F405RG": "STM32F405RGTx",
|
||||
"STM32F407VG": "STM32F407VGTx",
|
||||
"STM32F407ZG": "STM32F407ZGTx",
|
||||
"STM32F410RB": "STM32F410RBTx",
|
||||
"STM32F411RE": "STM32F411RETx",
|
||||
"STM32F412ZG": "STM32F412ZGTx",
|
||||
"STM32F413ZH": "STM32F413ZHTx",
|
||||
"STM32F429ZI": "STM32F429ZITx",
|
||||
"STM32F437VG": "STM32F437VGTx",
|
||||
"STM32F439VI": "STM32F439VITx",
|
||||
"STM32F439ZI": "STM32F439ZITx",
|
||||
"STM32F446RE": "STM32F446RETx",
|
||||
"STM32F446VE": "STM32F446VETx",
|
||||
"STM32F446ZE": "STM32F446ZETx",
|
||||
"STM32F469NI": "STM32F469NIHx",
|
||||
"STM32F746NG": "STM32F746NGHx",
|
||||
"STM32F746ZG": "STM32F746ZGTx",
|
||||
"STM32F756ZG": "STM32F756ZGTx",
|
||||
"STM32F767VI": "STM32F767VITx",
|
||||
"STM32F767ZI": "STM32F767ZITx",
|
||||
"STM32F769NI": "STM32F769NIHx",
|
||||
"STM32H743ZI": "STM32H743ZITx",
|
||||
"STM32L011K4": "STM32L011K4Tx",
|
||||
"STM32L031K6": "STM32L031K6Tx",
|
||||
"STM32L053C8": "STM32L053C8Tx",
|
||||
"STM32L053R8": "STM32L053R8Tx",
|
||||
"STM32L072CZ": "STM32L072CZTx",
|
||||
"STM32L073RZ": "STM32L073RZTx",
|
||||
"STM32L082CZ": "STM32L082CZYx",
|
||||
"STM32L432KC": "STM32L432KCUx",
|
||||
"STM32L433RC": "STM32L433RCTx",
|
||||
"STM32L443RC": "STM32L443RCTx",
|
||||
"STM32L471QG": "STM32L471QGIx",
|
||||
"STM32L475VG": "STM32L475VGTx",
|
||||
"STM32L476JG": "STM32L476JGYx",
|
||||
"STM32L476RG": "STM32L476RGTx",
|
||||
"STM32L476VG": "STM32L476VGTx",
|
||||
"STM32L486RG": "STM32L486RGTx",
|
||||
"STM32L496AG": "STM32L496AGIx",
|
||||
"STM32L496ZG": "STM32L496ZGTx",
|
||||
"STM32L4R5ZI": "STM32L4R5ZITx"
|
||||
}
|
||||
Reference in New Issue
Block a user