Skip to content

Commit cd7abc0

Browse files
authored
Merge pull request #3996 from c1728p9/algo_generation
Check in algo generation code
2 parents 35a5612 + 424fd78 commit cd7abc0

File tree

8 files changed

+545
-0
lines changed

8 files changed

+545
-0
lines changed

targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/flash_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
// This file is automagically generated
2222

23+
#if DEVICE_FLASH
24+
2325
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
2426
static uint32_t FLASH_ALGO[] = {
2527
0xb5104935, 0x60084449, 0x21004834, 0x48356001, 0x44484a33, 0x22016002, 0x04926041, 0x02926082,
@@ -99,3 +101,5 @@ void flash_set_target_config(flash_t *obj)
99101
obj->flash_algo = &flash_algo_config;
100102
obj->target_config = &flash_target_config;
101103
}
104+
105+
#endif

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/flash_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
// This file is automagically generated
2222

23+
#if DEVICE_FLASH
24+
2325
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
2426
static uint32_t FLASH_ALGO[] = {
2527
0xb5104938, 0x60084449, 0xf24c4837, 0x81c15120, 0x1128f64d, 0x880181c1, 0x0101f021, 0x48348001,
@@ -85,3 +87,5 @@ void flash_set_target_config(flash_t *obj)
8587
obj->flash_algo = &flash_algo_config;
8688
obj->target_config = &flash_target_config;
8789
}
90+
91+
#endif

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F429xI/device/flash_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
// This file is automagically generated
2222

23+
#if DEVICE_FLASH
24+
2325
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
2426
static uint32_t FLASH_ALGO[] = {
2527
0xf3c04601, 0x28203007, 0x2204bf24, 0x1050eb02, 0x2810d205, 0x2203bf26, 0x1010eb02, 0xf4110880,
@@ -72,3 +74,5 @@ void flash_set_target_config(flash_t *obj)
7274
obj->flash_algo = &flash_algo_config;
7375
obj->target_config = &flash_target_config;
7476
}
77+
78+
#endif

targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F439xI/device/flash_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
// This file is automagically generated
2222

23+
#if DEVICE_FLASH
24+
2325
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
2426
static uint32_t FLASH_ALGO[] = {
2527
0xf3c04601, 0x28203007, 0x2204bf24, 0x1050eb02, 0x2810d205, 0x2203bf26, 0x1010eb02, 0xf4110880,
@@ -72,3 +74,5 @@ void flash_set_target_config(flash_t *obj)
7274
obj->flash_algo = &flash_algo_config;
7375
obj->target_config = &flash_target_config;
7476
}
77+
78+
#endif

targets/TARGET_STM/TARGET_STM32F4/TARGET_UBLOX_EVK_ODIN_W2/flash_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
// This file is automagically generated
2222

23+
#if DEVICE_FLASH
24+
2325
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
2426
static uint32_t FLASH_ALGO[] = {
2527
0xf3c04601, 0x28203007, 0x2204bf24, 0x1050eb02, 0x2810d205, 0x2203bf26, 0x1010eb02, 0xf4110880,
@@ -72,3 +74,5 @@ void flash_set_target_config(flash_t *obj)
7274
obj->flash_algo = &flash_algo_config;
7375
obj->target_config = &flash_target_config;
7476
}
77+
78+
#endif

tools/flash_algo/c_blob_mbed.tmpl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
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+
#include "flash_api.h"
18+
#include "flash_data.h"
19+
#include "critical.h"
20+
21+
// This file is automagically generated
22+
23+
#if DEVICE_FLASH
24+
25+
// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
26+
static uint32_t FLASH_ALGO[] = {
27+
{{algo.format_algo_data(4, 8, "c")}}
28+
};
29+
30+
static const flash_algo_t flash_algo_config = {
31+
.init = {{'0x%x' % algo.symbols['Init']}},
32+
.uninit = {{'0x%x' % algo.symbols['UnInit']}},
33+
.erase_sector = {{'0x%x' % algo.symbols['EraseSector']}},
34+
.program_page = {{'0x%x' % algo.symbols['ProgramPage']}},
35+
.static_base = {{'0x%x' % algo.rw_start}},
36+
.algo_blob = FLASH_ALGO
37+
};
38+
39+
static const sector_info_t sectors_info[] = {
40+
{%- for start, size in algo.sector_sizes %}
41+
{{ "{0x%x, 0x%x}" % (start + algo.flash_start, size) }},
42+
{%- endfor %}
43+
};
44+
45+
static const flash_target_config_t flash_target_config = {
46+
.page_size = {{'0x%x' % algo.page_size}},
47+
.flash_start = {{'0x%x' % algo.flash_start}},
48+
.flash_size = {{'0x%x' % algo.flash_size}},
49+
.sectors = sectors_info,
50+
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
51+
};
52+
53+
void flash_set_target_config(flash_t *obj)
54+
{
55+
obj->flash_algo = &flash_algo_config;
56+
obj->target_config = &flash_target_config;
57+
}
58+
59+
#endif

