Skip to content

Commit

Permalink
Suit storage modifications
Browse files Browse the repository at this point in the history
* Add purge for nRF9280
* Add cellular domain definitions for suit storage
  • Loading branch information
anttik-nordic authored and parttimaa committed Nov 27, 2024
1 parent c0070f2 commit 6145ae8
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 10 deletions.
12 changes: 12 additions & 0 deletions subsys/suit/metadata/include/suit_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ typedef enum {
/** Manifest role uninitialized (invalid). */
SUIT_MANIFEST_UNKNOWN = 0x00,

#if 1
/** Manifest describes the entry-point for all Nordic-controlled manifests. */
SUIT_MANIFEST_SEC_TOP = 0x10,
#endif
/** Manifest describes SDFW firmware and recovery updates. */
SUIT_MANIFEST_SEC_SDFW = 0x11,
/** Manifest describes SYSCTRL firmware update and boot procedures. */
Expand All @@ -107,6 +109,13 @@ typedef enum {
SUIT_MANIFEST_RAD_LOCAL_1 = 0x31,
/** Manifest describes OEM-specific binaries, specific for radio core. */
SUIT_MANIFEST_RAD_LOCAL_2 = 0x32,

#if 0
/** Manifest describes the entry-point for all Nordic-controlled manifests. */
SUIT_MANIFEST_NORDIC_TOP = 0x40,
#endif
/** Manifest describes Cellular Domain firmware update and boot procedures. */
SUIT_MANIFEST_NORDIC_CELLFW = 0x41,
} suit_manifest_role_t;

/* Manifest domain nibble. */
Expand All @@ -122,6 +131,9 @@ typedef enum {

/** Manifest domain for Radio-controlled manifests. */
SUIT_MANIFEST_DOMAIN_RAD = 0x30,

/** Manifest domain for Nordic-controlled manifests (Cellular). */
SUIT_MANIFEST_DOMAIN_NORDIC_CELL = 0x40,
} suit_manifest_domain_t;

/** The 128-bit UUID, used for identifying vendors as well as classes. */
Expand Down
2 changes: 2 additions & 0 deletions subsys/suit/platform/sdfw/src/suit_plat_authenticate.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ int suit_plat_authenticate_manifest(struct zcbor_string *manifest_component_id,
return SUIT_ERR_UNSUPPORTED_PARAMETER;
}

LOG_WRN("Decoded key ID: %08x", public_key_id);

/* Validate KEY ID */
ret = suit_mci_signing_key_id_validate(class_id, public_key_id);
if (ret != SUIT_PLAT_SUCCESS) {
Expand Down
10 changes: 10 additions & 0 deletions subsys/suit/storage/src/suit_storage_mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ suit_plat_err_t suit_storage_mpi_configuration_load(suit_manifest_role_t role, c
const suit_manifest_class_id_t *new_class_id = NULL;
suit_storage_mpi_t *mpi = (suit_storage_mpi_t *)addr;

LOG_INF("Suit manifest role: %02x", role);

if ((role == SUIT_MANIFEST_UNKNOWN) || (addr == NULL) || (size == 0)) {
return SUIT_PLAT_ERR_INVAL;
}
Expand Down Expand Up @@ -113,7 +115,10 @@ suit_plat_err_t suit_storage_mpi_configuration_load(suit_manifest_role_t role, c
/* Validate downgrade prevention policy value. */
switch (mpi->downgrade_prevention_policy) {
case SUIT_MPI_DOWNGRADE_PREVENTION_DISABLED:
LOG_INF("Downgrade prevention policy disabled");
break;
case SUIT_MPI_DOWNGRADE_PREVENTION_ENABLED:
LOG_INF("Downgrade prevention policy enabled");
break;
default:
LOG_ERR("Invalid downgrade prevention policy value for role 0x%x%s: %d", role,
Expand Down Expand Up @@ -141,8 +146,13 @@ suit_plat_err_t suit_storage_mpi_configuration_load(suit_manifest_role_t role, c
/* Validate signature verification policy value. */
switch (mpi->signature_verification_policy) {
case SUIT_MPI_SIGNATURE_CHECK_DISABLED:
LOG_INF("Signature check disabled");
break;
case SUIT_MPI_SIGNATURE_CHECK_ENABLED_ON_UPDATE:
LOG_INF("Signature check enabled on update");
break;
case SUIT_MPI_SIGNATURE_CHECK_ENABLED_ON_UPDATE_AND_BOOT:
LOG_INF("Signature check enabled on update and boot");
break;
default:
LOG_ERR("Invalid signature verification policy value for role 0x%x%s: %d", role,
Expand Down
106 changes: 96 additions & 10 deletions subsys/suit/storage/src/suit_storage_nrf9280.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ static const suit_storage_mpi_t mpi_nordic[] = {
.vendor_id = {0x76, 0x17, 0xda, 0xa5, 0x71, 0xfd, 0x5a, 0x85, 0x8f, 0x94, 0xe2,
0x8d, 0x73, 0x5c, 0xe9, 0xf4},
/* RFC4122 uuid5(nordic_vid, 'nRF9280_nordic_top') */
.class_id = {0x92, 0x54, 0x3b, 0x3b, 0xb9, 0xbc, 0x5c, 0x7c, 0x9f, 0x46, 0x4e, 0x4a,
0x07, 0xb9, 0xac, 0x13},
.class_id = {0xa9, 0x6d, 0x08, 0xa3, 0x21, 0x8f, 0x5a, 0x9c, 0xa3, 0x9e, 0xea, 0x33,
0xce, 0x8f, 0x56, 0x50},
},
{
.version = SUIT_MPI_INFO_VERSION,
Expand All @@ -204,8 +204,8 @@ static const suit_storage_mpi_t mpi_nordic[] = {
.vendor_id = {0x76, 0x17, 0xda, 0xa5, 0x71, 0xfd, 0x5a, 0x85, 0x8f, 0x94, 0xe2,
0x8d, 0x73, 0x5c, 0xe9, 0xf4},
/* RFC4122 uuid5(nordic_vid, 'nRF9280_sec') */
.class_id = {0xdc, 0xf1, 0xba, 0x81, 0xdb, 0x65, 0x5a, 0x8c, 0x9b, 0xef, 0x6b, 0x59,
0x33, 0x65, 0xa4, 0x84},
.class_id = {0xef, 0x05, 0xbe, 0xf3, 0x7d, 0x8b, 0x58, 0xb7, 0xae, 0xdd, 0xd6, 0x90,
0x4e, 0x86, 0xb6, 0x49},
},
{
.version = SUIT_MPI_INFO_VERSION,
Expand All @@ -219,8 +219,8 @@ static const suit_storage_mpi_t mpi_nordic[] = {
.vendor_id = {0x76, 0x17, 0xda, 0xa5, 0x71, 0xfd, 0x5a, 0x85, 0x8f, 0x94, 0xe2,
0x8d, 0x73, 0x5c, 0xe9, 0xf4},
/* RFC4122 uuid5(nordic_vid, 'nRF9280_sys') */
.class_id = {0x31, 0x39, 0xb5, 0xe8, 0xa9, 0x2d, 0x51, 0x63, 0x9c, 0x3e, 0x3b, 0x6a,
0x41, 0x7e, 0x7f, 0xb4},
.class_id = {0xe4, 0xa0, 0xb0, 0xd4, 0xbf, 0xff, 0x5a, 0x9d, 0x8f, 0xb1, 0x61, 0xba,
0xc6, 0xde, 0xc4, 0xbc},
}};

static suit_plat_err_t find_manifest_area(suit_manifest_role_t role, const uint8_t **addr,
Expand All @@ -246,6 +246,10 @@ static suit_plat_err_t find_manifest_area(suit_manifest_role_t role, const uint8
*addr = nordic_storage->nordic.scfw;
*size = sizeof(nordic_storage->nordic.scfw);
break;
case SUIT_MANIFEST_NORDIC_CELLFW:
*addr = nordic_storage_cell->nordic_cell.cellfw;
*size = sizeof(nordic_storage_cell->nordic_cell.top);
break;
case SUIT_MANIFEST_RAD_RECOVERY:
*addr = rad_storage->rad.recovery;
*size = sizeof(rad_storage->rad.recovery);
Expand Down Expand Up @@ -950,17 +954,17 @@ suit_plat_err_t suit_storage_installed_envelope_get(const suit_manifest_class_id
return err;
}

LOG_DBG("Decode envelope with role: 0x%x%s address: 0x%lx", role, suit_role_name_get(role),
LOG_INF("Decode envelope with role: 0x%x%s address: 0x%lx", role, suit_role_name_get(role),
(intptr_t)(*addr));

err = suit_storage_envelope_get(*addr, *size, id, addr, size);
if (err != SUIT_PLAT_SUCCESS) {
LOG_WRN("Unable to parse envelope with role 0x%x%s", role,
suit_role_name_get(role));
LOG_WRN("Unable to parse envelope with role 0x%x%s, address: 0x%lx", role,
suit_role_name_get(role), (intptr_t)(*addr));
return err;
}

LOG_DBG("Valid envelope with given class ID and role 0x%x%s found", role,
LOG_INF("Valid envelope with given class ID and role 0x%x%s found", role,
suit_role_name_get(role));

return err;
Expand Down Expand Up @@ -1083,3 +1087,85 @@ suit_plat_err_t suit_storage_report_read(size_t index, const uint8_t **buf, size

return suit_storage_report_internal_read(area_addr, area_size, buf, len);
}


suit_plat_err_t suit_storage_purge(suit_manifest_domain_t domain)
{
struct suit_storage_nordic *nordic_storage =
(struct suit_storage_nordic *)SUIT_STORAGE_NORDIC_ADDRESS;
struct suit_storage_rad *rad_storage = (struct suit_storage_rad *)SUIT_STORAGE_RAD_ADDRESS;
struct suit_storage_app *app_storage = (struct suit_storage_app *)SUIT_STORAGE_APP_ADDRESS;
struct suit_storage_nordic_cell *cell_storage = (struct suit_storage_nordic_cell *)SUIT_STORAGE_NORDIC_CELL_ADDRESS;
const struct device *fdev = SUIT_PLAT_INTERNAL_NVM_DEV;
suit_plat_err_t ret = SUIT_PLAT_SUCCESS;
int err = 0;

if (!device_is_ready(fdev)) {
return SUIT_PLAT_ERR_HW_NOT_READY;
}

switch (domain) {
case SUIT_MANIFEST_DOMAIN_APP:
/* Clear regular entry, inluding NVV and NVV backup. */
err = flash_erase(fdev,
suit_plat_mem_nvm_offset_get((uint8_t *)&app_storage->app_area),
sizeof(app_storage->app_area));
if (err == 0) {
/* Clear MPI backup. */
err = flash_erase(fdev,
suit_plat_mem_nvm_offset_get(
(uint8_t *)&nordic_storage->nordic.app_mpi_bak),
sizeof(nordic_storage->nordic.app_mpi_bak));
}

/* Clear reports (incl. recovery flag and update candidate info). */
ret = suit_storage_report_clear(0);
break;

case SUIT_MANIFEST_DOMAIN_RAD:
/* Clear regular entry. */
err = flash_erase(fdev,
suit_plat_mem_nvm_offset_get((uint8_t *)&rad_storage->rad_area),
sizeof(rad_storage->rad_area));
if (err == 0) {
/* Clear MPI backup. */
err = flash_erase(fdev,
suit_plat_mem_nvm_offset_get(
(uint8_t *)&nordic_storage->nordic.rad_mpi_bak),
sizeof(nordic_storage->nordic.rad_mpi_bak));
}
break;

case SUIT_MANIFEST_DOMAIN_NORDIC_CELL:
/* Clear regular entry. */
err = flash_erase(fdev,
suit_plat_mem_nvm_offset_get((uint8_t *)&cell_storage->nordic_cell.cellfw),
sizeof(cell_storage->nordic_cell.cellfw));
#if 0 /* No backup for CellFW */
if (err == 0) {
/* Clear MPI backup. */
err = flash_erase(fdev,
suit_plat_mem_nvm_offset_get(
(uint8_t *)&nordic_storage->nordic.rad_mpi_bak),
sizeof(nordic_storage->nordic.rad_mpi_bak));
}
#endif
break;

default:
return SUIT_PLAT_ERR_INVAL;
}

/* Reinitialize SUIT storage internal structures.
* Ignore return code as an init failure on erased SUIT storage area
* does not indicate that the purge failed.
*/
(void)suit_storage_init();

/* In case of IO error, ignore the suit processor return code. */
if (err != 0) {
return SUIT_PLAT_ERR_IO;
}

return ret;
}

0 comments on commit 6145ae8

Please sign in to comment.