Skip to content

Commit c8e15ac

Browse files
committed
Platform siwigsm initial commit
Signed-off-by: Ajay Bhargav <[email protected]>
0 parents  commit c8e15ac

File tree

7 files changed

+352
-0
lines changed

7 files changed

+352
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__/
2+
.vscode

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SIWIGSM platform for Platformio
2+
3+

boards/s20gsm.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"build": {
3+
"core": "s20",
4+
"cpu": "arm9ejs",
5+
"f_cpu": "260000000L",
6+
"mcu": "MT2503",
7+
"variant": "s20u",
8+
"newlib": "nano",
9+
"siwilib": "release",
10+
"hwids": [
11+
[
12+
"0x0E8D",
13+
"0x0003"
14+
]
15+
]
16+
},
17+
"frameworks": [
18+
"siwisdk"
19+
],
20+
"name": "S20 GSM Module",
21+
"upload": {
22+
"maximum_ram_size": 96256,
23+
"maximum_size": 262144,
24+
"require_upload_port": true,
25+
"speed": 460800
26+
},
27+
"url": "",
28+
"vendor": "SiWi Embedded Solutions Pvt. Ltd."
29+
}

builder/framework/siwisdk.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Copyright 2020 SiWi Embedded Solutions Pvt. Ltd.
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
6+
import os
7+
from os.path import isdir, isfile, join, dirname
8+
from shutil import copyfile
9+
10+
from SCons.Script import DefaultEnvironment
11+
12+
env = DefaultEnvironment()
13+
platform = env.PioPlatform()
14+
board = env.BoardConfig()
15+
16+
FRAMEWORK_DIR = platform.get_package_dir("framework-siwisdk")
17+
assert isdir(FRAMEWORK_DIR)
18+
19+
# Create Project Template
20+
main_c = join(env.subst("$PROJECT_DIR"), "src", "main.c")
21+
if False == isfile(main_c):
22+
copyfile(join(FRAMEWORK_DIR, "template", "main.c"), main_c)
23+
24+
GFH_Generator = join(FRAMEWORK_DIR,
25+
"tools",
26+
"GFH_Generator.exe")
27+
FOTA_Generator = join(FRAMEWORK_DIR,
28+
"tools",
29+
"FOTA_Generator.exe")
30+
31+
32+
def gen_bin_file(target, source, env):
33+
cmd = ["$OBJCOPY"]
34+
(target_firm, ) = target
35+
(target_elf, ) = source
36+
37+
temp_firm = os.path.dirname(target_firm.get_abspath()) + "\\temp.bin"
38+
cmd.extend(["-O", "binary"])
39+
cmd.append(target_elf.get_abspath())
40+
cmd.append(temp_firm)
41+
env.Execute(env.VerboseAction(" ".join(cmd), "Elf to Binary"))
42+
43+
cmd_gfh = [GFH_Generator]
44+
cmd_gfh.append(temp_firm)
45+
cmd_gfh.append(target_firm.get_abspath())
46+
env.Execute(env.VerboseAction(" ".join(cmd_gfh), "Adding GFH Header"))
47+
48+
os.remove(temp_firm)
49+
50+
51+
# Setup ENV
52+
env.Append(
53+
ASFLAGS=["-x", "assembler-with-cpp"],
54+
55+
CCFLAGS=[
56+
"-Os", # optimize for size
57+
"-g",
58+
"-march=armv5te",
59+
"-mfloat-abi=soft",
60+
"-fmessage-length=0",
61+
"-ffunction-sections", # place each function in its own section
62+
"-fdata-sections",
63+
"-fsigned-char",
64+
"-Wall",
65+
"-mthumb",
66+
"-mthumb-interwork",
67+
"-std=gnu11"
68+
],
69+
70+
CXXFLAGS=[
71+
"-std=gnu++11",
72+
"-fno-rtti",
73+
"-fno-exceptions",
74+
"-fno-use-cxa-atexit",
75+
"-fno-threadsafe-statics"
76+
],
77+
78+
CPPDEFINES=[
79+
("__BUFSIZ__", "512"),
80+
("__FILENAME_MAX__", "256")
81+
],
82+
83+
CPPPATH=[
84+
join(FRAMEWORK_DIR, "include"),
85+
join(FRAMEWORK_DIR, "include", "ril")
86+
],
87+
88+
LINKFLAGS=[
89+
"-march=armv5te",
90+
"-mthumb",
91+
"-mthumb-interwork",
92+
"-mfloat-abi=soft",
93+
"-Os",
94+
"-Wl,--gc-sections,--relax",
95+
"-nostartfiles",
96+
"-nostdlib",
97+
"-nostartfiles",
98+
"-nodefaultlibs"
99+
],
100+
101+
LIBS=["siwisdk", "c", "gcc", "m"],
102+
LDSCRIPT_PATH=join(FRAMEWORK_DIR, "lib", "linkerscript.ld"),
103+
LIBPATH=[
104+
join(FRAMEWORK_DIR, "lib")
105+
],
106+
LIBSOURCE_DIRS=[join(FRAMEWORK_DIR, "libraries")],
107+
BUILDERS=dict(
108+
ElfToBin=Builder(
109+
action=env.VerboseAction(gen_bin_file, "Generating $TARGET"),
110+
suffix=".bin"
111+
),
112+
BinToFOTA=Builder(
113+
action=env.VerboseAction(" ".join([
114+
FOTA_Generator,
115+
"$SOURCES",
116+
"$TARGET"
117+
]), "Creating FOTA firmware $TARGET"),
118+
suffix=".bin"
119+
)
120+
)
121+
)
122+
123+
if board.get("build.newlib") == "nano":
124+
env.Append(
125+
LINKFLAGS=[
126+
"--specs=nano.specs",
127+
"-u _printf_float",
128+
"-u _scanf_float",
129+
"--specs=nosys.specs"
130+
]
131+
)
132+
133+
# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode)
134+
env.Append(ASFLAGS=env.get("CCFLAGS", [])[:])
135+
136+
137+
def load_siwilib_debug():
138+
for i, libs in enumerate(env["LIBS"]):
139+
if libs == "siwisdk":
140+
env["LIBS"][i] = "siwisdk_debug"
141+
142+
143+
if board.get("build.siwilib") == "debug":
144+
load_siwilib_debug()
145+
146+
if env.GetBuildType() == "debug":
147+
load_siwilib_debug()

