目录
1.安全启动模式回顾
2.为什么要讨论BOOT_MAC
3.S32K1如何更新?
1.安全启动模式回顾
Paraller Secure Boot:CSEc模块执行“安全启动”程序,同时用户应用程序也运行;值得一提的是,如果验证失败,应用程序不会停止,只是用户无法使用设置了BOOT_PROT属性的密钥; Sequential Secure Boot:CSEc先执行“安全启动”程序,验证成功后才会释放Host Core执行用户程序;当然如果验证失败,Sanction与并行启动一致; Strict Boot:所谓严苛的启动,就是在顺序启动基础上,新增了验证失败后CPU一直复位的Sanction。并且一旦配置了该启动模式,就不可逆了。
2.为什么要讨论BOOT_MAC
3.S32K1如何更新?
手动添加BOOT_MAC CSEc自动添加BOOT_MAC
导入BOOT_MAC_KEY到CSEc模块中的Secure NVM(其他Key也可同步导入); 送CMD_BOOT_DEFINE或者调用SDK API -- BOOT_DEFINE来定义需要计算MAC的Flash空间、定义启动模式; 使用BOOT_MAC_KEY计算上述Flash空间的MAC,可以通过加载RAM_KEY的方式进行计算; 将计算好的MAC加载到BOOT_MAC槽位中; 复位设备,CSEc会进行MAC匹配,通过FCSESTAT.BOK = 1可判断安全启动是否成功。
/* Step-2 Define the secure boot flavor and the BOOT_SIZE*/ csec_error = BOOT_DEFINE(128*1024*8, 1); /* ----- For Automatic BOOT_MAC generation stop execution here and reset the part twice for automatic BOOT_MAC generation and verification ----- */ /* ----- For Manually set-up BOOT_MAC continue with the following steps ----- */ /* Step-3 Calculate the CMAC using RAM_KEY feature of the CSEc */ /*Load BOOT_MAC_KEY into RAM_KEY slot */ csec_error = LOAD_RAM_KEY(BOOT_MAC_KEY_VALUE); /*Generate MAC for first 128kB data starting at memory address 0x0. */ uint32_t *flash_pointer = (uint32_t *)(0x00000000); csec_error = MAC_SECURE_BOOT(boot_mac, flash_pointer, RAM_KEY, 128*1024*8); /* Step-4 Store BOOT_MAC at secure location */ calculate_M1_to_M5(M1, M2, M3, M4, M5, MASTER_ECU_KEY_VALUE, boot_mac, MASTER_ECU_KEY, BOOT_MAC, 1, 0); /* Calculate M1 to M5 in Software, Authorizing Key = Master ECU Key */ csec_error = LOAD_KEY(M4_out, M5_out, M1, M2, M3, BOOT_MAC); /* Load the key using M1 to M3, returns M4 and M5 */
CSE_PRAM->RAMn[4].DATA_32 = 0;
CSE_PRAM->RAMn[5].DATA_32 = 0;
CSE_PRAM->RAMn[6].DATA_32 = 0;
CSE_PRAM->RAMn[7].DATA_32 = message_length;
CSEc密钥槽中的所有密钥没有设置写保护属性,可以重新擦除该区域恢复到出厂设置,然后按照首次添加BOOT_MAC进行更新,广泛用于开发阶段; CSEc密钥槽任一或者多个密钥设置写保护属性,根据协议要求,该属性不可逆,密钥也不能再修改,因此只能将BOOT_MAC_KEY加载到RAM_KEY区域,然后进行计算;或者通过离线计算再根据协议进行BOOT_MAC的更新即可,一般用于ECU量产阶段。