Skip to content

Commit 2a00bd4

Browse files
unicornxRbb666
authored andcommitted
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>
1 parent 90e81cf commit 2a00bd4

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

bsp/k230/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ packages/
44
install/
55

66
rtthread.*
7+
link.lds.generated
78

89
__pycache__
910
.config.old

bsp/k230/SConstruct

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
11
import os
22
import sys
33
import rtconfig
4+
import platform
5+
import subprocess
46

57
from rtconfig import RTT_ROOT
68
import sys
79

10+
def generate_ldscript(input, output):
11+
12+
if not os.path.exists(input):
13+
print('Error: file', input, 'not found')
14+
return
15+
16+
if os.path.exists(output):
17+
os.remove(output)
18+
19+
if rtconfig.PLATFORM == 'gcc':
20+
21+
gcc_cmd = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
22+
23+
# gcc -E -P -x c $input -o $output
24+
if (platform.system() == 'Windows'):
25+
child = subprocess.Popen([gcc_cmd, '-E', '-P', '-x', 'c', input, '-o', output], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
26+
else:
27+
child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
28+
29+
child.communicate()
30+
31+
print(output, 'is generated from', input)
32+
33+
834
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
935
from building import *
1036

@@ -26,12 +52,7 @@ Export('rtconfig')
2652
# prepare building environment
2753
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
2854

29-
stack_size = 4096
30-
31-
stack_lds = open('link_stacksize.lds', 'w')
32-
if GetDepend('__STACKSIZE__'): stack_size = GetDepend('__STACKSIZE__')
33-
stack_lds.write('__STACKSIZE__ = %d;' % stack_size)
34-
stack_lds.close()
55+
generate_ldscript('link.lds', 'link.lds.generated')
3556

3657
# make a building
3758
DoBuilding(TARGET, objs)

bsp/k230/link.lds

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* 2020/12/12 bernard The first version
99
*/
1010

11-
INCLUDE "link_stacksize.lds"
11+
#include "rtconfig.h"
1212

1313
OUTPUT_ARCH( "riscv" )
1414

@@ -22,7 +22,7 @@ OUTPUT_ARCH( "riscv" )
2222

2323
MEMORY
2424
{
25-
SRAM : ORIGIN = 0xffffffc000020000, LENGTH = 262012K
25+
SRAM : ORIGIN = KERNEL_VADDR_START, LENGTH = 262012K
2626
}
2727

2828
ENTRY(_start)

bsp/k230/link_stacksize.lds

Lines changed: 0 additions & 1 deletion
This file was deleted.

bsp/k230/rtconfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
DEVICE = ' -mcmodel=medany -march=rv64imafdcv -mabi=lp64d'
4545
CFLAGS = DEVICE + ' -Wno-cpp -fvar-tracking -ffreestanding -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -D_POSIX_SOURCE '
4646
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__'
47-
LFLAGS = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T link.lds' + ' -lsupc++ -lgcc -static'
47+
LFLAGS = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T link.lds.generated' + ' -lsupc++ -lgcc -static'
4848
CPATH = ''
4949
LPATH = ''
5050

0 commit comments

Comments
 (0)