Skip to content

Commit 5da0026

Browse files
committed
Add --get-elf-class for march-to-cpu-opt
1 parent 22f2d28 commit 5da0026

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

scripts/march-to-cpu-opt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def parse_opt(argv):
3030
parser.add_argument('-march', '--with-arch', type=str, dest='march')
3131
parser.add_argument('-selftest', action='store_true')
3232
parser.add_argument('--get-riscv-tag', type=str)
33+
parser.add_argument('--get-elf-class', type=str)
3334
opt = parser.parse_args()
3435
return opt
3536

@@ -160,11 +161,19 @@ class TestArchStringParse(unittest.TestCase):
160161
def selftest():
161162
unittest.main(argv=sys.argv[1:])
162163

163-
def read_arch_attr (path):
164+
def open_elf(path):
164165
try:
165166
elffile = elftools.elf.elffile.ELFFile(open(path, 'rb'))
166167
except elftools.common.exceptions.ELFError:
167168
raise Exception("%s is not ELF file!" % path)
169+
return elffile
170+
171+
def read_elf_class(path):
172+
elffile = open_elf(path)
173+
return elffile.elfclass
174+
175+
def read_arch_attr (path):
176+
elffile = open_elf(path)
168177

169178
attr_sec = elffile.get_section_by_name(".riscv.attributes")
170179
if attr_sec:
@@ -200,8 +209,12 @@ def main(argv):
200209
if opt.selftest:
201210
selftest()
202211
return 0
203-
if (opt.with_elf):
204-
march = read_arch_attr (opt.with_elf)
212+
if (opt.get_elf_class):
213+
elf_class = read_elf_class (opt.get_elf_class)
214+
print (elf_class)
215+
return
216+
if (opt.get_riscv_tag):
217+
march = read_arch_attr (opt.get_riscv_tag)
205218
else:
206219
march = opt.march
207220
cpu_opt = conver_arch_to_qemu_cpu_opt(march)

scripts/wrapper/qemu/riscv64-unknown-linux-gnu-run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ do
1010
shift
1111
done
1212

13-
xlen="$(readelf -h $1 | grep 'Class' | cut -d: -f 2 | xargs echo | sed 's/^ELF//')"
13+
xlen="$(march-to-cpu-opt --get-elf-class $1)"
1414

1515
QEMU_CPU="$(march-to-cpu-opt --get-riscv-tag $1)" qemu-riscv$xlen -r 5.10 "${qemu_args[@]}" -L ${RISC_V_SYSROOT} "$@"

0 commit comments

Comments
 (0)