Python script to add cmsis/rtx changes in mbed-os

pull/5407/head
deepikabhavnani 2017-10-30 16:57:28 -05:00
parent 1566395323
commit 021caa6dcf
3 changed files with 301 additions and 0 deletions

6
tools/importer/README.md Normal file
View File

@ -0,0 +1,6 @@
## Porting CMSIS/RTX Code in Mbed OS
This directory contains scripts to import latest CMSIS/RTX code into mbed-os local repository.
CMSIS/RTX fixes and new releases are imported into mbed-os on regular basis using the `cmsis_importer.py` python script input to which is `cmsis_importer.json`
Verify the files and path in `cmsis_importer.json`

View File

@ -0,0 +1,143 @@
import os, json, stat, sys, shutil, errno, subprocess
from os.path import dirname, abspath, basename, join
ROOT = abspath(join(dirname(__file__), "../.."))
CMSIS_REPO = "CMSIS_Repo"
CMSIS_PATH = abspath(join(dirname(__file__), CMSIS_REPO))
RTOS_UPDATE_BRANCH = "rtos_update"
def del_file(name):
result = []
search_path = [join(ROOT, 'rtos'), join(ROOT, 'cmsis')]
for path in search_path:
for root, dirs, files in os.walk(path):
if name in files:
result.append(os.path.join(root, name))
for file in result:
print os.path.relpath(file, ROOT)
os.remove(file)
def rmtree(top):
for root, dirs, files in os.walk(top, topdown=False):
for name in files:
filename = os.path.join(root, name)
os.chmod(filename, stat.S_IWUSR)
os.remove(filename)
for name in dirs:
os.rmdir(os.path.join(root, name))
os.rmdir(top)
def copy_file(file, path):
try:
shutil.copy(file, path)
except IOError as e:
if e.errno != errno.ENOENT:
raise
## Create directories
os.makedirs(os.path.dirname(path))
shutil.copy(file, path)
print os.path.relpath(path, ROOT)
def copy_folder(folder, path):
files = os.listdir(folder)
for file in files:
abs_src_file = os.path.join(folder, file)
if os.path.isfile(abs_src_file):
abs_dst_file = os.path.join(path, file)
copy_file(abs_src_file, abs_dst_file)
def run_cmd(command, exit_on_failure=False):
""" Passes a command to the system and returns a True/False result once the
command has been executed, indicating success/failure. Commands are passed
as a list of tokens.
E.g. The command 'git remote -v' would be passed in as ['git', 'remote', '-v']
"""
return_code = subprocess.call(command, shell=True)
if return_code:
print("The command %s failed with return code: %s"
%(' '.join(command), return_code))
if exit_on_failure:
sys.exit(1)
return return_code
def remove_repo(folder):
os.chdir(abspath(dirname(__file__)))
if os.path.exists(folder):
rmtree(folder)
def get_repo(repo, branch, folder):
""" Get the Repository files from git, at depth level 1
repo - Git repository link
branch - repository branch
folder - folder at which repo will be cloned
"""
remove_repo(folder)
clone_cmd = ['git', 'clone', repo, "-b", branch, "--depth", '1', folder]
run_cmd(clone_cmd, exit_on_failure=True)
if __name__ == "__main__":
# Read configuration data
with open(os.path.join(os.path.dirname(__file__), "cmsis_importer.json"), 'r') as config:
json_data = json.load(config)
config = json_data["config"]
cmsis_repo = config['cmsis_repo']
cmsis_branch = config['cmsis_branch']
data_files = json_data["files"]
data_folders = json_data["folders"]
print "Fetching git repo"
get_repo(cmsis_repo, cmsis_branch, CMSIS_REPO)
## Remove all files listed in .json from mbed-os repo to avoid duplications
print "Cleaning up:"
for file in data_files:
cmsis_file = file['cmsis_file']
del_file(os.path.basename(cmsis_file))
for folder in data_folders:
cmsis_folder = os.path.join(CMSIS_PATH, folder['cmsis_folder'])
files = os.listdir(cmsis_folder)
for file in files:
del_file(os.path.basename(file))
## Copy all the CMSIS files listed in json file to mbed-os
print "Files Copied:"
for file in data_files:
cmsis_file = os.path.join(CMSIS_PATH, file['cmsis_file'])
mbed_path = os.path.join(ROOT, file['mbed_file'])
copy_file(cmsis_file, mbed_path)
for folder in data_folders:
cmsis_folder = os.path.join(CMSIS_PATH, folder['cmsis_folder'])
mbed_path = os.path.join(ROOT, folder['mbed_folder'])
copy_folder(cmsis_folder, mbed_path)
#Remove CMSIS Repo
remove_repo(CMSIS_REPO)
## Create new branch with all changes
create_branch = ['git', 'checkout', '-b', RTOS_UPDATE_BRANCH]
run_cmd(create_branch, exit_on_failure=True)
add_files = ['git', 'add', '-A']
run_cmd(add_files, exit_on_failure=True)
commit_branch = ['git', 'commit', '-m', "CMSIS/RTX: Update CMSIS/RTX"]
run_cmd(commit_branch, exit_on_failure=True)
## Apply commits specific to mbed-os changes
mbed_sha = json_data["Mbed_sha"]
for sha in mbed_sha:
cherry_pick_sha = ['git', 'cherry-pick', sha]
run_cmd(cherry_pick_sha, exit_on_failure=True)

