@@ -24,6 +24,7 @@ export type PackageConfig = {
2424export type CompilerConfig = {
2525 runtimeDir : string ,
2626 compilerToolchainDir : string ,
27+ espDir : string
2728} ;
2829
2930export type MemoryLayout = {
@@ -87,7 +88,7 @@ export class Compiler {
8788 packageReader : ( name : string ) => PackageConfig ,
8889 ) {
8990 this . config = config ;
90- this . espidfComponents = new ESPIDFComponents ( config . runtimeDir ) ;
91+ this . espidfComponents = new ESPIDFComponents ( config . runtimeDir , config . espDir ) ;
9192 this . memory = new ShadowMemory ( memoryLayout ) ;
9293 this . packageReader = packageReader ;
9394 const elfReader = new ElfReader ( RUNTIME_ELF_PATH ( this . config ) ) ;
@@ -177,7 +178,8 @@ export class Compiler {
177178 this . memory ,
178179 [ ...this . definedSymbols . values ( ) ] ,
179180 mainEntryPoint ,
180- subModuleEntryPoints
181+ subModuleEntryPoints ,
182+ this . espidfComponents . ldFiles
181183 ) ;
182184 fs . writeFileSync ( LINKER_SCRIPT ( mainPackage ) , linkerscript ) ;
183185 await executeCommand ( `${ LD_PATH ( this . config ) } -o ${ LINKED_ELF_PATH ( mainPackage ) } -T ${ LINKER_SCRIPT ( mainPackage ) } --gc-sections` , cwd ) ;
@@ -202,7 +204,7 @@ export class Compiler {
202204 const espArchivesFromPkg = this . espidfComponents . getArchiveFilePaths ( pkg . espIdfComponents ) ;
203205 espArchivesFromPkg . forEach ( ar => addEspArchive ( ar ) ) ;
204206 }
205- this . espidfComponents . commonArchiveFilePaths . forEach ( ar => addEspArchive ( ar ) ) ;
207+ this . espidfComponents . commonArchiveFiles . forEach ( ar => addEspArchive ( ar ) ) ;
206208 return resultArchives ;
207209 }
208210
@@ -350,7 +352,8 @@ class TranspilerWithPkgSystem {
350352
351353class ESPIDFComponents {
352354 public readonly commonIncludeDirs : string [ ] ;
353- public readonly commonArchiveFilePaths : string [ ] ;
355+ public readonly commonArchiveFiles : string [ ] ;
356+ public readonly ldFiles : string [ ] ;
354357
355358 private readonly COMPONENTS_PATH_PREFIX = / ^ .* m i c r o c o n t r o l l e r / ;
356359 private readonly COMMON_COMPONENTS = [ "cxx" , "newlib" , "freertos" , "esp_hw_support" , "heap" , "log" , "soc" , "hal" , "esp_rom" , "esp_common" , "esp_system" , "xtensa" ] ;
@@ -366,13 +369,14 @@ class ESPIDFComponents {
366369 include_dirs : string [ ]
367370 } } ;
368371
369- constructor ( runtimeDir : string ) {
372+ constructor ( runtimeDir : string , espDir : string ) {
370373 this . RUNTIME_DIR = runtimeDir ;
371374 this . SDK_CONFIG_DIR = path . join ( runtimeDir , 'ports/esp32/build/config' ) ;
372375 const dependenciesFile = path . join ( runtimeDir , 'ports/esp32/build/project_description.json' ) ;
373376 this . dependenciesInfo = JSON . parse ( fs . readFileSync ( dependenciesFile ) . toString ( ) ) . build_component_info ;
374377 this . commonIncludeDirs = this . getIncludeDirs ( this . COMMON_COMPONENTS ) ;
375- this . commonArchiveFilePaths = this . getArchiveFilePaths ( this . COMMON_COMPONENTS ) ;
378+ this . commonArchiveFiles = this . getArchiveFilePaths ( this . COMMON_COMPONENTS ) ;
379+ this . ldFiles = this . getLdFiles ( espDir ) ;
376380 }
377381
378382 public getIncludeDirs ( rootComponentNames : string [ ] ) {
@@ -387,6 +391,20 @@ class ESPIDFComponents {
387391 return includeDirs ;
388392 }
389393
394+ private getLdFiles ( espDir : string ) {
395+ // These paths are extracted from logs of `idf.py build` command.
396+ // Should be improved.
397+ return [
398+ path . join ( espDir , `esp-idf/components/esp_rom/esp32/ld/esp32.rom.ld` ) ,
399+ path . join ( espDir , `esp-idf/components/esp_rom/esp32/ld/esp32.rom.api.ld` ) ,
400+ path . join ( espDir , `esp-idf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld` ) ,
401+ path . join ( espDir , `esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld` ) ,
402+ path . join ( espDir , `esp-idf/components/esp_rom/esp32/ld/esp32.rom.syscalls.ld` ) ,
403+ path . join ( espDir , `esp-idf/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld` ) ,
404+ path . join ( espDir , `esp-idf/components/soc/esp32/ld/esp32.peripherals.ld` ) ,
405+ ]
406+ }
407+
390408 public getArchiveFilePaths ( rootComponentNames : string [ ] ) {
391409 return this . getComponents ( rootComponentNames ) . map ( c => c . file ) ;
392410 }
@@ -410,10 +428,6 @@ class ESPIDFComponents {
410428 }
411429 return components ;
412430 }
413-
414- private convertRuntimeDirPath ( absolutePath : string ) {
415- return absolutePath . replace ( this . COMPONENTS_PATH_PREFIX , this . RUNTIME_DIR ) ;
416- }
417431}
418432
419433
0 commit comments