Skip to content

Check in algo generation code #3996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions targets/TARGET_Freescale/TARGET_KLXX/TARGET_KL46Z/flash_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// This file is automagically generated

#if DEVICE_FLASH

// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
static uint32_t FLASH_ALGO[] = {
0xb5104935, 0x60084449, 0x21004834, 0x48356001, 0x44484a33, 0x22016002, 0x04926041, 0x02926082,
Expand Down Expand Up @@ -99,3 +101,5 @@ void flash_set_target_config(flash_t *obj)
obj->flash_algo = &flash_algo_config;
obj->target_config = &flash_target_config;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// This file is automagically generated

#if DEVICE_FLASH

// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
static uint32_t FLASH_ALGO[] = {
0xb5104938, 0x60084449, 0xf24c4837, 0x81c15120, 0x1128f64d, 0x880181c1, 0x0101f021, 0x48348001,
Expand Down Expand Up @@ -85,3 +87,5 @@ void flash_set_target_config(flash_t *obj)
obj->flash_algo = &flash_algo_config;
obj->target_config = &flash_target_config;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// This file is automagically generated

#if DEVICE_FLASH

// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
static uint32_t FLASH_ALGO[] = {
0xf3c04601, 0x28203007, 0x2204bf24, 0x1050eb02, 0x2810d205, 0x2203bf26, 0x1010eb02, 0xf4110880,
Expand Down Expand Up @@ -72,3 +74,5 @@ void flash_set_target_config(flash_t *obj)
obj->flash_algo = &flash_algo_config;
obj->target_config = &flash_target_config;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// This file is automagically generated

#if DEVICE_FLASH

// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
static uint32_t FLASH_ALGO[] = {
0xf3c04601, 0x28203007, 0x2204bf24, 0x1050eb02, 0x2810d205, 0x2203bf26, 0x1010eb02, 0xf4110880,
Expand Down Expand Up @@ -72,3 +74,5 @@ void flash_set_target_config(flash_t *obj)
obj->flash_algo = &flash_algo_config;
obj->target_config = &flash_target_config;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

// This file is automagically generated

#if DEVICE_FLASH

// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
static uint32_t FLASH_ALGO[] = {
0xf3c04601, 0x28203007, 0x2204bf24, 0x1050eb02, 0x2810d205, 0x2203bf26, 0x1010eb02, 0xf4110880,
Expand Down Expand Up @@ -72,3 +74,5 @@ void flash_set_target_config(flash_t *obj)
obj->flash_algo = &flash_algo_config;
obj->target_config = &flash_target_config;
}

#endif
59 changes: 59 additions & 0 deletions tools/flash_algo/c_blob_mbed.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* 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.
*/

#include "flash_api.h"
#include "flash_data.h"
#include "critical.h"

// This file is automagically generated

#if DEVICE_FLASH

// This is a flash algo binary blob. It is PIC (position independent code) that should be stored in RAM
static uint32_t FLASH_ALGO[] = {
{{algo.format_algo_data(4, 8, "c")}}
};

static const flash_algo_t flash_algo_config = {
.init = {{'0x%x' % algo.symbols['Init']}},
.uninit = {{'0x%x' % algo.symbols['UnInit']}},
.erase_sector = {{'0x%x' % algo.symbols['EraseSector']}},
.program_page = {{'0x%x' % algo.symbols['ProgramPage']}},
.static_base = {{'0x%x' % algo.rw_start}},
.algo_blob = FLASH_ALGO
};

static const sector_info_t sectors_info[] = {
{%- for start, size in algo.sector_sizes %}
{{ "{0x%x, 0x%x}" % (start + algo.flash_start, size) }},
{%- endfor %}
};

static const flash_target_config_t flash_target_config = {
.page_size = {{'0x%x' % algo.page_size}},
.flash_start = {{'0x%x' % algo.flash_start}},
.flash_size = {{'0x%x' % algo.flash_size}},
.sectors = sectors_info,
.sector_info_count = sizeof(sectors_info) / sizeof(sector_info_t)
};

void flash_set_target_config(flash_t *obj)
{
obj->flash_algo = &flash_algo_config;
obj->target_config = &flash_target_config;
}

#endif
107 changes: 107 additions & 0 deletions tools/flash_algo/extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python
"""
mbed
Copyright (c) 2017-2017 ARM Limited

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 __future__ import print_function
import sys
import os
import argparse
from os.path import join, abspath, dirname
from flash_algo import PackFlashAlgo

# Be sure that the tools directory is in the search path
ROOT = abspath(join(dirname(__file__), "..", ".."))
sys.path.insert(0, ROOT)

from tools.targets import TARGETS
from tools.arm_pack_manager import Cache

TEMPLATE_PATH = "c_blob_mbed.tmpl"


def main():
"""Generate flash algorithms"""
parser = argparse.ArgumentParser(description='Flash generator')
parser.add_argument("--rebuild_all", action="store_true",
help="Rebuild entire cache")
parser.add_argument("--rebuild_descriptors", action="store_true",
help="Rebuild descriptors")
parser.add_argument("--target", default=None,
help="Name of target to generate algo for")
parser.add_argument("--all", action="store_true",
help="Build all flash algos for devcies")
args = parser.parse_args()

cache = Cache(True, True)
if args.rebuild_all:
cache.cache_everything()
print("Cache rebuilt")
return

if args.rebuild_descriptors:
cache.cache_descriptors()
print("Descriptors rebuilt")
return

if args.target is None:
device_and_filenames = [(target.device_name, target.name) for target
in TARGETS if hasattr(target, "device_name")]
else:
device_and_filenames = [(args.target, args.target.replace("/", "-"))]

try:
os.mkdir("output")
except OSError:
# Directory already exists
pass

for device, filename in device_and_filenames:
dev = cache.index[device]
binaries = cache.get_flash_algorthim_binary(device, all=True)
algos = [PackFlashAlgo(binary.read()) for binary in binaries]
filtered_algos = algos if args.all else filter_algos(dev, algos)
for idx, algo in enumerate(filtered_algos):
file_name = ("%s_%i.c" % (filename, idx)
if args.all or len(filtered_algos) != 1
else "%s.c" % filename)
output_path = join("output", file_name)
algo.process_template(TEMPLATE_PATH, output_path)
print("%s: %s \r" % (device, filename))


def filter_algos(dev, algos):
if "memory" not in dev:
return algos
if "IROM1" not in dev["memory"]:
return algos
if "IROM2" in dev["memory"]:
return algos

rom_rgn = dev["memory"]["IROM1"]
try:
start = int(rom_rgn["start"], 0)
size = int(rom_rgn["size"], 0)
except ValueError:
return algos

matching_algos = [algo for algo in algos if
algo.flash_start == start and algo.flash_size == size]
return matching_algos if len(matching_algos) == 1 else algos


if __name__ == '__main__':
main()
Loading