View File

@ -0,0 +1,152 @@
{
"config" : {
"cmsis_repo" : "https://github.com/ARM-software/CMSIS_5",
"cmsis_branch" : "develop"
},
"files" : [
{
"cmsis_file" : "CMSIS/Core/Template/ARMv8-M/tz_context.c",
"mbed_file" : "platform/mbed_tz_context.c"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Config/handlers.c",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Config/TARGET_CORTEX_A/handlers.c"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Config/RTX_Config.h",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Config/RTX_Config.h"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Config/RTX_Config.c",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Config/RTX_Config.c"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm0.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M0/irq_cm0.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm0.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M0P/irq_cm0.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_armv8mbl.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M23/irq_armv8mbl.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm3.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M3/irq_cm3.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_armv8mml.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M33/irq_armv8mml.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm4f.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_RTOS_M4_M7/irq_cm4f.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_ca.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_CORTEX_A/irq_ca.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm0.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M0/irq_cm0.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm0.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M0P/irq_cm0.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_armv8mbl.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M23/irq_armv8mbl.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm3.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M3/irq_cm3.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_armv8mml.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M33/irq_armv8mml.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm4f.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_RTOS_M4_M7/irq_cm4f.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_ca.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_CORTEX_A/irq_ca.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm0.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M0/irq_cm0.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm0.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M0P/irq_cm0.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_armv8mbl_common.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M23/irq_armv8mbl_common.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm3.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M3/irq_cm3.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_armv8mml_common.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M33/irq_armv8mml_common.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm4f.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_RTOS_M4_M7/irq_cm4f.S"
},
{
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_ca.S",
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_CORTEX_A/irq_ca.S"
}
],
"folders" : [
{
"cmsis_folder" : "CMSIS/Core/Include/",
"mbed_folder" : "cmsis/TARGET_CORTEX_M/"
},
{
"cmsis_folder" : "CMSIS/RTOS2/Include/",
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/Include/"
},
{
"cmsis_folder" : "CMSIS/RTOS2/RTX/Include1/",
"mbed_folder" : "rtos/TARGET_CORTEX/rtx4/"
},
{
"cmsis_folder" : "CMSIS/RTOS2/RTX/Include/",
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/RTX/Include/"
},
{
"cmsis_folder" : "CMSIS/RTOS2/RTX/Source/",
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/"
},
{
"cmsis_folder" : "CMSIS/RTOS2/RTX/Source/",
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/"
},
{
"cmsis_folder" : "CMSIS/Core_A/Include/",
"mbed_folder" : "cmsis/TARGET_CORTEX_A/"
},
{
"cmsis_folder" : "CMSIS/Core_A/Source/",
"mbed_folder" : "cmsis/TARGET_CORTEX_A/"
}
],
"Mbed_sha" : [
"428acae1b2ac15c3ad523e8d40755a9301220822",
"d9d622afe0ca8c7ab9d24c17f9fe59b54dcc61c9",
"a1fcd36be8ee00aba2c9c1b079f5728368922bc8",
"f3db103d481d8729950414868cfc8123b8055601",
"c07cc6b0f42ff4fe215aa1641a043e205d9128a5",
"dd8fdf4c768e5fef3a7ce2e014de4339dbafe5ce",
"2a837ea97900cc30f82e5a23b95b3f293d17eae1"
]
}