Skip to content

Commit 021caa6

Browse files
author
deepikabhavnani
committed
Python script to add cmsis/rtx changes in mbed-os
1 parent 1566395 commit 021caa6

File tree

3 files changed

+301
-0
lines changed

3 files changed

+301
-0
lines changed

tools/importer/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Porting CMSIS/RTX Code in Mbed OS
2+
3+
This directory contains scripts to import latest CMSIS/RTX code into mbed-os local repository.
4+
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`
5+
6+
Verify the files and path in `cmsis_importer.json`

tools/importer/cmsis_imorter.py

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import os, json, stat, sys, shutil, errno, subprocess
2+
from os.path import dirname, abspath, basename, join
3+
4+
ROOT = abspath(join(dirname(__file__), "../.."))
5+
CMSIS_REPO = "CMSIS_Repo"
6+
CMSIS_PATH = abspath(join(dirname(__file__), CMSIS_REPO))
7+
RTOS_UPDATE_BRANCH = "rtos_update"
8+
9+
def del_file(name):
10+
result = []
11+
search_path = [join(ROOT, 'rtos'), join(ROOT, 'cmsis')]
12+
for path in search_path:
13+
for root, dirs, files in os.walk(path):
14+
if name in files:
15+
result.append(os.path.join(root, name))
16+
for file in result:
17+
print os.path.relpath(file, ROOT)
18+
os.remove(file)
19+
20+
def rmtree(top):
21+
for root, dirs, files in os.walk(top, topdown=False):
22+
for name in files:
23+
filename = os.path.join(root, name)
24+
os.chmod(filename, stat.S_IWUSR)
25+
os.remove(filename)
26+
for name in dirs:
27+
os.rmdir(os.path.join(root, name))
28+
os.rmdir(top)
29+
30+
def copy_file(file, path):
31+
try:
32+
shutil.copy(file, path)
33+
except IOError as e:
34+
if e.errno != errno.ENOENT:
35+
raise
36+
## Create directories
37+
os.makedirs(os.path.dirname(path))
38+
shutil.copy(file, path)
39+
print os.path.relpath(path, ROOT)
40+
41+
def copy_folder(folder, path):
42+
files = os.listdir(folder)
43+
for file in files:
44+
abs_src_file = os.path.join(folder, file)
45+
if os.path.isfile(abs_src_file):
46+
abs_dst_file = os.path.join(path, file)
47+
copy_file(abs_src_file, abs_dst_file)
48+
49+
def run_cmd(command, exit_on_failure=False):
50+
""" Passes a command to the system and returns a True/False result once the
51+
command has been executed, indicating success/failure. Commands are passed
52+
as a list of tokens.
53+
E.g. The command 'git remote -v' would be passed in as ['git', 'remote', '-v']
54+
"""
55+
return_code = subprocess.call(command, shell=True)
56+
57+
if return_code:
58+
print("The command %s failed with return code: %s"
59+
%(' '.join(command), return_code))
60+
if exit_on_failure:
61+
sys.exit(1)
62+
63+
return return_code
64+
65+
def remove_repo(folder):
66+
os.chdir(abspath(dirname(__file__)))
67+
if os.path.exists(folder):
68+
rmtree(folder)
69+
70+
def get_repo(repo, branch, folder):
71+
""" Get the Repository files from git, at depth level 1
72+
repo - Git repository link
73+
branch - repository branch
74+
folder - folder at which repo will be cloned
75+
"""
76+
remove_repo(folder)
77+
clone_cmd = ['git', 'clone', repo, "-b", branch, "--depth", '1', folder]
78+
run_cmd(clone_cmd, exit_on_failure=True)
79+
80+
if __name__ == "__main__":
81+
82+
# Read configuration data
83+
with open(os.path.join(os.path.dirname(__file__), "cmsis_importer.json"), 'r') as config:
84+
json_data = json.load(config)
85+
config = json_data["config"]
86+
cmsis_repo = config['cmsis_repo']
87+
cmsis_branch = config['cmsis_branch']
88+
data_files = json_data["files"]
89+
data_folders = json_data["folders"]
90+
91+
print "Fetching git repo"
92+
get_repo(cmsis_repo, cmsis_branch, CMSIS_REPO)
93+
94+
## Remove all files listed in .json from mbed-os repo to avoid duplications
95+
print "Cleaning up:"
96+
for file in data_files:
97+
cmsis_file = file['cmsis_file']
98+
del_file(os.path.basename(cmsis_file))
99+
100+
for folder in data_folders:
101+
cmsis_folder = os.path.join(CMSIS_PATH, folder['cmsis_folder'])
102+
files = os.listdir(cmsis_folder)
103+
for file in files:
104+
del_file(os.path.basename(file))
105+
106+
## Copy all the CMSIS files listed in json file to mbed-os
107+
print "Files Copied:"
108+
for file in data_files:
109+
cmsis_file = os.path.join(CMSIS_PATH, file['cmsis_file'])
110+
mbed_path = os.path.join(ROOT, file['mbed_file'])
111+
copy_file(cmsis_file, mbed_path)
112+
113+
for folder in data_folders:
114+
cmsis_folder = os.path.join(CMSIS_PATH, folder['cmsis_folder'])
115+
mbed_path = os.path.join(ROOT, folder['mbed_folder'])
116+
copy_folder(cmsis_folder, mbed_path)
117+
118+
#Remove CMSIS Repo
119+
remove_repo(CMSIS_REPO)
120+
121+
## Create new branch with all changes
122+
create_branch = ['git', 'checkout', '-b', RTOS_UPDATE_BRANCH]
123+
run_cmd(create_branch, exit_on_failure=True)
124+
125+
add_files = ['git', 'add', '-A']
126+
run_cmd(add_files, exit_on_failure=True)
127+
128+
commit_branch = ['git', 'commit', '-m', "CMSIS/RTX: Update CMSIS/RTX"]
129+
run_cmd(commit_branch, exit_on_failure=True)
130+
131+
## Apply commits specific to mbed-os changes
132+
mbed_sha = json_data["Mbed_sha"]
133+
134+
for sha in mbed_sha:
135+
cherry_pick_sha = ['git', 'cherry-pick', sha]
136+
run_cmd(cherry_pick_sha, exit_on_failure=True)
137+
138+
139+
140+
141+
142+
143+

tools/importer/cmsis_importer.json

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
{
2+
"config" : {
3+
"cmsis_repo" : "https://github.com/ARM-software/CMSIS_5",
4+
"cmsis_branch" : "develop"
5+
},
6+
"files" : [
7+
{
8+
"cmsis_file" : "CMSIS/Core/Template/ARMv8-M/tz_context.c",
9+
"mbed_file" : "platform/mbed_tz_context.c"
10+
},
11+
{
12+
"cmsis_file" : "CMSIS/RTOS2/RTX/Config/handlers.c",
13+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Config/TARGET_CORTEX_A/handlers.c"
14+
},
15+
{
16+
"cmsis_file" : "CMSIS/RTOS2/RTX/Config/RTX_Config.h",
17+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Config/RTX_Config.h"
18+
},
19+
{
20+
"cmsis_file" : "CMSIS/RTOS2/RTX/Config/RTX_Config.c",
21+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Config/RTX_Config.c"
22+
},
23+
{
24+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm0.S",
25+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M0/irq_cm0.S"
26+
},
27+
{
28+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm0.S",
29+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M0P/irq_cm0.S"
30+
},
31+
{
32+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_armv8mbl.S",
33+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M23/irq_armv8mbl.S"
34+
},
35+
{
36+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm3.S",
37+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M3/irq_cm3.S"
38+
},
39+
{
40+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_armv8mml.S",
41+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_M33/irq_armv8mml.S"
42+
},
43+
{
44+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_cm4f.S",
45+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_RTOS_M4_M7/irq_cm4f.S"
46+
},
47+
{
48+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/ARM/irq_ca.S",
49+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_ARM/TARGET_CORTEX_A/irq_ca.S"
50+
},
51+
{
52+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm0.S",
53+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M0/irq_cm0.S"
54+
},
55+
{
56+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm0.S",
57+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M0P/irq_cm0.S"
58+
},
59+
{
60+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_armv8mbl.S",
61+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M23/irq_armv8mbl.S"
62+
},
63+
{
64+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm3.S",
65+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M3/irq_cm3.S"
66+
},
67+
{
68+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_armv8mml.S",
69+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_M33/irq_armv8mml.S"
70+
},
71+
{
72+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_cm4f.S",
73+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_RTOS_M4_M7/irq_cm4f.S"
74+
},
75+
{
76+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/GCC/irq_ca.S",
77+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_GCC/TARGET_CORTEX_A/irq_ca.S"
78+
},
79+
{
80+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm0.S",
81+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M0/irq_cm0.S"
82+
},
83+
{
84+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm0.S",
85+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M0P/irq_cm0.S"
86+
},
87+
{
88+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_armv8mbl_common.S",
89+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M23/irq_armv8mbl_common.S"
90+
},
91+
{
92+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm3.S",
93+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M3/irq_cm3.S"
94+
},
95+
{
96+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_armv8mml_common.S",
97+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_M33/irq_armv8mml_common.S"
98+
},
99+
{
100+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_cm4f.S",
101+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_RTOS_M4_M7/irq_cm4f.S"
102+
},
103+
{
104+
"cmsis_file" : "CMSIS/RTOS2/RTX/Source/IAR/irq_ca.S",
105+
"mbed_file" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/TOOLCHAIN_IAR/TARGET_CORTEX_A/irq_ca.S"
106+
}
107+
],
108+
"folders" : [
109+
{
110+
"cmsis_folder" : "CMSIS/Core/Include/",
111+
"mbed_folder" : "cmsis/TARGET_CORTEX_M/"
112+
},
113+
{
114+
"cmsis_folder" : "CMSIS/RTOS2/Include/",
115+
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/Include/"
116+
},
117+
{
118+
"cmsis_folder" : "CMSIS/RTOS2/RTX/Include1/",
119+
"mbed_folder" : "rtos/TARGET_CORTEX/rtx4/"
120+
},
121+
{
122+
"cmsis_folder" : "CMSIS/RTOS2/RTX/Include/",
123+
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/RTX/Include/"
124+
},
125+
{
126+
"cmsis_folder" : "CMSIS/RTOS2/RTX/Source/",
127+
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/"
128+
},
129+
{
130+
"cmsis_folder" : "CMSIS/RTOS2/RTX/Source/",
131+
"mbed_folder" : "rtos/TARGET_CORTEX/rtx5/RTX/Source/"
132+
},
133+
{
134+
"cmsis_folder" : "CMSIS/Core_A/Include/",
135+
"mbed_folder" : "cmsis/TARGET_CORTEX_A/"
136+
},
137+
{
138+
"cmsis_folder" : "CMSIS/Core_A/Source/",
139+
"mbed_folder" : "cmsis/TARGET_CORTEX_A/"
140+
}
141+
],
142+
"Mbed_sha" : [
143+
"428acae1b2ac15c3ad523e8d40755a9301220822",
144+
"d9d622afe0ca8c7ab9d24c17f9fe59b54dcc61c9",
145+
"a1fcd36be8ee00aba2c9c1b079f5728368922bc8",
146+
"f3db103d481d8729950414868cfc8123b8055601",
147+
"c07cc6b0f42ff4fe215aa1641a043e205d9128a5",
148+
"dd8fdf4c768e5fef3a7ce2e014de4339dbafe5ce",
149+
"2a837ea97900cc30f82e5a23b95b3f293d17eae1"
150+
]
151+
}
152+

0 commit comments

Comments
 (0)