1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| String[] gccCommand = { riscvGcc, "-march=rv32e", "-mabi=ilp32e", "-O3", "-nostdlib", "-flto", "-ffreestanding", "-ffunction-sections", "-fdata-sections", "-fno-builtin", "--specs=nano.specs", "--specs=nosys.specs", "-Wl,--build-id=none", "-Wl,-Bstatic", "-Wl,-T," + linkerScript, "-Wl,-Map=" + mapFile, "-L.", "-o", elfOutput, projectDir + "\start.S", projectDir + "\" + mainCode + ".c" // 源文件2:主代码.c }; publish("执行编译命令:" + String.join(" ", gccCommand)); if (!runCommand(gccCommand)) return null; // 执行命令,失败则退出
// 步骤2:生成反汇编.s文件(objdump -S) String[] objdumpCommand = {objdump, "-S", elfOutput}; publish("\n执行反汇编:" + String.join(" ", objdumpCommand)); if (!runCommandToFile(objdumpCommand, asmOutput)) return null;
// 步骤3:生成bin文件(objcopy -O binary) String[] binCommand = {objcopy, "-O", "binary", elfOutput, binOutput}; publish("\n生成bin文件:" + String.join(" ", binCommand)); if (!runCommand(binCommand)) return null;
// 步骤4:生成hex文件(objcopy -O verilog) String[] hexCommand = {objcopy, "-O", "verilog", "--verilog-data-width", "4", elfOutput, hexOutput}; publish("\n生成hex文件:" + String.join(" ", hexCommand)); if (!runCommand(hexCommand)) return null;
|