Skip to content

Commit c211bb2

Browse files
committed
top-level index for firmware documentation
1 parent 8722616 commit c211bb2

File tree

4 files changed

+145
-143
lines changed

4 files changed

+145
-143
lines changed

README.md

Lines changed: 33 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,147 +1,64 @@
11
<!---
22
-->
33

4-
# Particle Firmware for the Core and Photon
4+
# Particle Firmware for the Core and Photon
55

66
This is the main source code repository of the Particle firmware libraries.
77

8-
1. [Download and Install Dependencies](docs/dependencies.md#1-download-and-install-dependencies)
9-
2. [Download and Build Repositories](#2-download-and-build-repositories)
10-
3. [Edit and Rebuild](#3-edit-and-rebuild)
11-
4. [Flash It!](#4-flash-it)
12-
13-
## 2. Download and Build Repositories
8+
# Getting Started
149

15-
The entire Particle firmware is contained in this repository.
10+
To get started building firmware locally, see [Getting Started](docs/gettingstarted.md.)
1611

17-
There are two ways to download
18-
- through the git command line interface
19-
- download the zipped file from the github website
2012

21-
We recommend the first approach, since it makes keeping up to date with new releases
22-
much simpler.
13+
# Resources
2314

24-
**Method 1:** Through the git command line interface.
15+
- [Latest Release - 0.4.3](releases/tag/0.4.3-rc2)
16+
- [Changelog](CHANGELOG.md)
2517

26-
Open up a terminal window, navigate to your destination directory and type the following commands:
2718

28-
(Make sure you have git installed on your machine!)
19+
## Build System
2920

30-
* `git clone https://github.com/spark/firmware.git`
21+
- [Requirements/Dependencies](docs/dependencies.md)
3122

32-
**Method 2:** Download the zipped files directly from the GitHub website
23+
## Application Firmware Development
3324

34-
* [firmware](https://github.com/spark/firmware/archive/master.zip)
25+
- [Debugging support](debugging.md)
26+
- [make command syntax](docs/build.md)
27+
- [Firmware API](http://docs.particle.io/photon/firmware/)
3528

36-
#### How do we *build* these repositories?
29+
## System Firmware Development
3730

38-
Make sure you have downloaded and installed all the required dependencies as mentioned [previously.](docs/dependencies.md#1-download-and-install-dependencies).
39-
Note, if you've downloaded or cloned these previously, you'll want to `git pull` or redownload all of them before proceeding.
31+
- [System Flags](system/system-flags.md)
32+
- [Continuous Integration](ci/README.md)
33+
- [Module Descriptor linking and retrieval](dynalib/src/readme.md)
34+
- [Photon SoftAP Protocol](hal/src/photon/soft-ap.md)
35+
- [WiFi Tester Firmware](user/applications/wifitester/readme.md)
36+
- [Testing](user/tests/readme.md)
37+
- [API Changes Checklist](wiki/Firmware-API-Changes-Checklist)
38+
- [Firmware Release Checklist](wiki/Firmware-Release-Checklist)
39+
- [System describe message](https://github.com/spark/firmware/wiki/Module-descriptor-format)
40+
- [build test suite](build/test/readme.md)
4041

41-
Open up a terminal window, navigate to the `main` folder under firmware
42-
(i.e. `cd firmware/main`) and type:
42+
### Modules
4343

44-
make
44+
- Bootloader [overview](bootloader/README.md) and [internals](bootloader/documentation.md)
45+
- [Cloud Communications](communication/README.md)
4546

46-
This will build your main application (`firmware/user/src/application.cpp`) and required dependencies.
47+
### Platforms
4748

48-
*For example:* `D:\Spark\firmware\main [master]> make`
49+
- [Virtual Device](hal/src/gcc/readme.md)
50+
- [Starting a New Platform Hardware Abstraction Layer](hal/src/newhal/readme.md)
51+
- [Installing the USB Driver on Windows](misc/driver/windows/readme.md)
4952

50-
You won't see any compiler output for about 30 seconds or so since verbose output is disabled by default and can be enabled with the `v=1` switch.
5153

52-
*For example:* `D:\Spark\firmware\main [master]> make v=1`
5354

54-
The [makefile documentation](docs/build.md) describes the build options supported and how to targeting platforms other than the Core.
55-
56-
##### Common Errors
57-
58-
* `arm-none-eabi-gcc` and other required gcc/arm binaries not in the PATH.
59-
Solution: Add the /bin folder to your $PATH (i.e. `export PATH="$PATH:<SOME_GCC_ARM_DIR>/bin`).
60-
Google "Add binary to PATH" for more details.
61-
62-
* You get `make: *** No targets specified and no makefile found. Stop.`
63-
Solution: `cd firmware/main`
64-
65-
Please issue a pull request if you come across similar issues/fixes that trip you up.
66-
67-
### Navigating the code base
68-
69-
All of the top-level directories are sub divided into functional folders that are
70-
the various libraries that make up the firmware.
71-
72-
- platform: bare-metal services, the lowest layer in the system
73-
- bootloader: the bootloader, with sources for each platform
74-
- hal: the Hardware Abstraction Layer interface and an implementation for each supported platform
75-
- services: platform neutral services and macros (LED control, debug macros, static assertions)
76-
- communication: implements the protocol between the device and the cloud
77-
- dynalib: framework for producing dynamically linked libraries
78-
- system: the system firmware (Networking, firmware updates.)
79-
- wiring: the Wiring API
80-
- user: contains the default application code (Tinker) and your own applications
81-
- main: top-level project to build the firmware for a device
82-
- modules: dynamically linked modules for the Photon/P0/P1
83-
84-
Within each library, the structure is
85-
86-
1. `/src` holds all the source code files
87-
2. `/inc` holds all the header files
88-
89-
The compiled `.bin` and `.hex` files are output to a subdirectory of `build/target/`.
90-
The exact location is given in the final compiler output. (It depends upon the platform and on what is being built.)
91-
92-
## 3. Edit and Rebuild
93-
94-
Now that you have your hands on the firmware, its time to start hacking!
95-
96-
### What to edit and what not to edit?
97-
98-
The main user code sits in the application.cpp file under firmware/user/src/ folder. Unless you know what you are doing, refrain yourself from making changes to any other files.
99-
100-
After you are done editing the files, you can rebuild the repository by running the `make` command in the `firmware/main/` directory.
101-
If you have made changes to any of the other directories, make automatically determines which files need to be rebuilt and builds them for you.
102-
103-
## 4. Flash It!
104-
105-
Its now time to transfer your code to your Particle device! You can always do this using the Over the Air update feature or, if you like wires, do it over the USB.
106-
107-
*Make sure you have the `dfu-util` command installed and available through the command line*
108-
109-
#### Steps:
110-
1. Put your device into the DFU mode by holding down the mode/setup button on the device and then tapping on the RESET button once. Release the MODE/setup button after you start to see the RGB LED flashing in yellow.
111-
It's easy to get this one wrong: Make sure you don't let go of the MODE/SETUP button until you see flashing yellow, about 3 seconds after you release the RESET button.
112-
A flash of white then flashing green can happen when you get this wrong. You want flashing yellow.
113-
114-
2. Open up a terminal window on your computer and type this command to find out if the device indeed being detected correctly.
115-
116-
`dfu-util -l`
117-
you should get something similar to this in return:
118-
```
119-
Found DFU: [1d50:607f] devnum=0, cfg=1, intf=0, alt=0, name="@Internal Flash /0x08000000/20*001Ka,108*001Kg"
120-
Found DFU: [1d50:607f] devnum=0, cfg=1, intf=0, alt=1, name="@SPI Flash : SST25x/0x00000000/512*04Kg"
121-
```
122-
123-
(Windows users will need to use the Zatig utility to replace the USB driver as described earlier)
124-
125-
3. Now, from the `main/` folder in your firmware repository and use the following command to transfer the *.bin* file into the device.
126-
```
127-
make program-dfu
128-
```
129-
130-
Upon successful transfer, the device will automatically reset and start the running the program.
131-
132-
##### Common Errors
133-
* As of 12/4/13, you will likely see `Error during download get_status` as the last line from
134-
the `dfu-util` command. You can ignore this message for now. We're not sure what this error is all about.
135-
136-
* If you are having trouble with dfu-util, (like invalid dfuse address), try a newer version of dfu-util. v0.7 works well.
137-
138-
**Still having troubles?** Checkout our [resources page](https://www.spark.io/resources), hit us up on IRC, etc.
13955

14056
### CREDITS AND ATTRIBUTIONS
14157

142-
The Particle application team: Zachary Crockett, Satish Nair, Zach Supalla, David Middlecamp and Mohit Bhoite.
58+
The firmware uses the GNU GCC toolchain for ARM Cortex-M processors, ARM's CMSIS libraries, STM32 standard peripheral libraries and Arduino's implementation of Wiring.
14359

144-
The firmware uses the GNU GCC toolchain for ARM Cortex-M processors, ARM's CMSIS libraries, TI's CC3000 host driver libraries, STM32 standard peripheral libraries and Arduino's implementation of Wiring.
60+
On the Core: TI's CC3000 host driver libraries,
61+
On the photon: Broadcom's WICED WiFi SDK.
14562

14663
### LICENSE
14764

bootloader/README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,20 @@
55
* Really make sure you have a working programmer shield and an ST-link programmer.
66
* Is this a brand new core from scratch (that you made? nice!) goto 1, or is it this a core that came from Spark - goto "unlocking your bootloader"
77

8+
Please note this documentation is for the Core only. The photon automaatically updates the bootloader as needed.
9+
810
### Unlocking your bootloader
911

1012
Welcome! The bootloader on the stm32 is protected by a "write protect" flag that helps prevent accidental "bricking" of a core for those without a programmer shield / st-link programmer. But that's not you, you want to fully erase your core, or re-write your bootloader, and you're not scared of "bricking" anything.
1113

1214
* Grab the "unlocker" from here: (https://github.com/spark/firmware/tree/master/bootloader/tools (use "raw")
1315
* dfu that with a: `dfu-util -d 1d50:607f -a 0 -s 0x08005000:leave -D unlocker-firmware.bin`
14-
* Your core should restart, flash some lights, and end with a 'green' flash before wiping saved wifi profiles and resetting
16+
* Your core should restart, flash some lights, and end with a 'green' flash before wiping saved wifi profiles and resetting
1517
* Your bootloader is unlocked!
1618

1719
**1. Make sure you have st-flash installed, or have a copy of the ST-Link Utility software.**
1820

19-
* You can find the software on their site if you're using windows: http://www.st.com/web/catalog/tools/FM146/CL1984/SC724/SS1677/PF251168
21+
* You can find the software on their site if you're using windows: http://www.st.com/web/catalog/tools/FM146/CL1984/SC724/SS1677/PF251168
2022

2123
* If you're on mac / linux grab "st-flash" you can grab and build a tool yourself:
2224
```
@@ -27,7 +29,7 @@ Welcome! The bootloader on the stm32 is protected by a "write protect" flag that
2729
make
2830
make install
2931
```
30-
32+
3133
**2. Grab a copy of the latest bootloader from here:**
3234
3335
https://github.com/spark/firmware/blob/master/bootloader/build/bootloader.bin?raw=true5.) With your core in your programmer shield / st-link connected, lets re-flash some stuff!
@@ -54,35 +56,35 @@ Welcome! The bootloader on the stm32 is protected by a "write protect" flag that
5456
### It's time to write some stuff to external flash!
5557
5658
**1. Lets make some keys (optional step if your keys have been fine):**
57-
59+
5860
```
5961
openssl genrsa -out core.pem 1024
6062
openssl rsa -in core.pem -pubout -out core_public.pem
6163
openssl rsa -in core.pem -outform DER -out core_private.der
6264
```
63-
64-
**2. Flash your new private key:**
65-
65+
66+
**2. Flash your new private key:**
67+
6668
`dfu-util -d 1d50:607f -a 1 -s 0x00002000 -v -D core_private.der`
67-
68-
**3. Grab the server public key, and flash it:**
69+
70+
**3. Grab the server public key, and flash it:**
6971
https://s3.amazonaws.com/spark-website/cloud_public.der
70-
72+
7173
`dfu-util -d 1d50:607f -a 1 -s 0x00001000 -v -D cloud_public.der`
7274
73-
**4. Grab the latest firmware and flash it**
74-
75+
**4. Grab the latest firmware and flash it**
76+
7577
https://github.com/spark/firmware/blob/master/main/build/core-firmware.bin?raw=true
76-
78+
7779
```
78-
# to the factory reset spot
80+
# to the factory reset spot
7981
dfu-util -a 1 -s 0x00020000 -v -D core-firmware.bin
8082

8183
## to the main firmware spot
8284
dfu-util -a 0 -s 0x08005000:leave -D core-firmware.bin
8385
```
84-
86+
8587
**5. If you made new keys, be sure to send someone at Spark your new public key, along with your core id, otherwise your core won't connect to the cloud again!**
86-
87-
*(Thanks to David for putting this together)*
88+
89+
*(Thanks to David for putting this together)*
8890
Ref: https://community.spark.io/t/st-link-programmer-shield-only-so-youve-decided-you-want-to-update-your-bootloader-and-everything/2355

build/test/readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Integration Tests for the makefile build
22

3-
# Setup
3+
## Setup
44

55
Install BATS.
66

7-
# Running
7+
## Running
88

99
```
1010
cd build/test
1111
bats build.bats
1212
```
1313

14+
That's it. :-)
1415

1516

dynalib/src/readme.md

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Module Info
22

3-
The `module_info.h` file describes the structure of the module into that is
4-
inserted into modules supporting self-describing placement and CRC checks.
3+
The `module_info.h` file describes the structure of the block of metadata (module info) that is
4+
inserted into modules supporting self-describing memory location and CRC checks.
55

6-
The structure is initialized via `module_info.c` and link at a specific
7-
location by the linker script. The linker script provides the locations for the very
8-
start of the module and the very end of the module.
6+
The structure is initialized by the code in `module_info.c` and linked at a specific
7+
location by the linker script. The linker script also provides the addresses of the
8+
start of the module and the end of the module.
99

1010
## Locating the module info struct
1111

1212
The module info struct is located like this:
1313

14-
- examine the first 4 address at the start of the module.
14+
- examine the first 4 address at the start of the module.
1515

16-
- If this is a module with an interrupt vector table (VTOR) the first address
16+
- If this is a module with an interrupt vector table (VTOR) the first address
1717
will contain the top of the stack in ram (0x20xxxxxx). In this case the info table
18-
will be placed immediately after the VTOR table. For STM32F205, the VTOR table
18+
will be placed immediately after the VTOR table. For STM32F205, the VTOR table
1919
comprises 97 interrupt vectors, giving a total size of 388 (0x184) bytes.
2020

2121
- The other case is a module without the VTOR, where the module info appears at
@@ -35,3 +35,85 @@ can be cast and assigned to a `const module_info_t*`
3535
const module_info_t* module_info = (const module_info*)address;
3636
```
3737

38+
The binaries consumed in the Particle ecosystem should include "module info" descriptors that appear at fixed locations in the binary. There are 2 module info structures:
39+
40+
- start info: appears at the start of the binary, this defines the platform, version, module type, module dependencies
41+
- end info: appears at the end of the binary. Defines product ID and version, as set in user code and provides storage for the SHA256 and CRC32 hashes that are added after the binary is built.
42+
43+
44+
# Compiling Module Info
45+
46+
The module info structures are defined in `dynalib/inc/module_info.h`. The structures are instantiated in `dynalib/inc/module_info.inc` which defines the default values for all platforms.
47+
48+
The `main` project compiles the module info structure instances into a `module_info.o` object file - `main/src/module_info.c` simply includes `module_info.inc` from dynalib so the instance declarations become static data.
49+
50+
## Linking Module Info
51+
52+
Your project's linker script describes how the various object files are placed into the final firmware image. The module infos need to be placed at specific locations, and so we must use linker scripting to instruct the linker to place these at the desired locations.
53+
54+
We provide some linker scripts to make this process simple (and avoid copy/pasting code.) All the linker scripts are stored in `build/arm/linker`. If not already done, you should add this directory to the linker search path with
55+
56+
```
57+
LDFLAGS += -L$(COMMON_BUILD)/arm/linker
58+
```
59+
60+
Add this alongside the other linker flags defines in your HAL `include.mk` file.
61+
62+
63+
All the linker script changes add data to the program memory region - this is where the main executable code is stored. To reuse our linker scripts that inject the module info, this section should be named `APP_FLASH`. For example,
64+
65+
```
66+
.somesection :
67+
{
68+
// .. declarations
69+
} > APP_FLASH
70+
71+
.text :
72+
{
73+
// .. more declarations
74+
} > APP_FLASH
75+
```
76+
77+
78+
### Module Start Symbol
79+
80+
A symbol for the module start is used to compute various offsets.
81+
82+
Add this include before any other APP_FLASH section.
83+
```
84+
INCLUDE 'module_start.ld'
85+
```
86+
87+
In the example, this would come before `.somesection`.
88+
89+
### Module Info Start
90+
91+
After any mandatory sections in program memory, such as ISR vector tables, add
92+
93+
```
94+
INCLUDE 'module_info.ld'
95+
```
96+
97+
In the example, this would come after `.somesection` if that section must remain at the start of the binary image. If `.somesection` can appear anywhere, the include would be placed before it so that the module info is placed at the very beginning of the module.
98+
99+
100+
### Module Info End
101+
102+
After all other `APP_FLASH` sections, add
103+
104+
```
105+
INCLUDE 'module_end.ld'
106+
```
107+
108+
In the example, this would be placed after the `.text` section.
109+
110+
111+
112+
## Troubleshooting
113+
114+
Without the module info end structures in place, building `main` will fail since the module info end data isn't present. This includes default SHA256 and CRC32 values that are built into the binary, and the buidl will fail when those do not match the values expected. This is a sanity check in the build that it's overwriting the correct data when writing the SHA256 and CRC32 hashes to offsets from the end of the file.
115+
116+
117+
118+
119+

0 commit comments

Comments
 (0)