forked from jeankalud/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'panda/' content from commit c371fe6
git-subtree-dir: panda git-subtree-split: c371fe6
- Loading branch information
Vehicle Researcher
committed
Dec 24, 2017
0 parents
commit c251b31
Showing
257 changed files
with
54,725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.pyc | ||
.*.swp | ||
.*.swo | ||
*.o | ||
a.out | ||
*~ | ||
.#* | ||
dist/ | ||
pandacan.egg-info/ | ||
board/obj/ | ||
examples/output.csv | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
language: python | ||
|
||
cache: | ||
directories: | ||
- build/commaai/panda/boardesp/esp-open-sdk/crosstool-NG | ||
|
||
addons: | ||
apt: | ||
packages: | ||
- gcc-arm-none-eabi | ||
- libnewlib-arm-none-eabi | ||
- gperf | ||
- texinfo | ||
- help2man | ||
|
||
script: | ||
- python setup.py install | ||
- pushd board && make bin && popd | ||
- pushd boardesp && git clone --recursive https://github.com/pfalcon/esp-open-sdk.git && pushd esp-open-sdk && git checkout 03f5e898a059451ec5f3de30e7feff30455f7cec && LD_LIBRARY_PATH="" make STANDALONE=y && popd && popd | ||
- pushd boardesp && make user1.bin && popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2016, Comma.ai, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Welcome to panda | ||
====== | ||
|
||
[panda](http://github.com/commaai/panda) is the nicest universal car interface ever. | ||
|
||
<a href="https://panda.comma.ai"><img src="https://github.com/commaai/panda/blob/master/panda.png"> | ||
|
||
<img src="https://github.com/commaai/panda/blob/master/buy.png"></a> | ||
|
||
It supports 3x CAN, 2x LIN, and 1x GMLAN. It also charges a phone. On the computer side, it has both USB and Wi-Fi. | ||
|
||
It uses an [STM32F413](http://www.st.com/en/microcontrollers/stm32f413-423.html?querycriteria=productId=LN2004) for low level stuff and an [ESP8266](https://en.wikipedia.org/wiki/ESP8266) for Wi-Fi. They are connected over high speed SPI, so the panda is actually capable of dumping the full contents of the busses over Wi-Fi, unlike every other dongle on amazon. ELM327 is weak, panda is strong. | ||
|
||
It is 2nd gen hardware, reusing code and parts from the [NEO](https://github.com/commaai/neo) interface board. | ||
|
||
[![Build Status](https://travis-ci.org/commaai/panda.svg?branch=master)](https://travis-ci.org/commaai/panda) | ||
|
||
Usage | ||
------ | ||
|
||
To install the library: | ||
``` | ||
# pip install pandacan | ||
``` | ||
|
||
See [this class](https://github.com/commaai/panda/blob/master/python/__init__.py#L80) for how to interact with the panda. | ||
|
||
For example, to receive CAN messages: | ||
``` | ||
>>> from panda import Panda | ||
>>> panda = Panda() | ||
>>> panda.can_recv() | ||
``` | ||
And to send one on bus 0: | ||
``` | ||
>>> panda.can_send(0x1aa, "message", 0) | ||
``` | ||
More examples coming soon | ||
|
||
Software interface support | ||
------ | ||
|
||
As a universal car interface, it should support every reasonable software interface. | ||
|
||
- User space ([done](https://github.com/commaai/panda/tree/master/python)) | ||
- socketcan in kernel ([alpha](https://github.com/commaai/panda/tree/master/drivers/linux)) | ||
- ELM327 ([done](https://github.com/commaai/panda/blob/master/boardesp/elm327.c)) | ||
- Windows J2534 ([alpha](https://github.com/commaai/panda/tree/master/drivers/windows)) | ||
|
||
Directory structure | ||
------ | ||
|
||
- board -- Code that runs on the STM32 | ||
- boardesp -- Code that runs on the ESP8266 | ||
- drivers -- Drivers (not needed for use with python) | ||
- python -- Python userspace library for interfacing with the panda | ||
- tests -- Tests and helper programs for panda | ||
|
||
Programming (over USB) | ||
------ | ||
|
||
[Programming the Board (STM32)](board/README.md) | ||
|
||
[Programming the ESP](boardesp/README.md) | ||
|
||
|
||
Debugging | ||
------ | ||
|
||
To print out the serial console from the STM32, run tests/debug_console.py | ||
|
||
To print out the serial console from the ESP8266, run PORT=1 tests/debug_console.py | ||
|
||
Safety Model | ||
------ | ||
|
||
When a panda powers up, by default it's in "SAFETY_NOOUTPUT" mode. While in no output mode, the buses are also forced to be silent. In order to send messages, you have to select a safety mode. Currently, setting safety modes is only supported over USB. | ||
|
||
Safety modes can also optionally support "controls_allowed", which allows or blocks a subset of messages based on a piece of state in the board. | ||
|
||
Hardware | ||
------ | ||
|
||
Check out the hardware [guide](https://github.com/commaai/panda/blob/master/docs/guide.pdf) | ||
|
||
Licensing | ||
------ | ||
|
||
panda software is released under the MIT license unless otherwise specified. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
** Projects ** | ||
|
||
== ELM327 Emulator == | ||
|
||
Write an elm327 emulator in boardesp/elm327.c and make it work with Torque | ||
|
||
You'll find a start at this in the "elm327" branch. | ||
|
||
== socketcan Kernel Driver == | ||
|
||
Write a kernel driver version of lib/panda.py that exposes the Panda on socketcan and makes it work with those tools. | ||
|
||
You may want to switch to interrupt endpoint first. Should LIN be exposed as a serial interface? | ||
|
||
== Windows J2534 DLL == | ||
|
||
Write a Windows DLL that exposes the J2534 API. | ||
|
||
Will make the Panda work with car diagnostic software. | ||
|
||
|
||
** Refactors ** | ||
|
||
== USB Interrupt Endpoint == | ||
|
||
Switch USB to use an interrupt endpoint instead of a bulk endpoint for can recv | ||
|
||
== WebSocket Support == | ||
|
||
Add CAN streaming over WebSocket to the ELM code in addition to the UDP pipe. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Updating your panda | ||
|
||
Panda should update automatically via the [Chffr](http://chffr.comma.ai/) app ([apple](https://itunes.apple.com/us/app/chffr-dash-cam-that-remembers/id1146683979) and [android](https://play.google.com/store/apps/details?id=ai.comma.chffr)) | ||
|
||
If it doesn't however, you can use the following commands on linux or Mac OSX | ||
`sudo pip install --upgrade pandacan` | ||
` PYTHONPATH="" sudo python -c "import panda; panda.flash_release()"` | ||
|
||
(You'll need to have `pip` and `sudo` installed.) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v1.0.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .python import Panda, PandaWifiStreaming, PandaDFU, ESPROM, CesantaFlasher, flash_release, BASEDIR, ensure_st_up_to_date, build_st |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
PROJ_NAME = panda | ||
CFLAGS = -g -Wall | ||
|
||
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 | ||
CFLAGS += -mhard-float -DSTM32F4 -DSTM32F413xx | ||
STARTUP_FILE = startup_stm32f413xx | ||
|
||
include build.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# :set noet | ||
PROJ_NAME = comma | ||
CFLAGS = -g -Wall | ||
|
||
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3 | ||
CFLAGS += -msoft-float -DSTM32F2 -DSTM32F205xx | ||
STARTUP_FILE = startup_stm32f205xx | ||
|
||
include build.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
Dependencies | ||
-------- | ||
|
||
**Mac** | ||
|
||
``` | ||
./get_sdk_mac.sh | ||
``` | ||
|
||
**Debian / Ubuntu** | ||
|
||
``` | ||
./get_sdk.sh | ||
``` | ||
|
||
|
||
Programming | ||
---- | ||
|
||
**Panda** | ||
|
||
``` | ||
make | ||
``` | ||
|
||
**NEO** | ||
|
||
``` | ||
make -f Makefile.legacy | ||
``` | ||
|
||
Troubleshooting | ||
---- | ||
|
||
If your panda will not flash and is quickly blinking a single Green LED, use: | ||
``` | ||
make recover | ||
``` | ||
|
||
|
||
[dfu-util](http://github.com/dsigma/dfu-util.git) for flashing |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#define BOOTSTUB | ||
|
||
#include "config.h" | ||
#include "obj/gitversion.h" | ||
|
||
#ifdef STM32F4 | ||
#define PANDA | ||
#include "stm32f4xx.h" | ||
#include "stm32f4xx_hal_gpio_ex.h" | ||
#else | ||
#include "stm32f2xx.h" | ||
#include "stm32f2xx_hal_gpio_ex.h" | ||
#endif | ||
|
||
#include "libc.h" | ||
#include "provision.h" | ||
|
||
#include "drivers/drivers.h" | ||
|
||
#include "drivers/llgpio.h" | ||
#include "gpio.h" | ||
|
||
#include "drivers/spi.h" | ||
#include "drivers/usb.h" | ||
//#include "drivers/uart.h" | ||
|
||
int puts(const char *a) { return 0; } | ||
void puth(unsigned int i) {} | ||
|
||
#include "crypto/rsa.h" | ||
#include "crypto/sha.h" | ||
|
||
#include "obj/cert.h" | ||
|
||
#include "spi_flasher.h" | ||
|
||
void __initialize_hardware_early() { | ||
early(); | ||
} | ||
|
||
void fail() { | ||
soft_flasher_start(); | ||
} | ||
|
||
// know where to sig check | ||
extern void *_app_start[]; | ||
|
||
int main() { | ||
__disable_irq(); | ||
clock_init(); | ||
detect(); | ||
|
||
if (revision == PANDA_REV_C) { | ||
set_usb_power_mode(USB_POWER_CLIENT); | ||
} | ||
|
||
if (enter_bootloader_mode == ENTER_SOFTLOADER_MAGIC) { | ||
enter_bootloader_mode = 0; | ||
soft_flasher_start(); | ||
} | ||
|
||
// validate length | ||
int len = (int)_app_start[0]; | ||
if ((len < 8) || (len > (0x1000000 - 0x4000 - 4 - RSANUMBYTES))) goto fail; | ||
|
||
// compute SHA hash | ||
uint8_t digest[SHA_DIGEST_SIZE]; | ||
SHA_hash(&_app_start[1], len-4, digest); | ||
|
||
// verify RSA signature | ||
if (RSA_verify(&release_rsa_key, ((void*)&_app_start[0]) + len, RSANUMBYTES, digest, SHA_DIGEST_SIZE)) { | ||
goto good; | ||
} | ||
|
||
// allow debug if built from source | ||
#ifdef ALLOW_DEBUG | ||
if (RSA_verify(&debug_rsa_key, ((void*)&_app_start[0]) + len, RSANUMBYTES, digest, SHA_DIGEST_SIZE)) { | ||
goto good; | ||
} | ||
#endif | ||
|
||
// here is a failure | ||
fail: | ||
fail(); | ||
return 0; | ||
good: | ||
// jump to flash | ||
((void(*)()) _app_start[1])(); | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
CFLAGS += -I inc -I ../ -nostdlib -fno-builtin -std=gnu11 -O0 | ||
CFLAGS += -Tstm32_flash.ld | ||
|
||
CC = arm-none-eabi-gcc | ||
OBJCOPY = arm-none-eabi-objcopy | ||
OBJDUMP = arm-none-eabi-objdump | ||
|
||
ifeq ($(RELEASE),1) | ||
CERT = ../../pandaextra/certs/release | ||
else | ||
# enable the debug cert | ||
CERT = ../certs/debug | ||
CFLAGS += "-DALLOW_DEBUG" | ||
endif | ||
|
||
DFU_UTIL = "dfu-util" | ||
|
||
# this no longer pushes the bootstub | ||
flash: obj/$(PROJ_NAME).bin | ||
PYTHONPATH=../ python -c "from panda import Panda; Panda().flash('obj/$(PROJ_NAME).bin')" | ||
|
||
ota: obj/$(PROJ_NAME).bin | ||
curl http://192.168.0.10/stupdate --upload-file $< | ||
|
||
bin: obj/$(PROJ_NAME).bin | ||
|
||
# this flashes everything | ||
recover: obj/bootstub.$(PROJ_NAME).bin obj/$(PROJ_NAME).bin | ||
-PYTHONPATH=../ python -c "from panda import Panda; Panda().reset(enter_bootloader=True)" | ||
sleep 1.0 | ||
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08004000 -D obj/$(PROJ_NAME).bin | ||
$(DFU_UTIL) -d 0483:df11 -a 0 -s 0x08000000:leave -D obj/bootstub.$(PROJ_NAME).bin | ||
|
||
include ../common/version.mk | ||
|
||
obj/cert.h: ../crypto/getcertheader.py | ||
../crypto/getcertheader.py ../certs/debug.pub ../certs/release.pub > $@ | ||
|
||
obj/%.$(PROJ_NAME).o: %.c obj/cert.h obj/gitversion.h config.h drivers/*.h gpio.h libc.h provision.h safety.h safety/*.h spi_flasher.h | ||
$(CC) $(CFLAGS) -o $@ -c $< | ||
|
||
obj/%.$(PROJ_NAME).o: ../crypto/%.c | ||
$(CC) $(CFLAGS) -o $@ -c $< | ||
|
||
obj/$(STARTUP_FILE).o: $(STARTUP_FILE).s | ||
$(CC) $(CFLAGS) -o $@ -c $< | ||
|
||
obj/$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/main.$(PROJ_NAME).o | ||
# hack | ||
$(CC) -Wl,--section-start,.isr_vector=0x8004000 $(CFLAGS) -o obj/$(PROJ_NAME).elf $^ | ||
$(OBJCOPY) -v -O binary obj/$(PROJ_NAME).elf obj/code.bin | ||
SETLEN=1 ../crypto/sign.py obj/code.bin $@ $(CERT) | ||
|
||
obj/bootstub.$(PROJ_NAME).bin: obj/$(STARTUP_FILE).o obj/bootstub.$(PROJ_NAME).o obj/sha.$(PROJ_NAME).o obj/rsa.$(PROJ_NAME).o | ||
$(CC) $(CFLAGS) -o obj/bootstub.$(PROJ_NAME).elf $^ | ||
$(OBJCOPY) -v -O binary obj/bootstub.$(PROJ_NAME).elf $@ | ||
|
||
clean: | ||
@rm -f obj/* |
Oops, something went wrong.