Skip to content

Commit

Permalink
Merge branch 'master-09052023' into dev-priv/master
Browse files Browse the repository at this point in the history
* pre-commit: autoupdate hooks (commaai#1536)

* Update pre-commit hook versions

* fix

---------

Co-authored-by: adeebshihadeh <adeebshihadeh@users.noreply.github.com>

* debug endpoint for custom clock source period (commaai#1538)

* debug endpoint for custom clock source period

* cleanup

---------

Co-authored-by: Comma Device <device@comma.ai>

* Force relay drive (commaai#1539)

force drive

Co-authored-by: Comma Device <device@comma.ai>

* Stable ADC on H7 (commaai#1540)

* 256x oversampling

* reduce to 128x

* fix misra

---------

Co-authored-by: Comma Device <device@comma.ai>

* Harness tick at 8Hz (commaai#1541)

harness tick at 8Hz

Co-authored-by: Comma Device <device@comma.ai>

* Subaru: cleanup panda logic (commaai#1543)

cleanup subaru

* Honda: remove duplicated relay transition time check (commaai#1544)

already checked

* cleanup build, prep for jungle (commaai#1549)

* cleanup build, prep for jungle

* cleanup

* update pedal obj path

* fix paths when building with different SConstruct

* Move CanHandle to python/ (commaai#1550)

* panda jungle (commaai#1547)

* mv jungle

* match pedal style

* fix linter

* fix fw path

* fix paths

* safety!

* cleanup old pedal stuff (commaai#1552)

* cleanup bus count constant

* jungle: SBU provisioning tests (commaai#1553)

* jungle: SBU provisioning tests

* update can_send

* cleanup

* fix misra

* space

* Subaru: Add measured steering angle and vehicle speed (commaai#1528)

* correct vehicle speed and add measured angle

* misra

* misra

* common test for angle

* PR cleanup

* use subaru prefix

* clean it up a bit

* minimize whitespace diff

* need float for deg_to_can

* Safety: Add desired angle to safety helpers (commaai#1554)

add desired angle

* CI: reflash jungle (commaai#1546)

* more complete jungle reflash (commaai#1557)

* more complete jungle reflash

* no spi!

* mv flash

* mv that

* libpanda: silence build warning

* jungle: disable transceivers while doing CAN multiplexing (commaai#1555)

* init

* keep unneeded trans off

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>

* python: fast reconnect (commaai#1558)

* python: replace warning with logging

* In-circuit debugging (commaai#1560)

* openocd script and readme

* do not disable SWD on boot

* finish esp/gps removal (commaai#1559)

* pedal: fix warning on invalid serial (commaai#1563)

* pedal: fix warning on invalid serial

* fix

* fix:

* shouldn't need that

* fix

---------

Co-authored-by: Bruce Wayne <batman@comma.ai>

* switch to ruff linter (commaai#1564)

* switch to ruff linter

* cleanup

* ruff: enable bugbear checks (commaai#1565)

* misc hitl test cleanup (commaai#1562)

* misc hitl test cleanup

* adjust that

* update

* tres fix

---------

Co-authored-by: Bruce Wayne <batman@comma.ai>
Co-authored-by: Comma Device <device@comma.ai>

* run HITL tests in parallel (commaai#1566)

* seems to work

* cleanup

* run in ci

* fail on first

* fix jungle scope

---------

Co-authored-by: Bruce Wayne <batman@comma.ai>

* don't try to reflash bootstub when reconnecting

* Subaru: convert measured angle to centigrees (commaai#1567)

convert to centigrees

* set OBD to False after test (commaai#1568)

* reset OBD after test

* add comment

* panda: disable transceivers while doing CAN multiplexing (commaai#1556)

init

* remove safety replay test (commaai#1569)

* jungle: add back set_can_sinent() (commaai#1571)

init

* CI: bump up safety test timeout

* panda: add CAN-FD throughput test (commaai#1572)

init

* GM: clean up longitudinal safety test (commaai#1573)

* clean up gm long safety test

* move to long base

* common brake

* GM: move more longitudinal related function into class (commaai#1574)

move these into the long test

* Safety: generic limit safety check (commaai#1575)

* generic limit safety check

* fix messagefunction

* Safety Tests: Create common gas brake safety test (commaai#1537)

* create common gas brake safety test

* remove unrelated subaru reference

* also test below min_value

* better name and hardcoded

* use same as acceleration limits

* revert gm

* remove callable

* added common brake test and moved generic test to base safety class

* remove duplicate test

* wip

* wip

* rename longitudinalaccelsafety

* revert limits correct test

* fix controls allowed test

* move gm over to long gas brake test

* assert that limits are reasonable

* fix typing

* fix linter again

* fix linter again

* fix linter again

* like to make it clear

* typo

* fix from merge

* clearer names

* dont need thesemore

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>

* Subaru: cancel safety (commaai#1576)

* subaru cancel safety

* misra

* Safety: alternate longitudinal limits (commaai#1577)

alt limits

* Ruff: propgate config from OP (commaai#1579)

* Subaru: prepare tests for long and angle control (commaai#1580)

* prepare tests for long and angle control

* fix names

* jungle: add pin header control (commaai#1581)

* init

* style

* clean + gpio output

* safety tests: test one of each MCU type

* pre-commit: autoupdate hooks (commaai#1582)

Update pre-commit hook versions

Co-authored-by: adeebshihadeh <adeebshihadeh@users.noreply.github.com>

* Safety: Rename alt transmission rpm (commaai#1583)

* renamre transmision rpm

* consistent whitespace

* rename declarations too

* Subaru: Global gen1 longitudinal safety (commaai#1500)

* Add subaru long TX and RX messages

* misra c2012 fix

* fix tests

* Reorder signals

* increase max steering torque

* merge fix

* merge fix, remove cnt from test

* Move subaru logitudinal behind flag, add safety test

* update subaru_longitudinal checks

* cleanup

* Add subaru longitudinal checks

* misra fix

* Add subaru rpm and throttle rate limit checks

* temporary disable cruise throttle and cruise rpm checks

* update subaru long test

* update longitudinal safety and add tests

* fix tests

* fix misra

* subaru long signals limits checks

* Add controls_allowed to long tests

* remove unused variables

* Add AEB passthru and tests

* Add bus

* Update AEB logic

* Add GEN2 AEB support

* syntax fix

* Update AEB tests

* Add comment for subaru_aeb

* Do not check cruise_throttle and cruise_rpm limits when gas pressed

* use long limits struct

* Subaru: longitudinal checks only when controls_allowed, use ES_LKAS_State LKAS_Alert for AEB

* fix misra, set controls_allowed for es_brake test

* fix misra

* Fix es_brake violation check

* Add 0x323 to longitudinal test

* Remove stock fcw from aeb signals

* Use GET_BYTES

* Revert "export FW_PATH"

This reverts commit 2a5058d.

* Revert "cleanup fw filename conventions (commaai#1434)"

This reverts commit 4dd2735.

* Revert "Revert "export FW_PATH""

This reverts commit 86e8d32.

* Revert "Revert "cleanup fw filename conventions (commaai#1434)""

This reverts commit 5aae671.

* cleaned up safety

* cleanup subaru long safety

* subaru_aeb -> stock_aeb for other platforms

* fix unittests

* pretty

* need to upload this route

* remove AEB stuff for now

* remove unrequired rpm checks

* add comment

* added comment about acceleration and use throttle limit for rpm too

* inactive_throttle_fix

* Update board/safety/safety_subaru.h

Co-authored-by: Shane Smiskol <shane@smiskol.com>

* added comments about long limits

* increase max brake

* revert that

* cleanup

* rename throttle to gas

* add safety replay

* remove todo

* rename throttle to gas

* move subaru stuff out of common test

* PR cleanup

* added min gas

* reduce initial complexity by not intercepting cruisecontrol or brake_status

* create common gas brake safety test

* remove unrelated subaru reference

* also test below min_value

* fix fwd hook test

* better name and hardcoded

* use same as acceleration limits

* revert gm

* remove callable

* also limit rpm

* remove safety replay for now

* revert unrelated changes

* pr cleanup

* remove unused gasbrake safety test

* fix ruff linter

* PR cleanup

* pr cleanup?

* added common brake test and moved generic test to base safety class

* remove duplicate test

* wip

* wip

* rename longitudinalaccelsafety

* revert limits correct test

* fix controls allowed test

* move gm over to long gas brake test

* assert that limits are reasonable

* fix typing

* fix linter again

* fix linter again

* fix linter again

* like to make it clear

* typo

* fix from merge

* clearer names

* dont need thesemore

* subaru: use common test

* fix merge issue

* inactive gas from long limits

* fix tests

* linter

* fix gen2

* fix linter

* also test torque when doing long control

* renamre transmision rpm

* consistent whitespace

* rename declarations too

* rename transmission rpm

* same line

* actually is transmission rpm

---------

Co-authored-by: Martin Lillepuu <martin@mlp.ee>
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Shane Smiskol <shane@smiskol.com>

* Hyundai CAN FD: fix PCM cruise check (commaai#1584)

* add pcm

* fix

* NA

* explicitly check cruise status

* comment and misra

* Subaru: cleanup to prepare for angle controller (commaai#1585)

cleanup prepare for angle

* add FW size checker script

* fix linter

* Hyundai: match openpilot standstill check (commaai#1586)

* checks that we can replicate in openpilot

* clean up

* fix test

* can simplify this

* can also simplify this

* Subaru: gen2 long safety (commaai#1587)

* setup proper safety for gen2 long

* whitespace

* misra

* alt bus

* high beam assist

* better names

* whitespace

* whitespace

* whitespace

* GM: switch to common gas/brake test (commaai#1578)

* gm switch to common gas/brake test

* fix typo

* add comment about regen

* body: set vehicle_moving (commaai#1591)

* add vehicle_moving

* Update board/safety/safety_body.h

* Revert "Subaru: gen2 long safety (commaai#1587)"

This reverts commit 2ae2567.

* Safety: unify `controls_allowed` with boolean (commaai#1589)

* prefix openpilot imports (commaai#1593)

* unify CAN/FDCAN odjects naming (commaai#1596)

* init

* happy MISRA

* Subaru: infrastructure to support the new angle based controllers (commaai#1590)

* pre-commit: autoupdate hooks (commaai#1600)

Update pre-commit hook versions

Co-authored-by: adeebshihadeh <adeebshihadeh@users.noreply.github.com>

* Revert "Subaru: infrastructure to support the new angle based control… (commaai#1601)

Revert "Subaru: infrastructure to support the new angle based controllers (commaai#1590)"

This reverts commit ea16a54.

* H7: clean up peripherals.h (commaai#1597)

init

* Subaru: add new angle LKAS message definitions (commaai#1602)

* just add the lkas message to start

* added to tests too

* default parameter

* peripherals.h clean and duplicates removal (commaai#1599)

* init

* ULPI disable

* not related to clocks

* F4: fix UART clocks (commaai#1588)

init

* MacOS: Homebrew GCC is now version 13 (commaai#1603)

* add --minimal build flag (commaai#1604)

* H7: few more Kb of RAM found (commaai#1605)

* init

* remove discard

* python lib: close USB context properly (commaai#1606)

* python lib: close USB context properly

* fix jungle

* rm that

---------

Co-authored-by: Comma Device <device@comma.ai>

* jungle: fix can_health update on request

* Honda: match openpilot button enable check (commaai#1607)

* NONE -> not BUTTON

* update test and fix safety

* cleaner

* jungle: force CAN core reset on bus off detection

* iso-tp: more sanity checks (commaai#1487)

* assert rx not done for single frame to be valid

* not sure if this is correct yet

* return if updated

reverts some of commaai#1314

* Revert "return if updated"

This reverts commit ba4c4f1.

* iso-tp: return if updated (commaai#1610)

return if updated

reverts some of commaai#1314

* Toyota: ACC message relay check (commaai#1612)

* toyota: add safety for tester present

* block ACC_HUD

* check stock ECU

* clean up

* not this

* test new addr

* comment

* rm

* cmt

* Revert "iso-tp: more checks (commaai#1487)" (commaai#1616)

* Revert "iso-tp: return if updated (commaai#1610)"

This reverts commit 0eb04fa.

* Revert "iso-tp: more sanity checks (commaai#1487)"

This reverts commit 01db9e4.

* Revert "Toyota: ACC message relay check (commaai#1612)" (commaai#1617)

This reverts commit 5a9d8cf.

* Update README.md

change Mac OS gcc version

* H7: decrease FDCAN TX FIFOs to 1 (commaai#1614)

init

* H7: reorganize RAM (commaai#1619)

init

* H7: comments for RAM organization reasoning

* Hyundai CAN FD: fix boolean types in fwd hook (commaai#1620)

* Safety: Utilize boolean values for message block checks in forward hooks

* Revert "Safety: Utilize boolean values for message block checks in forward hooks"

This reverts commit ee9809d.

* others

* Revert "others"

This reverts commit f64cc1c.

* just do hyundai

* function to get steering address

* unclear if this is cleaner

Revert "function to get steering address"

This reverts commit 2a2b972.

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>

* Hyundai CAN-FD: Alternate `LKAS` steering message (commaai#1504)

* new steering message!

* fix

* check tx

* fix var

* allow all tx to test LFA suppression

* Attempt to block laneline information to suppress LFA

* Try 0x364

* Block all bus 2/6 messages

* Final test to block LFA

* Fix tx

* in another PR

* cleanup

* lint

* Add new tx to unit test

* linter

* Apply suggestions

* Revert to this

* Unnecessary

* clean up

* rename to hda2

* prototype

---------

Co-authored-by: Shane Smiskol <shane@smiskol.com>

* pre-commit: autoupdate hooks (commaai#1618)

* Update pre-commit hook versions

* fix ranges

---------

Co-authored-by: adeebshihadeh <adeebshihadeh@users.noreply.github.com>
Co-authored-by: Shane Smiskol <shane@smiskol.com>

* Subaru: add steer req bit test (commaai#1613)

add active bit test

* Revert "pre-commit: autoupdate hooks (commaai#1618)"

This reverts commit 526588b.

* python: show lib and fw versions in error (commaai#1622)

* python: show lib and fw versions in error

* fix

* cleanup

* disable forest while it's rebuilt

* F4: fix wrong PCLK value (commaai#1608)

* fix mistake

* clean

* F4: fix GMLAN clocks (commaai#1624)

* init

* misra

* Subaru: preglobal check steer req bit (commaai#1626)

* GM: check steer req bit (commaai#1629)

for gm

* Chrysler: check steer bit (commaai#1628)

* chrysler

* misra

* Safety: Convert message addresses from decimal to hexadecimal (commaai#1623)

* Safety: Convert message addresses from decimal to hexadecimal

* unit tests

* fix

* In another PR

* Safety tests: Convert message addresses from decimal to hexadecimal (commaai#1633)

* Subaru: gen2 long safety (commaai#1594)

gen2 long safety

* VW MQB: Check steer req bit (commaai#1631)

vq mqb

* fix upstream conflict

* sync with upstream

* Upstream merge fixes

---------

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: adeebshihadeh <adeebshihadeh@users.noreply.github.com>
Co-authored-by: Comma Device <device@comma.ai>
Co-authored-by: Robbe Derks <robbe.derks@gmail.com>
Co-authored-by: Justin Newberry <justin@comma.ai>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: Igor Biletskyy <briskspirit@users.noreply.github.com>
Co-authored-by: Bruce Wayne <batman@comma.ai>
Co-authored-by: Martin Lillepuu <martin@mlp.ee>
Co-authored-by: Igor Biletksyy <bs@privacy.im>
Co-authored-by: Willem Melching <willem.melching@gmail.com>
  • Loading branch information
12 people authored Sep 6, 2023
2 parents 446ad94 + c2b2129 commit a2288bf
Show file tree
Hide file tree
Showing 155 changed files with 3,766 additions and 2,158 deletions.
21 changes: 3 additions & 18 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
run: ${{ env.RUN }} "ENABLE_SPI=1 scons -j4"
- name: Build with UBSan
run: ${{ env.RUN }} "scons -j4 --ubsan"
- name: Build jungle firmware with FINAL_PROVISIONING support
run: ${{ env.RUN }} "FINAL_PROVISIONING=1 scons -j4 board/jungle"

unit_tests:
name: unit tests
Expand Down Expand Up @@ -76,7 +78,7 @@ jobs:
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety tests
timeout-minutes: 4
timeout-minutes: 5
run: |
${{ env.RUN }} "cd .. && \
scons -c && \
Expand All @@ -85,23 +87,6 @@ jobs:
scons -j$(nproc) ${{ matrix.flags }} && \
tests/safety/test.sh"
safety_replay:
name: safety replay
runs-on: ubuntu-20.04
strategy:
matrix:
flags: ['', '--ubsan']
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Build Docker image
run: eval "$BUILD"
- name: Run safety replay
run: |
${{ env.RUN }} "scons -j$(nproc) ${{ matrix.flags }} && \
cd tests/safety_replay && \
./test_safety_replay.py"
misra:
name: misra c2012
runs-on: ubuntu-20.04
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a.out
.#*
dist/
pandacan.egg-info/
board/obj/
obj/
examples/output.csv
.DS_Store
.vscode*
Expand Down
11 changes: 2 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ RUN curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-instal
ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"

ENV PANDA_PATH=/tmp/openpilot/panda
ENV OPENPILOT_REF="80bbba14f74e57bbe90216dfd0a99f6f68d77ca2"
ENV OPENDBC_REF="5880fbbccf5a670631b51836f20e446de643795a"
ENV OPENPILOT_REF="5690386d8d731c9bebda536a5c71c890f6dfe98c"
ENV OPENDBC_REF="12dd7675c5ab2f49aedb813a79e6131b370b379f"

COPY requirements.txt /tmp/
RUN pyenv install 3.11.4 && \
Expand Down Expand Up @@ -80,13 +80,6 @@ RUN cd /tmp && \
rm -rf /tmp/openpilot/panda && \
rm -rf /tmp/tmppilot

RUN cd /tmp/openpilot && \
git clone https://github.com/commaai/panda_jungle.git && \
cd panda_jungle && \
git fetch && \
git checkout 3a791be1f1877a69cf45de16a670992380622297 && \
rm -rf .git/

RUN cd /tmp/openpilot && \
pip install --no-cache-dir -r opendbc/requirements.txt && \
pip install --no-cache-dir --upgrade aenum lru-dict pycurl tenacity atomicwrites serial smbus2
Expand Down
9 changes: 6 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
def docker_run(String step_label, int timeout_mins, String cmd) {
timeout(time: timeout_mins, unit: 'MINUTES') {
sh script: "docker run --rm --privileged \
--env PARTIAL_TESTS=${env.PARTIAL_TESTS} \
--env PYTHONWARNINGS=error \
--volume /dev/bus/usb:/dev/bus/usb \
--volume /var/run/dbus:/var/run/dbus \
Expand Down Expand Up @@ -62,7 +61,6 @@ pipeline {
agent any
environment {
CI = "1"
//PARTIAL_TESTS = "${env.BRANCH_NAME == 'master' ? ' ' : '1'}"
PYTHONWARNINGS= "error"
DOCKER_IMAGE_TAG = "panda:build-${env.GIT_COMMIT}"

Expand All @@ -83,6 +81,7 @@ pipeline {
phone_steps("panda-dos", [
["build", "scons -j4"],
["flash", "cd tests/ && ./reflash_internal_panda.py"],
["flash jungle", "cd board/jungle && ./flash.py"],
["test", "cd tests/hitl && HW_TYPES=6 pytest --durations=0 [2-7]*.py -k 'not test_send_recv'"],
])
}
Expand All @@ -94,11 +93,13 @@ pipeline {
phone_steps("panda-tres", [
["build", "scons -j4"],
["flash", "cd tests/ && ./reflash_internal_panda.py"],
["flash jungle", "cd board/jungle && ./flash.py"],
["test", "cd tests/hitl && HW_TYPES=9 pytest --durations=0 2*.py [5-9]*.py"],
])
}
}

/*
stage ('Acquire resource locks') {
options {
lock(resource: "pandas")
Expand Down Expand Up @@ -133,7 +134,8 @@ pipeline {
stage('HITL tests') {
steps {
script {
docker_run("HITL tests", 35, 'PANDAS_JUNGLE=23002d000851393038373731 PANDAS_EXCLUDE="1d0002000c51303136383232 2f002e000c51303136383232" ./tests/hitl/test.sh')
docker_run("parallel tests", 5, 'PANDAS_JUNGLE=23002d000851393038373731 PANDAS_EXCLUDE="1d0002000c51303136383232 2f002e000c51303136383232" ./tests/hitl/run_parallel_tests.sh')
docker_run("serial tests", 9, 'PANDAS_JUNGLE=23002d000851393038373731 PANDAS_EXCLUDE="1d0002000c51303136383232 2f002e000c51303136383232" ./tests/hitl/run_serial_tests.sh')
}
}
}
Expand All @@ -146,6 +148,7 @@ pipeline {
}
}
}
*/
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sudo apt-get install dfu-util gcc-arm-none-eabi python3-pip libffi-dev git
```bash
# macOS
brew install --cask gcc-arm-embedded
brew install python3 dfu-util gcc@12
brew install python3 dfu-util gcc@13
```

Clone panda repository:
Expand Down Expand Up @@ -112,7 +112,7 @@ to ensure that the behavior remains unchanged.
* compiling the code and flashing it through USB.
* receiving, sending, and forwarding CAN messages on all buses, over USB.

In addition, we run the [pylint](https://www.pylint.org/) and [flake8](https://github.com/PyCQA/flake8) linters on all python files within the panda repo.
In addition, we run the [ruff linter](https://github.com/astral-sh/ruff) on all python files within the panda repo.

## Hardware

Expand Down
186 changes: 185 additions & 1 deletion SConscript
Original file line number Diff line number Diff line change
@@ -1,6 +1,190 @@
import os
import subprocess


PREFIX = "arm-none-eabi-"
BUILDER = "DEV"

common_flags = []

panda_root = Dir('.').abspath

if os.getenv("RELEASE"):
BUILD_TYPE = "RELEASE"
cert_fn = os.getenv("CERT")
assert cert_fn is not None, 'No certificate file specified. Please set CERT env variable'
assert os.path.exists(cert_fn), 'Certificate file not found. Please specify absolute path'
else:
BUILD_TYPE = "DEBUG"
cert_fn = File("./certs/debug").srcnode().abspath
common_flags += ["-DALLOW_DEBUG"]

if os.getenv("DEBUG"):
common_flags += ["-DDEBUG"]

def objcopy(source, target, env, for_signature):
return '$OBJCOPY -O binary %s %s' % (source[0], target[0])

def get_version(builder, build_type):
try:
git = subprocess.check_output(["git", "rev-parse", "--short=8", "HEAD"], encoding='utf8').strip()
except subprocess.CalledProcessError:
git = "unknown"
return f"{builder}-{git}-{build_type}"

def get_key_header(name):
from Crypto.PublicKey import RSA

public_fn = File(f'./certs/{name}.pub').srcnode().abspath
with open(public_fn) as f:
rsa = RSA.importKey(f.read())
assert(rsa.size_in_bits() == 1024)

rr = pow(2**1024, 2, rsa.n)
n0inv = 2**32 - pow(rsa.n, -1, 2**32)

r = [
f"RSAPublicKey {name}_rsa_key = {{",
f" .len = 0x20,",
f" .n0inv = {n0inv}U,",
f" .n = {to_c_uint32(rsa.n)},",
f" .rr = {to_c_uint32(rr)},",
f" .exponent = {rsa.e},",
f"}};",
]
return r

def to_c_uint32(x):
nums = []
for _ in range(0x20):
nums.append(x % (2**32))
x //= (2**32)
return "{" + 'U,'.join(map(str, nums)) + "U}"


def build_project(project_name, project, extra_flags):
linkerscript_fn = File(project["LINKER_SCRIPT"]).srcnode().abspath

flags = project["PROJECT_FLAGS"] + extra_flags + common_flags + [
"-Wall",
"-Wextra",
"-Wstrict-prototypes",
"-Werror",
"-mlittle-endian",
"-mthumb",
"-nostdlib",
"-fno-builtin",
"-std=gnu11",
"-fmax-errors=3",
f"-T{linkerscript_fn}",
]

includes = [
'.',
'..',
panda_root,
f"{panda_root}/board/",
f"{panda_root}/board/stm32fx/inc",
f"{panda_root}/board/stm32h7/inc",
]

env = Environment(
ENV=os.environ,
CC=PREFIX + 'gcc',
AS=PREFIX + 'gcc',
OBJCOPY=PREFIX + 'objcopy',
OBJDUMP=PREFIX + 'objdump',
CFLAGS=flags,
ASFLAGS=flags,
LINKFLAGS=flags,
CPPPATH=includes,
ASCOM="$AS $ASFLAGS -o $TARGET -c $SOURCES",
BUILDERS={
'Objcopy': Builder(generator=objcopy, suffix='.bin', src_suffix='.elf')
}
)

startup = env.Object(f"obj/startup_{project_name}", project["STARTUP_FILE"])

# Bootstub
crypto_obj = [
env.Object(f"rsa-{project_name}", f"{panda_root}/crypto/rsa.c"),
env.Object(f"sha-{project_name}", f"{panda_root}/crypto/sha.c")
]
bootstub_obj = env.Object(f"bootstub-{project_name}", File(project.get("BOOTSTUB", f"{panda_root}/board/bootstub.c")))
bootstub_elf = env.Program(f"obj/bootstub.{project_name}.elf",
[startup] + crypto_obj + [bootstub_obj])
env.Objcopy(f"obj/bootstub.{project_name}.bin", bootstub_elf)

# Build main
main_obj = env.Object(f"main-{project_name}", project["MAIN"])
main_elf = env.Program(f"obj/{project_name}.elf", [startup, main_obj],
LINKFLAGS=[f"-Wl,--section-start,.isr_vector={project['APP_START_ADDRESS']}"] + flags)
main_bin = env.Objcopy(f"obj/{project_name}.bin", main_elf)

# Sign main
sign_py = File(f"{panda_root}/crypto/sign.py").srcnode().abspath
env.Command(f"obj/{project_name}.bin.signed", main_bin, f"SETLEN=1 {sign_py} $SOURCE $TARGET {cert_fn}")


base_project_f4 = {
"MAIN": "main.c",
"STARTUP_FILE": File("./board/stm32fx/startup_stm32f413xx.s"),
"LINKER_SCRIPT": File("./board/stm32fx/stm32f4_flash.ld"),
"APP_START_ADDRESS": "0x8004000",
"PROJECT_FLAGS": [
"-mcpu=cortex-m4",
"-mhard-float",
"-DSTM32F4",
"-DSTM32F413xx",
"-mfpu=fpv4-sp-d16",
"-fsingle-precision-constant",
"-Os",
"-g",
],
}

base_project_h7 = {
"MAIN": "main.c",
"STARTUP_FILE": File("./board/stm32h7/startup_stm32h7x5xx.s"),
"LINKER_SCRIPT": File("./board/stm32h7/stm32h7x5_flash.ld"),
"APP_START_ADDRESS": "0x8020000",
"PROJECT_FLAGS": [
"-mcpu=cortex-m7",
"-mhard-float",
"-DSTM32H7",
"-DSTM32H725xx",
"-mfpu=fpv5-d16",
"-fsingle-precision-constant",
"-Os",
"-g",
],
}

Export('base_project_f4', 'base_project_h7', 'build_project')


# Common autogenerated includes
with open("board/obj/gitversion.h", "w") as f:
f.write(f'const uint8_t gitversion[] = "{get_version(BUILDER, BUILD_TYPE)}";\n')

with open("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:
for cert in certs:
f.write("\n".join(cert) + "\n")

# panda fw
SConscript('board/SConscript')

# pedal fw
SConscript('board/pedal/SConscript')

# panda jungle fw
SConscript('board/jungle/SConscript')

# test files
if GetOption('test'):
if GetOption('extras'):
SConscript('tests/libpanda/SConscript')
7 changes: 4 additions & 3 deletions SConstruct
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
AddOption('--test',
action='store_true',
AddOption('--minimal',
action='store_false',
dest='extras',
default=True,
help='build test files')
help='the minimum build. no tests, tools, etc.')

AddOption('--ubsan',
action='store_true',
Expand Down
5 changes: 5 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from .python.constants import McuType, BASEDIR, FW_PATH, USBPACKET_MAX_SIZE # noqa: F401
from .python.spi import PandaSpiException, PandaProtocolMismatch # noqa: F401
from .python.serial import PandaSerial # noqa: F401
from .python.canhandle import CanHandle # noqa: F401
from .python import (Panda, PandaDFU, # noqa: F401
pack_can_buffer, unpack_can_buffer, calculate_checksum, unpack_log,
DLC_TO_LEN, LEN_TO_DLC, ALTERNATIVE_EXPERIENCE, CANPACKET_HEAD_SIZE)


# panda jungle
from .board.jungle import PandaJungle, PandaJungleDFU # noqa: F401
Loading

0 comments on commit a2288bf

Please sign in to comment.