Skip to content

Commit ab54cf7

Browse files
committed
Move security support from main app to drivers
- No board change; continue selecting `SECURITY` config - Security state enum moved to driver header - Update related doc Signed-off-by: Tim Crawford <[email protected]>
1 parent d598e41 commit ab54cf7

File tree

10 files changed

+97
-38
lines changed

10 files changed

+97
-38
lines changed

docs/security.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Firmware security
22

33
The firmware security feature can be configured by setting `CONFIG_SECURITY=1`
4-
in the `src/board/system76/[board]/board.mk` file. This feature prevents
4+
in the `src/board/system76/<board>/board.mk` file. This feature prevents
55
programming the EC firmware at runtime, unless the EC is unlocked with the
66
`system76-ectool security unlock` command. After this, on the next reboot, the
7-
EC will respond to the SPI and reset commands. On boards where the `ME_WE` GPIO
8-
exists, it will be set high when the EC security state is unlocked.
7+
EC will respond to the SPI and reset commands.
8+
9+
This feature will drive the `ME_WE` pin high when the state is unlocked. On
10+
Intel hosts, this pin is connected to `HDA_SDO` and will disable security
11+
policies set in the flash descriptor.
12+
13+
- `HDA_SDO`: Flash Descriptor Security Override
914

1015
Other firmware components can use this state to perform their own locking and
11-
unlocking primitives. For example, in `coreboot`, flash regions may be locked
12-
when the EC security state is locked. In `EDK2`, a physical presence dialog may
13-
be shown when the EC security state is unlocked.
16+
unlocking primitives. For example, in coreboot, flash regions may be locked
17+
when the EC security state is locked. In the UEFI payload, a physical presence
18+
dialog may be shown when the EC security state is unlocked.

src/app/main/Makefile.mk

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ app-y += pnp.c
1818
app-y += ps2.c
1919
app-y += pwm.c
2020
app-y += scratch.c
21-
app-$(CONFIG_SECURITY) += security.c
2221
app-y += smbus.c
2322
app-y += smfi.c
2423
app-y += stdio.c
@@ -40,10 +39,6 @@ CFLAGS += -DI2C_SMBUS=$(CONFIG_I2C_SMBUS)
4039
# Uncomment to enable I2C debug on 0x76
4140
#CFLAGS+=-DI2C_DEBUGGER=0x76
4241

43-
ifeq ($(CONFIG_SECURITY),y)
44-
CFLAGS+=-DCONFIG_SECURITY=1
45-
endif
46-
4742
ifeq ($(CONFIG_PLATFORM_INTEL),y)
4843
app-y += peci.c
4944
app-y += power/intel.c

src/app/main/include/app/security.h

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/app/main/power/intel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#endif
2727

2828
#if CONFIG_SECURITY
29-
#include <app/security.h>
29+
#include <drivers/security/security.h>
3030
#endif // CONFIG_SECURITY
3131

3232
#define GPIO_SET_DEBUG(G, V) \

src/app/main/security.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-3.0-only
22

3-
#include <app/security.h>
3+
#include "security.h"
44
#include <board/gpio.h>
55

66
static enum SecurityState security_state = SECURITY_STATE_LOCK;

src/app/main/smfi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <app/scratch.h>
2323

2424
#if CONFIG_SECURITY
25-
#include <app/security.h>
25+
#include <drivers/security/security.h>
2626
#endif // CONFIG_SECURITY
2727
#endif // !defined(__SCRATCH__)
2828

src/common/include/common/command.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,4 @@ enum CommandSpiFlag {
7777

7878
#define CMD_LED_INDEX_ALL 0xFF
7979

80-
enum SecurityState {
81-
// Default value, flashing is prevented, cannot be set with CMD_SECURITY_SET
82-
SECURITY_STATE_LOCK = 0,
83-
// Flashing is allowed, cannot be set with CMD_SECURITY_SET
84-
SECURITY_STATE_UNLOCK = 1,
85-
// Flashing will be prevented on the next reboot
86-
SECURITY_STATE_PREPARE_LOCK = 2,
87-
// Flashing will be allowed on the next reboot
88-
SECURITY_STATE_PREPARE_UNLOCK = 3,
89-
};
90-
9180
#endif // _COMMON_COMMAND_H

src/drivers/security/Makefile.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: GPL-3.0-only
2+
# SPDX-FileCopyrightText: 2025 System76, Inc.
3+
4+
# Firmware security state feature.
5+
#
6+
# Requires:
7+
# - Board must declare the `ME_WE` pin.
8+
#
9+
# External integrations:
10+
# - system76/coreboot: `ec/system76/ec` config `EC_SYSTEM76_EC_LOCKDOWN`.
11+
# - system76/firmware-setup: UEFI protocol for physical presence prompt.
12+
13+
ifeq ($(CONFIG_SECURITY),y)
14+
15+
CFLAGS += -DCONFIG_SECURITY=1
16+
17+
drivers-y += security.c
18+
19+
endif

src/drivers/security/security.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
3+
#include "security.h"
4+
#include <board/gpio.h>
5+
6+
static enum SecurityState security_state = SECURITY_STATE_LOCK;
7+
8+
enum SecurityState security_get(void) {
9+
return security_state;
10+
}
11+
12+
bool security_set(enum SecurityState state) {
13+
switch (state) {
14+
// Allow prepare states to be set
15+
case SECURITY_STATE_PREPARE_LOCK:
16+
case SECURITY_STATE_PREPARE_UNLOCK:
17+
security_state = state;
18+
return true;
19+
// Any other states will be ignored
20+
default:
21+
return false;
22+
}
23+
}
24+
25+
bool security_power(void) {
26+
switch (security_state) {
27+
// Apply lock state and power on
28+
case SECURITY_STATE_PREPARE_LOCK:
29+
gpio_set(&ME_WE, false);
30+
security_state = SECURITY_STATE_LOCK;
31+
return true;
32+
// Apply unlock state and power on
33+
case SECURITY_STATE_PREPARE_UNLOCK:
34+
gpio_set(&ME_WE, true);
35+
security_state = SECURITY_STATE_UNLOCK;
36+
return true;
37+
// Any other states will be ignored
38+
default:
39+
return false;
40+
}
41+
}

src/drivers/security/security.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
3+
#ifndef _DRIVERS_SECURITY_H
4+
#define _DRIVERS_SECURITY_H
5+
6+
#include <stdbool.h>
7+
8+
enum SecurityState {
9+
// Default value, flashing is prevented, cannot be set with CMD_SECURITY_SET
10+
SECURITY_STATE_LOCK = 0,
11+
// Flashing is allowed, cannot be set with CMD_SECURITY_SET
12+
SECURITY_STATE_UNLOCK = 1,
13+
// Flashing will be prevented on the next reboot
14+
SECURITY_STATE_PREPARE_LOCK = 2,
15+
// Flashing will be allowed on the next reboot
16+
SECURITY_STATE_PREPARE_UNLOCK = 3,
17+
};
18+
19+
enum SecurityState security_get(void);
20+
bool security_set(enum SecurityState state);
21+
bool security_power(void);
22+
23+
#endif // _DRIVERS_SECURITY_H

0 commit comments

Comments
 (0)