Skip to content
This repository was archived by the owner on Apr 16, 2019. It is now read-only.

Commit eba242b

Browse files
committed
format: start using clang-format with style=Google
1 parent e1bc0eb commit eba242b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+14897
-14449
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
BasedOnStyle: Google

bootloader/bootloader.c

+96-93
Original file line numberDiff line numberDiff line change
@@ -19,132 +19,135 @@
1919

2020
#include <string.h>
2121

22-
#include <libopencm3/stm32/rcc.h>
23-
#include <libopencm3/stm32/gpio.h>
2422
#include <libopencm3/cm3/scb.h>
23+
#include <libopencm3/stm32/gpio.h>
24+
#include <libopencm3/stm32/rcc.h>
2525

2626
#include "bootloader.h"
27-
#include "signatures.h"
2827
#include "buttons.h"
28+
#include "layout.h"
29+
#include "memory.h"
30+
#include "oled.h"
31+
#include "rng.h"
2932
#include "setup.h"
33+
#include "signatures.h"
3034
#include "usb.h"
31-
#include "oled.h"
3235
#include "util.h"
33-
#include "signatures.h"
34-
#include "layout.h"
35-
#include "rng.h"
36-
#include "memory.h"
3736

38-
void layoutFirmwareFingerprint(const uint8_t *hash)
39-
{
40-
char str[4][17];
41-
for (int i = 0; i < 4; i++) {
42-
data2hex(hash + i * 8, 8, str[i]);
43-
}
44-
layoutDialog(&bmp_icon_question, "Abort", "Continue", "Compare fingerprints", str[0], str[1], str[2], str[3], NULL, NULL);
37+
void layoutFirmwareFingerprint(const uint8_t *hash) {
38+
char str[4][17];
39+
for (int i = 0; i < 4; i++) {
40+
data2hex(hash + i * 8, 8, str[i]);
41+
}
42+
layoutDialog(&bmp_icon_question, "Abort", "Continue", "Compare fingerprints",
43+
str[0], str[1], str[2], str[3], NULL, NULL);
4544
}
4645

47-
bool get_button_response(void)
48-
{
49-
do {
50-
delay(100000);
51-
buttonUpdate();
52-
} while (!button.YesUp && !button.NoUp);
53-
return button.YesUp;
46+
bool get_button_response(void) {
47+
do {
48+
delay(100000);
49+
buttonUpdate();
50+
} while (!button.YesUp && !button.NoUp);
51+
return button.YesUp;
5452
}
5553

56-
void show_halt(const char *line1, const char *line2)
57-
{
58-
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, line1, line2, NULL, "Unplug your TREZOR,", "reinstall firmware.", NULL);
59-
shutdown();
54+
void show_halt(const char *line1, const char *line2) {
55+
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, line1, line2, NULL,
56+
"Unplug your TREZOR,", "reinstall firmware.", NULL);
57+
shutdown();
6058
}
6159

62-
static void show_unofficial_warning(const uint8_t *hash)
63-
{
64-
layoutDialog(&bmp_icon_warning, "Abort", "I'll take the risk", NULL, "WARNING!", NULL, "Unofficial firmware", "detected.", NULL, NULL);
60+
static void show_unofficial_warning(const uint8_t *hash) {
61+
layoutDialog(&bmp_icon_warning, "Abort", "I'll take the risk", NULL,
62+
"WARNING!", NULL, "Unofficial firmware", "detected.", NULL,
63+
NULL);
6564

66-
bool but = get_button_response();
67-
if (!but) { // no button was pressed -> halt
68-
show_halt("Unofficial firmware", "aborted.");
69-
}
65+
bool but = get_button_response();
66+
if (!but) { // no button was pressed -> halt
67+
show_halt("Unofficial firmware", "aborted.");
68+
}
7069

71-
layoutFirmwareFingerprint(hash);
70+
layoutFirmwareFingerprint(hash);
7271

73-
but = get_button_response();
74-
if (!but) { // no button was pressed -> halt
75-
show_halt("Unofficial firmware", "aborted.");
76-
}
72+
but = get_button_response();
73+
if (!but) { // no button was pressed -> halt
74+
show_halt("Unofficial firmware", "aborted.");
75+
}
7776

78-
// everything is OK, user pressed 2x Continue -> continue program
77+
// everything is OK, user pressed 2x Continue -> continue program
7978
}
8079

81-
static void __attribute__((noreturn)) load_app(int signed_firmware)
82-
{
83-
// zero out SRAM
84-
memset_reg(_ram_start, _ram_end, 0);
80+
static void __attribute__((noreturn)) load_app(int signed_firmware) {
81+
// zero out SRAM
82+
memset_reg(_ram_start, _ram_end, 0);
8583

86-
jump_to_firmware((const vector_table_t *) FLASH_PTR(FLASH_APP_START), signed_firmware);
84+
jump_to_firmware((const vector_table_t *)FLASH_PTR(FLASH_APP_START),
85+
signed_firmware);
8786
}
8887

89-
static void bootloader_loop(void)
90-
{
91-
oledClear();
92-
oledDrawBitmap(0, 0, &bmp_logo64);
93-
if (firmware_present_new()) {
94-
oledDrawStringCenter(90, 10, "TREZOR", FONT_STANDARD);
95-
oledDrawStringCenter(90, 30, "Bootloader", FONT_STANDARD);
96-
oledDrawStringCenter(90, 50, VERSTR(VERSION_MAJOR) "." VERSTR(VERSION_MINOR) "." VERSTR(VERSION_PATCH), FONT_STANDARD);
97-
} else {
98-
oledDrawStringCenter(90, 10, "Welcome!", FONT_STANDARD);
99-
oledDrawStringCenter(90, 30, "Please visit", FONT_STANDARD);
100-
oledDrawStringCenter(90, 50, "trezor.io/start", FONT_STANDARD);
101-
}
102-
oledRefresh();
103-
104-
usbLoop();
88+
static void bootloader_loop(void) {
89+
oledClear();
90+
oledDrawBitmap(0, 0, &bmp_logo64);
91+
if (firmware_present_new()) {
92+
oledDrawStringCenter(90, 10, "TREZOR", FONT_STANDARD);
93+
oledDrawStringCenter(90, 30, "Bootloader", FONT_STANDARD);
94+
oledDrawStringCenter(90, 50,
95+
VERSTR(VERSION_MAJOR) "." VERSTR(
96+
VERSION_MINOR) "." VERSTR(VERSION_PATCH),
97+
FONT_STANDARD);
98+
} else {
99+
oledDrawStringCenter(90, 10, "Welcome!", FONT_STANDARD);
100+
oledDrawStringCenter(90, 30, "Please visit", FONT_STANDARD);
101+
oledDrawStringCenter(90, 50, "trezor.io/start", FONT_STANDARD);
102+
}
103+
oledRefresh();
104+
105+
usbLoop();
105106
}
106107

107-
int main(void)
108-
{
108+
int main(void) {
109109
#ifndef APPVER
110-
setup();
110+
setup();
111111
#endif
112-
__stack_chk_guard = random32(); // this supports compiler provided unpredictable stack protection checks
112+
__stack_chk_guard = random32(); // this supports compiler provided
113+
// unpredictable stack protection checks
113114
#ifndef APPVER
114-
memory_protect();
115-
oledInit();
115+
memory_protect();
116+
oledInit();
116117
#endif
117118

118-
mpu_config_bootloader();
119+
mpu_config_bootloader();
119120

120121
#ifndef APPVER
121-
bool left_pressed = (buttonRead() & BTN_PIN_NO) == 0;
122-
123-
if (firmware_present_new() && !left_pressed) {
124-
125-
oledClear();
126-
oledDrawBitmap(40, 0, &bmp_logo64_empty);
127-
oledRefresh();
128-
129-
const image_header *hdr = (const image_header *)FLASH_PTR(FLASH_FWHEADER_START);
130-
131-
uint8_t fingerprint[32];
132-
int signed_firmware = signatures_new_ok(hdr, fingerprint);
133-
if (SIG_OK != signed_firmware) {
134-
show_unofficial_warning(fingerprint);
135-
}
136-
137-
if (SIG_OK != check_firmware_hashes(hdr)) {
138-
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Broken firmware", "detected.", NULL, "Unplug your TREZOR,", "reinstall firmware.", NULL);
139-
shutdown();
140-
}
141-
142-
mpu_config_off();
143-
load_app(signed_firmware);
144-
}
122+
bool left_pressed = (buttonRead() & BTN_PIN_NO) == 0;
123+
124+
if (firmware_present_new() && !left_pressed) {
125+
oledClear();
126+
oledDrawBitmap(40, 0, &bmp_logo64_empty);
127+
oledRefresh();
128+
129+
const image_header *hdr =
130+
(const image_header *)FLASH_PTR(FLASH_FWHEADER_START);
131+
132+
uint8_t fingerprint[32];
133+
int signed_firmware = signatures_new_ok(hdr, fingerprint);
134+
if (SIG_OK != signed_firmware) {
135+
show_unofficial_warning(fingerprint);
136+
}
137+
138+
if (SIG_OK != check_firmware_hashes(hdr)) {
139+
layoutDialog(&bmp_icon_error, NULL, NULL, NULL, "Broken firmware",
140+
"detected.", NULL, "Unplug your TREZOR,",
141+
"reinstall firmware.", NULL);
142+
shutdown();
143+
}
144+
145+
mpu_config_off();
146+
load_app(signed_firmware);
147+
}
145148
#endif
146149

147-
bootloader_loop();
150+
bootloader_loop();
148151

149-
return 0;
152+
return 0;
150153
}

bootloader/bootloader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#define VERSION_MINOR_CHAR "\x08"
3232
#define VERSION_PATCH_CHAR "\x00"
3333

34-
#include <stdint.h>
3534
#include <stdbool.h>
35+
#include <stdint.h>
3636

3737
void show_halt(const char *line1, const char *line2);
3838
void layoutFirmwareFingerprint(const uint8_t *hash);

0 commit comments

Comments
 (0)