Browse Source

Add -WP option so that IDF version can be passed in - stored in globals.idf_version. The version is checked in t_freertos.pas and for esp-idf version 4.3.x an extra link file is added, also running ldgen.py is skipped as that seems unused.

ccrause 3 years ago
parent
commit
5289aab4f2
3 changed files with 166 additions and 38 deletions
  1. 2 0
      compiler/globals.pas
  2. 119 0
      compiler/options.pas
  3. 45 38
      compiler/systems/t_freertos.pas

+ 2 - 0
compiler/globals.pas

@@ -265,6 +265,8 @@ interface
 {$ifdef XTENSA}
 {$ifdef XTENSA}
        { specified with -Ff }
        { specified with -Ff }
        idfpath           : TPathStr;
        idfpath           : TPathStr;
+       { specified with }
+       idf_version       : longint;
 {$endif XTENSA}
 {$endif XTENSA}
        { external assembler extra option }
        { external assembler extra option }
        asmextraopt       : string;
        asmextraopt       : string;

+ 119 - 0
compiler/options.pas

@@ -78,9 +78,14 @@ Type
     procedure ForceStaticLinking;
     procedure ForceStaticLinking;
    protected
    protected
     MacVersionSet: boolean;
     MacVersionSet: boolean;
+    IdfVersionSet: boolean;
     processorstr: TCmdStr;
     processorstr: TCmdStr;
     function ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
     function ParseMacVersionMin(out minstr, emptystr: string; const compvarname, value: string; ios: boolean): boolean;
     procedure MaybeSetDefaultMacVersionMacro;
     procedure MaybeSetDefaultMacVersionMacro;
+{$ifdef XTENSA}
+    function ParseVersionStr(out ver: longint; const compvarname, value: string): boolean;
+    procedure MaybeSetIdfVersionMacro;
+{$endif}
     procedure VerifyTargetProcessor;
     procedure VerifyTargetProcessor;
   end;
   end;
 
 
