-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharmgcc.lua
More file actions
84 lines (77 loc) · 2.31 KB
/
Copy patharmgcc.lua
File metadata and controls
84 lines (77 loc) · 2.31 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
local cflags = {
"-mcpu=cortex-m4",
" -mthumb",
"-mfloat-abi=hard -mfpu=fpv4-sp-d16",
"-fdata-sections -ffunction-sections",
"-nostartfiles",
"-Os",
}
local ldflags = {
"-specs=nano.specs",
"-lc",
"-lm",
"-lnosys",
"-Wl,--gc-sections",
}
function use_toolchain(sdk_path)
toolchain("arm-gcc")
set_kind("cross")
set_description("Stm32 Arm Embedded Compiler")
set_sdkdir(sdk_path)
set_toolset("cc", "arm-none-eabi-gcc")
set_toolset("ld", "arm-none-eabi-gcc")
set_toolset("ar", "arm-none-eabi-ar")
set_toolset("as", "arm-none-eabi-gcc")
toolchain_end()
set_toolchains("arm-gcc")
end
rule("arm-gcc")
on_load(function (target)
-- force add ld flags, ldflags {force = true}
target:set("policy", "check.auto_ignore_flags", false)
target:add("cxflags", cflags)
target:add("asflags", cflags)
-- use gcc to link
target:add("ldflags", cflags)
target:add("ldflags", ldflags)
end)
after_build(function (target)
print("$(env ARM_TOOL)")
print("after_build: generate hex files")
local out = target:targetfile() or ""
local gen_fi = "build/"..target:name()
print(string.format("%s => %s", out, gen_fi))
os.exec("arm-none-eabi-objcopy -Obinary "..out.." "..gen_fi..".bin")
-- https://github.com/xmake-io/xmake/discussions/2125
-- os.exec("arm-none-eabi-objdump -S "..out.." > "..gen_fi..".asm")
-- local asm = os.iorun("arm-none-eabi-objdump -S build/cross/cortex-m4/release/minimal-proj")
-- io.writefile(gen_fi..".asm", asm)
os.execv("arm-none-eabi-objdump", {"-S", out}, {stdout=gen_fi..".asm"})
os.exec("arm-none-eabi-objcopy -O ihex "..out.." "..gen_fi..".hex")
-- -I binary
-- $(Q) $(OBJ_COPY) -O ihex $@ $(BUILD_DIR)/$(TARGET).hex
-- $(Q) $(OBJ_COPY) -O binary $@ $(BUILD_DIR)/$(TARGET).bin
-- os.exec("qemu-system-arm -M stm32-p103 -nographic -kernel"..bin_out)
end)
after_clean(function (target)
local gen_fi = "build/"..target:name()
os.rm(gen_fi..".*")
end)
rule_end()
task("qemu")
on_run(function ()
print("Run binary in Qemu!")
local bin_out = os.files("$(buildir)/*.bin")[1]
if bin_out then
os.exec("qemu-system-arm -M stm32-p103 -nographic -kernel "..bin_out)
else
print("Do not find bin file in $(buildir)/")
end
end)
set_menu {
-- Settings menu usage
usage = "xmake qemu",
-- Setup menu description
description = "Run binary in Qemu!"
}
task_end()