Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import os
import hashlib
import opendbc
import subprocess
import sys

PREFIX = "arm-none-eabi-"
BUILDER = "DEV"
Expand All @@ -15,7 +16,7 @@ if os.getenv("RELEASE"):
assert os.path.exists(cert_fn), 'Certificate file not found. Please specify absolute path'
else:
BUILD_TYPE = "DEBUG"
cert_fn = File("./board/certs/debug").srcnode().relpath
cert_fn = File("./board/certs/debug").srcnode().abspath
common_flags += ["-DALLOW_DEBUG"]

if os.getenv("DEBUG"):
Expand All @@ -34,7 +35,7 @@ def get_version(builder, build_type):
def get_key_header(name):
from Crypto.PublicKey import RSA

public_fn = File(f'./board/certs/{name}.pub').srcnode().get_path()
public_fn = File(f'./board/certs/{name}.pub').srcnode().abspath
with open(public_fn) as f:
rsa = RSA.importKey(f.read())
assert(rsa.size_in_bits() == 1024)
Expand Down Expand Up @@ -75,7 +76,7 @@ def build_project(project_name, project, main, extra_flags):
"-fno-builtin",
"-std=gnu11",
"-fmax-errors=1",
f"-T{File(project['LINKER_SCRIPT']).srcnode().relpath}",
f"-T{File(project['LINKER_SCRIPT']).srcnode().abspath}",
"-fsingle-precision-constant",
"-Os",
"-g",
Expand All @@ -91,7 +92,12 @@ def build_project(project_name, project, main, extra_flags):
CFLAGS=flags,
ASFLAGS=flags,
LINKFLAGS=flags,
CPPPATH=[Dir("./"), "./board/stm32h7/inc", opendbc.INCLUDE_PATH],
CPPPATH=[
Dir("./"),
Dir('.').srcnode().abspath,
f"{Dir('.').srcnode().abspath}/board/stm32h7/inc",
opendbc.INCLUDE_PATH
],
ASCOM="$AS $ASFLAGS -o $TARGET -c $SOURCES",
BUILDERS={
'Objcopy': Builder(generator=objcopy, suffix='.bin', src_suffix='.elf')
Expand All @@ -118,8 +124,8 @@ def build_project(project_name, project, main, extra_flags):
main
], LINKFLAGS=[f"-Wl,--section-start,.isr_vector={project['APP_START_ADDRESS']}"] + flags)
main_bin = env.Objcopy(f"{project_dir}/main.bin", main_elf)
sign_py = File(f"./board/crypto/sign.py").srcnode().relpath
env.Command(f"./board/obj/{project_name}.bin.signed", main_bin, f"SETLEN=1 {sign_py} $SOURCE $TARGET {cert_fn}")
sign_py = File(f"./board/crypto/sign.py").srcnode().abspath
env.Command(f"./board/obj/{project_name}.bin.signed", main_bin, f"SETLEN=1 {sys.executable} {sign_py} $SOURCE $TARGET {cert_fn}")



Expand All @@ -138,16 +144,19 @@ base_project_h7 = {
}

# Common autogenerated includes
with open("board/obj/gitversion.h", "w") as f:
build_dir = Dir('.').abspath
os.makedirs(os.path.join(build_dir, "board/obj"), exist_ok=True)

with open(os.path.join(build_dir, "board/obj/gitversion.h"), "w") as f:
version = get_version(BUILDER, BUILD_TYPE)
f.write(f'extern const uint8_t gitversion[{len(version)+1}];\n')
f.write(f'const uint8_t gitversion[{len(version)+1}] = "{version}";\n')

with open("board/obj/version", "w") as f:
with open(os.path.join(build_dir, "board/obj/version"), "w") as f:
f.write(f'{get_version(BUILDER, BUILD_TYPE)}')

certs = [get_key_header(n) for n in ["debug", "release"]]
with open("board/obj/cert.h", "w") as f:
with open(os.path.join(build_dir, "board/obj/cert.h"), "w") as f:
for cert in certs:
f.write("\n".join(cert) + "\n")

Expand All @@ -156,7 +165,9 @@ def version_hash(path):
with open(path, "rb") as f:
# Normalize line endings on Windows
return int.from_bytes(hashlib.sha256(f.read().replace(b'\r', b'')).digest()[:4], 'little')
hh, ch, jh = version_hash("board/health.h"), version_hash(os.path.join(opendbc.INCLUDE_PATH, "opendbc/safety/can.h")), version_hash("board/jungle/jungle_health.h")
src_dir = Dir('.').srcnode().abspath
hh, ch, jh = version_hash(os.path.join(src_dir, "board/health.h")), version_hash(os.path.join(opendbc.INCLUDE_PATH, "opendbc/safety/can.h")), version_hash(os.path.join(src_dir, "board/jungle/jungle_health.h"))

common_flags += [f"-DHEALTH_PACKET_VERSION=0x{hh:08X}U", f"-DCAN_PACKET_VERSION_HASH=0x{ch:08X}U",
f"-DJUNGLE_HEALTH_PACKET_VERSION=0x{jh:08X}U"]

Expand Down
20 changes: 11 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = [
"panda",
"panda.python",
"panda.board",
"panda.board.body",
"panda.board.jungle",
]
include-package-data = false

[tool.setuptools.package-data]
"panda.board" = ["health.h"]
"panda.board.jungle" = ["jungle_health.h"]
"*" = [
"**/*.c",
"**/*.h",
"**/*.ld",
"**/*.s",
"**/*.mk",
"certs/*",
"SConscript",
"py.typed"
]

[tool.setuptools.package-dir]
panda = "."
Expand Down
Loading