mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2025-06-06 06:35:09 +02:00
fxconv: allow output with assembly but no data
This commit is contained in:
parent
d24ae5eef9
commit
0acea3baf6
1 changed files with 45 additions and 29 deletions
|
@ -1060,6 +1060,11 @@ def elf(data, output, symbol, toolchain=None, arch=None, section=None,
|
||||||
symbol = symbol + "_staticdata"
|
symbol = symbol + "_staticdata"
|
||||||
data = data.data()
|
data = data.data()
|
||||||
|
|
||||||
|
if data is None and assembly is None:
|
||||||
|
raise fxconv.FxconvError("elf() but no data and no assembly")
|
||||||
|
|
||||||
|
# Toolchain parameters
|
||||||
|
|
||||||
if toolchain is None:
|
if toolchain is None:
|
||||||
toolchain = "sh3eb-elf"
|
toolchain = "sh3eb-elf"
|
||||||
if section is None:
|
if section is None:
|
||||||
|
@ -1078,22 +1083,14 @@ def elf(data, output, symbol, toolchain=None, arch=None, section=None,
|
||||||
raise FxconvError(f"non-trivial architecture for {toolchain} must be "+
|
raise FxconvError(f"non-trivial architecture for {toolchain} must be "+
|
||||||
"specified")
|
"specified")
|
||||||
|
|
||||||
|
# Generate data - in <output> directly if there is no assembly
|
||||||
|
|
||||||
|
if data:
|
||||||
fp_obj = tempfile.NamedTemporaryFile()
|
fp_obj = tempfile.NamedTemporaryFile()
|
||||||
fp_obj.write(data)
|
fp_obj.write(data)
|
||||||
fp_obj.flush()
|
fp_obj.flush()
|
||||||
|
|
||||||
if assembly is not None:
|
|
||||||
fp_asm = tempfile.NamedTemporaryFile()
|
|
||||||
fp_asm.write(assembly.encode('utf-8'))
|
|
||||||
fp_asm.flush()
|
|
||||||
|
|
||||||
proc = subprocess.run([
|
|
||||||
f"{toolchain}-as", "-c", fp_asm.name, "-o", fp_asm.name + ".o" ])
|
|
||||||
if proc.returncode != 0:
|
|
||||||
raise FxconvError(f"as returned {proc.returncode}")
|
|
||||||
|
|
||||||
sybl = "_binary_" + fp_obj.name.replace("/", "_")
|
sybl = "_binary_" + fp_obj.name.replace("/", "_")
|
||||||
|
|
||||||
objcopy_args = [
|
objcopy_args = [
|
||||||
f"{toolchain}-objcopy", "-I", "binary", "-O", "elf32-sh",
|
f"{toolchain}-objcopy", "-I", "binary", "-O", "elf32-sh",
|
||||||
"--binary-architecture", arch, "--file-alignment", "4",
|
"--binary-architecture", arch, "--file-alignment", "4",
|
||||||
|
@ -1101,23 +1098,42 @@ def elf(data, output, symbol, toolchain=None, arch=None, section=None,
|
||||||
"--redefine-sym", f"{sybl}_start={symbol}",
|
"--redefine-sym", f"{sybl}_start={symbol}",
|
||||||
"--redefine-sym", f"{sybl}_end={symbol}_end",
|
"--redefine-sym", f"{sybl}_end={symbol}_end",
|
||||||
"--redefine-sym", f"{sybl}_size={symbol}_size",
|
"--redefine-sym", f"{sybl}_size={symbol}_size",
|
||||||
fp_obj.name, output if assembly is None else fp_obj.name + "-tmp" ]
|
fp_obj.name, output if not assembly else fp_obj.name + ".o" ]
|
||||||
|
|
||||||
proc = subprocess.run(objcopy_args)
|
proc = subprocess.run(objcopy_args)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise FxconvError(f"objcopy returned {proc.returncode}")
|
raise FxconvError(f"objcopy returned {proc.returncode}")
|
||||||
|
|
||||||
if assembly is not None:
|
# Generate assembly - in <output> directly if there is no data
|
||||||
proc = subprocess.run([
|
|
||||||
f"{toolchain}-ld", "-r", fp_obj.name + "-tmp", fp_asm.name + ".o",
|
|
||||||
"-o", output ])
|
|
||||||
|
|
||||||
os.remove(fp_obj.name + "-tmp")
|
if assembly:
|
||||||
os.remove(fp_asm.name + ".o")
|
fp_asm = tempfile.NamedTemporaryFile()
|
||||||
|
fp_asm.write(assembly.encode('utf-8'))
|
||||||
|
fp_asm.flush()
|
||||||
|
|
||||||
|
as_args = [
|
||||||
|
f"{toolchain}-as", "-c", fp_asm.name, "-o",
|
||||||
|
output if not data else fp_asm.name + ".o" ]
|
||||||
|
|
||||||
|
proc = subprocess.run(as_args)
|
||||||
|
if proc.returncode != 0:
|
||||||
|
raise FxconvError(f"as returned {proc.returncode}")
|
||||||
|
|
||||||
|
# If both data and assembly are specified, merge everyone
|
||||||
|
|
||||||
|
if data and assembly:
|
||||||
|
ld_args = [
|
||||||
|
f"{toolchain}-ld", "-r", fp_obj.name + ".o", fp_asm.name + ".o",
|
||||||
|
"-o", output ]
|
||||||
|
|
||||||
|
proc = subprocess.run(ld_args)
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise FxconvError(f"ld returned {proc.returncode}")
|
raise FxconvError(f"ld returned {proc.returncode}")
|
||||||
|
|
||||||
fp_asm.close()
|
os.remove(fp_obj.name + ".o")
|
||||||
|
os.remove(fp_asm.name + ".o")
|
||||||
|
|
||||||
|
if data:
|
||||||
fp_obj.close()
|
fp_obj.close()
|
||||||
|
if assembly:
|
||||||
|
fp_asm.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue