18
18
19
19
from SCons .Script import Builder
20
20
21
- from platformio .util import cd
22
-
23
21
Import ("env" )
24
22
25
23
board = env .BoardConfig ()
28
26
# Embedded files helpers
29
27
#
30
28
29
+
31
30
def extract_files (cppdefines , files_type ):
32
31
files = []
33
32
if "build." + files_type in board :
34
33
files .extend (
35
- [join ("$PROJECT_DIR" , f ) for f in board .get (
36
- "build." + files_type , "" ).split () if f ])
34
+ [
35
+ join ("$PROJECT_DIR" , f )
36
+ for f in board .get ("build." + files_type , "" ).split ()
37
+ if f
38
+ ]
39
+ )
37
40
else :
38
41
files_define = "COMPONENT_" + files_type .upper ()
39
42
for define in cppdefines :
@@ -46,18 +49,20 @@ def extract_files(cppdefines, files_type):
46
49
return []
47
50
48
51
if not isinstance (value , str ):
49
- print ("Warning! %s macro must contain "
50
- "a list of files separated by ':'" % files_define )
52
+ print (
53
+ "Warning! %s macro must contain "
54
+ "a list of files separated by ':'" % files_define
55
+ )
51
56
return []
52
57
53
- for f in value .split (':' ):
58
+ for f in value .split (":" ):
54
59
if not f :
55
60
continue
56
61
files .append (join ("$PROJECT_DIR" , f ))
57
62
58
63
for f in files :
59
64
if not isfile (env .subst (f )):
60
- print (" Warning! Could not find file \ " %s\" " % basename (f ))
65
+ print (' Warning! Could not find file "%s"' % basename (f ))
61
66
62
67
return files
63
68
@@ -75,9 +80,9 @@ def prepare_file(source, target, env):
75
80
76
81
with open (filepath , "rb+" ) as fp :
77
82
fp .seek (- 1 , SEEK_END )
78
- if fp .read (1 ) != ' \0 ' :
83
+ if fp .read (1 ) != " \0 " :
79
84
fp .seek (0 , SEEK_CUR )
80
- fp .write (b' \0 ' )
85
+ fp .write (b" \0 " )
81
86
82
87
83
88
def revert_original_file (source , target , env ):
@@ -97,26 +102,74 @@ def embed_files(files, files_type):
97
102
env .AppendUnique (PIOBUILDFILES = [env .File (join ("$BUILD_DIR" , filename ))])
98
103
99
104
105
+ def transform_to_asm (target , source , env ):
106
+ return [join ("$BUILD_DIR" , s .name + ".S" ) for s in source ], source
107
+
100
108
env .Append (
101
109
BUILDERS = dict (
102
110
TxtToBin = Builder (
103
- action = env .VerboseAction (" " .join ([
104
- "xtensa-esp32-elf-objcopy" ,
105
- "--input-target" , "binary" ,
106
- "--output-target" , "elf32-xtensa-le" ,
107
- "--binary-architecture" , "xtensa" ,
108
- "--rename-section" , ".data=.rodata.embedded" ,
109
- "$SOURCE" , "$TARGET"
110
- ]), "Converting $TARGET" ),
111
- suffix = ".txt.o" ))
111
+ action = env .VerboseAction (
112
+ " " .join (
113
+ [
114
+ "xtensa-esp32-elf-objcopy" ,
115
+ "--input-target" ,
116
+ "binary" ,
117
+ "--output-target" ,
118
+ "elf32-xtensa-le" ,
119
+ "--binary-architecture" ,
120
+ "xtensa" ,
121
+ "--rename-section" ,
122
+ ".data=.rodata.embedded" ,
123
+ "$SOURCE" ,
124
+ "$TARGET" ,
125
+ ]
126
+ ),
127
+ "Converting $TARGET" ,
128
+ ),
129
+ suffix = ".txt.o" ,
130
+ ),
131
+ TxtToAsm = Builder (
132
+ action = env .VerboseAction (
133
+ " " .join (
134
+ [
135
+ join (
136
+ env .PioPlatform ().get_package_dir ("tool-cmake" ) or "" ,
137
+ "bin" ,
138
+ "cmake" ,
139
+ ),
140
+ "-DDATA_FILE=$SOURCE" ,
141
+ "-DSOURCE_FILE=$TARGET" ,
142
+ "-DFILE_TYPE=TEXT" ,
143
+ "-P" ,
144
+ join (
145
+ env .PioPlatform ().get_package_dir ("framework-espidf" ) or "" ,
146
+ "tools" ,
147
+ "cmake" ,
148
+ "scripts" ,
149
+ "data_file_embed_asm.cmake" ,
150
+ ),
151
+ ]
152
+ ),
153
+ "Generating assembly for $TARGET" ,
154
+ ),
155
+ emitter = transform_to_asm ,
156
+ single_source = True
157
+ ),
158
+ )
112
159
)
113
160
161
+
114
162
flags = env .get ("CPPDEFINES" )
115
163
for files_type in ("embed_txtfiles" , "embed_files" ):
116
- if "COMPONENT_" + files_type .upper () not in env .Flatten (
117
- flags ) and "build." + files_type not in board :
164
+ if (
165
+ "COMPONENT_" + files_type .upper () not in env .Flatten (flags )
166
+ and "build." + files_type not in board
167
+ ):
118
168
continue
119
169
120
170
files = extract_files (flags , files_type )
121
- embed_files (files , files_type )
122
- remove_config_define (flags , files_type )
171
+ if "espidf" in env .subst ("$PIOFRAMEWORK" ):
172
+ env .Requires (join ("$BUILD_DIR" , "${PROGNAME}.elf" ), env .TxtToAsm (files ))
173
+ else :
174
+ embed_files (files , files_type )
175
+ remove_config_define (flags , files_type )
0 commit comments