@@ -1146,6 +1151,85 @@ function toption.ParseMacVersionMin(out minstr, emptystr: string; const compvarn
     result:=true;
     result:=true;
   end;
   end;
 
 
+{$ifdef XTENSA}
+function TOption.ParseVersionStr(out ver: longint;
+  const compvarname, value: string): boolean;
+
+  function subval(start,maxlen: longint; out stop: longint): string;
+    var
+      i: longint;
+    begin
+      result:='';
+      i:=start;
+      while (i<=length(value)) and
+            (value[i] in ['0'..'9']) do
+        inc(i);
+      { sufficient amount of digits? }
+      if (i=start) or
+         (i-start>maxlen) then
+        exit;
+      result:=copy(value,start,i-start);
+      stop:=i;
+    end;
+
+  var
+    temp,
+    compvarvalue: string[15];
+    i: longint;
+  begin
+    IdfVersionSet:=false;
+    emptystr:='';
+    { check whether the value is a valid version number }
+    if value='' then
+      begin
+        undef_system_macro(compvarname);
+        exit(true);
+      end;
+    { major version number }
+    compvarvalue:=subval(1,2,i);
+    { not enough digits -> invalid }
+    if compvarvalue='' then
+      exit(false);
+    { already end of string -> invalid }
+    if (i>=length(value)) or
+       (value[i]<>'.') then
+      exit(false);
+    { minor version number }
+    temp:=subval(i+1,2,i);
+    if temp='' then
+      exit(false);
+    if length(temp)=1 then
+      temp:='0'+temp;
+    compvarvalue:=compvarvalue+temp;
+    { patch level }
+    if i<=length(value) then
+      begin
+        if value[i]<>'.' then
+          exit(false);
+        temp:=subval(i+1,2,i);
+        if temp='' then
+          exit(false);
+
+        if length(temp)=1 then
+          temp:='0'+temp;
+        compvarvalue:=compvarvalue+temp;
+        { must be the end }
+        if i<=length(value) then
+          exit(false);
+      end
+    else
+      begin
+        compvarvalue:=compvarvalue+'00';
+      end;
+    val(compvarvalue,idf_version,i);
+    if i=0 then
+      begin
+        set_system_compvar(compvarname,compvarvalue);
+        IdfVersionSet:=true;
+        result:=true;
+      end;
+end;
+{$endif XTENSA}
 
 
 procedure TOption.MaybeSetDefaultMacVersionMacro;
 procedure TOption.MaybeSetDefaultMacVersionMacro;
 var
 var
@@ -1221,6 +1305,29 @@ begin
   end;
   end;
 end;
 end;
 
 
+{$ifdef XTENSA}
+procedure TOption.MaybeSetIdfVersionMacro;
+begin
+  if not(target_info.system=system_xtensa_freertos) then
+    exit;
+  if IdfVersionSet then
+    exit;
+  { nothing specified -> defaults }
+  case current_settings.controllertype of
+    ct_esp8266:
+      begin
+        set_system_compvar('IDF_VERSION','30300');
+        idf_version:=30300;
+      end;
+    else
+      begin
+        set_system_compvar('IDF_VERSION','40200');
+        idf_version:=40200;
+      end;
+  end;
+end;
+{$endif XTENSA}
+
 procedure TOption.VerifyTargetProcessor;
 procedure TOption.VerifyTargetProcessor;
   begin
   begin
     { no custom target processor specified -> ok }
     { no custom target processor specified -> ok }
@@ -2812,6 +2919,13 @@ begin
                           begin
                           begin
                             break;
                             break;
                           end
                           end
+{$ifdef XTENSA}
+                        else if (target_info.system in [system_xtensa_freertos]) and
+                           ParseVersionStr(idf_version,'IDF_VERSION',copy(More,2,255)) then
+                          begin
+                            break;
+                          end
+{$endif XTENSA}
                         else
                         else
                           IllegalPara(opt);
                           IllegalPara(opt);
                       end;
                       end;
@@ -4573,6 +4687,11 @@ begin
   { set Mac OS X version default macros if not specified explicitly }
   { set Mac OS X version default macros if not specified explicitly }
   option.MaybeSetDefaultMacVersionMacro;
   option.MaybeSetDefaultMacVersionMacro;
 
 
+{$ifdef XTENSA}
+  { set ESP32 or ESP8266 default SDK versions }
+  option.MaybeSetIdfVersionMacro;
+{$endif XTENSA}
+
 {$ifdef cpufpemu}
 {$ifdef cpufpemu}
   { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
   { force fpu emulation on arm/wince, arm/gba, arm/embedded and arm/nds
     if fpu type not explicitly set }
     if fpu type not explicitly set }

+ 45 - 38
compiler/systems/t_freertos.pas

@@ -963,6 +963,7 @@ begin
   { idfpath can be set by -Ff, else default to environment value of IDF_PATH }
   { idfpath can be set by -Ff, else default to environment value of IDF_PATH }
   if idfpath='' then
   if idfpath='' then
     idfpath := trim(GetEnvironmentVariable('IDF_PATH'));
     idfpath := trim(GetEnvironmentVariable('IDF_PATH'));
+  idfpath:=ExcludeTrailingBackslash(idfpath);
 {$endif XTENSA}
 {$endif XTENSA}
 
 
   { for future use }
   { for future use }
@@ -977,7 +978,7 @@ begin
 {$ifdef XTENSA}
 {$ifdef XTENSA}
   { generate a sdkconfig.h if none is provided,
   { generate a sdkconfig.h if none is provided,
     only a few fields are provided to far }
     only a few fields are provided to far }
-  Assign(t,'sdkconfig.h');
+  Assign(t,inputfilepath+'/sdkconfig.h');
   {$push}{$I-}
   {$push}{$I-}
   Rewrite(t);
   Rewrite(t);
   if ioresult<>0 then
   if ioresult<>0 then
@@ -1013,9 +1014,9 @@ begin
 
 
   { generate an sdkconfig if none is provided,
   { generate an sdkconfig if none is provided,
     this is a dummy so far }
     this is a dummy so far }
-  if not(Sysutils.FileExists('sdkconfig')) then
+  if not(Sysutils.FileExists(inputfilepath+'/sdkconfig')) then
     begin
     begin
-      Assign(t,'sdkconfig');
+      Assign(t,inputfilepath+'/sdkconfig');
       {$push}{$I-}
       {$push}{$I-}
       Rewrite(t);
       Rewrite(t);
       if ioresult<>0 then
       if ioresult<>0 then
@@ -1031,9 +1032,9 @@ begin
 
 
   { generate an Kconfig if none is provided,
   { generate an Kconfig if none is provided,
     this is a dummy so far }
     this is a dummy so far }
-  if not(Sysutils.FileExists('Kconfig')) then
+  if not(Sysutils.FileExists(inputfilepath+'/Kconfig')) then
     begin
     begin
-      Assign(t,'Kconfig');
+      Assign(t,inputfilepath+'/Kconfig');
       {$push}{$I-}
       {$push}{$I-}
       Rewrite(t);
       Rewrite(t);
       if ioresult<>0 then
       if ioresult<>0 then
@@ -1049,9 +1050,9 @@ begin
 
 
   { generate an Kconfig.projbuild if none is provided,
   { generate an Kconfig.projbuild if none is provided,
     this is a dummy so far }
     this is a dummy so far }
-  if not(Sysutils.FileExists('Kconfig.projbuild')) then
+  if not(Sysutils.FileExists(inputfilepath+'/Kconfig.projbuild')) then
     begin
     begin
-      Assign(t,'Kconfig.projbuild');
+      Assign(t,inputfilepath+'/Kconfig.projbuild');
       {$push}{$I-}
       {$push}{$I-}
       Rewrite(t);
       Rewrite(t);
       if ioresult<>0 then
       if ioresult<>0 then
@@ -1067,9 +1068,9 @@ begin
 
 
   { generate an kconfigs.in if none is provided,
   { generate an kconfigs.in if none is provided,
     this is a dummy so far }
     this is a dummy so far }
-  if not(Sysutils.FileExists('kconfigs.in')) then
+  if not(Sysutils.FileExists(inputfilepath+'/kconfigs.in')) then
     begin
     begin
-      Assign(t,'kconfigs.in');
+      Assign(t,inputfilepath+'/kconfigs.in');
       {$push}{$I-}
       {$push}{$I-}
       Rewrite(t);
       Rewrite(t);
       if ioresult<>0 then
       if ioresult<>0 then
@@ -1085,9 +1086,9 @@ begin
 
 
   { generate an kconfigs_projbuild.in if none is provided,
   { generate an kconfigs_projbuild.in if none is provided,
     this is a dummy so far }
     this is a dummy so far }
-  if not(Sysutils.FileExists('kconfigs_projbuild.in')) then
+  if not(Sysutils.FileExists(inputfilepath+'/kconfigs_projbuild.in')) then
     begin
     begin
-      Assign(t,'kconfigs_projbuild.in');
+      Assign(t,inputfilepath+'/kconfigs_projbuild.in');
       {$push}{$I-}
       {$push}{$I-}
       Rewrite(t);
       Rewrite(t);
       if ioresult<>0 then
       if ioresult<>0 then
@@ -1104,7 +1105,7 @@ begin
   { generate a config.env if none is provided,
   { generate a config.env if none is provided,
     COMPONENT_KCONFIGS and COMPONENT_KCONFIGS_PROJBUILD are dummy fields and might
     COMPONENT_KCONFIGS and COMPONENT_KCONFIGS_PROJBUILD are dummy fields and might
     be needed to be filed properly }
     be needed to be filed properly }
-  Assign(t,'config.env');
+  Assign(t,inputfilepath+'/config.env');
   {$push}{$I-}
   {$push}{$I-}
   Rewrite(t);
   Rewrite(t);
   if ioresult<>0 then
   if ioresult<>0 then
@@ -1135,7 +1136,7 @@ begin
   {$pop}
   {$pop}
 
 
   { generate ldgen_libraries }
   { generate ldgen_libraries }
-  Assign(t,'ldgen_libraries');
+  Assign(t,inputfilepath+'/ldgen_libraries');
   {$push}{$I-}
   {$push}{$I-}
   Rewrite(t);
   Rewrite(t);
   if ioresult<>0 then
   if ioresult<>0 then
@@ -1172,10 +1173,11 @@ begin
   if current_settings.controllertype = ct_none then
   if current_settings.controllertype = ct_none then
     Message(exec_f_controllertype_expected)
     Message(exec_f_controllertype_expected)
   else if current_settings.controllertype = ct_esp32 then
   else if current_settings.controllertype = ct_esp32 then
-    cmdstr:='-C -P -x c -E -o esp32_out.ld -I . $IDF_PATH/components/esp32/ld/esp32.ld'
+    cmdstr:='-C -P -x c -E -o $OUTPUT/esp32_out.ld -I $OUTPUT/ $IDF_PATH/components/esp32/ld/esp32.ld'
   else
   else
-    cmdstr:='-C -P -x c -E -o esp8266_out.ld -I . $IDF_PATH/components/esp8266/ld/esp8266.ld';
+    cmdstr:='-C -P -x c -E -o $OUTPUT/esp8266_out.ld -I $OUTPUT/ $IDF_PATH/components/esp8266/ld/esp8266.ld';
   Replace(cmdstr,'$IDF_PATH',idfpath);
   Replace(cmdstr,'$IDF_PATH',idfpath);
+  Replace(cmdstr,'$OUTPUT',inputfilepath);
   success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,true);
   success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,true,true);
 
 
   { generate linker maps }
   { generate linker maps }
