summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChen Wang <[email protected]>2025-04-10 18:27:28 +0800
committerRbb666 <[email protected]>2025-04-24 14:34:25 +0800
commit2a00bd4ecb7947916a8c3fc3b0858de8aa973036 (patch)
treed5a3821ef80dbaa49cf2b066be9c29bb23ea1988
parent90e81cf4b69e7b37868d7f62615a375991ff3b4b (diff)
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 <[email protected]>
-rw-r--r--bsp/k230/.gitignore1
-rw-r--r--bsp/k230/SConstruct33
-rw-r--r--bsp/k230/link.lds4
-rw-r--r--bsp/k230/link_stacksize.lds1
-rw-r--r--bsp/k230/rtconfig.py2
5 files changed, 31 insertions, 10 deletions
diff --git a/bsp/k230/.gitignore b/bsp/k230/.gitignore
index fffebd9e3a..739c929cc2 100644
--- a/bsp/k230/.gitignore
+++ b/bsp/k230/.gitignore
@@ -4,6 +4,7 @@ packages/
install/
rtthread.*
+link.lds.generated
__pycache__
.config.old
diff --git a/bsp/k230/SConstruct b/bsp/k230/SConstruct
index c800dc6f5c..13bf49b42e 100644
--- a/bsp/k230/SConstruct
+++ b/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)
diff --git a/bsp/k230/link.lds b/bsp/k230/link.lds
index 3f3818cdd7..2ce0fe3f02 100644
--- a/bsp/k230/link.lds
+++ b/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)
diff --git a/bsp/k230/link_stacksize.lds b/bsp/k230/link_stacksize.lds
deleted file mode 100644
index 89ab4af217..0000000000
--- a/bsp/k230/link_stacksize.lds
+++ /dev/null
@@ -1 +0,0 @@
-__STACKSIZE__ = 65536; \ No newline at end of file
diff --git a/bsp/k230/rtconfig.py b/bsp/k230/rtconfig.py
index 4cd6df869a..10987fa320 100644
--- a/bsp/k230/rtconfig.py
+++ b/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 = ''