builder/main.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Copyright 2020 SiWi Embedded Solutions Pvt. Ltd.
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
6+
import sys
7+
from platform import system
8+
from os import makedirs
9+
from os.path import basename, isdir, join
10+
11+
from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild,
12+
Builder, Default, DefaultEnvironment)
13+
14+
env = DefaultEnvironment()
15+
platform = env.PioPlatform()
16+
board = env.BoardConfig()
17+
18+
env.Replace(
19+
AR="arm-none-eabi-ar",
20+
AS="arm-none-eabi-as",
21+
CC="arm-none-eabi-gcc",
22+
CXX="arm-none-eabi-g++",
23+
GDB="arm-none-eabi-gdb",
24+
OBJCOPY="arm-none-eabi-objcopy",
25+
RANLIB="arm-none-eabi-ranlib",
26+
SIZETOOL="arm-none-eabi-size",
27+
28+
ARFLAGS=["rc"],
29+
30+
SIZEPROGREGEXP=r"^(?:\.text|\.data|\.rodata|\.text.align|\.ARM.exidx|\.ARM.extab|\.ll|\.initdata)\s+(\d+).*",
31+
SIZEDATAREGEXP=r"^(?:\.data|\.bss|\.noinit)\s+(\d+).*",
32+
SIZECHECKCMD="$SIZETOOL -A -d $SOURCES",
33+
SIZEPRINTCMD='$SIZETOOL -B -d $SOURCES',
34+
35+
PROGSUFFIX=".elf",
36+
SIWIFLASHER=join(platform.get_package_dir(
37+
"tool-siwiflasher") or "", "siwiflasher"),
38+
REFLASH_FLAGS=[
39+
"-r"
40+
],
41+
REFLASH_CMD='"$SIWIFLASHER" $REFLASH_FLAGS'
42+
)
43+
44+
# Allow user to override via pre:script
45+
if env.get("PROGNAME", "program") == "program":
46+
env.Replace(PROGNAME="firmware")
47+
48+
#
49+
# Target: Build executable and linkable firmware
50+
#
51+
52+
target_elf = None
53+
if "nobuild" in COMMAND_LINE_TARGETS:
54+
target_elf = join("$BUILD_DIR", "${PROGNAME}.elf")
55+
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
56+
target_firm_fota = join("$BUILD_DIR", "fota_${PROGNAME}.bin")
57+
else:
58+
target_elf = env.BuildProgram()
59+
target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf)
60+
target_firm_fota = env.BinToFOTA(
61+
join("$BUILD_DIR", "fota_${PROGNAME}"), target_firm)
62+
63+
AlwaysBuild(env.Alias("nobuild", target_firm))
64+
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
65+
66+
#
67+
# Target: Build FOTA Binary
68+
#
69+
70+
target_buildota = env.Alias("buildfota", target_firm_fota, target_firm_fota)
71+
AlwaysBuild(target_buildota)
72+
73+
#
74+
# Target: Print binary size
75+
#
76+
77+
target_size = env.Alias("size", target_elf, env.VerboseAction(
78+
"$SIZEPRINTCMD", "Calculating size $SOURCE"))
79+
AlwaysBuild(target_size)
80+
81+
#
82+
# Target: Reflash core
83+
#
84+
AlwaysBuild(
85+
env.Alias("reflash", None, [
86+
env.VerboseAction("$REFLASH_CMD", "Reflashing core...")
87+
]))
88+
89+
#
90+
# Target: Upload by default .bin file
91+
#
92+
env.Replace(
93+
UPLOADER="$SIWIFLASHER",
94+
UPLOADERFLAGS=[
95+
"-b", "$UPLOAD_SPEED",
96+
"-p", '"$UPLOAD_PORT"',
97+
],
98+
UPLOADCMD='"$UPLOADER" $UPLOADERFLAGS $SOURCE'
99+
)
100+
upload_source = target_firm
101+
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
102+
103+
if env.subst("$UPLOAD_PORT") == "":
104+
env.Append(
105+
UPLOADERFLAGS=[
106+
"-u"
107+
],
108+
REFLASH_FLAGS=[
109+
"-u"
110+
]
111+
)
112+
113+
AlwaysBuild(env.Alias("upload", upload_source, upload_actions))
114+
115+
#
116+
# Setup default targets
117+
#
118+
119+
Default([target_buildprog, target_buildota, target_size])

