| 244 | #endif |
| 245 | |
| 246 | Util::FlashBootloader Util::flash_bootloader() |
| 247 | { |
| 248 | uint32_t fw_size; |
| 249 | const char *fw_name = "bootloader.bin"; |
| 250 | |
| 251 | EXPECT_DELAY_MS(11000); |
| 252 | |
| 253 | const uint8_t *fw = AP_ROMFS::find_decompress(fw_name, fw_size); |
| 254 | if (!fw) { |
| 255 | Debug("failed to find %s\n", fw_name); |
| 256 | return FlashBootloader::NOT_AVAILABLE; |
| 257 | } |
| 258 | |
| 259 | #if AP_SIGNED_FIRMWARE |
| 260 | if (!AP_CheckFirmware::check_signed_bootloader(fw, fw_size)) { |
| 261 | // don't allow flashing of an unsigned bootloader in a secure |
| 262 | // setup. This prevents the easy mistake of leaving an |
| 263 | // unsigned bootloader in ROMFS, which would give a trivail |
| 264 | // way to bypass signing |
| 265 | AP_ROMFS::free(fw); |
| 266 | return FlashBootloader::NOT_SIGNED; |
| 267 | } |
| 268 | #endif |
| 269 | |
| 270 | // make sure size is multiple of 32 |
| 271 | fw_size = (fw_size + 31U) & ~31U; |
| 272 | |
| 273 | bool uptodate = true; |
| 274 | const uint32_t addr = hal.flash->getpageaddr(0); |
| 275 | |
| 276 | if (memcmp(fw, (const void*)addr, fw_size) != 0) { |
| 277 | uptodate = false; |
| 278 | } |
| 279 | |
| 280 | #if HAL_ENABLE_SAVE_PERSISTENT_PARAMS |
| 281 | // see if we should store persistent parameters along with the |
| 282 | // bootloader. We only do this on boards using a single sector for |
| 283 | // the bootloader. The persistent parameters are stored as text at |
| 284 | // the end of the sector |
| 285 | const int32_t space_available = hal.flash->getpagesize(0) - int32_t(fw_size); |
| 286 | ExpandingString persistent_params {}, old_persistent_params {}; |
| 287 | if (get_persistent_params(persistent_params) && |
| 288 | space_available >= persistent_params.get_length() && |
| 289 | (!load_persistent_params(old_persistent_params) || |
| 290 | strcmp(persistent_params.get_string(), |
| 291 | old_persistent_params.get_string()) != 0)) { |
| 292 | // persistent parameters have changed, we will update |
| 293 | // bootloader to allow storage of the params |
| 294 | uptodate = false; |
| 295 | } |
| 296 | #endif |
| 297 | |
| 298 | if (uptodate) { |
| 299 | Debug("Bootloader up-to-date\n"); |
| 300 | AP_ROMFS::free(fw); |
| 301 | return FlashBootloader::NO_CHANGE; |
| 302 | } |
| 303 |
nothing calls this directly
no test coverage detected