فهرست منبع

bsp: k230: use rtconfig.h for linkscript

For linker script, use constant macro defined from
rtconfig.h, not immediate value.

Also cleanup the link_statksize.lds, it is also not
needed when using new mechanism.

Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
Chen Wang 3 هفته پیش
والد
کامیت
2a00bd4ecb
5فایلهای تغییر یافته به همراه31 افزوده شده و 10 حذف شده
  1. 1 0
      bsp/k230/.gitignore
  2. 27 6
      bsp/k230/SConstruct
  3. 2 2
      bsp/k230/link.lds
  4. 0 1
      bsp/k230/link_stacksize.lds
  5. 1 1
      bsp/k230/rtconfig.py

+ 1 - 0
bsp/k230/.gitignore

@@ -4,6 +4,7 @@ packages/
 install/
 
 rtthread.*
+link.lds.generated
 
 __pycache__
 .config.old

+ 27 - 6
bsp/k230/SConstruct

@@ -1,10 +1,36 @@
 import os
 import sys
 import rtconfig
+import platform
+import subprocess
 
 from rtconfig import RTT_ROOT
 import sys
 
+def generate_ldscript(input, output):
+
+    if not os.path.exists(input):
+        print('Error: file', input, 'not found')
+        return
+
+    if os.path.exists(output):
+        os.remove(output)
+
+    if rtconfig.PLATFORM == 'gcc':
+
+        gcc_cmd = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
+
+        # gcc -E -P -x c $input -o $output
+        if (platform.system() == 'Windows'):
+            child = subprocess.Popen([gcc_cmd, '-E', '-P', '-x', 'c', input, '-o', output], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+        else:
+            child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
+
+        child.communicate()
+
+        print(output, 'is generated from', input)
+
+
 sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
 from building import *
 
@@ -26,12 +52,7 @@ Export('rtconfig')
 # prepare building environment
 objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
 
-stack_size = 4096
-
-stack_lds = open('link_stacksize.lds', 'w')
-if GetDepend('__STACKSIZE__'): stack_size = GetDepend('__STACKSIZE__')
-stack_lds.write('__STACKSIZE__ = %d;' % stack_size)
-stack_lds.close()
+generate_ldscript('link.lds', 'link.lds.generated')
 
 # make a building
 DoBuilding(TARGET, objs)

+ 2 - 2
bsp/k230/link.lds

@@ -8,7 +8,7 @@
  * 2020/12/12     bernard      The first version
  */
 
-INCLUDE "link_stacksize.lds"
+#include "rtconfig.h"
 
 OUTPUT_ARCH( "riscv" )
 
@@ -22,7 +22,7 @@ OUTPUT_ARCH( "riscv" )
 
 MEMORY
 {
-   SRAM : ORIGIN = 0xffffffc000020000, LENGTH = 262012K
+   SRAM : ORIGIN = KERNEL_VADDR_START, LENGTH = 262012K
 }
 
 ENTRY(_start)

+ 0 - 1
bsp/k230/link_stacksize.lds

@@ -1 +0,0 @@
-__STACKSIZE__ = 65536;

+ 1 - 1
bsp/k230/rtconfig.py

@@ -44,7 +44,7 @@ if PLATFORM == 'gcc':
     DEVICE  = ' -mcmodel=medany -march=rv64imafdcv -mabi=lp64d'
     CFLAGS  = DEVICE + ' -Wno-cpp -fvar-tracking -ffreestanding -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -D_POSIX_SOURCE '
     AFLAGS  = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__'
-    LFLAGS  = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T link.lds' + ' -lsupc++ -lgcc -static'
+    LFLAGS  = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T link.lds.generated' + ' -lsupc++ -lgcc -static'
     CPATH   = ''
     LPATH   = ''