Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lotus,azalea: officially reserve the top 4096b of flash for SPI_FLAGS
Right now, the configuration storage support in
lotus/src/flash_storage.c claims overship of the top 0x1000 bytes of
flash and stores non-volatile configuration data in it.

However, the last 0x20 bytes of flash contain the RW_FWID (RW version)
section. In addition, RW_FW is specified as covering the entire top
0x40000 bytes of flash.

In short, flash looks roughly like this (not to scale)

+----------------------------------+-40000------------~----------------+
| RO_FW                            | RW_FW                             |
|                          RO_FRID |                           RW_FWID |
+----------------------------------+------------------~--------^-7FFE0-+

flash_storage can, if it grows large enough, corrupt the RW version
ID. If the RW firmware _also_ grows large enough, flash_storage can
overwrite part of it (!).

+----------------------------------+-40000------------~--+-7F000-------+
| RO_FW                            | RW_FW               |spi flag spi |
|                          RO_FRID |                     |flag Rp_ WlD |
+----------------------------------+------------------~--+-~---^-7FFE0-+

This change moves RW_FWID down to 0x7EFE0 and indicates in the FMAP that
the RW section can only occupy the top 0x3F000 bytes of flash.

The final layout looks more like this:

+----------------------------------+-40000----~----------+-7F000-------+
| RO_FW                            | RW_FW               |spi flag spi |
|                          RO_FRID |             RW_FWID |flag spi fla |
+----------------------------------+----------~--^-7EFE0-+-------------+

If the RW section grows too large for SPI flags, that will result in a
hard build break. That's probably better than runtime corruption of its
.text. :)
  • Loading branch information
DHowett committed Dec 18, 2023
commit 817e22093126d1506969518f32b3d88b1086644e
19 changes: 19 additions & 0 deletions zephyr/program/lotus/azalea/overlay.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,22 @@
>;
pinctrl-names = "default";
};

&binman {
ec-rw {
/*
* Azalea uses the last 0x1000 bytes of flash for non-volatile settings storage.
* Shrink the RW region by that much so that there is no conflict between RW_FWID
* or RW text and non-volatile settings.
*/
size = <0x3f000>;
rw-fw {
rw-fwid {
offset = <(0x3f000 - 32)>;
};
};
};
/* The remaining 0x1000 bytes will be used for non-volatile settings storage. */
pad-after = <0x1000>;
pad-byte = <0xFF>;
};
18 changes: 18 additions & 0 deletions zephyr/program/lotus/lotus/overlay.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,21 @@
pinctrl-names = "default";
};

&binman {
ec-rw {
/*
* Lotus uses the last 0x1000 bytes of flash for non-volatile settings storage.
* Shrink the RW region by that much so that there is no conflict between RW_FWID
* or RW text and non-volatile settings.
*/
size = <0x3f000>;
rw-fw {
rw-fwid {
offset = <(0x3f000 - 32)>;
};
};
};
/* The remaining 0x1000 bytes will be used for non-volatile settings storage. */
pad-after = <0x1000>;
pad-byte = <0xFF>;
};
1 change: 1 addition & 0 deletions zephyr/program/lotus/program.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=y
CONFIG_PLATFORM_EC_WP_DISABLE=y
CONFIG_PLATFORM_EC_UNIMPLEMENTED_GPIO=y
CONFIG_PLATFORM_EC_I2C_DEBUG=y
CONFIG_CROS_EC_RW_SIZE=0x3F000

# Port80
CONFIG_PLATFORM_EC_PORT80_4_BYTE=y
Expand Down