tools/flash_algo/extract.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python
2+
"""
3+
mbed
4+
Copyright (c) 2017-2017 ARM Limited
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
19+
from __future__ import print_function
20+
import sys
21+
import os
22+
import argparse
23+
from os.path import join, abspath, dirname
24+
from flash_algo import PackFlashAlgo
25+
26+
# Be sure that the tools directory is in the search path
27+
ROOT = abspath(join(dirname(__file__), "..", ".."))
28+
sys.path.insert(0, ROOT)
29+
30+
from tools.targets import TARGETS
31+
from tools.arm_pack_manager import Cache
32+
33+
TEMPLATE_PATH = "c_blob_mbed.tmpl"
34+
35+
36+
def main():
37+
"""Generate flash algorithms"""
38+
parser = argparse.ArgumentParser(description='Flash generator')
39+
parser.add_argument("--rebuild_all", action="store_true",
40+
help="Rebuild entire cache")
41+
parser.add_argument("--rebuild_descriptors", action="store_true",
42+
help="Rebuild descriptors")
43+
parser.add_argument("--target", default=None,
44+
help="Name of target to generate algo for")
45+
parser.add_argument("--all", action="store_true",
46+
help="Build all flash algos for devcies")
47+
args = parser.parse_args()
48+
49+
cache = Cache(True, True)
50+
if args.rebuild_all:
51+
cache.cache_everything()
52+
print("Cache rebuilt")
53+
return
54+
55+
if args.rebuild_descriptors:
56+
cache.cache_descriptors()
57+
print("Descriptors rebuilt")
58+
return
59+
60+
if args.target is None:
61+
device_and_filenames = [(target.device_name, target.name) for target
62+
in TARGETS if hasattr(target, "device_name")]
63+
else:
64+
device_and_filenames = [(args.target, args.target.replace("/", "-"))]
65+
66+
try:
67+
os.mkdir("output")
68+
except OSError:
69+
# Directory already exists
70+
pass
71+
72+
for device, filename in device_and_filenames:
73+
dev = cache.index[device]
74+
binaries = cache.get_flash_algorthim_binary(device, all=True)
75+
algos = [PackFlashAlgo(binary.read()) for binary in binaries]
76+
filtered_algos = algos if args.all else filter_algos(dev, algos)
77+
for idx, algo in enumerate(filtered_algos):
78+
file_name = ("%s_%i.c" % (filename, idx)
79+
if args.all or len(filtered_algos) != 1
80+
else "%s.c" % filename)
81+
output_path = join("output", file_name)
82+
algo.process_template(TEMPLATE_PATH, output_path)
83+
print("%s: %s \r" % (device, filename))
84+
85+
86+
def filter_algos(dev, algos):
87+
if "memory" not in dev:
88+
return algos
89+
if "IROM1" not in dev["memory"]:
90+
return algos
91+
if "IROM2" in dev["memory"]:
92+
return algos
93+
94+
rom_rgn = dev["memory"]["IROM1"]
95+
try:
96+
start = int(rom_rgn["start"], 0)
97+
size = int(rom_rgn["size"], 0)
98+
except ValueError:
99+
return algos
100+
101+
matching_algos = [algo for algo in algos if
102+
algo.flash_start == start and algo.flash_size == size]
103+
return matching_algos if len(matching_algos) == 1 else algos
104+
105+
106+
if __name__ == '__main__':
107+
main()

0 commit comments

Comments
 (0)