t_freertos.pas 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672
  1. {
  2. Copyright (c) 2005-2017 by Free Pascal Compiler team
  3. This unit implements support import, export, link routines
  4. for the FreeRTOS Target
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit t_freertos;
  19. {$i fpcdefs.inc}
  20. interface
  21. implementation
  22. uses
  23. SysUtils,
  24. cutils,cfileutl,cclasses,
  25. globtype,globals,systems,verbose,comphook,cscript,fmodule,i_freertos,link,
  26. cpuinfo;
  27. type
  28. TlinkerFreeRTOS=class(texternallinker)
  29. private
  30. Function WriteResponseFile: Boolean;
  31. {$ifdef XTENSA}
  32. procedure GenerateDefaultLinkerScripts(var memory_filename,sections_filename: AnsiString);
  33. {$endif XTENSA}
  34. public
  35. constructor Create; override;
  36. procedure SetDefaultInfo; override;
  37. function MakeExecutable:boolean; override;
  38. function postprocessexecutable(const fn : string;isdll:boolean):boolean;
  39. end;
  40. {*****************************************************************************
  41. TlinkerEmbedded
  42. *****************************************************************************}
  43. constructor TlinkerFreeRTOS.Create;
  44. begin
  45. Inherited Create;
  46. SharedLibFiles.doubles:=true;
  47. StaticLibFiles.doubles:=true;
  48. end;
  49. procedure TlinkerFreeRTOS.SetDefaultInfo;
  50. const
  51. {$ifdef mips}
  52. {$ifdef mipsel}
  53. platform_select='-EL';
  54. {$else}
  55. platform_select='-EB';
  56. {$endif}
  57. {$else}
  58. platform_select='';
  59. {$endif}
  60. begin
  61. Info.ExeCmd[1]:='ld -g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  62. end;
  63. function TlinkerFreeRTOS.WriteResponseFile: Boolean;
  64. Var
  65. linkres : TLinkRes;
  66. i : longint;
  67. HPath : TCmdStrListItem;
  68. s,s1,s2 : TCmdStr;
  69. prtobj : string[80];
  70. linklibc : boolean;
  71. found1,
  72. found2 : boolean;
  73. {$if defined(ARM)}
  74. LinkStr : string;
  75. {$endif}
  76. begin
  77. WriteResponseFile:=False;
  78. linklibc:=(SharedLibFiles.Find('c')<>nil);
  79. {$if defined(ARM) or defined(i386) or defined(x86_64) or defined(AVR) or defined(MIPSEL) or defined(RISCV32) or defined(XTENSA)}
  80. prtobj:='';
  81. {$else}
  82. prtobj:='prt0';
  83. if linklibc then
  84. prtobj:='cprt0';
  85. {$endif}
  86. { Open link.res file }
  87. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  88. { Write path to search libraries }
  89. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  90. while assigned(HPath) do
  91. begin
  92. s:=HPath.Str;
  93. if (cs_link_on_target in current_settings.globalswitches) then
  94. s:=ScriptFixFileName(s);
  95. LinkRes.Add('-L'+s);
  96. HPath:=TCmdStrListItem(HPath.Next);
  97. end;
  98. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  99. while assigned(HPath) do
  100. begin
  101. s:=HPath.Str;
  102. if s<>'' then
  103. LinkRes.Add('SEARCH_DIR("'+s+'")');
  104. HPath:=TCmdStrListItem(HPath.Next);
  105. end;
  106. LinkRes.Add('INPUT (');
  107. { add objectfiles, start with prt0 always }
  108. //s:=FindObjectFile('prt0','',false);
  109. if prtobj<>'' then
  110. begin
  111. s:=FindObjectFile(prtobj,'',false);
  112. LinkRes.AddFileName(s);
  113. end;
  114. { xtensa FreeRTOS links always against libc, the runtime needs it }
  115. if not(target_info.system in [system_xtensa_freertos]) then
  116. begin
  117. { try to add crti and crtbegin if linking to C }
  118. if linklibc then
  119. begin
  120. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  121. LinkRes.AddFileName(s);
  122. if librarysearchpath.FindFile('crti.o',false,s) then
  123. LinkRes.AddFileName(s);
  124. end;
  125. end;
  126. while not ObjectFiles.Empty do
  127. begin
  128. s:=ObjectFiles.GetFirst;
  129. if s<>'' then
  130. begin
  131. { vlink doesn't use SEARCH_DIR for object files }
  132. if not(cs_link_on_target in current_settings.globalswitches) then
  133. s:=FindObjectFile(s,'',false);
  134. LinkRes.AddFileName((maybequoted(s)));
  135. end;
  136. end;
  137. { Write staticlibraries }
  138. if not(StaticLibFiles.Empty) then
  139. begin
  140. LinkRes.Add(')');
  141. LinkRes.Add('GROUP(');
  142. while not StaticLibFiles.Empty do
  143. begin
  144. S:=StaticLibFiles.GetFirst;
  145. LinkRes.AddFileName((maybequoted(s)));
  146. end;
  147. end;
  148. { xtensa FreeRTOS links always against libc, the runtime needs it }
  149. if not(target_info.system in [system_xtensa_freertos]) then
  150. begin
  151. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  152. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  153. linklibc:=false;
  154. while not SharedLibFiles.Empty do
  155. begin
  156. S:=SharedLibFiles.GetFirst;
  157. if s<>'c' then
  158. begin
  159. i:=Pos(target_info.sharedlibext,S);
  160. if i>0 then
  161. Delete(S,i,255);
  162. LinkRes.Add('-l'+s);
  163. end
  164. else
  165. begin
  166. LinkRes.Add('-l'+s);
  167. linklibc:=true;
  168. end;
  169. end;
  170. { be sure that libc&libgcc is the last lib }
  171. if linklibc then
  172. begin
  173. LinkRes.Add('-lc');
  174. LinkRes.Add('-lgcc');
  175. end;
  176. end;
  177. LinkRes.Add(')');
  178. { xtensa FreeRTOS links always against libc }
  179. if not(target_info.system in [system_xtensa_freertos]) then
  180. begin
  181. { objects which must be at the end }
  182. if linklibc then
  183. begin
  184. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  185. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  186. if found1 or found2 then
  187. begin
  188. LinkRes.Add('INPUT(');
  189. if found1 then
  190. LinkRes.AddFileName(s1);
  191. if found2 then
  192. LinkRes.AddFileName(s2);
  193. LinkRes.Add(')');
  194. end;
  195. end;
  196. end;
  197. {$ifdef ARM}
  198. with embedded_controllers[current_settings.controllertype] do
  199. with linkres do
  200. begin
  201. Add('ENTRY(_START)');
  202. Add('MEMORY');
  203. Add('{');
  204. if flashsize<>0 then
  205. begin
  206. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  207. + ', LENGTH = 0x' + IntToHex(flashsize,8);
  208. Add(LinkStr);
  209. end;
  210. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  211. + ', LENGTH = 0x' + IntToHex(sramsize,8);
  212. Add(LinkStr);
  213. Add('}');
  214. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  215. Add('SECTIONS');
  216. Add('{');
  217. Add(' .text :');
  218. Add(' {');
  219. Add(' _text_start = .;');
  220. Add(' KEEP(*(.init .init.*))');
  221. Add(' *(.text .text.*)');
  222. Add(' *(.strings)');
  223. Add(' *(.rodata .rodata.*)');
  224. Add(' *(.comment)');
  225. Add(' . = ALIGN(4);');
  226. Add(' _etext = .;');
  227. if flashsize<>0 then
  228. begin
  229. Add(' } >flash');
  230. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  231. end
  232. else
  233. begin
  234. Add(' } >ram');
  235. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  236. end;
  237. Add(' .data :');
  238. Add(' {');
  239. Add(' _data = .;');
  240. Add(' *(.data .data.*)');
  241. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  242. Add(' _edata = .;');
  243. if flashsize<>0 then
  244. begin
  245. Add(' } >ram AT >flash');
  246. end
  247. else
  248. begin
  249. Add(' } >ram');
  250. end;
  251. Add(' .bss :');
  252. Add(' {');
  253. Add(' _bss_start = .;');
  254. Add(' *(.bss .bss.*)');
  255. Add(' *(COMMON)');
  256. Add(' } >ram');
  257. Add(' . = ALIGN(4);');
  258. Add(' _bss_end = . ;');
  259. Add('}');
  260. Add('_end = .;');
  261. end;
  262. {$endif ARM}
  263. {$ifdef i386}
  264. with linkres do
  265. begin
  266. Add('ENTRY(_START)');
  267. Add('SECTIONS');
  268. Add('{');
  269. Add(' . = 0x100000;');
  270. Add(' .text ALIGN (0x1000) :');
  271. Add(' {');
  272. Add(' _text = .;');
  273. Add(' KEEP(*(.init .init.*))');
  274. Add(' *(.text .text.*)');
  275. Add(' *(.strings)');
  276. Add(' *(.rodata .rodata.*)');
  277. Add(' *(.comment)');
  278. Add(' _etext = .;');
  279. Add(' }');
  280. Add(' .data ALIGN (0x1000) :');
  281. Add(' {');
  282. Add(' _data = .;');
  283. Add(' *(.data .data.*)');
  284. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  285. Add(' _edata = .;');
  286. Add(' }');
  287. Add(' . = ALIGN(4);');
  288. Add(' .bss :');
  289. Add(' {');
  290. Add(' _bss_start = .;');
  291. Add(' *(.bss .bss.*)');
  292. Add(' *(COMMON)');
  293. Add(' }');
  294. Add('_bss_end = . ;');
  295. Add('}');
  296. Add('_end = .;');
  297. end;
  298. {$endif i386}
  299. {$ifdef x86_64}
  300. with linkres do
  301. begin
  302. Add('ENTRY(_START)');
  303. Add('SECTIONS');
  304. Add('{');
  305. Add(' . = 0x100000;');
  306. Add(' .text ALIGN (0x1000) :');
  307. Add(' {');
  308. Add(' _text = .;');
  309. Add(' KEEP(*(.init .init.*))');
  310. Add(' *(.text .text.*)');
  311. Add(' *(.strings)');
  312. Add(' *(.rodata .rodata.*)');
  313. Add(' *(.comment)');
  314. Add(' _etext = .;');
  315. Add(' }');
  316. Add(' .data ALIGN (0x1000) :');
  317. Add(' {');
  318. Add(' _data = .;');
  319. Add(' *(.data .data.*)');
  320. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  321. Add(' _edata = .;');
  322. Add(' }');
  323. Add(' . = ALIGN(4);');
  324. Add(' .bss :');
  325. Add(' {');
  326. Add(' _bss_start = .;');
  327. Add(' *(.bss .bss.*)');
  328. Add(' *(COMMON)');
  329. Add(' }');
  330. Add('_bss_end = . ;');
  331. Add('}');
  332. Add('_end = .;');
  333. end;
  334. {$endif x86_64}
  335. {$ifdef AVR}
  336. with linkres do
  337. begin
  338. { linker script from ld 2.19 }
  339. Add('ENTRY(_START)');
  340. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  341. case current_settings.cputype of
  342. cpu_avr1:
  343. Add('OUTPUT_ARCH(avr:1)');
  344. cpu_avr2:
  345. Add('OUTPUT_ARCH(avr:2)');
  346. cpu_avr25:
  347. Add('OUTPUT_ARCH(avr:25)');
  348. cpu_avr3:
  349. Add('OUTPUT_ARCH(avr:3)');
  350. cpu_avr31:
  351. Add('OUTPUT_ARCH(avr:31)');
  352. cpu_avr35:
  353. Add('OUTPUT_ARCH(avr:35)');
  354. cpu_avr4:
  355. Add('OUTPUT_ARCH(avr:4)');
  356. cpu_avr5:
  357. Add('OUTPUT_ARCH(avr:5)');
  358. cpu_avr51:
  359. Add('OUTPUT_ARCH(avr:51)');
  360. cpu_avr6:
  361. Add('OUTPUT_ARCH(avr:6)');
  362. cpu_avrxmega3:
  363. Add('OUTPUT_ARCH(avr:103)');
  364. cpu_avrtiny:
  365. Add('OUTPUT_ARCH(avr:100)');
  366. else
  367. Internalerror(2015072701);
  368. end;
  369. Add('MEMORY');
  370. with embedded_controllers[current_settings.controllertype] do
  371. begin
  372. Add('{');
  373. Add(' text (rx) : ORIGIN = 0, LENGTH = 0x'+IntToHex(flashsize,6));
  374. Add(' data (rw!x) : ORIGIN = 0x'+IntToHex($800000+srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  375. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x'+IntToHex(eepromsize,6));
  376. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  377. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  378. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  379. Add('}');
  380. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  381. end;
  382. Add('SECTIONS');
  383. Add('{');
  384. Add(' /* Read-only sections, merged into text segment: */');
  385. Add(' .hash : { *(.hash) }');
  386. Add(' .dynsym : { *(.dynsym) }');
  387. Add(' .dynstr : { *(.dynstr) }');
  388. Add(' .gnu.version : { *(.gnu.version) }');
  389. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  390. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  391. Add(' .rel.init : { *(.rel.init) }');
  392. Add(' .rela.init : { *(.rela.init) }');
  393. Add(' .rel.text :');
  394. Add(' {');
  395. Add(' *(.rel.text)');
  396. Add(' *(.rel.text.*)');
  397. Add(' *(.rel.gnu.linkonce.t*)');
  398. Add(' }');
  399. Add(' .rela.text :');
  400. Add(' {');
  401. Add(' *(.rela.text)');
  402. Add(' *(.rela.text.*)');
  403. Add(' *(.rela.gnu.linkonce.t*)');
  404. Add(' }');
  405. Add(' .rel.fini : { *(.rel.fini) }');
  406. Add(' .rela.fini : { *(.rela.fini) }');
  407. Add(' .rel.rodata :');
  408. Add(' {');
  409. Add(' *(.rel.rodata)');
  410. Add(' *(.rel.rodata.*)');
  411. Add(' *(.rel.gnu.linkonce.r*)');
  412. Add(' }');
  413. Add(' .rela.rodata :');
  414. Add(' {');
  415. Add(' *(.rela.rodata)');
  416. Add(' *(.rela.rodata.*)');
  417. Add(' *(.rela.gnu.linkonce.r*)');
  418. Add(' }');
  419. Add(' .rel.data :');
  420. Add(' {');
  421. Add(' *(.rel.data)');
  422. Add(' *(.rel.data.*)');
  423. Add(' *(.rel.gnu.linkonce.d*)');
  424. Add(' }');
  425. Add(' .rela.data :');
  426. Add(' {');
  427. Add(' *(.rela.data)');
  428. Add(' *(.rela.data.*)');
  429. Add(' *(.rela.gnu.linkonce.d*)');
  430. Add(' }');
  431. Add(' .rel.ctors : { *(.rel.ctors) }');
  432. Add(' .rela.ctors : { *(.rela.ctors) }');
  433. Add(' .rel.dtors : { *(.rel.dtors) }');
  434. Add(' .rela.dtors : { *(.rela.dtors) }');
  435. Add(' .rel.got : { *(.rel.got) }');
  436. Add(' .rela.got : { *(.rela.got) }');
  437. Add(' .rel.bss : { *(.rel.bss) }');
  438. Add(' .rela.bss : { *(.rela.bss) }');
  439. Add(' .rel.plt : { *(.rel.plt) }');
  440. Add(' .rela.plt : { *(.rela.plt) }');
  441. Add(' /* Internal text space or external memory. */');
  442. Add(' .text :');
  443. Add(' {');
  444. Add(' KEEP(*(.init .init.*))');
  445. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  446. Add(' *(.progmem.gcc*)');
  447. Add(' *(.progmem*)');
  448. Add(' . = ALIGN(2);');
  449. Add(' __trampolines_start = . ;');
  450. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  451. Add(' *(.trampolines)');
  452. Add(' *(.trampolines*)');
  453. Add(' __trampolines_end = . ;');
  454. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  455. Add(' We don''t relax jump/call instructions within these sections. */');
  456. Add(' *(.jumptables)');
  457. Add(' *(.jumptables*)');
  458. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  459. Add(' *(.lowtext)');
  460. Add(' *(.lowtext*)');
  461. Add(' __ctors_start = . ;');
  462. Add(' *(.ctors)');
  463. Add(' __ctors_end = . ;');
  464. Add(' __dtors_start = . ;');
  465. Add(' *(.dtors)');
  466. Add(' __dtors_end = . ;');
  467. Add(' KEEP(SORT(*)(.ctors))');
  468. Add(' KEEP(SORT(*)(.dtors))');
  469. Add(' /* From this point on, we don''t bother about wether the insns are');
  470. Add(' below or above the 16 bits boundary. */');
  471. Add(' *(.init0) /* Start here after reset. */');
  472. Add(' KEEP (*(.init0))');
  473. Add(' *(.init1)');
  474. Add(' KEEP (*(.init1))');
  475. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  476. Add(' KEEP (*(.init2))');
  477. Add(' *(.init3)');
  478. Add(' KEEP (*(.init3))');
  479. Add(' *(.init4) /* Initialize data and BSS. */');
  480. Add(' KEEP (*(.init4))');
  481. Add(' *(.init5)');
  482. Add(' KEEP (*(.init5))');
  483. Add(' *(.init6) /* C++ constructors. */');
  484. Add(' KEEP (*(.init6))');
  485. Add(' *(.init7)');
  486. Add(' KEEP (*(.init7))');
  487. Add(' *(.init8)');
  488. Add(' KEEP (*(.init8))');
  489. Add(' *(.init9) /* Call main(). */');
  490. Add(' KEEP (*(.init9))');
  491. Add(' *(.text)');
  492. Add(' . = ALIGN(2);');
  493. Add(' *(.text.*)');
  494. Add(' . = ALIGN(2);');
  495. Add(' *(.fini9) /* _exit() starts here. */');
  496. Add(' KEEP (*(.fini9))');
  497. Add(' *(.fini8)');
  498. Add(' KEEP (*(.fini8))');
  499. Add(' *(.fini7)');
  500. Add(' KEEP (*(.fini7))');
  501. Add(' *(.fini6) /* C++ destructors. */');
  502. Add(' KEEP (*(.fini6))');
  503. Add(' *(.fini5)');
  504. Add(' KEEP (*(.fini5))');
  505. Add(' *(.fini4)');
  506. Add(' KEEP (*(.fini4))');
  507. Add(' *(.fini3)');
  508. Add(' KEEP (*(.fini3))');
  509. Add(' *(.fini2)');
  510. Add(' KEEP (*(.fini2))');
  511. Add(' *(.fini1)');
  512. Add(' KEEP (*(.fini1))');
  513. Add(' *(.fini0) /* Infinite loop after program termination. */');
  514. Add(' KEEP (*(.fini0))');
  515. Add(' _etext = . ;');
  516. Add(' } > text');
  517. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  518. Add(' {');
  519. Add(' PROVIDE (__data_start = .) ;');
  520. Add(' *(.data)');
  521. Add(' *(.data*)');
  522. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  523. Add(' *(.rodata*) /* with -fdata-sections. */');
  524. Add(' *(.gnu.linkonce.d*)');
  525. Add(' . = ALIGN(2);');
  526. Add(' _edata = . ;');
  527. Add(' PROVIDE (__data_end = .) ;');
  528. Add(' } > data');
  529. Add(' .bss : AT (ADDR (.bss))');
  530. Add(' {');
  531. Add(' PROVIDE (__bss_start = .) ;');
  532. Add(' *(.bss)');
  533. Add(' *(.bss*)');
  534. Add(' *(COMMON)');
  535. Add(' PROVIDE (__bss_end = .) ;');
  536. Add(' } > data');
  537. Add(' __data_load_start = LOADADDR(.data);');
  538. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  539. Add(' /* Global data not cleared after reset. */');
  540. Add(' .noinit :');
  541. Add(' {');
  542. Add(' PROVIDE (__noinit_start = .) ;');
  543. Add(' *(.noinit*)');
  544. Add(' PROVIDE (__noinit_end = .) ;');
  545. Add(' _end = . ;');
  546. Add(' PROVIDE (__heap_start = .) ;');
  547. Add(' } > data');
  548. Add(' .eeprom :');
  549. Add(' {');
  550. Add(' *(.eeprom*)');
  551. Add(' __eeprom_end = . ;');
  552. Add(' } > eeprom');
  553. Add(' .fuse :');
  554. Add(' {');
  555. Add(' KEEP(*(.fuse))');
  556. Add(' KEEP(*(.lfuse))');
  557. Add(' KEEP(*(.hfuse))');
  558. Add(' KEEP(*(.efuse))');
  559. Add(' } > fuse');
  560. Add(' .lock :');
  561. Add(' {');
  562. Add(' KEEP(*(.lock*))');
  563. Add(' } > lock');
  564. Add(' .signature :');
  565. Add(' {');
  566. Add(' KEEP(*(.signature*))');
  567. Add(' } > signature');
  568. Add(' /* Stabs debugging sections. */');
  569. Add(' .stab 0 : { *(.stab) }');
  570. Add(' .stabstr 0 : { *(.stabstr) }');
  571. Add(' .stab.excl 0 : { *(.stab.excl) }');
  572. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  573. Add(' .stab.index 0 : { *(.stab.index) }');
  574. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  575. Add(' .comment 0 : { *(.comment) }');
  576. Add(' /* DWARF debug sections.');
  577. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  578. Add(' of the section so we begin them at 0. */');
  579. Add(' /* DWARF 1 */');
  580. Add(' .debug 0 : { *(.debug) }');
  581. Add(' .line 0 : { *(.line) }');
  582. Add(' /* GNU DWARF 1 extensions */');
  583. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  584. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  585. Add(' /* DWARF 1.1 and DWARF 2 */');
  586. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  587. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  588. Add(' /* DWARF 2 */');
  589. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  590. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  591. Add(' .debug_line 0 : { *(.debug_line) }');
  592. Add(' .debug_frame 0 : { *(.debug_frame) }');
  593. Add(' .debug_str 0 : { *(.debug_str) }');
  594. Add(' .debug_loc 0 : { *(.debug_loc) }');
  595. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  596. Add('}');
  597. end;
  598. {$endif AVR}
  599. {$ifdef MIPSEL}
  600. case current_settings.controllertype of
  601. ct_none:
  602. begin
  603. end;
  604. ct_pic32mx110f016b,
  605. ct_pic32mx110f016c,
  606. ct_pic32mx110f016d,
  607. ct_pic32mx120f032b,
  608. ct_pic32mx120f032c,
  609. ct_pic32mx120f032d,
  610. ct_pic32mx130f064b,
  611. ct_pic32mx130f064c,
  612. ct_pic32mx130f064d,
  613. ct_pic32mx150f128b,
  614. ct_pic32mx150f128c,
  615. ct_pic32mx150f128d,
  616. ct_pic32mx210f016b,
  617. ct_pic32mx210f016c,
  618. ct_pic32mx210f016d,
  619. ct_pic32mx220f032b,
  620. ct_pic32mx220f032c,
  621. ct_pic32mx220f032d,
  622. ct_pic32mx230f064b,
  623. ct_pic32mx230f064c,
  624. ct_pic32mx230f064d,
  625. ct_pic32mx250f128b,
  626. ct_pic32mx250f128c,
  627. ct_pic32mx250f128d,
  628. ct_pic32mx775f256h,
  629. ct_pic32mx775f256l,
  630. ct_pic32mx775f512h,
  631. ct_pic32mx775f512l,
  632. ct_pic32mx795f512h,
  633. ct_pic32mx795f512l:
  634. begin
  635. with embedded_controllers[current_settings.controllertype] do
  636. with linkres do
  637. begin
  638. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  639. Add('OUTPUT_ARCH(pic32mx)');
  640. Add('ENTRY(_reset)');
  641. Add('PROVIDE(_vector_spacing = 0x00000001);');
  642. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  643. Add('_RESET_ADDR = 0xBFC00000;');
  644. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  645. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  646. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  647. Add('MEMORY');
  648. Add('{');
  649. if flashsize<>0 then
  650. begin
  651. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  652. //TODO This should better be placed into the controllertype records
  653. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  654. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  655. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  656. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  657. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  658. end;
  659. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  660. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  661. Add('}');
  662. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  663. end;
  664. end
  665. end;
  666. with linkres do
  667. begin
  668. Add('SECTIONS');
  669. Add('{');
  670. Add(' .reset _RESET_ADDR :');
  671. Add(' {');
  672. Add(' KEEP(*(.reset .reset.*))');
  673. Add(' KEEP(*(.startup .startup.*))');
  674. Add(' } > kseg1_boot_mem');
  675. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  676. Add(' {');
  677. Add(' KEEP(*(.bev_handler))');
  678. Add(' } > kseg1_boot_mem');
  679. Add(' .text :');
  680. Add(' {');
  681. Add(' _text_start = .;');
  682. Add(' . = _text_start + 0x180;');
  683. Add(' KEEP(*(.gen_handler))');
  684. Add(' . = _text_start + 0x200;');
  685. Add(' KEEP(*(.init .init.*))');
  686. Add(' *(.text .text.*)');
  687. Add(' *(.strings)');
  688. Add(' *(.rodata .rodata.*)');
  689. Add(' *(.comment)');
  690. Add(' _etext = .;');
  691. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  692. begin
  693. Add(' } >kseg0_program_mem');
  694. end
  695. else
  696. begin
  697. Add(' } >ram');
  698. end;
  699. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  700. Add(' .data :');
  701. Add(' {');
  702. Add(' _data = .;');
  703. Add(' *(.data .data.*)');
  704. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  705. Add(' . = .;');
  706. Add(' _gp = ALIGN(16) + 0x7ff0;');
  707. Add(' _edata = .;');
  708. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  709. begin
  710. Add(' } >ram AT >kseg0_program_mem');
  711. end
  712. else
  713. begin
  714. Add(' } >ram');
  715. end;
  716. Add(' .config_BFC00BF0 : {');
  717. Add(' KEEP(*(.config_BFC00BF0))');
  718. Add(' } > config3');
  719. Add(' .config_BFC00BF4 : {');
  720. Add(' KEEP(*(.config_BFC00BF4))');
  721. Add(' } > config2');
  722. Add(' .config_BFC00BF8 : {');
  723. Add(' KEEP(*(.config_BFC00BF8))');
  724. Add(' } > config1');
  725. Add(' .config_BFC00BFC : {');
  726. Add(' KEEP(*(.config_BFC00BFC))');
  727. Add(' } > config0');
  728. Add(' .bss :');
  729. Add(' {');
  730. Add(' _bss_start = .;');
  731. Add(' *(.bss .bss.*)');
  732. Add(' *(COMMON)');
  733. Add(' } >ram');
  734. Add('. = ALIGN(4);');
  735. Add('_bss_end = . ;');
  736. Add(' .comment 0 : { *(.comment) }');
  737. Add(' /* DWARF debug sections.');
  738. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  739. Add(' of the section so we begin them at 0. */');
  740. Add(' /* DWARF 1 */');
  741. Add(' .debug 0 : { *(.debug) }');
  742. Add(' .line 0 : { *(.line) }');
  743. Add(' /* GNU DWARF 1 extensions */');
  744. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  745. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  746. Add(' /* DWARF 1.1 and DWARF 2 */');
  747. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  748. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  749. Add(' /* DWARF 2 */');
  750. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  751. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  752. Add(' /DISCARD/ : { *(.debug_line) }');
  753. Add(' .debug_frame 0 : { *(.debug_frame) }');
  754. Add(' .debug_str 0 : { *(.debug_str) }');
  755. Add(' /DISCARD/ : { *(.debug_loc) }');
  756. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  757. Add(' /* SGI/MIPS DWARF 2 extensions */');
  758. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  759. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  760. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  761. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  762. Add(' /* DWARF 3 */');
  763. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  764. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  765. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  766. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  767. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  768. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  769. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  770. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  771. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  772. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  773. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  774. Add(' /DISCARD/ : { *(.rel.dyn) }');
  775. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  776. Add('}');
  777. Add('_end = .;');
  778. end;
  779. {$endif MIPSEL}
  780. {$ifdef RISCV32}
  781. with linkres do
  782. begin
  783. Add('OUTPUT_ARCH("riscv")');
  784. Add('ENTRY(_START)');
  785. Add('MEMORY');
  786. with embedded_controllers[current_settings.controllertype] do
  787. begin
  788. Add('{');
  789. Add(' flash (rx) : ORIGIN = 0x'+IntToHex(flashbase,6)+', LENGTH = 0x'+IntToHex(flashsize,6));
  790. Add(' ram (rw!x) : ORIGIN = 0x'+IntToHex(srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  791. Add('}');
  792. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  793. end;
  794. Add('SECTIONS');
  795. Add('{');
  796. Add(' .text :');
  797. Add(' {');
  798. Add(' _text_start = .;');
  799. Add(' KEEP(*(.init .init.*))');
  800. Add(' *(.text .text.*)');
  801. Add(' *(.strings)');
  802. Add(' *(.rodata .rodata.*)');
  803. Add(' *(.comment)');
  804. Add(' . = ALIGN(4);');
  805. Add(' _etext = .;');
  806. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  807. begin
  808. Add(' } >flash');
  809. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  810. end
  811. else
  812. begin
  813. Add(' } >ram');
  814. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  815. end;
  816. Add(' .data :');
  817. Add(' {');
  818. Add(' _data = .;');
  819. Add(' *(.data .data.*)');
  820. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  821. Add(' _edata = .;');
  822. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  823. begin
  824. Add(' } >ram AT >flash');
  825. end
  826. else
  827. begin
  828. Add(' } >ram');
  829. end;
  830. Add(' .bss :');
  831. Add(' {');
  832. Add(' _bss_start = .;');
  833. Add(' *(.bss .bss.*)');
  834. Add(' *(COMMON)');
  835. Add(' } >ram');
  836. Add(' . = ALIGN(4);');
  837. Add(' _bss_end = . ;');
  838. Add(' /* Stabs debugging sections. */');
  839. Add(' .stab 0 : { *(.stab) }');
  840. Add(' .stabstr 0 : { *(.stabstr) }');
  841. Add(' .stab.excl 0 : { *(.stab.excl) }');
  842. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  843. Add(' .stab.index 0 : { *(.stab.index) }');
  844. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  845. Add(' .comment 0 : { *(.comment) }');
  846. Add(' /* DWARF debug sections.');
  847. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  848. Add(' of the section so we begin them at 0. */');
  849. Add(' /* DWARF 1 */');
  850. Add(' .debug 0 : { *(.debug) }');
  851. Add(' .line 0 : { *(.line) }');
  852. Add(' /* GNU DWARF 1 extensions */');
  853. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  854. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  855. Add(' /* DWARF 1.1 and DWARF 2 */');
  856. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  857. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  858. Add(' /* DWARF 2 */');
  859. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  860. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  861. Add(' .debug_line 0 : { *(.debug_line) }');
  862. Add(' .debug_frame 0 : { *(.debug_frame) }');
  863. Add(' .debug_str 0 : { *(.debug_str) }');
  864. Add(' .debug_loc 0 : { *(.debug_loc) }');
  865. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  866. Add(' /* SGI/MIPS DWARF 2 extensions */');
  867. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  868. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  869. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  870. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  871. Add(' /* DWARF 3 */');
  872. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  873. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  874. Add('}');
  875. Add('_end = .;');
  876. end;
  877. {$endif RISCV32}
  878. {$ifdef XTENSA}
  879. with linkres do
  880. begin
  881. Add('SECTIONS');
  882. Add('{');
  883. Add(' .data :');
  884. Add(' {');
  885. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  886. Add(' }');
  887. Add('}');
  888. end;
  889. {$endif XTENSA}
  890. { Write and Close response }
  891. linkres.writetodisk;
  892. linkres.free;
  893. WriteResponseFile:=True;
  894. end;
  895. {$ifdef XTENSA}
  896. { If espX.project.ld or espX_out.ld scripts cannot be located, generate
  897. default scripts so that linking can proceed. Note: the generated
  898. scripts may not match the actual options chosen when the libraries
  899. were built. }
  900. procedure TlinkerFreeRTOS.GenerateDefaultLinkerScripts(var memory_filename,
  901. sections_filename: AnsiString);
  902. type
  903. Tesp_idf_index=(esp32_v4_2=0,esp32_v4_4,esp8266_v3_3);
  904. const
  905. esp_fragment_list: array[esp32_v4_2..esp8266_v3_3] of array of string=(
  906. ('xtensa/linker',
  907. 'soc/linker',
  908. 'esp_event/linker',
  909. 'spi_flash/linker',
  910. 'esp_wifi/linker',
  911. 'lwip/linker',
  912. 'heap/linker',
  913. 'esp_ringbuf/linker',
  914. 'espcoredump/linker',
  915. 'esp32/linker',
  916. 'esp32/ld/esp32_fragments',
  917. 'freertos/linker',
  918. 'newlib/newlib',
  919. 'esp_gdbstub/linker'),
  920. ('driver/linker',
  921. 'esp_pm/linker',
  922. 'spi_flash/linker',
  923. 'esp_gdbstub/linker',
  924. 'espcoredump/linker',
  925. 'esp_phy/linker',
  926. 'esp_system/linker',
  927. 'esp_system/app',
  928. 'hal/linker',
  929. 'esp_event/linker',
  930. 'esp_wifi/linker',
  931. 'lwip/linker',
  932. 'log/linker',
  933. 'heap/linker',
  934. 'soc/linker',
  935. 'esp_hw_support/linker',
  936. 'xtensa/linker',
  937. 'esp_common/common',
  938. 'esp_common/soc',
  939. 'freertos/linker',
  940. 'newlib/newlib',
  941. 'newlib/system_libs',
  942. 'app_trace/linker',
  943. 'bt/linker'),
  944. ('esp8266/ld/esp8266_fragments',
  945. 'esp8266/ld/esp8266_bss_fragments',
  946. 'esp8266/linker',
  947. 'freertos/linker',
  948. 'log/linker',
  949. 'lwip/linker',
  950. 'spi_flash/linker'));
  951. var
  952. S: Ansistring;
  953. t: Text;
  954. hp: TCmdStrListItem;
  955. filepath: TCmdStr = '';
  956. i,j: integer;
  957. idf_index: Tesp_idf_index;
  958. lib,
  959. binstr,
  960. cmdstr: AnsiString;
  961. success: boolean;
  962. begin
  963. { generate a sdkconfig.h if none is provided,
  964. only a few fields are provided to far.
  965. Assume that if linker scripts are not located,
  966. sdkconfig.h is also missing }
  967. Assign(t,outputexedir+'/sdkconfig.h');
  968. {$push}{$I-}
  969. Rewrite(t);
  970. if ioresult<>0 then
  971. exit;
  972. if (current_settings.controllertype = ct_esp32) then
  973. begin
  974. writeln(t,'#pragma once');
  975. writeln(t,'#define CONFIG_APP_BUILD_USE_FLASH_SECTIONS 1');
  976. writeln(t,'#define CONFIG_BT_RESERVE_DRAM 0x0');
  977. writeln(t,'#define CONFIG_ESP32_ULP_COPROC_RESERVE_MEM 0');
  978. writeln(t,'#define CONFIG_ESP32_TRACEMEM_RESERVE_DRAM 0x0');
  979. end
  980. else
  981. begin
  982. { TODO: APP_OFFSET & APP_SIZE depends on partition table
  983. Default for partition table: Single factory app, no OTA }
  984. writeln(t,'#define APP_OFFSET 0x10000');
  985. writeln(t,'#define APP_SIZE 0xf0000');
  986. { Include build version of sdkconfig.h for custom configuration, if available }
  987. S:=idfpath+'/libs/sdkconfig.h';
  988. if SysUtils.FileExists(S) then
  989. writeln(t,'#include "'+S+'"')
  990. else
  991. { Assume SOC_FULL_ICACHE option not selected (default) }
  992. writeln(t,'#define CONFIG_SOC_IRAM_SIZE 0xC000');
  993. end;
  994. Close(t);
  995. if ioresult<>0 then
  996. exit;
  997. {$pop}
  998. { generate an sdkconfig if none is provided,
  999. this is a dummy so far }
  1000. if not(Sysutils.FileExists(outputexedir+'/sdkconfig')) then
  1001. begin
  1002. Assign(t,outputexedir+'/sdkconfig');
  1003. {$push}{$I-}
  1004. Rewrite(t);
  1005. if ioresult<>0 then
  1006. exit;
  1007. writeln(t);
  1008. Close(t);
  1009. if ioresult<>0 then
  1010. exit;
  1011. {$pop}
  1012. end;
  1013. { generate an Kconfig if none is provided,
  1014. this is a dummy so far }
  1015. if not(Sysutils.FileExists(outputexedir+'/Kconfig')) then
  1016. begin
  1017. Assign(t,outputexedir+'/Kconfig');
  1018. {$push}{$I-}
  1019. Rewrite(t);
  1020. if ioresult<>0 then
  1021. exit;
  1022. writeln(t);
  1023. Close(t);
  1024. if ioresult<>0 then
  1025. exit;
  1026. {$pop}
  1027. end;
  1028. { generate an Kconfig.projbuild if none is provided,
  1029. this is a dummy so far }
  1030. if not(Sysutils.FileExists(outputexedir+'/Kconfig.projbuild')) then
  1031. begin
  1032. Assign(t,outputexedir+'/Kconfig.projbuild');
  1033. {$push}{$I-}
  1034. Rewrite(t);
  1035. if ioresult<>0 then
  1036. exit;
  1037. writeln(t);
  1038. Close(t);
  1039. if ioresult<>0 then
  1040. exit;
  1041. {$pop}
  1042. end;
  1043. { generate an kconfigs.in if none is provided,
  1044. this is a dummy so far }
  1045. if not(Sysutils.FileExists(outputexedir+'/kconfigs.in')) then
  1046. begin
  1047. Assign(t,outputexedir+'/kconfigs.in');
  1048. {$push}{$I-}
  1049. Rewrite(t);
  1050. if ioresult<>0 then
  1051. exit;
  1052. writeln(t);
  1053. Close(t);
  1054. if ioresult<>0 then
  1055. exit;
  1056. {$pop}
  1057. end;
  1058. { generate an kconfigs_projbuild.in if none is provided,
  1059. this is a dummy so far }
  1060. if not(Sysutils.FileExists(outputexedir+'/kconfigs_projbuild.in')) then
  1061. begin
  1062. Assign(t,outputexedir+'/kconfigs_projbuild.in');
  1063. {$push}{$I-}
  1064. Rewrite(t);
  1065. if ioresult<>0 then
  1066. exit;
  1067. writeln(t);
  1068. Close(t);
  1069. if ioresult<>0 then
  1070. exit;
  1071. {$pop}
  1072. end;
  1073. { generate a config.env if none is provided,
  1074. COMPONENT_KCONFIGS and COMPONENT_KCONFIGS_PROJBUILD are dummy fields and might
  1075. be needed to be filed properly }
  1076. Assign(t,outputexedir+'/config.env');
  1077. {$push}{$I-}
  1078. Rewrite(t);
  1079. if ioresult<>0 then
  1080. exit;
  1081. writeln(t,'{');
  1082. if (current_settings.controllertype = ct_esp32) then
  1083. begin
  1084. writeln(t,' "COMPONENT_KCONFIGS": "Kconfig",');
  1085. writeln(t,' "COMPONENT_KCONFIGS_PROJBUILD": "Kconfig.projbuild",');
  1086. writeln(t,' "IDF_CMAKE": "y",');
  1087. writeln(t,' "IDF_TARGET": "esp32",');
  1088. writeln(t,' "IDF_PATH": "'+TargetFixPath(idfpath,false)+'",');
  1089. writeln(t,' "COMPONENT_KCONFIGS_SOURCE_FILE": "'+outputexedir+'/kconfigs.in",');
  1090. writeln(t,' "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE": "'+outputexedir+'/kconfigs_projbuild.in"');
  1091. end
  1092. else
  1093. begin
  1094. writeln(t,' "IDF_PATH": "'+TargetFixPath(idfpath,false)+'",');
  1095. writeln(t,' "IDF_TARGET": "esp8266",');
  1096. writeln(t,' "IDF_CMAKE": "n"');
  1097. end;
  1098. writeln(t,'}');
  1099. Close(t);
  1100. if ioresult<>0 then
  1101. exit;
  1102. {$pop}
  1103. { generate ldgen_libraries }
  1104. Assign(t,outputexedir+'/ldgen_libraries');
  1105. {$push}{$I-}
  1106. Rewrite(t);
  1107. if ioresult<>0 then
  1108. exit;
  1109. { extract libraries from linker options and add to static libraries list }
  1110. Info.ExtraOptions:=trim(Info.ExtraOptions);
  1111. i := pos('-l', Info.ExtraOptions);
  1112. while i > 0 do
  1113. begin
  1114. j:=pos(' ',Info.ExtraOptions);
  1115. if j=0 then
  1116. j:=length(Info.ExtraOptions)+1;
  1117. lib:=copy(Info.ExtraOptions,i+2,j-i-2);
  1118. AddStaticCLibrary(lib);
  1119. delete(Info.ExtraOptions,i,j);
  1120. trim(Info.ExtraOptions);
  1121. i := pos('-l', Info.ExtraOptions);
  1122. end;
  1123. hp:=TCmdStrListItem(StaticLibFiles.First);
  1124. while assigned(hp) do
  1125. begin
  1126. FindLibraryFile(hp.Str,target_info.staticClibprefix,target_info.staticClibext,filepath);
  1127. writeln(t,filepath);
  1128. hp:=TCmdStrListItem(hp.Next);
  1129. end;
  1130. Close(t);
  1131. if ioresult<>0 then
  1132. exit;
  1133. {$pop}
  1134. memory_filename:=IncludeTrailingPathDelimiter(outputexedir)+memory_filename;
  1135. cmdstr:='-C -P -x c -E -o '+memory_filename+' -I $OUTPUT ';
  1136. binstr:='gcc';
  1137. if current_settings.controllertype = ct_none then
  1138. Message(exec_f_controllertype_expected)
  1139. else if current_settings.controllertype = ct_esp32 then
  1140. begin
  1141. if idf_version>=40400 then
  1142. cmdstr:=cmdstr+'$IDF_PATH/components/esp_system/ld/esp32/sections.ld.in'
  1143. else
  1144. cmdstr:=cmdstr+'$IDF_PATH/components/esp32/ld/esp32.ld';
  1145. end
  1146. else
  1147. cmdstr:=cmdstr+'$IDF_PATH/components/esp8266/ld/esp8266.ld';
  1148. Replace(cmdstr,'$IDF_PATH',idfpath);
  1149. Replace(cmdstr,'$OUTPUT',outputexedir);
  1150. success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,true);
  1151. { generate linker maps }
  1152. {$ifdef UNIX}
  1153. binstr:=TargetFixPath(idfpath,false)+'/tools/ldgen/ldgen.py';
  1154. {$else}
  1155. binstr:='python';
  1156. {$endif UNIX}
  1157. if source_info.exeext<>'' then
  1158. binstr:=binstr+source_info.exeext;
  1159. sections_filename:=IncludeTrailingPathDelimiter(outputexedir)+sections_filename;
  1160. cmdstr:={$ifndef UNIX}'$IDF_PATH/tools/ldgen/ldgen.py '+{$endif UNIX}
  1161. '--config $OUTPUT/sdkconfig --fragments';
  1162. { Pick corresponding linker fragments list for SDK version }
  1163. if (current_settings.controllertype = ct_esp32) then
  1164. if idf_version>=40400 then
  1165. idf_index:=esp32_v4_4
  1166. else
  1167. idf_index:=esp32_v4_2
  1168. else
  1169. idf_index:=esp8266_v3_3;
  1170. for S in esp_fragment_list[idf_index] do
  1171. cmdstr:=cmdstr+' $IDF_PATH/components/'+S+'.lf';
  1172. if (current_settings.controllertype = ct_esp32) then
  1173. begin
  1174. if idf_version>=40400 then
  1175. cmdstr:=cmdstr+' --input $IDF_PATH/components/esp_system/esp32/ld/sections.ld.in'
  1176. else
  1177. cmdstr:=cmdstr+' --input $IDF_PATH/components/esp32/ld/esp32.project.ld.in';
  1178. end
  1179. else
  1180. begin
  1181. cmdstr:=cmdstr+
  1182. ' --env "COMPONENT_KCONFIGS_PROJBUILD= $IDF_PATH/components/bootloader/Kconfig.projbuild'+
  1183. ' $IDF_PATH/components/esptool_py/Kconfig.projbuild $IDF_PATH/components/partition_table/Kconfig.projbuild"'+
  1184. ' --env "COMPONENT_KCONFIGS=$IDF_PATH/components/app_update/Kconfig'+
  1185. ' $IDF_PATH/components/esp8266/Kconfig $IDF_PATH/components/freertos/Kconfig'+
  1186. ' $IDF_PATH/components/log/Kconfig $IDF_PATH/components/lwip/Kconfig"'+
  1187. ' --input $IDF_PATH/components/esp8266/ld/esp8266.project.ld.in';
  1188. end;
  1189. S:=FindUtil(utilsprefix+'objdump');
  1190. cmdstr:=cmdstr+' --output '+sections_filename+
  1191. ' --kconfig $IDF_PATH/Kconfig'+
  1192. ' --env-file $OUTPUT/config.env'+
  1193. ' --libraries-file $OUTPUT/ldgen_libraries'+
  1194. ' --objdump '+S;
  1195. Replace(cmdstr,'$IDF_PATH',idfpath);
  1196. Replace(cmdstr,'$OUTPUT',outputexedir);
  1197. if success then
  1198. success:=DoExec(binstr,cmdstr,true,false);
  1199. end;
  1200. {$endif XTENSA}
  1201. function TlinkerFreeRTOS.MakeExecutable:boolean;
  1202. var
  1203. StaticStr,
  1204. binstr,
  1205. cmdstr,
  1206. mapstr: Ansistring;
  1207. success : boolean;
  1208. GCSectionsStr,
  1209. DynLinkStr,
  1210. StripStr,
  1211. FixedExeFileName: string;
  1212. {$ifdef XTENSA}
  1213. memory_script,
  1214. sections_script: AnsiString;
  1215. {$endif XTENSA}
  1216. begin
  1217. {$ifdef XTENSA}
  1218. { idfpath can be set by -Ff, else default to environment value of IDF_PATH }
  1219. if idfpath='' then
  1220. idfpath := trim(GetEnvironmentVariable('IDF_PATH'));
  1221. idfpath:=ExcludeTrailingBackslash(idfpath);
  1222. {$endif XTENSA}
  1223. { for future use }
  1224. StaticStr:='';
  1225. StripStr:='';
  1226. mapstr:='';
  1227. DynLinkStr:='';
  1228. success:=true;
  1229. Result:=false;
  1230. {$ifdef XTENSA}
  1231. { Locate linker scripts. If not found, generate defaults. }
  1232. { Cater for different script names in different esp-idf versions }
  1233. if (current_settings.controllertype = ct_esp32) then
  1234. begin
  1235. if idf_version >= 40400 then
  1236. begin
  1237. memory_script := 'memory.ld';
  1238. sections_script := 'sections.ld';
  1239. end
  1240. else
  1241. begin
  1242. memory_script := 'esp32_out.ld';
  1243. sections_script := 'esp32.project.ld';
  1244. end;
  1245. end
  1246. else if (current_settings.controllertype = ct_esp8266) then
  1247. begin
  1248. memory_script := 'esp8266_out.ld';
  1249. sections_script := 'esp8266.project.ld';
  1250. end;
  1251. if not (FindLibraryFile(memory_script,'','',memory_script) and
  1252. FindLibraryFile(sections_script,'','',sections_script)) then
  1253. GenerateDefaultLinkerScripts(memory_script,sections_script);
  1254. if (current_settings.controllertype = ct_esp32) then
  1255. begin
  1256. Info.ExeCmd[1]:=Info.ExeCmd[1]+' -u call_user_start_cpu0 -u ld_include_panic_highint_hdl -u esp_app_desc -u vfs_include_syscalls_impl -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u newlib_include_locks_impl '+
  1257. '-u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority '+
  1258. '-L $IDF_PATH/components/esp_rom/esp32/ld '+
  1259. '-T esp32.rom.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.rom.newlib-funcs.ld '+
  1260. '-T '+memory_script+' -T '+sections_script;
  1261. if idf_version<40400 then
  1262. Info.ExeCmd[1]:=Info.ExeCmd[1]+' -L $IDF_PATH/components/esp32/ld -T esp32.peripherals.ld'
  1263. else
  1264. Info.ExeCmd[1]:=Info.ExeCmd[1]+' -L $IDF_PATH/components/soc/esp32/ld -T esp32.peripherals.ld';
  1265. if idf_version>=40300 then
  1266. Info.ExeCmd[1]:=Info.ExeCmd[1]+' -T esp32.rom.api.ld';
  1267. if idf_version>=40400 then
  1268. Info.ExeCmd[1]:=Info.ExeCmd[1]+' -T esp32.rom.newlib-time.ld';
  1269. end
  1270. else
  1271. begin
  1272. Info.ExeCmd[1] := Info.ExeCmd[1]+' -u call_user_start -u g_esp_sys_info -u _printf_float -u _scanf_float '+
  1273. '-L $IDF_PATH/components/esp8266/ld -T esp8266.peripherals.ld -T esp8266.rom.ld '+ { SDK scripts }
  1274. '-T '+memory_script+' -T '+sections_script; { Project scripts }
  1275. end;
  1276. Replace(Info.ExeCmd[1],'$IDF_PATH',idfpath);
  1277. {$endif XTENSA}
  1278. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
  1279. GCSectionsStr:='--gc-sections';
  1280. if not(cs_link_nolink in current_settings.globalswitches) then
  1281. Message1(exec_i_linking,current_module.exefilename);
  1282. if (cs_link_map in current_settings.globalswitches) then
  1283. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1284. { Write used files and libraries }
  1285. WriteResponseFile();
  1286. { Call linker }
  1287. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1288. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1289. if not(cs_link_on_target in current_settings.globalswitches) then
  1290. begin
  1291. Replace(cmdstr,'$EXE',FixedExeFileName);
  1292. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1293. Replace(cmdstr,'$STATIC',StaticStr);
  1294. Replace(cmdstr,'$STRIP',StripStr);
  1295. Replace(cmdstr,'$MAP',mapstr);
  1296. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1297. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1298. end
  1299. else
  1300. begin
  1301. Replace(cmdstr,'$EXE',FixedExeFileName);
  1302. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1303. Replace(cmdstr,'$STATIC',StaticStr);
  1304. Replace(cmdstr,'$STRIP',StripStr);
  1305. Replace(cmdstr,'$MAP',mapstr);
  1306. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1307. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1308. end;
  1309. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1310. { Remove ReponseFile }
  1311. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1312. DeleteFile(outputexedir+Info.ResName);
  1313. { Post process }
  1314. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1315. success:=PostProcessExecutable(FixedExeFileName,false);
  1316. {$ifdef XTENSA}
  1317. if success then
  1318. begin
  1319. {$ifdef UNIX}
  1320. binstr:=TargetFixPath(idfpath,false)+'/components/esptool_py/esptool/esptool.py';
  1321. cmdstr:='';
  1322. {$else}
  1323. binstr:='python';
  1324. cmdstr:=idfpath+'/components/esptool_py/esptool/esptool.py ';
  1325. {$endif UNIX}
  1326. if source_info.exeext<>'' then
  1327. binstr:=binstr+source_info.exeext;
  1328. if (current_settings.controllertype = ct_esp32) then
  1329. begin
  1330. success:=DoExec(binstr,cmdstr+'--chip esp32 elf2image --flash_mode dio --flash_freq 40m '+
  1331. '--flash_size '+tostr(embedded_controllers[current_settings.controllertype].flashsize div (1024*1024))+'MB '+
  1332. '--elf-sha256-offset 0xb0 '+
  1333. '-o '+maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin')))+' '+
  1334. FixedExeFileName,
  1335. true,false);
  1336. end
  1337. else if (current_settings.controllertype = ct_esp8266) then
  1338. begin
  1339. success:=DoExec(binstr,cmdstr+'--chip esp8266 elf2image --flash_mode dout --flash_freq 40m '+
  1340. '--flash_size '+tostr(embedded_controllers[current_settings.controllertype].flashsize div (1024*1024))+'MB '+
  1341. '--version=3 '+
  1342. '-o '+maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin')))+' '+
  1343. FixedExeFileName,
  1344. true,false);
  1345. end
  1346. end
  1347. else
  1348. {$endif XTENSA}
  1349. if success then
  1350. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1351. FixedExeFileName+' '+
  1352. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1353. MakeExecutable:=success; { otherwise a recursive call to link method }
  1354. end;
  1355. function TlinkerFreeRTOS.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1356. type
  1357. TElf32header=packed record
  1358. magic0123 : longint;
  1359. file_class : byte;
  1360. data_encoding : byte;
  1361. file_version : byte;
  1362. padding : array[$07..$0f] of byte;
  1363. e_type : word;
  1364. e_machine : word;
  1365. e_version : longint;
  1366. e_entry : longint; { entrypoint }
  1367. e_phoff : longint; { program header offset }
  1368. e_shoff : longint; { sections header offset }
  1369. e_flags : longint;
  1370. e_ehsize : word; { elf header size in bytes }
  1371. e_phentsize : word; { size of an entry in the program header array }
  1372. e_phnum : word; { 0..e_phnum-1 of entrys }
  1373. e_shentsize : word; { size of an entry in sections header array }
  1374. e_shnum : word; { 0..e_shnum-1 of entrys }
  1375. e_shstrndx : word; { index of string section header }
  1376. end;
  1377. TElf32sechdr=packed record
  1378. sh_name : longint;
  1379. sh_type : longint;
  1380. sh_flags : longint;
  1381. sh_addr : longint;
  1382. sh_offset : longint;
  1383. sh_size : longint;
  1384. sh_link : longint;
  1385. sh_info : longint;
  1386. sh_addralign : longint;
  1387. sh_entsize : longint;
  1388. end;
  1389. function MayBeSwapHeader(h : telf32header) : telf32header;
  1390. begin
  1391. result:=h;
  1392. if source_info.endian<>target_info.endian then
  1393. with h do
  1394. begin
  1395. result.e_type:=swapendian(e_type);
  1396. result.e_machine:=swapendian(e_machine);
  1397. result.e_version:=swapendian(e_version);
  1398. result.e_entry:=swapendian(e_entry);
  1399. result.e_phoff:=swapendian(e_phoff);
  1400. result.e_shoff:=swapendian(e_shoff);
  1401. result.e_flags:=swapendian(e_flags);
  1402. result.e_ehsize:=swapendian(e_ehsize);
  1403. result.e_phentsize:=swapendian(e_phentsize);
  1404. result.e_phnum:=swapendian(e_phnum);
  1405. result.e_shentsize:=swapendian(e_shentsize);
  1406. result.e_shnum:=swapendian(e_shnum);
  1407. result.e_shstrndx:=swapendian(e_shstrndx);
  1408. end;
  1409. end;
  1410. function MaybeSwapSecHeader(h : telf32sechdr) : telf32sechdr;
  1411. begin
  1412. result:=h;
  1413. if source_info.endian<>target_info.endian then
  1414. with h do
  1415. begin
  1416. result.sh_name:=swapendian(sh_name);
  1417. result.sh_type:=swapendian(sh_type);
  1418. result.sh_flags:=swapendian(sh_flags);
  1419. result.sh_addr:=swapendian(sh_addr);
  1420. result.sh_offset:=swapendian(sh_offset);
  1421. result.sh_size:=swapendian(sh_size);
  1422. result.sh_link:=swapendian(sh_link);
  1423. result.sh_info:=swapendian(sh_info);
  1424. result.sh_addralign:=swapendian(sh_addralign);
  1425. result.sh_entsize:=swapendian(sh_entsize);
  1426. end;
  1427. end;
  1428. var
  1429. f : file;
  1430. function ReadSectionName(pos : longint) : String;
  1431. var
  1432. oldpos : longint;
  1433. c : char;
  1434. begin
  1435. oldpos:=filepos(f);
  1436. seek(f,pos);
  1437. Result:='';
  1438. while true do
  1439. begin
  1440. blockread(f,c,1);
  1441. if c=#0 then
  1442. break;
  1443. Result:=Result+c;
  1444. end;
  1445. seek(f,oldpos);
  1446. end;
  1447. var
  1448. elfheader : TElf32header;
  1449. secheader : TElf32sechdr;
  1450. i : longint;
  1451. stringoffset : longint;
  1452. secname : string;
  1453. begin
  1454. postprocessexecutable:=false;
  1455. { open file }
  1456. assign(f,fn);
  1457. {$push}{$I-}
  1458. reset(f,1);
  1459. if ioresult<>0 then
  1460. Message1(execinfo_f_cant_open_executable,fn);
  1461. { read header }
  1462. blockread(f,elfheader,sizeof(tElf32header));
  1463. elfheader:=MayBeSwapHeader(elfheader);
  1464. seek(f,elfheader.e_shoff);
  1465. { read string section header }
  1466. seek(f,elfheader.e_shoff+sizeof(TElf32sechdr)*elfheader.e_shstrndx);
  1467. blockread(f,secheader,sizeof(secheader));
  1468. secheader:=MaybeSwapSecHeader(secheader);
  1469. stringoffset:=secheader.sh_offset;
  1470. seek(f,elfheader.e_shoff);
  1471. status.codesize:=0;
  1472. status.datasize:=0;
  1473. for i:=0 to elfheader.e_shnum-1 do
  1474. begin
  1475. blockread(f,secheader,sizeof(secheader));
  1476. secheader:=MaybeSwapSecHeader(secheader);
  1477. secname:=ReadSectionName(stringoffset+secheader.sh_name);
  1478. if pos('.text',secname)<>0 then
  1479. begin
  1480. Message1(execinfo_x_codesize,tostr(secheader.sh_size));
  1481. status.codesize:=secheader.sh_size;
  1482. end
  1483. else if secname='.data' then
  1484. begin
  1485. Message1(execinfo_x_initdatasize,tostr(secheader.sh_size));
  1486. inc(status.datasize,secheader.sh_size);
  1487. end
  1488. else if secname='.bss' then
  1489. begin
  1490. Message1(execinfo_x_uninitdatasize,tostr(secheader.sh_size));
  1491. inc(status.datasize,secheader.sh_size);
  1492. end;
  1493. end;
  1494. close(f);
  1495. {$pop}
  1496. if ioresult<>0 then
  1497. ;
  1498. postprocessexecutable:=true;
  1499. end;
  1500. {*****************************************************************************
  1501. Initialize
  1502. *****************************************************************************}
  1503. initialization
  1504. {$ifdef arm}
  1505. RegisterLinker(ld_freertos,TlinkerFreeRTOS);
  1506. RegisterTarget(system_arm_freertos_info);
  1507. {$endif arm}
  1508. {$ifdef avr}
  1509. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1510. RegisterTarget(system_avr_embedded_info);
  1511. {$endif avr}
  1512. {$ifdef i386}
  1513. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1514. RegisterTarget(system_i386_embedded_info);
  1515. {$endif i386}
  1516. {$ifdef x86_64}
  1517. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1518. RegisterTarget(system_x86_64_embedded_info);
  1519. {$endif x86_64}
  1520. {$ifdef i8086}
  1521. { no need to register linker ld_embedded, because i8086_embedded uses the
  1522. regular msdos linker. In case a flat binary, relocated for a specific
  1523. segment address is needed (e.g. for a BIOS or a real mode bootloader), it
  1524. can be produced post-compilation with exe2bin or a similar tool. }
  1525. RegisterTarget(system_i8086_embedded_info);
  1526. {$endif i8086}
  1527. {$ifdef mipsel}
  1528. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1529. RegisterTarget(system_mipsel_embedded_info);
  1530. {$endif mipsel}
  1531. {$ifdef m68k}
  1532. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1533. RegisterTarget(system_m68k_embedded_info);
  1534. {$endif m68k}
  1535. {$ifdef riscv32}
  1536. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1537. RegisterTarget(system_riscv32_embedded_info);
  1538. {$endif riscv32}
  1539. {$ifdef riscv64}
  1540. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1541. RegisterTarget(system_riscv64_embedded_info);
  1542. {$endif riscv64}
  1543. {$ifdef xtensa}
  1544. RegisterLinker(ld_freertos,TlinkerFreeRTOS);
  1545. RegisterTarget(system_xtensa_freertos_info);
  1546. {$endif xtensa}
  1547. end.