Skip to content

Commit aa07e12

Browse files
committed
Use upgrade table for unavailable CMP data
1 parent 74f45fb commit aa07e12

File tree

3 files changed

+113
-243
lines changed

3 files changed

+113
-243
lines changed

tools/arm_pack_manager/__init__.py

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,10 @@
1616
limitations under the License.
1717
"""
1818

19-
try:
20-
from urllib2 import urlopen, URLError
21-
except ImportError:
22-
from urllib.request import urlopen, URLError
23-
from bs4 import BeautifulSoup
24-
from os.path import join, dirname, basename
25-
from os import makedirs
26-
from errno import EEXIST
27-
from threading import Thread
28-
try:
29-
from Queue import Queue
30-
except ImportError:
31-
from queue import Queue
32-
from re import compile, sub
33-
from sys import stderr, stdout
34-
from itertools import takewhile
35-
import argparse
36-
from json import dump, load
37-
from zipfile import ZipFile
38-
from tempfile import gettempdir
19+
from os.path import join, dirname
20+
from json import load, dump
3921
import warnings
4022
from cmsis_pack_manager import Cache as _Cache
41-
from distutils.version import LooseVersion
4223

4324
from tools.flash_algo import PackFlashAlgo
4425

@@ -49,40 +30,64 @@
4930
LocalPackDir = dirname(__file__)
5031
LocalPackIndex = join(LocalPackDir, "index.json")
5132
LocalPackAliases = join(LocalPackDir, "aliases.json")
33+
LocalPackLegacyNames = join(LocalPackDir, "legacy-names.json")
5234

5335

36+
class _CacheLookup(object):
37+
def __init__(self, index, legacy_names):
38+
self.index = index
39+
self.legacy_names = legacy_names
5440

55-
class Cache (_Cache):
41+
def __getitem__(self, name):
42+
try:
43+
return self.index[name]
44+
except KeyError:
45+
return self.index[self.legacy_names[name]]
46+
47+
def __contains__(self, name):
48+
return name in self.index or name in self.legacy_names
49+
50+
51+
class Cache(object):
5652
""" The Cache object is the only relevant API object at the moment
5753
5854
Constructing the Cache object does not imply any caching.
5955
A user of the API must explicitly call caching functions.
6056
61-
:param silent: A boolean that, when True, significantly reduces the printing of this Object
57+
:param silent: Not used
6258
:type silent: bool
63-
:param no_timeouts: A boolean that, when True, disables the default connection timeout and low speed timeout for downloading things.
59+
:param no_timeouts: Not used
6460
:type no_timeouts: bool
6561
"""
66-
def __init__ (self, silent, no_timeouts):
67-
super(Cache, self).__init__(
62+
def __init__(self, silent, no_timeouts):
63+
self._cache = _Cache(
6864
silent, no_timeouts,
6965
json_path=LocalPackDir, data_path=LocalPackDir
7066
)
67+
try:
68+
self._legacy_names = load(open(LocalPackLegacyNames))
69+
except IOError:
70+
self._legacy_names = {}
7171

7272
def _get_sectors(self, device):
7373
"""Extract sector sizes from device FLM algorithm
7474
75-
Will return None if there is no algorithm, pdsc URL formatted in correctly
75+
Will return None if there is no algorithm, pdsc URL formatted in
76+
correctly
7677
7778
:return: A list tuples of sector start and size
7879
:rtype: [list]
7980
"""
8081
try:
81-
pack = self.pack_from_cache(device)
82+
pack = self._cache.pack_from_cache(device)
8283
ret = []
8384
for algo in device['algorithms']:
8485
try:
85-
flm = pack.open(algo["file_name"].replace("\\\\", "/").replace("\\", "/"))
86+
flm = pack.open(
87+
algo["file_name"]
88+
.replace("\\\\", "/")
89+
.replace("\\", "/")
90+
)
8691
flash_alg = PackFlashAlgo(flm.read())
8792
sectors = [(flash_alg.flash_start + offset, size)
8893
for offset, size in flash_alg.sector_sizes]
@@ -97,14 +102,21 @@ def _get_sectors(self, device):
97102
print(e)
98103
return None
99104

105+
@property
106+
def index(self):
107+
return _CacheLookup(self._cache.index, self._legacy_names)
108+
109+
def cache_descriptors(self):
110+
self._cache.cache_descriptors
111+
100112
def cache_everything(self):
101-
super(Cache, self).cache_everything()
102-
for name, device in self.index.items():
113+
self._cache.cache_everything()
114+
for name, device in self._cache.index.items():
103115
if name != "version":
104116
device["sectors"] = self._get_sectors(device)
105117
self.generate_index()
106118

107-
def get_svd_file(self, device_name) :
119+
def get_svd_file(self, device_name):
108120
"""Retrieve the flash algorithm file for a particular part.
109121
110122
Assumes that both the PDSC and the PACK file associated with that part are in the cache.
@@ -120,5 +132,6 @@ def get_svd_file(self, device_name) :
120132