@@ -1189,21 +1191,21 @@ begin
   S:=FindUtil(utilsprefix+'objdump');
   S:=FindUtil(utilsprefix+'objdump');
   if (current_settings.controllertype = ct_esp32) then
   if (current_settings.controllertype = ct_esp32) then
     cmdstr:={$ifndef UNIX}'$IDF_PATH/tools/ldgen/ldgen.py '+{$endif UNIX}
     cmdstr:={$ifndef UNIX}'$IDF_PATH/tools/ldgen/ldgen.py '+{$endif UNIX}
-            '--config sdkconfig '+
+            '--config $OUTPUT/sdkconfig '+
             '--fragments $IDF_PATH/components/xtensa/linker.lf $IDF_PATH/components/soc/linker.lf $IDF_PATH/components/esp_event/linker.lf '+
             '--fragments $IDF_PATH/components/xtensa/linker.lf $IDF_PATH/components/soc/linker.lf $IDF_PATH/components/esp_event/linker.lf '+
             '$IDF_PATH/components/spi_flash/linker.lf $IDF_PATH/components/esp_wifi/linker.lf $IDF_PATH/components/lwip/linker.lf '+
             '$IDF_PATH/components/spi_flash/linker.lf $IDF_PATH/components/esp_wifi/linker.lf $IDF_PATH/components/lwip/linker.lf '+
             '$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 '+
             '$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 '+
             '$IDF_PATH/components/esp32/ld/esp32_fragments.lf $IDF_PATH/components/freertos/linker.lf $IDF_PATH/components/newlib/newlib.lf '+
             '$IDF_PATH/components/esp32/ld/esp32_fragments.lf $IDF_PATH/components/freertos/linker.lf $IDF_PATH/components/newlib/newlib.lf '+
             '$IDF_PATH/components/esp_gdbstub/linker.lf '+
             '$IDF_PATH/components/esp_gdbstub/linker.lf '+
             '--input $IDF_PATH/components/esp32/ld/esp32.project.ld.in '+
             '--input $IDF_PATH/components/esp32/ld/esp32.project.ld.in '+
