summaryrefslogtreecommitdiff
path: root/bsp/ESP32_C3/SConstruct
blob: 916d12345f46f3f11c7fa93c649d514961a2a18a (plain)
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
import os
import sys
import rtconfig
from esptool.bin_image import ELFFile, ImageSegment, LoadFirmwareImage
from esptool.targets import CHIP_DEFS, CHIP_LIST, ROM_LIST

def elf2image(target, source, env):
    e = ELFFile("rtthread.elf")

    print("Creating esp32c3 image...")

    image = CHIP_DEFS["esp32c3"].BOOTLOADER_IMAGE()
    image.min_rev = 3
    image.entrypoint = e.entrypoint
    image.flash_mode = 2 # flash_mode: dio

    # ELFSection is a subclass of ImageSegment, so can use interchangeably
    image.segments = e.sections
    image.flash_size_freq = image.ROM_LOADER.parse_flash_size_arg("4MB")
    image.flash_size_freq += image.ROM_LOADER.parse_flash_freq_arg("80m")

    image.elf_sha256 = e.sha256()
    image.elf_sha256_offset = 0xb0

    before = len(image.segments)
    image.merge_adjacent_segments()
    if len(image.segments) != before:
        delta = before - len(image.segments)
        print("Merged %d ELF section%s" % (delta, "s" if delta > 1 else ""))

    image.verify()

    image.save("rtthread.bin")

    print("Successfully created esp32c3 image.")

if os.getenv('RTT_ROOT'):
    RTT_ROOT = os.getenv('RTT_ROOT')
else:
    RTT_ROOT = os.path.join(os.getcwd(), '..', '..')

sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *

TARGET = 'rtthread.' + rtconfig.TARGET_EXT

DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
    AS   = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
    CC   = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
    CXX  = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
    AR   = rtconfig.AR, ARFLAGS = '-rc',
    LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
env['ASCOM'] = env['ASPPCOM']

Export('RTT_ROOT')
Export('rtconfig')

# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, remove_components = ['libc'])

# make a building
DoBuilding(TARGET, objs)

# 添加构建后的钩子函数
env.AddPostAction(TARGET, elf2image)