t_freertos.pas 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822
  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. public
  32. constructor Create; override;
  33. procedure SetDefaultInfo; override;
  34. function MakeExecutable:boolean; override;
  35. function postprocessexecutable(const fn : string;isdll:boolean):boolean;
  36. end;
  37. {*****************************************************************************
  38. TlinkerEmbedded
  39. *****************************************************************************}
  40. Constructor TlinkerFreeRTOS.Create;
  41. begin
  42. Inherited Create;
  43. SharedLibFiles.doubles:=true;
  44. StaticLibFiles.doubles:=true;
  45. end;
  46. procedure TlinkerFreeRTOS.SetDefaultInfo;
  47. const
  48. {$ifdef mips}
  49. {$ifdef mipsel}
  50. platform_select='-EL';
  51. {$else}
  52. platform_select='-EB';
  53. {$endif}
  54. {$else}
  55. platform_select='';
  56. {$endif}
  57. begin
  58. with Info do
  59. begin
  60. if target_info.system=system_xtensa_freertos then
  61. ExeCmd[1]:='ld -g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES '+
  62. '-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 -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority '+
  63. '-L $IDF_PATH/components/esp_rom/esp32/ld -T esp32.rom.newlib-funcs-time.ld '+
  64. '-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 '+
  65. '-L . -T esp32_out.ld -T esp32.project.ld '+
  66. '-L $IDF_PATH/components/esp32/ld -T esp32.peripherals.ld'
  67. else
  68. ExeCmd[1]:='ld -g '+platform_select+' $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE -T $RES';
  69. end;
  70. end;
  71. Function TlinkerFreeRTOS.WriteResponseFile: Boolean;
  72. Var
  73. linkres : TLinkRes;
  74. i : longint;
  75. HPath : TCmdStrListItem;
  76. s,s1,s2 : TCmdStr;
  77. prtobj,
  78. cprtobj : string[80];
  79. linklibc : boolean;
  80. found1,
  81. found2 : boolean;
  82. {$if defined(ARM)}
  83. LinkStr : string;
  84. {$endif}
  85. begin
  86. WriteResponseFile:=False;
  87. linklibc:=(SharedLibFiles.Find('c')<>nil);
  88. {$if defined(ARM) or defined(i386) or defined(x86_64) or defined(AVR) or defined(MIPSEL) or defined(RISCV32) or defined(XTENSA)}
  89. prtobj:='';
  90. {$else}
  91. prtobj:='prt0';
  92. {$endif}
  93. cprtobj:='cprt0';
  94. if linklibc then
  95. prtobj:=cprtobj;
  96. { Open link.res file }
  97. LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,true);
  98. { Write path to search libraries }
  99. HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
  100. while assigned(HPath) do
  101. begin
  102. s:=HPath.Str;
  103. if (cs_link_on_target in current_settings.globalswitches) then
  104. s:=ScriptFixFileName(s);
  105. LinkRes.Add('-L'+s);
  106. HPath:=TCmdStrListItem(HPath.Next);
  107. end;
  108. HPath:=TCmdStrListItem(LibrarySearchPath.First);
  109. while assigned(HPath) do
  110. begin
  111. s:=HPath.Str;
  112. if s<>'' then
  113. LinkRes.Add('SEARCH_DIR("'+s+'")');
  114. HPath:=TCmdStrListItem(HPath.Next);
  115. end;
  116. LinkRes.Add('INPUT (');
  117. { add objectfiles, start with prt0 always }
  118. //s:=FindObjectFile('prt0','',false);
  119. if prtobj<>'' then
  120. begin
  121. s:=FindObjectFile(prtobj,'',false);
  122. LinkRes.AddFileName(s);
  123. end;
  124. { try to add crti and crtbegin if linking to C }
  125. if linklibc then
  126. begin
  127. if librarysearchpath.FindFile('crtbegin.o',false,s) then
  128. LinkRes.AddFileName(s);
  129. if librarysearchpath.FindFile('crti.o',false,s) then
  130. LinkRes.AddFileName(s);
  131. end;
  132. while not ObjectFiles.Empty do
  133. begin
  134. s:=ObjectFiles.GetFirst;
  135. if s<>'' then
  136. begin
  137. { vlink doesn't use SEARCH_DIR for object files }
  138. if not(cs_link_on_target in current_settings.globalswitches) then
  139. s:=FindObjectFile(s,'',false);
  140. LinkRes.AddFileName((maybequoted(s)));
  141. end;
  142. end;
  143. { Write staticlibraries }
  144. if not(StaticLibFiles.Empty) then
  145. begin
  146. LinkRes.Add(')');
  147. LinkRes.Add('GROUP(');
  148. while not StaticLibFiles.Empty do
  149. begin
  150. S:=StaticLibFiles.GetFirst;
  151. LinkRes.AddFileName((maybequoted(s)));
  152. end;
  153. end;
  154. LinkRes.Add(')');
  155. { Write sharedlibraries like -l<lib>, also add the needed dynamic linker
  156. here to be sure that it gets linked this is needed for glibc2 systems (PFV) }
  157. linklibc:=false;
  158. while not SharedLibFiles.Empty do
  159. begin
  160. S:=SharedLibFiles.GetFirst;
  161. if s<>'c' then
  162. begin
  163. i:=Pos(target_info.sharedlibext,S);
  164. if i>0 then
  165. Delete(S,i,255);
  166. LinkRes.Add('-l'+s);
  167. end
  168. else
  169. begin
  170. LinkRes.Add('-l'+s);
  171. linklibc:=true;
  172. end;
  173. end;
  174. { be sure that libc&libgcc is the last lib }
  175. if linklibc then
  176. begin
  177. LinkRes.Add('-lc');
  178. LinkRes.Add('-lgcc');
  179. end;
  180. { objects which must be at the end }
  181. if linklibc then
  182. begin
  183. found1:=librarysearchpath.FindFile('crtend.o',false,s1);
  184. found2:=librarysearchpath.FindFile('crtn.o',false,s2);
  185. if found1 or found2 then
  186. begin
  187. LinkRes.Add('INPUT(');
  188. if found1 then
  189. LinkRes.AddFileName(s1);
  190. if found2 then
  191. LinkRes.AddFileName(s2);
  192. LinkRes.Add(')');
  193. end;
  194. end;
  195. {$ifdef ARM}
  196. case current_settings.controllertype of
  197. ct_none:
  198. begin
  199. end;
  200. ct_lpc810m021fn8,
  201. ct_lpc811m001fdh16,
  202. ct_lpc812m101fdh16,
  203. ct_lpc812m101fd20,
  204. ct_lpc812m101fdh20,
  205. ct_lpc1110fd20,
  206. ct_lpc1111fdh20_002,
  207. ct_lpc1111fhn33_101,
  208. ct_lpc1111fhn33_102,
  209. ct_lpc1111fhn33_103,
  210. ct_lpc1111fhn33_201,
  211. ct_lpc1111fhn33_202,
  212. ct_lpc1111fhn33_203,
  213. ct_lpc1112fd20_102,
  214. ct_lpc1112fdh20_102,
  215. ct_lpc1112fdh28_102,
  216. ct_lpc1112fhn33_101,
  217. ct_lpc1112fhn33_102,
  218. ct_lpc1112fhn33_103,
  219. ct_lpc1112fhn33_201,
  220. ct_lpc1112fhn24_202,
  221. ct_lpc1112fhn33_202,
  222. ct_lpc1112fhn33_203,
  223. ct_lpc1112fhi33_202,
  224. ct_lpc1112fhi33_203,
  225. ct_lpc1113fhn33_201,
  226. ct_lpc1113fhn33_202,
  227. ct_lpc1113fhn33_203,
  228. ct_lpc1113fhn33_301,
  229. ct_lpc1113fhn33_302,
  230. ct_lpc1113fhn33_303,
  231. ct_lpc1113bfd48_301,
  232. ct_lpc1113bfd48_302,
  233. ct_lpc1113bfd48_303,
  234. ct_lpc1114fdh28_102,
  235. ct_lpc1114fn28_102,
  236. ct_lpc1114fhn33_201,
  237. ct_lpc1114fhn33_202,
  238. ct_lpc1114fhn33_203,
  239. ct_lpc1114fhn33_301,
  240. ct_lpc1114fhn33_302,
  241. ct_lpc1114fhn33_303,
  242. ct_lpc1114fhn33_333,
  243. ct_lpc1114fhi33_302,
  244. ct_lpc1114fhi33_303,
  245. ct_lpc1114bfd48_301,
  246. ct_lpc1114bfd48_302,
  247. ct_lpc1114bfd48_303,
  248. ct_lpc1114bfd48_323,
  249. ct_lpc1114bfd48_333,
  250. ct_lpc1115bfd48_303,
  251. ct_lpc11c12fd48_301,
  252. ct_lpc11c14fd48_301,
  253. ct_lpc11c22fd48_301,
  254. ct_lpc11c24fd48_301,
  255. ct_lpc11d24fd48_301,
  256. ct_lpc1224fbd48_101,
  257. ct_lpc1224fbd48_121,
  258. ct_lpc1224fbd64_101,
  259. ct_lpc1224fbd64_121,
  260. ct_lpc1225fbd48_301,
  261. ct_lpc1225fbd48_321,
  262. ct_lpc1225fbd64_301,
  263. ct_lpc1225fbd64_321,
  264. ct_lpc1226fbd48_301,
  265. ct_lpc1226fbd64_301,
  266. ct_lpc1227fbd48_301,
  267. ct_lpc1227fbd64_301,
  268. ct_lpc12d27fbd100_301,
  269. ct_lpc1311fhn33,
  270. ct_lpc1311fhn33_01,
  271. ct_lpc1313fhn33,
  272. ct_lpc1313fhn33_01,
  273. ct_lpc1313fbd48,
  274. ct_lpc1313fbd48_01,
  275. ct_lpc1315fhn33,
  276. ct_lpc1315fbd48,
  277. ct_lpc1316fhn33,
  278. ct_lpc1316fbd48,
  279. ct_lpc1317fhn33,
  280. ct_lpc1317fbd48,
  281. ct_lpc1317fbd64,
  282. ct_lpc1342fhn33,
  283. ct_lpc1342fbd48,
  284. ct_lpc1343fhn33,
  285. ct_lpc1343fbd48,
  286. ct_lpc1345fhn33,
  287. ct_lpc1345fbd48,
  288. ct_lpc1346fhn33,
  289. ct_lpc1346fbd48,
  290. ct_lpc1347fhn33,
  291. ct_lpc1347fbd48,
  292. ct_lpc1347fbd64,
  293. ct_lpc2114,
  294. ct_lpc2124,
  295. ct_lpc2194,
  296. ct_lpc1768,
  297. ct_at91sam7s256,
  298. ct_at91sam7se256,
  299. ct_at91sam7x256,
  300. ct_at91sam7xc256,
  301. ct_stm32f030c6,
  302. ct_stm32f030c8,
  303. ct_stm32f030f4,
  304. ct_stm32f030k6,
  305. ct_stm32f030r8,
  306. ct_stm32f050c4,
  307. ct_stm32f050c6,
  308. ct_stm32f050f4,
  309. ct_stm32f050f6,
  310. ct_stm32f050g4,
  311. ct_stm32f050g6,
  312. ct_stm32f050k4,
  313. ct_stm32f050k6,
  314. ct_stm32f051c4,
  315. ct_stm32f051c6,
  316. ct_stm32f051c8,
  317. ct_stm32f051k4,
  318. ct_stm32f051k6,
  319. ct_stm32f051k8,
  320. ct_stm32f051r4,
  321. ct_stm32f051r6,
  322. ct_stm32f051r8,
  323. ct_stm32f091cc,
  324. ct_stm32f091cb,
  325. ct_stm32f091rc,
  326. ct_stm32f091rb,
  327. ct_stm32f091vc,
  328. ct_stm32f091vb,
  329. ct_stm32f100x4,
  330. ct_stm32f100x6,
  331. ct_stm32f100x8,
  332. ct_stm32f100xB,
  333. ct_stm32f100xC,
  334. ct_stm32f100xD,
  335. ct_stm32f100xE,
  336. ct_stm32f101x4,
  337. ct_stm32f101x6,
  338. ct_stm32f101x8,
  339. ct_stm32f101xB,
  340. ct_stm32f101xC,
  341. ct_stm32f101xD,
  342. ct_stm32f101xE,
  343. ct_stm32f101xF,
  344. ct_stm32f101xG,
  345. ct_stm32f102x4,
  346. ct_stm32f102x6,
  347. ct_stm32f102x8,
  348. ct_stm32f102xB,
  349. ct_stm32f103x4,
  350. ct_stm32f103x6,
  351. ct_stm32f103x8,
  352. ct_stm32f103xB,
  353. ct_stm32f103xC,
  354. ct_stm32f103xD,
  355. ct_stm32f103xE,
  356. ct_stm32f103xF,
  357. ct_stm32f103xG,
  358. ct_stm32f107x8,
  359. ct_stm32f107xB,
  360. ct_stm32f107xC,
  361. ct_stm32f105r8,
  362. ct_stm32f105rb,
  363. ct_stm32f105rc,
  364. ct_stm32f105v8,
  365. ct_stm32f105vb,
  366. ct_stm32f105vc,
  367. ct_stm32f107rb,
  368. ct_stm32f107rc,
  369. ct_stm32f107vb,
  370. ct_stm32f107vc,
  371. ct_stm32f401cb,
  372. ct_stm32f401rb,
  373. ct_stm32f401vb,
  374. ct_stm32f401cc,
  375. ct_stm32f401rc,
  376. ct_stm32f401vc,
  377. ct_discoveryf401vc,
  378. ct_stm32f401cd,
  379. ct_stm32f401rd,
  380. ct_stm32f401vd,
  381. ct_stm32f401ce,
  382. ct_stm32f401re,
  383. ct_nucleof401re,
  384. ct_stm32f401ve,
  385. ct_stm32f407vg,
  386. ct_discoveryf407vg,
  387. ct_stm32f407ig,
  388. ct_stm32f407zg,
  389. ct_stm32f407ve,
  390. ct_stm32f407ze,
  391. ct_stm32f407ie,
  392. ct_stm32f411cc,
  393. ct_stm32f411rc,
  394. ct_stm32f411vc,
  395. ct_stm32f411ce,
  396. ct_stm32f411re,
  397. ct_nucleof411re,
  398. ct_stm32f411ve,
  399. ct_discoveryf411ve,
  400. ct_stm32f429vg,
  401. ct_stm32f429zg,
  402. ct_stm32f429ig,
  403. ct_stm32f429vi,
  404. ct_stm32f429zi,
  405. ct_discoveryf429zi,
  406. ct_stm32f429ii,
  407. ct_stm32f429ve,
  408. ct_stm32f429ze,
  409. ct_stm32f429ie,
  410. ct_stm32f429bg,
  411. ct_stm32f429bi,
  412. ct_stm32f429be,
  413. ct_stm32f429ng,
  414. ct_stm32f429ni,
  415. ct_stm32f429ne,
  416. ct_stm32f446mc,
  417. ct_stm32f446rc,
  418. ct_stm32f446vc,
  419. ct_stm32f446zc,
  420. ct_stm32f446me,
  421. ct_stm32f446re,
  422. ct_nucleof446re,
  423. ct_stm32f446ve,
  424. ct_stm32f446ze,
  425. ct_stm32f745xe,
  426. ct_stm32f745xg,
  427. ct_stm32f746xe,
  428. ct_stm32f746xg,
  429. ct_stm32f756xe,
  430. ct_stm32f756xg,
  431. { TI - 64 K Flash, 16 K SRAM Devices }
  432. ct_lm3s1110,
  433. ct_lm3s1133,
  434. ct_lm3s1138,
  435. ct_lm3s1150,
  436. ct_lm3s1162,
  437. ct_lm3s1165,
  438. ct_lm3s1166,
  439. ct_lm3s2110,
  440. ct_lm3s2139,
  441. ct_lm3s6100,
  442. ct_lm3s6110,
  443. { TI 128 K Flash, 32 K SRAM devices - Fury Class }
  444. ct_lm3s1601,
  445. ct_lm3s1608,
  446. ct_lm3s1620,
  447. ct_lm3s1635,
  448. ct_lm3s1636,
  449. ct_lm3s1637,
  450. ct_lm3s1651,
  451. ct_lm3s2601,
  452. ct_lm3s2608,
  453. ct_lm3s2620,
  454. ct_lm3s2637,
  455. ct_lm3s2651,
  456. ct_lm3s6610,
  457. ct_lm3s6611,
  458. ct_lm3s6618,
  459. ct_lm3s6633,
  460. ct_lm3s6637,
  461. ct_lm3s8630,
  462. { TI 256 K Flase, 32 K SRAM devices - Fury Class }
  463. ct_lm3s1911,
  464. ct_lm3s1918,
  465. ct_lm3s1937,
  466. ct_lm3s1958,
  467. ct_lm3s1960,
  468. ct_lm3s1968,
  469. ct_lm3s1969,
  470. ct_lm3s2911,
  471. ct_lm3s2918,
  472. ct_lm3s2919,
  473. ct_lm3s2939,
  474. ct_lm3s2948,
  475. ct_lm3s2950,
  476. ct_lm3s2965,
  477. ct_lm3s6911,
  478. ct_lm3s6918,
  479. ct_lm3s6938,
  480. ct_lm3s6950,
  481. ct_lm3s6952,
  482. ct_lm3s6965,
  483. ct_lm3s8930,
  484. ct_lm3s8933,
  485. ct_lm3s8938,
  486. ct_lm3s8962,
  487. ct_lm3s8970,
  488. ct_lm3s8971,
  489. { TI - Tempest Tempest - 256 K Flash, 64 K SRAM }
  490. ct_lm3s5951,
  491. ct_lm3s5956,
  492. ct_lm3s1b21,
  493. ct_lm3s2b93,
  494. ct_lm3s5b91,
  495. ct_lm3s9b81,
  496. ct_lm3s9b90,
  497. ct_lm3s9b92,
  498. ct_lm3s9b95,
  499. ct_lm3s9b96,
  500. ct_lm3s5d51,
  501. { TI - Stellaris something }
  502. ct_lm4f120h5,
  503. { Infineon }
  504. ct_xmc4500x1024,
  505. ct_xmc4500x768,
  506. ct_xmc4502x768,
  507. ct_xmc4504x512,
  508. { Allwinner }
  509. ct_allwinner_a20,
  510. { Freescale }
  511. ct_mk20dx128vfm5,
  512. ct_mk20dx128vft5,
  513. ct_mk20dx128vlf5,
  514. ct_mk20dx128vlh5,
  515. ct_teensy30,
  516. ct_mk20dx128vmp5,
  517. ct_mk20dx32vfm5,
  518. ct_mk20dx32vft5,
  519. ct_mk20dx32vlf5,
  520. ct_mk20dx32vlh5,
  521. ct_mk20dx32vmp5,
  522. ct_mk20dx64vfm5,
  523. ct_mk20dx64vft5,
  524. ct_mk20dx64vlf5,
  525. ct_mk20dx64vlh5,
  526. ct_mk20dx64vmp5,
  527. ct_mk20dx128vlh7,
  528. ct_mk20dx128vlk7,
  529. ct_mk20dx128vll7,
  530. ct_mk20dx128vmc7,
  531. ct_mk20dx256vlh7,
  532. ct_mk20dx256vlk7,
  533. ct_mk20dx256vll7,
  534. ct_mk20dx256vmc7,
  535. ct_teensy31,
  536. ct_teensy32,
  537. ct_mk20dx64vlh7,
  538. ct_mk20dx64vlk7,
  539. ct_mk20dx64vmc7,
  540. ct_mk22fn512cap12,
  541. ct_mk22fn512cbp12,
  542. ct_mk22fn512vdc12,
  543. ct_mk22fn512vlh12,
  544. ct_mk22fn512vll12,
  545. ct_mk22fn512vmp12,
  546. ct_freedom_k22f,
  547. { Atmel }
  548. ct_sam3x8e,
  549. ct_arduino_due,
  550. ct_flip_n_click,
  551. { Nordic Semiconductor }
  552. ct_nrf51422_xxaa,
  553. ct_nrf51422_xxab,
  554. ct_nrf51422_xxac,
  555. ct_nrf51822_xxaa,
  556. ct_nrf51822_xxab,
  557. ct_nrf51822_xxac,
  558. ct_nrf52832_xxaa,
  559. ct_nrf52840_xxaa,
  560. ct_sc32442b,
  561. { Raspberry Pi 2 }
  562. ct_raspi2,
  563. ct_thumb2bare:
  564. begin
  565. with embedded_controllers[current_settings.controllertype] do
  566. with linkres do
  567. begin
  568. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  569. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  570. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  571. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  572. Add('ENTRY(_LOWLEVELSTART)')
  573. else
  574. Add('ENTRY(_START)');
  575. Add('MEMORY');
  576. Add('{');
  577. if flashsize<>0 then
  578. begin
  579. LinkStr := ' flash : ORIGIN = 0x' + IntToHex(flashbase,8)
  580. + ', LENGTH = 0x' + IntToHex(flashsize,8);
  581. Add(LinkStr);
  582. end;
  583. LinkStr := ' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  584. + ', LENGTH = 0x' + IntToHex(sramsize,8);
  585. Add(LinkStr);
  586. Add('}');
  587. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  588. // Add Checksum Calculation for LPC Controllers so that the bootloader starts the uploaded binary
  589. writeln(controllerunitstr);
  590. if (controllerunitstr = 'LPC8xx') or (controllerunitstr = 'LPC11XX') or (controllerunitstr = 'LPC122X') then
  591. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + Hardfault_interrupt + 1);');
  592. if (controllerunitstr = 'LPC13XX') then
  593. Add('Startup_Checksum = 0 - (_stack_top + _START + 1 + NonMaskableInt_interrupt + 1 + MemoryManagement_interrupt + 1 + BusFault_interrupt + 1 + UsageFault_interrupt + 1);');
  594. end;
  595. end
  596. else
  597. if not (cs_link_nolink in current_settings.globalswitches) then
  598. internalerror(200902011);
  599. end;
  600. with linkres do
  601. begin
  602. Add('SECTIONS');
  603. Add('{');
  604. Add(' .text :');
  605. Add(' {');
  606. Add(' _text_start = .;');
  607. Add(' KEEP(*(.init .init.*))');
  608. if (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D5')
  609. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK20D7')
  610. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK22F51212')
  611. or (embedded_controllers[current_settings.controllertype].controllerunitstr='MK64F12') then
  612. begin
  613. Add(' . = 0x400;');
  614. Add(' KEEP(*(.flash_config *.flash_config.*))');
  615. end;
  616. Add(' *(.text .text.*)');
  617. Add(' *(.strings)');
  618. Add(' *(.rodata .rodata.*)');
  619. Add(' *(.comment)');
  620. Add(' . = ALIGN(4);');
  621. Add(' _etext = .;');
  622. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  623. begin
  624. Add(' } >flash');
  625. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  626. end
  627. else
  628. begin
  629. Add(' } >ram');
  630. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  631. end;
  632. Add(' .data :');
  633. Add(' {');
  634. Add(' _data = .;');
  635. Add(' *(.data .data.*)');
  636. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  637. Add(' _edata = .;');
  638. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  639. begin
  640. Add(' } >ram AT >flash');
  641. end
  642. else
  643. begin
  644. Add(' } >ram');
  645. end;
  646. Add(' .bss :');
  647. Add(' {');
  648. Add(' _bss_start = .;');
  649. Add(' *(.bss .bss.*)');
  650. Add(' *(COMMON)');
  651. Add(' } >ram');
  652. Add('. = ALIGN(4);');
  653. Add('_bss_end = . ;');
  654. Add('}');
  655. Add('_end = .;');
  656. end;
  657. {$endif ARM}
  658. {$ifdef i386}
  659. with linkres do
  660. begin
  661. Add('ENTRY(_START)');
  662. Add('SECTIONS');
  663. Add('{');
  664. Add(' . = 0x100000;');
  665. Add(' .text ALIGN (0x1000) :');
  666. Add(' {');
  667. Add(' _text = .;');
  668. Add(' KEEP(*(.init .init.*))');
  669. Add(' *(.text .text.*)');
  670. Add(' *(.strings)');
  671. Add(' *(.rodata .rodata.*)');
  672. Add(' *(.comment)');
  673. Add(' _etext = .;');
  674. Add(' }');
  675. Add(' .data ALIGN (0x1000) :');
  676. Add(' {');
  677. Add(' _data = .;');
  678. Add(' *(.data .data.*)');
  679. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  680. Add(' _edata = .;');
  681. Add(' }');
  682. Add(' . = ALIGN(4);');
  683. Add(' .bss :');
  684. Add(' {');
  685. Add(' _bss_start = .;');
  686. Add(' *(.bss .bss.*)');
  687. Add(' *(COMMON)');
  688. Add(' }');
  689. Add('_bss_end = . ;');
  690. Add('}');
  691. Add('_end = .;');
  692. end;
  693. {$endif i386}
  694. {$ifdef x86_64}
  695. with linkres do
  696. begin
  697. Add('ENTRY(_START)');
  698. Add('SECTIONS');
  699. Add('{');
  700. Add(' . = 0x100000;');
  701. Add(' .text ALIGN (0x1000) :');
  702. Add(' {');
  703. Add(' _text = .;');
  704. Add(' KEEP(*(.init .init.*))');
  705. Add(' *(.text .text.*)');
  706. Add(' *(.strings)');
  707. Add(' *(.rodata .rodata.*)');
  708. Add(' *(.comment)');
  709. Add(' _etext = .;');
  710. Add(' }');
  711. Add(' .data ALIGN (0x1000) :');
  712. Add(' {');
  713. Add(' _data = .;');
  714. Add(' *(.data .data.*)');
  715. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  716. Add(' _edata = .;');
  717. Add(' }');
  718. Add(' . = ALIGN(4);');
  719. Add(' .bss :');
  720. Add(' {');
  721. Add(' _bss_start = .;');
  722. Add(' *(.bss .bss.*)');
  723. Add(' *(COMMON)');
  724. Add(' }');
  725. Add('_bss_end = . ;');
  726. Add('}');
  727. Add('_end = .;');
  728. end;
  729. {$endif x86_64}
  730. {$ifdef AVR}
  731. with linkres do
  732. begin
  733. { linker script from ld 2.19 }
  734. Add('ENTRY(_START)');
  735. Add('OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")');
  736. case current_settings.cputype of
  737. cpu_avr1:
  738. Add('OUTPUT_ARCH(avr:1)');
  739. cpu_avr2:
  740. Add('OUTPUT_ARCH(avr:2)');
  741. cpu_avr25:
  742. Add('OUTPUT_ARCH(avr:25)');
  743. cpu_avr3:
  744. Add('OUTPUT_ARCH(avr:3)');
  745. cpu_avr31:
  746. Add('OUTPUT_ARCH(avr:31)');
  747. cpu_avr35:
  748. Add('OUTPUT_ARCH(avr:35)');
  749. cpu_avr4:
  750. Add('OUTPUT_ARCH(avr:4)');
  751. cpu_avr5:
  752. Add('OUTPUT_ARCH(avr:5)');
  753. cpu_avr51:
  754. Add('OUTPUT_ARCH(avr:51)');
  755. cpu_avr6:
  756. Add('OUTPUT_ARCH(avr:6)');
  757. cpu_avrxmega3:
  758. Add('OUTPUT_ARCH(avr:103)');
  759. cpu_avrtiny:
  760. Add('OUTPUT_ARCH(avr:100)');
  761. else
  762. Internalerror(2015072701);
  763. end;
  764. Add('MEMORY');
  765. with embedded_controllers[current_settings.controllertype] do
  766. begin
  767. Add('{');
  768. Add(' text (rx) : ORIGIN = 0, LENGTH = 0x'+IntToHex(flashsize,6));
  769. Add(' data (rw!x) : ORIGIN = 0x'+IntToHex($800000+srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  770. Add(' eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = 0x'+IntToHex(eepromsize,6));
  771. Add(' fuse (rw!x) : ORIGIN = 0x820000, LENGTH = 1K');
  772. Add(' lock (rw!x) : ORIGIN = 0x830000, LENGTH = 1K');
  773. Add(' signature (rw!x) : ORIGIN = 0x840000, LENGTH = 1K');
  774. Add('}');
  775. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  776. end;
  777. Add('SECTIONS');
  778. Add('{');
  779. Add(' /* Read-only sections, merged into text segment: */');
  780. Add(' .hash : { *(.hash) }');
  781. Add(' .dynsym : { *(.dynsym) }');
  782. Add(' .dynstr : { *(.dynstr) }');
  783. Add(' .gnu.version : { *(.gnu.version) }');
  784. Add(' .gnu.version_d : { *(.gnu.version_d) }');
  785. Add(' .gnu.version_r : { *(.gnu.version_r) }');
  786. Add(' .rel.init : { *(.rel.init) }');
  787. Add(' .rela.init : { *(.rela.init) }');
  788. Add(' .rel.text :');
  789. Add(' {');
  790. Add(' *(.rel.text)');
  791. Add(' *(.rel.text.*)');
  792. Add(' *(.rel.gnu.linkonce.t*)');
  793. Add(' }');
  794. Add(' .rela.text :');
  795. Add(' {');
  796. Add(' *(.rela.text)');
  797. Add(' *(.rela.text.*)');
  798. Add(' *(.rela.gnu.linkonce.t*)');
  799. Add(' }');
  800. Add(' .rel.fini : { *(.rel.fini) }');
  801. Add(' .rela.fini : { *(.rela.fini) }');
  802. Add(' .rel.rodata :');
  803. Add(' {');
  804. Add(' *(.rel.rodata)');
  805. Add(' *(.rel.rodata.*)');
  806. Add(' *(.rel.gnu.linkonce.r*)');
  807. Add(' }');
  808. Add(' .rela.rodata :');
  809. Add(' {');
  810. Add(' *(.rela.rodata)');
  811. Add(' *(.rela.rodata.*)');
  812. Add(' *(.rela.gnu.linkonce.r*)');
  813. Add(' }');
  814. Add(' .rel.data :');
  815. Add(' {');
  816. Add(' *(.rel.data)');
  817. Add(' *(.rel.data.*)');
  818. Add(' *(.rel.gnu.linkonce.d*)');
  819. Add(' }');
  820. Add(' .rela.data :');
  821. Add(' {');
  822. Add(' *(.rela.data)');
  823. Add(' *(.rela.data.*)');
  824. Add(' *(.rela.gnu.linkonce.d*)');
  825. Add(' }');
  826. Add(' .rel.ctors : { *(.rel.ctors) }');
  827. Add(' .rela.ctors : { *(.rela.ctors) }');
  828. Add(' .rel.dtors : { *(.rel.dtors) }');
  829. Add(' .rela.dtors : { *(.rela.dtors) }');
  830. Add(' .rel.got : { *(.rel.got) }');
  831. Add(' .rela.got : { *(.rela.got) }');
  832. Add(' .rel.bss : { *(.rel.bss) }');
  833. Add(' .rela.bss : { *(.rela.bss) }');
  834. Add(' .rel.plt : { *(.rel.plt) }');
  835. Add(' .rela.plt : { *(.rela.plt) }');
  836. Add(' /* Internal text space or external memory. */');
  837. Add(' .text :');
  838. Add(' {');
  839. Add(' KEEP(*(.init .init.*))');
  840. Add(' /* For data that needs to reside in the lower 64k of progmem. */');
  841. Add(' *(.progmem.gcc*)');
  842. Add(' *(.progmem*)');
  843. Add(' . = ALIGN(2);');
  844. Add(' __trampolines_start = . ;');
  845. Add(' /* The jump trampolines for the 16-bit limited relocs will reside here. */');
  846. Add(' *(.trampolines)');
  847. Add(' *(.trampolines*)');
  848. Add(' __trampolines_end = . ;');
  849. Add(' /* For future tablejump instruction arrays for 3 byte pc devices.');
  850. Add(' We don''t relax jump/call instructions within these sections. */');
  851. Add(' *(.jumptables)');
  852. Add(' *(.jumptables*)');
  853. Add(' /* For code that needs to reside in the lower 128k progmem. */');
  854. Add(' *(.lowtext)');
  855. Add(' *(.lowtext*)');
  856. Add(' __ctors_start = . ;');
  857. Add(' *(.ctors)');
  858. Add(' __ctors_end = . ;');
  859. Add(' __dtors_start = . ;');
  860. Add(' *(.dtors)');
  861. Add(' __dtors_end = . ;');
  862. Add(' KEEP(SORT(*)(.ctors))');
  863. Add(' KEEP(SORT(*)(.dtors))');
  864. Add(' /* From this point on, we don''t bother about wether the insns are');
  865. Add(' below or above the 16 bits boundary. */');
  866. Add(' *(.init0) /* Start here after reset. */');
  867. Add(' KEEP (*(.init0))');
  868. Add(' *(.init1)');
  869. Add(' KEEP (*(.init1))');
  870. Add(' *(.init2) /* Clear __zero_reg__, set up stack pointer. */');
  871. Add(' KEEP (*(.init2))');
  872. Add(' *(.init3)');
  873. Add(' KEEP (*(.init3))');
  874. Add(' *(.init4) /* Initialize data and BSS. */');
  875. Add(' KEEP (*(.init4))');
  876. Add(' *(.init5)');
  877. Add(' KEEP (*(.init5))');
  878. Add(' *(.init6) /* C++ constructors. */');
  879. Add(' KEEP (*(.init6))');
  880. Add(' *(.init7)');
  881. Add(' KEEP (*(.init7))');
  882. Add(' *(.init8)');
  883. Add(' KEEP (*(.init8))');
  884. Add(' *(.init9) /* Call main(). */');
  885. Add(' KEEP (*(.init9))');
  886. Add(' *(.text)');
  887. Add(' . = ALIGN(2);');
  888. Add(' *(.text.*)');
  889. Add(' . = ALIGN(2);');
  890. Add(' *(.fini9) /* _exit() starts here. */');
  891. Add(' KEEP (*(.fini9))');
  892. Add(' *(.fini8)');
  893. Add(' KEEP (*(.fini8))');
  894. Add(' *(.fini7)');
  895. Add(' KEEP (*(.fini7))');
  896. Add(' *(.fini6) /* C++ destructors. */');
  897. Add(' KEEP (*(.fini6))');
  898. Add(' *(.fini5)');
  899. Add(' KEEP (*(.fini5))');
  900. Add(' *(.fini4)');
  901. Add(' KEEP (*(.fini4))');
  902. Add(' *(.fini3)');
  903. Add(' KEEP (*(.fini3))');
  904. Add(' *(.fini2)');
  905. Add(' KEEP (*(.fini2))');
  906. Add(' *(.fini1)');
  907. Add(' KEEP (*(.fini1))');
  908. Add(' *(.fini0) /* Infinite loop after program termination. */');
  909. Add(' KEEP (*(.fini0))');
  910. Add(' _etext = . ;');
  911. Add(' } > text');
  912. Add(' .data : AT (ADDR (.text) + SIZEOF (.text))');
  913. Add(' {');
  914. Add(' PROVIDE (__data_start = .) ;');
  915. Add(' *(.data)');
  916. Add(' *(.data*)');
  917. Add(' *(.rodata) /* We need to include .rodata here if gcc is used */');
  918. Add(' *(.rodata*) /* with -fdata-sections. */');
  919. Add(' *(.gnu.linkonce.d*)');
  920. Add(' . = ALIGN(2);');
  921. Add(' _edata = . ;');
  922. Add(' PROVIDE (__data_end = .) ;');
  923. Add(' } > data');
  924. Add(' .bss : AT (ADDR (.bss))');
  925. Add(' {');
  926. Add(' PROVIDE (__bss_start = .) ;');
  927. Add(' *(.bss)');
  928. Add(' *(.bss*)');
  929. Add(' *(COMMON)');
  930. Add(' PROVIDE (__bss_end = .) ;');
  931. Add(' } > data');
  932. Add(' __data_load_start = LOADADDR(.data);');
  933. Add(' __data_load_end = __data_load_start + SIZEOF(.data);');
  934. Add(' /* Global data not cleared after reset. */');
  935. Add(' .noinit :');
  936. Add(' {');
  937. Add(' PROVIDE (__noinit_start = .) ;');
  938. Add(' *(.noinit*)');
  939. Add(' PROVIDE (__noinit_end = .) ;');
  940. Add(' _end = . ;');
  941. Add(' PROVIDE (__heap_start = .) ;');
  942. Add(' } > data');
  943. Add(' .eeprom :');
  944. Add(' {');
  945. Add(' *(.eeprom*)');
  946. Add(' __eeprom_end = . ;');
  947. Add(' } > eeprom');
  948. Add(' .fuse :');
  949. Add(' {');
  950. Add(' KEEP(*(.fuse))');
  951. Add(' KEEP(*(.lfuse))');
  952. Add(' KEEP(*(.hfuse))');
  953. Add(' KEEP(*(.efuse))');
  954. Add(' } > fuse');
  955. Add(' .lock :');
  956. Add(' {');
  957. Add(' KEEP(*(.lock*))');
  958. Add(' } > lock');
  959. Add(' .signature :');
  960. Add(' {');
  961. Add(' KEEP(*(.signature*))');
  962. Add(' } > signature');
  963. Add(' /* Stabs debugging sections. */');
  964. Add(' .stab 0 : { *(.stab) }');
  965. Add(' .stabstr 0 : { *(.stabstr) }');
  966. Add(' .stab.excl 0 : { *(.stab.excl) }');
  967. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  968. Add(' .stab.index 0 : { *(.stab.index) }');
  969. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  970. Add(' .comment 0 : { *(.comment) }');
  971. Add(' /* DWARF debug sections.');
  972. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  973. Add(' of the section so we begin them at 0. */');
  974. Add(' /* DWARF 1 */');
  975. Add(' .debug 0 : { *(.debug) }');
  976. Add(' .line 0 : { *(.line) }');
  977. Add(' /* GNU DWARF 1 extensions */');
  978. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  979. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  980. Add(' /* DWARF 1.1 and DWARF 2 */');
  981. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  982. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  983. Add(' /* DWARF 2 */');
  984. Add(' .debug_info 0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }');
  985. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  986. Add(' .debug_line 0 : { *(.debug_line) }');
  987. Add(' .debug_frame 0 : { *(.debug_frame) }');
  988. Add(' .debug_str 0 : { *(.debug_str) }');
  989. Add(' .debug_loc 0 : { *(.debug_loc) }');
  990. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  991. Add('}');
  992. end;
  993. {$endif AVR}
  994. {$ifdef MIPSEL}
  995. case current_settings.controllertype of
  996. ct_none:
  997. begin
  998. end;
  999. ct_pic32mx110f016b,
  1000. ct_pic32mx110f016c,
  1001. ct_pic32mx110f016d,
  1002. ct_pic32mx120f032b,
  1003. ct_pic32mx120f032c,
  1004. ct_pic32mx120f032d,
  1005. ct_pic32mx130f064b,
  1006. ct_pic32mx130f064c,
  1007. ct_pic32mx130f064d,
  1008. ct_pic32mx150f128b,
  1009. ct_pic32mx150f128c,
  1010. ct_pic32mx150f128d,
  1011. ct_pic32mx210f016b,
  1012. ct_pic32mx210f016c,
  1013. ct_pic32mx210f016d,
  1014. ct_pic32mx220f032b,
  1015. ct_pic32mx220f032c,
  1016. ct_pic32mx220f032d,
  1017. ct_pic32mx230f064b,
  1018. ct_pic32mx230f064c,
  1019. ct_pic32mx230f064d,
  1020. ct_pic32mx250f128b,
  1021. ct_pic32mx250f128c,
  1022. ct_pic32mx250f128d,
  1023. ct_pic32mx775f256h,
  1024. ct_pic32mx775f256l,
  1025. ct_pic32mx775f512h,
  1026. ct_pic32mx775f512l,
  1027. ct_pic32mx795f512h,
  1028. ct_pic32mx795f512l:
  1029. begin
  1030. with embedded_controllers[current_settings.controllertype] do
  1031. with linkres do
  1032. begin
  1033. Add('OUTPUT_FORMAT("elf32-tradlittlemips")');
  1034. Add('OUTPUT_ARCH(pic32mx)');
  1035. Add('ENTRY(_reset)');
  1036. Add('PROVIDE(_vector_spacing = 0x00000001);');
  1037. Add('_ebase_address = 0x'+IntToHex(flashbase,8)+';');
  1038. Add('_RESET_ADDR = 0xBFC00000;');
  1039. Add('_BEV_EXCPT_ADDR = 0xBFC00380;');
  1040. Add('_DBG_EXCPT_ADDR = 0xBFC00480;');
  1041. Add('_GEN_EXCPT_ADDR = _ebase_address + 0x180;');
  1042. Add('MEMORY');
  1043. Add('{');
  1044. if flashsize<>0 then
  1045. begin
  1046. Add(' kseg0_program_mem : ORIGIN = 0x'+IntToHex(flashbase,8)+', LENGTH = 0x'+IntToHex(flashsize,8));
  1047. //TODO This should better be placed into the controllertype records
  1048. Add(' kseg1_boot_mem : ORIGIN = 0xBFC00000, LENGTH = 0xbef');
  1049. Add(' config3 : ORIGIN = 0xBFC00BF0, LENGTH = 0x4');
  1050. Add(' config2 : ORIGIN = 0xBFC00BF4, LENGTH = 0x4');
  1051. Add(' config1 : ORIGIN = 0xBFC00BF8, LENGTH = 0x4');
  1052. Add(' config0 : ORIGIN = 0xBFC00BFC, LENGTH = 0x4');
  1053. end;
  1054. Add(' ram : ORIGIN = 0x' + IntToHex(srambase,8)
  1055. + ', LENGTH = 0x' + IntToHex(sramsize,8));
  1056. Add('}');
  1057. Add('_stack_top = 0x' + IntToHex(sramsize+srambase,8) + ';');
  1058. end;
  1059. end
  1060. end;
  1061. with linkres do
  1062. begin
  1063. Add('SECTIONS');
  1064. Add('{');
  1065. Add(' .reset _RESET_ADDR :');
  1066. Add(' {');
  1067. Add(' KEEP(*(.reset .reset.*))');
  1068. Add(' KEEP(*(.startup .startup.*))');
  1069. Add(' } > kseg1_boot_mem');
  1070. Add(' .bev_excpt _BEV_EXCPT_ADDR :');
  1071. Add(' {');
  1072. Add(' KEEP(*(.bev_handler))');
  1073. Add(' } > kseg1_boot_mem');
  1074. Add(' .text :');
  1075. Add(' {');
  1076. Add(' _text_start = .;');
  1077. Add(' . = _text_start + 0x180;');
  1078. Add(' KEEP(*(.gen_handler))');
  1079. Add(' . = _text_start + 0x200;');
  1080. Add(' KEEP(*(.init .init.*))');
  1081. Add(' *(.text .text.*)');
  1082. Add(' *(.strings)');
  1083. Add(' *(.rodata .rodata.*)');
  1084. Add(' *(.comment)');
  1085. Add(' _etext = .;');
  1086. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1087. begin
  1088. Add(' } >kseg0_program_mem');
  1089. end
  1090. else
  1091. begin
  1092. Add(' } >ram');
  1093. end;
  1094. Add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
  1095. Add(' .data :');
  1096. Add(' {');
  1097. Add(' _data = .;');
  1098. Add(' *(.data .data.*)');
  1099. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1100. Add(' . = .;');
  1101. Add(' _gp = ALIGN(16) + 0x7ff0;');
  1102. Add(' _edata = .;');
  1103. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1104. begin
  1105. Add(' } >ram AT >kseg0_program_mem');
  1106. end
  1107. else
  1108. begin
  1109. Add(' } >ram');
  1110. end;
  1111. Add(' .config_BFC00BF0 : {');
  1112. Add(' KEEP(*(.config_BFC00BF0))');
  1113. Add(' } > config3');
  1114. Add(' .config_BFC00BF4 : {');
  1115. Add(' KEEP(*(.config_BFC00BF4))');
  1116. Add(' } > config2');
  1117. Add(' .config_BFC00BF8 : {');
  1118. Add(' KEEP(*(.config_BFC00BF8))');
  1119. Add(' } > config1');
  1120. Add(' .config_BFC00BFC : {');
  1121. Add(' KEEP(*(.config_BFC00BFC))');
  1122. Add(' } > config0');
  1123. Add(' .bss :');
  1124. Add(' {');
  1125. Add(' _bss_start = .;');
  1126. Add(' *(.bss .bss.*)');
  1127. Add(' *(COMMON)');
  1128. Add(' } >ram');
  1129. Add('. = ALIGN(4);');
  1130. Add('_bss_end = . ;');
  1131. Add(' .comment 0 : { *(.comment) }');
  1132. Add(' /* DWARF debug sections.');
  1133. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1134. Add(' of the section so we begin them at 0. */');
  1135. Add(' /* DWARF 1 */');
  1136. Add(' .debug 0 : { *(.debug) }');
  1137. Add(' .line 0 : { *(.line) }');
  1138. Add(' /* GNU DWARF 1 extensions */');
  1139. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1140. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1141. Add(' /* DWARF 1.1 and DWARF 2 */');
  1142. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1143. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1144. Add(' /* DWARF 2 */');
  1145. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1146. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1147. Add(' /DISCARD/ : { *(.debug_line) }');
  1148. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1149. Add(' .debug_str 0 : { *(.debug_str) }');
  1150. Add(' /DISCARD/ : { *(.debug_loc) }');
  1151. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1152. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1153. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1154. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1155. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1156. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1157. Add(' /* DWARF 3 */');
  1158. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1159. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1160. Add(' .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }');
  1161. Add(' .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }');
  1162. Add(' .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }');
  1163. Add(' .mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }');
  1164. Add(' .mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }');
  1165. Add(' .mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }');
  1166. Add(' .mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }');
  1167. Add(' .mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }');
  1168. Add(' .mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }');
  1169. Add(' /DISCARD/ : { *(.rel.dyn) }');
  1170. Add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
  1171. Add('}');
  1172. Add('_end = .;');
  1173. end;
  1174. {$endif MIPSEL}
  1175. {$ifdef RISCV32}
  1176. with linkres do
  1177. begin
  1178. Add('OUTPUT_ARCH("riscv")');
  1179. Add('ENTRY(_START)');
  1180. Add('MEMORY');
  1181. with embedded_controllers[current_settings.controllertype] do
  1182. begin
  1183. Add('{');
  1184. Add(' flash (rx) : ORIGIN = 0x'+IntToHex(flashbase,6)+', LENGTH = 0x'+IntToHex(flashsize,6));
  1185. Add(' ram (rw!x) : ORIGIN = 0x'+IntToHex(srambase,6)+', LENGTH = 0x'+IntToHex(sramsize,6));
  1186. Add('}');
  1187. Add('_stack_top = 0x' + IntToHex(srambase+sramsize-1,4) + ';');
  1188. end;
  1189. Add('SECTIONS');
  1190. Add('{');
  1191. Add(' .text :');
  1192. Add(' {');
  1193. Add(' _text_start = .;');
  1194. Add(' KEEP(*(.init .init.*))');
  1195. Add(' *(.text .text.*)');
  1196. Add(' *(.strings)');
  1197. Add(' *(.rodata .rodata.*)');
  1198. Add(' *(.comment)');
  1199. Add(' . = ALIGN(4);');
  1200. Add(' _etext = .;');
  1201. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1202. begin
  1203. Add(' } >flash');
  1204. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >flash ');
  1205. end
  1206. else
  1207. begin
  1208. Add(' } >ram');
  1209. //Add(' .note.gnu.build-id : { *(.note.gnu.build-id) } >ram ');
  1210. end;
  1211. Add(' .data :');
  1212. Add(' {');
  1213. Add(' _data = .;');
  1214. Add(' *(.data .data.*)');
  1215. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1216. Add(' _edata = .;');
  1217. if embedded_controllers[current_settings.controllertype].flashsize<>0 then
  1218. begin
  1219. Add(' } >ram AT >flash');
  1220. end
  1221. else
  1222. begin
  1223. Add(' } >ram');
  1224. end;
  1225. Add(' .bss :');
  1226. Add(' {');
  1227. Add(' _bss_start = .;');
  1228. Add(' *(.bss .bss.*)');
  1229. Add(' *(COMMON)');
  1230. Add(' } >ram');
  1231. Add(' . = ALIGN(4);');
  1232. Add(' _bss_end = . ;');
  1233. Add(' /* Stabs debugging sections. */');
  1234. Add(' .stab 0 : { *(.stab) }');
  1235. Add(' .stabstr 0 : { *(.stabstr) }');
  1236. Add(' .stab.excl 0 : { *(.stab.excl) }');
  1237. Add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
  1238. Add(' .stab.index 0 : { *(.stab.index) }');
  1239. Add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
  1240. Add(' .comment 0 : { *(.comment) }');
  1241. Add(' /* DWARF debug sections.');
  1242. Add(' Symbols in the DWARF debugging sections are relative to the beginning');
  1243. Add(' of the section so we begin them at 0. */');
  1244. Add(' /* DWARF 1 */');
  1245. Add(' .debug 0 : { *(.debug) }');
  1246. Add(' .line 0 : { *(.line) }');
  1247. Add(' /* GNU DWARF 1 extensions */');
  1248. Add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
  1249. Add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
  1250. Add(' /* DWARF 1.1 and DWARF 2 */');
  1251. Add(' .debug_aranges 0 : { *(.debug_aranges) }');
  1252. Add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
  1253. Add(' /* DWARF 2 */');
  1254. Add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
  1255. Add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
  1256. Add(' .debug_line 0 : { *(.debug_line) }');
  1257. Add(' .debug_frame 0 : { *(.debug_frame) }');
  1258. Add(' .debug_str 0 : { *(.debug_str) }');
  1259. Add(' .debug_loc 0 : { *(.debug_loc) }');
  1260. Add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
  1261. Add(' /* SGI/MIPS DWARF 2 extensions */');
  1262. Add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
  1263. Add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
  1264. Add(' .debug_typenames 0 : { *(.debug_typenames) }');
  1265. Add(' .debug_varnames 0 : { *(.debug_varnames) }');
  1266. Add(' /* DWARF 3 */');
  1267. Add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
  1268. Add(' .debug_ranges 0 : { *(.debug_ranges) }');
  1269. Add('}');
  1270. Add('_end = .;');
  1271. end;
  1272. {$endif RISCV32}
  1273. {$ifdef XTENSA}
  1274. with linkres do
  1275. begin
  1276. Add('SECTIONS');
  1277. Add('{');
  1278. Add(' .data :');
  1279. Add(' {');
  1280. Add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
  1281. Add(' }');
  1282. Add('}');
  1283. end;
  1284. {$endif XTENSA}
  1285. { Write and Close response }
  1286. linkres.writetodisk;
  1287. linkres.free;
  1288. WriteResponseFile:=True;
  1289. end;
  1290. function TlinkerFreeRTOS.MakeExecutable:boolean;
  1291. var
  1292. StaticStr,
  1293. S,
  1294. binstr,
  1295. cmdstr,
  1296. mapstr: Ansistring;
  1297. success : boolean;
  1298. GCSectionsStr,
  1299. DynLinkStr,
  1300. StripStr,
  1301. FixedExeFileName: string;
  1302. t: Text;
  1303. hp: TCmdStrListItem;
  1304. filepath: TCmdStr;
  1305. begin
  1306. { for future use }
  1307. StaticStr:='';
  1308. StripStr:='';
  1309. mapstr:='';
  1310. DynLinkStr:='';
  1311. Result:=false;
  1312. if target_info.system=system_xtensa_freertos then
  1313. begin
  1314. { generate a sdkconfig.h if none is provided,
  1315. only a few fields are provided to far }
  1316. if not(Sysutils.FileExists('sdkconfig.h')) then
  1317. begin
  1318. Assign(t,'sdkconfig.h');
  1319. {$push}{$I-}
  1320. Rewrite(t);
  1321. if ioresult<>0 then
  1322. exit;
  1323. writeln(t,'#pragma once');
  1324. writeln(t,'#define CONFIG_APP_BUILD_USE_FLASH_SECTIONS 1');
  1325. writeln(t,'#define CONFIG_BT_RESERVE_DRAM 0x0');
  1326. writeln(t,'#define CONFIG_ESP32_ULP_COPROC_RESERVE_MEM 0');
  1327. writeln(t,'#define CONFIG_ESP32_TRACEMEM_RESERVE_DRAM 0x0');
  1328. Close(t);
  1329. if ioresult<>0 then
  1330. exit;
  1331. {$pop}
  1332. end;
  1333. { generate an sdkconfig if none is provided,
  1334. this is a dummy so far }
  1335. if not(Sysutils.FileExists('sdkconfig')) then
  1336. begin
  1337. Assign(t,'sdkconfig');
  1338. {$push}{$I-}
  1339. Rewrite(t);
  1340. if ioresult<>0 then
  1341. exit;
  1342. writeln(t);
  1343. Close(t);
  1344. if ioresult<>0 then
  1345. exit;
  1346. {$pop}
  1347. end;
  1348. { generate an kconfigs.in if none is provided,
  1349. this is a dummy so far }
  1350. if not(Sysutils.FileExists('kconfigs.in')) then
  1351. begin
  1352. Assign(t,'kconfigs.in');
  1353. {$push}{$I-}
  1354. Rewrite(t);
  1355. if ioresult<>0 then
  1356. exit;
  1357. writeln(t);
  1358. Close(t);
  1359. if ioresult<>0 then
  1360. exit;
  1361. {$pop}
  1362. end;
  1363. { generate an kconfigs_projbuild.in if none is provided,
  1364. this is a dummy so far }
  1365. if not(Sysutils.FileExists('kconfigs_projbuild.in')) then
  1366. begin
  1367. Assign(t,'kconfigs_projbuild.in');
  1368. {$push}{$I-}
  1369. Rewrite(t);
  1370. if ioresult<>0 then
  1371. exit;
  1372. writeln(t);
  1373. Close(t);
  1374. if ioresult<>0 then
  1375. exit;
  1376. {$pop}
  1377. end;
  1378. { generate a config.env if none is provided,
  1379. COMPONENT_KCONFIGS and COMPONENT_KCONFIGS_PROJBUILD are dummy fields and might
  1380. be needed to be filed properly }
  1381. if not(Sysutils.FileExists('config.env')) then
  1382. begin
  1383. Assign(t,'config.env');
  1384. {$push}{$I-}
  1385. Rewrite(t);
  1386. if ioresult<>0 then
  1387. exit;
  1388. writeln(t,'{');
  1389. writeln(t,' "COMPONENT_KCONFIGS": "",');
  1390. writeln(t,' "COMPONENT_KCONFIGS_PROJBUILD": "",');
  1391. writeln(t,' "IDF_CMAKE": "y",');
  1392. writeln(t,' "IDF_TARGET": "esp32",');
  1393. writeln(t,' "IDF_PATH": "'+GetEnvironmentVariable('IDF_PATH')+'",');
  1394. writeln(t,' "COMPONENT_KCONFIGS_SOURCE_FILE": "kconfigs.in",');
  1395. writeln(t,' "COMPONENT_KCONFIGS_PROJBUILD_SOURCE_FILE": "kconfigs_projbuild.in"');
  1396. writeln(t,'}');
  1397. Close(t);
  1398. if ioresult<>0 then
  1399. exit;
  1400. {$pop}
  1401. end;
  1402. { generate ldgen_libraries }
  1403. Assign(t,'ldgen_libraries');
  1404. {$push}{$I-}
  1405. Rewrite(t);
  1406. if ioresult<>0 then
  1407. exit;
  1408. hp:=TCmdStrListItem(StaticLibFiles.First);
  1409. while assigned(hp) do
  1410. begin
  1411. FindLibraryFile(hp.Str,target_info.staticClibprefix,target_info.staticClibext,filepath);
  1412. writeln(t,filepath);
  1413. hp:=TCmdStrListItem(hp.Next);
  1414. end;
  1415. Close(t);
  1416. if ioresult<>0 then
  1417. exit;
  1418. {$pop}
  1419. binstr:='xtensa-esp32-elf-gcc';
  1420. cmdstr:='-C -P -x c -E -o esp32_out.ld -I . $IDF_PATH/components/esp32/ld/esp32.ld';
  1421. Replace(binstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  1422. Replace(cmdstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  1423. success:=DoExec(binstr,cmdstr,true,true);
  1424. { generate linker maps for esp32 }
  1425. binstr:='$IDF_PATH/tools/ldgen/ldgen.py';
  1426. cmdstr:='--config sdkconfig --fragments $IDF_PATH/components/xtensa/linker.lf $IDF_PATH/components/soc/linker.lf $IDF_PATH/components/esp_event/linker.lf '+
  1427. '$IDF_PATH/components/spi_flash/linker.lf $IDF_PATH/components/esp_wifi/linker.lf $IDF_PATH/components/lwip/linker.lf $IDF_PATH/components/log/linker.lf '+
  1428. '$IDF_PATH/components/heap/linker.lf $IDF_PATH/components/esp_ringbuf/linker.lf $IDF_PATH/components/espcoredump/linker.lf $IDF_PATH/components/esp32/linker.lf '+
  1429. '$IDF_PATH/components/esp32/ld/esp32_fragments.lf $IDF_PATH/components/freertos/linker.lf $IDF_PATH/components/newlib/newlib.lf '+
  1430. '$IDF_PATH/components/app_trace/linker.lf $IDF_PATH/components/esp_gdbstub/linker.lf '+
  1431. '--input $IDF_PATH/components/esp32/ld/esp32.project.ld.in --output ./esp32.project.ld --kconfig $IDF_PATH/Kconfig --env-file config.env '+
  1432. '--libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump';
  1433. Replace(binstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  1434. Replace(cmdstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  1435. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1436. success:=DoExec(binstr,cmdstr,true,false);
  1437. end;
  1438. FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
  1439. GCSectionsStr:='--gc-sections';
  1440. //if not(cs_link_extern in current_settings.globalswitches) then
  1441. if not(cs_link_nolink in current_settings.globalswitches) then
  1442. Message1(exec_i_linking,current_module.exefilename);
  1443. if (cs_link_map in current_settings.globalswitches) then
  1444. mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
  1445. { Write used files and libraries }
  1446. WriteResponseFile();
  1447. { Call linker }
  1448. SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
  1449. Replace(cmdstr,'$OPT',Info.ExtraOptions);
  1450. if target_info.system=system_xtensa_freertos then
  1451. Replace(cmdstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  1452. if not(cs_link_on_target in current_settings.globalswitches) then
  1453. begin
  1454. Replace(cmdstr,'$EXE',FixedExeFileName);
  1455. Replace(cmdstr,'$RES',(maybequoted(ScriptFixFileName(outputexedir+Info.ResName))));
  1456. Replace(cmdstr,'$STATIC',StaticStr);
  1457. Replace(cmdstr,'$STRIP',StripStr);
  1458. Replace(cmdstr,'$MAP',mapstr);
  1459. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1460. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1461. end
  1462. else
  1463. begin
  1464. Replace(cmdstr,'$EXE',FixedExeFileName);
  1465. Replace(cmdstr,'$RES',maybequoted(ScriptFixFileName(outputexedir+Info.ResName)));
  1466. Replace(cmdstr,'$STATIC',StaticStr);
  1467. Replace(cmdstr,'$STRIP',StripStr);
  1468. Replace(cmdstr,'$MAP',mapstr);
  1469. Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  1470. Replace(cmdstr,'$DYNLINK',DynLinkStr);
  1471. end;
  1472. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1473. success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);
  1474. { Remove ReponseFile }
  1475. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1476. DeleteFile(outputexedir+Info.ResName);
  1477. { Post process }
  1478. if success and not(cs_link_nolink in current_settings.globalswitches) then
  1479. success:=PostProcessExecutable(FixedExeFileName,false);
  1480. if success and (target_info.system=system_xtensa_freertos) then
  1481. begin
  1482. binstr:='$IDF_PATH/components/esptool_py/esptool/esptool.py';
  1483. Replace(binstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  1484. success:=DoExec(binstr,'--chip esp32 elf2image --flash_mode dio --flash_freq 40m '+
  1485. '--flash_size '+tostr(embedded_controllers[current_settings.controllertype].flashsize div (1024*1024))+'MB '+
  1486. '--elf-sha256-offset 0xb0 '+
  1487. '-o '+maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin')))+' '+
  1488. FixedExeFileName,
  1489. true,false);
  1490. end
  1491. else
  1492. if success then
  1493. success:=DoExec(FindUtil(utilsprefix+'objcopy'),'-O binary '+
  1494. FixedExeFileName+' '+
  1495. maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.bin'))),true,false);
  1496. MakeExecutable:=success; { otherwise a recursive call to link method }
  1497. end;
  1498. function TlinkerFreeRTOS.postprocessexecutable(const fn : string;isdll:boolean):boolean;
  1499. type
  1500. TElf32header=packed record
  1501. magic0123 : longint;
  1502. file_class : byte;
  1503. data_encoding : byte;
  1504. file_version : byte;
  1505. padding : array[$07..$0f] of byte;
  1506. e_type : word;
  1507. e_machine : word;
  1508. e_version : longint;
  1509. e_entry : longint; { entrypoint }
  1510. e_phoff : longint; { program header offset }
  1511. e_shoff : longint; { sections header offset }
  1512. e_flags : longint;
  1513. e_ehsize : word; { elf header size in bytes }
  1514. e_phentsize : word; { size of an entry in the program header array }
  1515. e_phnum : word; { 0..e_phnum-1 of entrys }
  1516. e_shentsize : word; { size of an entry in sections header array }
  1517. e_shnum : word; { 0..e_shnum-1 of entrys }
  1518. e_shstrndx : word; { index of string section header }
  1519. end;
  1520. TElf32sechdr=packed record
  1521. sh_name : longint;
  1522. sh_type : longint;
  1523. sh_flags : longint;
  1524. sh_addr : longint;
  1525. sh_offset : longint;
  1526. sh_size : longint;
  1527. sh_link : longint;
  1528. sh_info : longint;
  1529. sh_addralign : longint;
  1530. sh_entsize : longint;
  1531. end;
  1532. function MayBeSwapHeader(h : telf32header) : telf32header;
  1533. begin
  1534. result:=h;
  1535. if source_info.endian<>target_info.endian then
  1536. with h do
  1537. begin
  1538. result.e_type:=swapendian(e_type);
  1539. result.e_machine:=swapendian(e_machine);
  1540. result.e_version:=swapendian(e_version);
  1541. result.e_entry:=swapendian(e_entry);
  1542. result.e_phoff:=swapendian(e_phoff);
  1543. result.e_shoff:=swapendian(e_shoff);
  1544. result.e_flags:=swapendian(e_flags);
  1545. result.e_ehsize:=swapendian(e_ehsize);
  1546. result.e_phentsize:=swapendian(e_phentsize);
  1547. result.e_phnum:=swapendian(e_phnum);
  1548. result.e_shentsize:=swapendian(e_shentsize);
  1549. result.e_shnum:=swapendian(e_shnum);
  1550. result.e_shstrndx:=swapendian(e_shstrndx);
  1551. end;
  1552. end;
  1553. function MaybeSwapSecHeader(h : telf32sechdr) : telf32sechdr;
  1554. begin
  1555. result:=h;
  1556. if source_info.endian<>target_info.endian then
  1557. with h do
  1558. begin
  1559. result.sh_name:=swapendian(sh_name);
  1560. result.sh_type:=swapendian(sh_type);
  1561. result.sh_flags:=swapendian(sh_flags);
  1562. result.sh_addr:=swapendian(sh_addr);
  1563. result.sh_offset:=swapendian(sh_offset);
  1564. result.sh_size:=swapendian(sh_size);
  1565. result.sh_link:=swapendian(sh_link);
  1566. result.sh_info:=swapendian(sh_info);
  1567. result.sh_addralign:=swapendian(sh_addralign);
  1568. result.sh_entsize:=swapendian(sh_entsize);
  1569. end;
  1570. end;
  1571. var
  1572. f : file;
  1573. function ReadSectionName(pos : longint) : String;
  1574. var
  1575. oldpos : longint;
  1576. c : char;
  1577. begin
  1578. oldpos:=filepos(f);
  1579. seek(f,pos);
  1580. Result:='';
  1581. while true do
  1582. begin
  1583. blockread(f,c,1);
  1584. if c=#0 then
  1585. break;
  1586. Result:=Result+c;
  1587. end;
  1588. seek(f,oldpos);
  1589. end;
  1590. var
  1591. elfheader : TElf32header;
  1592. secheader : TElf32sechdr;
  1593. i : longint;
  1594. stringoffset : longint;
  1595. secname : string;
  1596. begin
  1597. postprocessexecutable:=false;
  1598. { open file }
  1599. assign(f,fn);
  1600. {$push}{$I-}
  1601. reset(f,1);
  1602. if ioresult<>0 then
  1603. Message1(execinfo_f_cant_open_executable,fn);
  1604. { read header }
  1605. blockread(f,elfheader,sizeof(tElf32header));
  1606. elfheader:=MayBeSwapHeader(elfheader);
  1607. seek(f,elfheader.e_shoff);
  1608. { read string section header }
  1609. seek(f,elfheader.e_shoff+sizeof(TElf32sechdr)*elfheader.e_shstrndx);
  1610. blockread(f,secheader,sizeof(secheader));
  1611. secheader:=MaybeSwapSecHeader(secheader);
  1612. stringoffset:=secheader.sh_offset;
  1613. seek(f,elfheader.e_shoff);
  1614. status.datasize:=0;
  1615. for i:=0 to elfheader.e_shnum-1 do
  1616. begin
  1617. blockread(f,secheader,sizeof(secheader));
  1618. secheader:=MaybeSwapSecHeader(secheader);
  1619. secname:=ReadSectionName(stringoffset+secheader.sh_name);
  1620. if secname='.text' then
  1621. begin
  1622. Message1(execinfo_x_codesize,tostr(secheader.sh_size));
  1623. status.codesize:=secheader.sh_size;
  1624. end
  1625. else if secname='.data' then
  1626. begin
  1627. Message1(execinfo_x_initdatasize,tostr(secheader.sh_size));
  1628. inc(status.datasize,secheader.sh_size);
  1629. end
  1630. else if secname='.bss' then
  1631. begin
  1632. Message1(execinfo_x_uninitdatasize,tostr(secheader.sh_size));
  1633. inc(status.datasize,secheader.sh_size);
  1634. end;
  1635. end;
  1636. close(f);
  1637. {$pop}
  1638. if ioresult<>0 then
  1639. ;
  1640. postprocessexecutable:=true;
  1641. end;
  1642. {*****************************************************************************
  1643. Initialize
  1644. *****************************************************************************}
  1645. initialization
  1646. {$ifdef arm}
  1647. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1648. RegisterTarget(system_arm_embedded_info);
  1649. {$endif arm}
  1650. {$ifdef avr}
  1651. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1652. RegisterTarget(system_avr_embedded_info);
  1653. {$endif avr}
  1654. {$ifdef i386}
  1655. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1656. RegisterTarget(system_i386_embedded_info);
  1657. {$endif i386}
  1658. {$ifdef x86_64}
  1659. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1660. RegisterTarget(system_x86_64_embedded_info);
  1661. {$endif x86_64}
  1662. {$ifdef i8086}
  1663. { no need to register linker ld_embedded, because i8086_embedded uses the
  1664. regular msdos linker. In case a flat binary, relocated for a specific
  1665. segment address is needed (e.g. for a BIOS or a real mode bootloader), it
  1666. can be produced post-compilation with exe2bin or a similar tool. }
  1667. RegisterTarget(system_i8086_embedded_info);
  1668. {$endif i8086}
  1669. {$ifdef mipsel}
  1670. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1671. RegisterTarget(system_mipsel_embedded_info);
  1672. {$endif mipsel}
  1673. {$ifdef m68k}
  1674. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1675. RegisterTarget(system_m68k_embedded_info);
  1676. {$endif m68k}
  1677. {$ifdef riscv32}
  1678. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1679. RegisterTarget(system_riscv32_embedded_info);
  1680. {$endif riscv32}
  1681. {$ifdef riscv64}
  1682. RegisterLinker(ld_freertos,TLinkerEmbedded);
  1683. RegisterTarget(system_riscv64_embedded_info);
  1684. {$endif riscv64}
  1685. {$ifdef xtensa}
  1686. RegisterLinker(ld_freertos,TlinkerFreeRTOS);
  1687. RegisterTarget(system_xtensa_freertos_info);
  1688. {$endif xtensa}
  1689. end.