platform.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "siwigsm",
3+
"title": "SIWI GSM Platform",
4+
"description": "GSM development platform for MT2503 SoC.",
5+
"url": "http://siwi.in/",
6+
"homepage": "http://siwi.in",
7+
"license": {
8+
"type": "MIT",
9+
"url": "https://opensource.org/licenses/MIT"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/siwiembedded/siwigsm.git"
14+
},
15+
"version": "v0.1.0",
16+
"vendor": "SiWi Embedded Solutions Pvt. Ltd.",
17+
"packageRepositories": [
18+
"http://dl.platformio.org/packages/manifest.json"
19+
],
20+
"frameworks": {
21+
"siwisdk": {
22+
"package": "framework-siwisdk",
23+
"script": "builder/framework/siwisdk.py"
24+
}
25+
},
26+
"packages": {
27+
"toolchain-gccarmnoneeabi": {
28+
"type": "toolchain",
29+
"version": "1.80201.190214"
30+
},
31+
"framework-siwisdk": {
32+
"type": "framework",
33+
"version": "~0.0.0"
34+
},
35+
"tool-siwiflasher": {
36+
"type": "uploader",
37+
"version": "~1.0.0"
38+
}
39+
}
40+
}

platform.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2020 SiWi Embedded Solutions Pvt. Ltd.
2+
#
3+
# SPDX-License-Identifier: MIT
4+
#
5+
6+
from platform import system
7+
from platformio.managers.platform import PlatformBase
8+
9+
class SiwigsmPlatform(PlatformBase):
10+
def configure_default_packages(self, variables, target):
11+
return PlatformBase.configure_default_packages(self, variables,
12+
target)

0 commit comments

Comments
 (0)