121133
def generate_index(self):
122134
with open(LocalPackIndex, "wb+") as out:
123-
self._index["version"] = "0.2.0"
124-
dump(self._index, out, indent=4, sort_keys=True)
135+
self._cache.index["version"] = "0.2.0"
136+
dump(self._cache.index, out, indent=4, sort_keys=True)
137+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"MK22DN512xxx5": "MK22FN512VLH5",
3+
"MK24FN1M0xxx12": "MK24FN1M0VLL12",
4+
"MKL26Z128xxx4": "MKL26Z128VLH4",
5+
"MKL27Z64xxx4": "MKL27Z64VLH4",
6+
"MKL43Z256xxx4": "MKL43Z256VLH4",
7+
"MKL46Z256xxx4": "MKL46Z256VLL4",
8+
"MKL82Z128xxx7": "MKL82Z128VLK7",
9+
"R7S72103": "R7S72100",
10+
"STM32F030R8": "STM32F030R8Tx",
11+
"STM32F031K6": "STM32F031K6Tx",
12+
"STM32F042K6": "STM32F042K6Tx",
13+
"STM32F051R8": "STM32F051R8Tx",
14+
"STM32F070RB": "STM32F070RBTx",
15+
"STM32F072RB": "STM32F072RBTx",
16+
"STM32F091RC": "STM32F091RCTx",
17+
"STM32F207ZG": "STM32F207ZGTx",
18+
"STM32F302R8": "STM32F302R8Tx",
19+
"STM32F303K8": "STM32F303K8Tx",
20+
"STM32F303RE": "STM32F303RETx",
21+
"STM32F303VC": "STM32F303VCTx",
22+
"STM32F303ZE": "STM32F303ZETx",
23+
"STM32F334C8": "STM32F334C8Tx",
24+
"STM32F334R8": "STM32F334R8Tx",
25+
"STM32F401RE": "STM32F401RETx",
26+
"STM32F401VC": "STM32F401VCTx",
27+
"STM32F401VE": "STM32F401VETx",
28+
"STM32F405RG": "STM32F405RGTx",
29+
"STM32F407VG": "STM32F407VGTx",
30+
"STM32F410RB": "STM32F410RBTx",
31+
"STM32F411RE": "STM32F411RETx",
32+
"STM32F412ZG": "STM32F412ZGTx",
33+
"STM32F413ZH": "STM32F413ZHTx",
34+
"STM32F429ZI": "STM32F429ZITx",
35+
"STM32F437VG": "STM32F437VGTx",
36+
"STM32F439VI": "STM32F439VITx",
37+
"STM32F439ZI": "STM32F439ZITx",
38+
"STM32F446RE": "STM32F446RETx",
39+
"STM32F446VE": "STM32F446VETx",
40+
"STM32F446ZE": "STM32F446ZETx",
41+
"STM32F469NI": "STM32F469NIHx",
42+
"STM32F746NG": "STM32F746NGHx",
43+
"STM32F746ZG": "STM32F746ZGTx",
44+
"STM32F756ZG": "STM32F756ZGTx",
45+
"STM32F767ZI": "STM32F767ZITx",
46+
"STM32F769NI": "STM32F769NIHx",
47+
"STM32L011K4": "STM32L011K4Tx",
48+
"STM32L031K6": "STM32L031K6Tx",
49+
"STM32L053C8": "STM32L053C8Tx",
50+
"STM32L053R8": "STM32L053R8Tx",
51+
"STM32L072CZ": "STM32L072CZTx",
52+
"STM32L073RZ": "STM32L073RZTx",
53+
"STM32L082CZ": "STM32L082CZYx",
54+
"STM32L432KC": "STM32L432KCUx",
55+
"STM32L433RC": "STM32L433RCTx",
56+
"STM32L443RC": "STM32L443RCTx",
57+
"STM32L471QG": "STM32L471QGIx",
58+
"STM32L475VG": "STM32L475VGTx",
59+
"STM32L476JG": "STM32L476JGYx",
60+
"STM32L476RG": "STM32L476RGTx",
61+
"STM32L476VG": "STM32L476VGTx",
62+
"STM32L486RG": "STM32L486RGTx",
63+
"STM32L496AG": "STM32L496AGIx",
64+
"STM32L496ZG": "STM32L496ZGTx",
65+
"STM32L4R5ZI": "STM32L4R5ZITx"
66+
}

0 commit comments

Comments
 (0)