-            '--output ./esp32.project.ld '+
+            '--output $OUTPUT/esp32.project.ld '+
             '--kconfig $IDF_PATH/Kconfig '+
             '--kconfig $IDF_PATH/Kconfig '+
-            '--env-file config.env '+
-            '--libraries-file ldgen_libraries '+
+            '--env-file $OUTPUT/config.env '+
+            '--libraries-file $OUTPUT/ldgen_libraries '+
             '--objdump '+S
             '--objdump '+S
   else
   else
     cmdstr:={$ifndef UNIX}'$IDF_PATH/tools/ldgen/ldgen.py '+{$endif UNIX}
     cmdstr:={$ifndef UNIX}'$IDF_PATH/tools/ldgen/ldgen.py '+{$endif UNIX}
-            '--config sdkconfig '+
+            '--config $OUTPUT/sdkconfig '+
             '--fragments $IDF_PATH/components/esp8266/ld/esp8266_fragments.lf '+
             '--fragments $IDF_PATH/components/esp8266/ld/esp8266_fragments.lf '+
             '$IDF_PATH/components/esp8266/ld/esp8266_bss_fragments.lf $IDF_PATH/components/esp8266/linker.lf '+
             '$IDF_PATH/components/esp8266/ld/esp8266_bss_fragments.lf $IDF_PATH/components/esp8266/linker.lf '+
             '$IDF_PATH/components/freertos/linker.lf $IDF_PATH/components/log/linker.lf '+
             '$IDF_PATH/components/freertos/linker.lf $IDF_PATH/components/log/linker.lf '+
@@ -1214,29 +1216,39 @@ begin
             '$IDF_PATH/components/esp8266/Kconfig  $IDF_PATH/components/freertos/Kconfig '+
             '$IDF_PATH/components/esp8266/Kconfig  $IDF_PATH/components/freertos/Kconfig '+
             '$IDF_PATH/components/log/Kconfig $IDF_PATH/components/lwip/Kconfig" '+
             '$IDF_PATH/components/log/Kconfig $IDF_PATH/components/lwip/Kconfig" '+
             '--input $IDF_PATH/components/esp8266/ld/esp8266.project.ld.in '+
             '--input $IDF_PATH/components/esp8266/ld/esp8266.project.ld.in '+
-            '--output ./esp8266.project.ld '+
+            '--output $OUTPUT/esp8266.project.ld '+
             '--kconfig $IDF_PATH/Kconfig '+
             '--kconfig $IDF_PATH/Kconfig '+
-            '--env-file config.env '+
-            '--libraries-file ldgen_libraries '+
+            '--env-file $OUTPUT/config.env '+
+            '--libraries-file $OUTPUT/ldgen_libraries '+
             '--objdump '+S;
             '--objdump '+S;
 
 
   Replace(cmdstr,'$IDF_PATH',idfpath);
   Replace(cmdstr,'$IDF_PATH',idfpath);
-  if success and not(cs_link_nolink in current_settings.globalswitches) then
+  Replace(cmdstr,'$OUTPUT',inputfilepath);
+  if success and not(cs_link_nolink in current_settings.globalswitches) and
+    { Newer version doesn't need to build linker script via ldgen.py }
+    ((current_settings.controllertype = ct_esp32) and (idf_version < 40300)) then
     success:=DoExec(binstr,cmdstr,true,false);
     success:=DoExec(binstr,cmdstr,true,false);
 
 
   if (current_settings.controllertype = ct_esp32) then
   if (current_settings.controllertype = ct_esp32) then
-    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 '+
+    begin
+      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 '+
        '-u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority '+
        '-u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority '+
        '-L $IDF_PATH/components/esp_rom/esp32/ld '+
        '-L $IDF_PATH/components/esp_rom/esp32/ld '+
        '-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 '+
        '-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 '+
-       '-L . -T esp32_out.ld -T esp32.project.ld '+
-       '-L $IDF_PATH/components/esp32/ld -T esp32.peripherals.ld'
+       '-L $OUTPUT -T esp32_out.ld -T esp32.project.ld '+
+       '-L $IDF_PATH/components/esp32/ld -T esp32.peripherals.ld';
+      if idf_version>=40300 then
+        Info.ExeCmd[1]:=Info.ExeCmd[1]+' -L $IDF_PATH/components/esp32_rom/esp32/ld -T esp32.rom.api.ld';
+    end
   else
   else
-    Info.ExeCmd[1] := Info.ExeCmd[1]+' -u call_user_start -u g_esp_sys_info -u _printf_float -u _scanf_float '+
-      '-L $IDF_PATH/components/esp8266/ld -T esp8266.peripherals.ld -T esp8266.rom.ld '+ { SDK scripts }
-      '-L . -T esp8266_out.ld -T esp8266.project.ld'; { Project scripts }
+    begin
+      Info.ExeCmd[1] := Info.ExeCmd[1]+' -u call_user_start -u g_esp_sys_info -u _printf_float -u _scanf_float '+
+        '-L $IDF_PATH/components/esp8266/ld -T esp8266.peripherals.ld -T esp8266.rom.ld '+ { SDK scripts }
+        '-L $OUTPUT -T esp8266_out.ld -T esp8266.project.ld'; { Project scripts }
+    end;
 
 
   Replace(Info.ExeCmd[1],'$IDF_PATH',idfpath);
   Replace(Info.ExeCmd[1],'$IDF_PATH',idfpath);
+  Replace(Info.ExeCmd[1],'$OUTPUT',inputfilepath);
 {$endif XTENSA}
 {$endif XTENSA}
 
 
   FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
   FixedExeFileName:=maybequoted(ScriptFixFileName(ChangeFileExt(current_module.exefilename,'.elf')));
@@ -1462,19 +1474,14 @@ function TlinkerFreeRTOS.postprocessexecutable(const fn : string;isdll:boolean):
         if pos('.text',secname)<>0 then
         if pos('.text',secname)<>0 then
           begin
           begin
             Message1(execinfo_x_codesize,tostr(secheader.sh_size));
             Message1(execinfo_x_codesize,tostr(secheader.sh_size));
-            inc(status.codesize,secheader.sh_size);
-          end
-        else if pos('.data',secname)<>0 then
-          begin
-            Message1(execinfo_x_initdatasize,tostr(secheader.sh_size));
-            inc(status.datasize,secheader.sh_size);
+            status.codesize:=secheader.sh_size;
           end
           end
-        else if pos('.rodata',secname)<>0 then
+        else if secname='.data' then
           begin
           begin
             Message1(execinfo_x_initdatasize,tostr(secheader.sh_size));
             Message1(execinfo_x_initdatasize,tostr(secheader.sh_size));
             inc(status.datasize,secheader.sh_size);
             inc(status.datasize,secheader.sh_size);
           end
           end
-        else if pos('.bss',secname)<>0 then
+        else if secname='.bss' then
           begin
           begin
             Message1(execinfo_x_uninitdatasize,tostr(secheader.sh_size));
             Message1(execinfo_x_uninitdatasize,tostr(secheader.sh_size));
             inc(status.datasize,secheader.sh_size);
             inc(status.datasize,secheader.sh_size);