Skip to content

Commit

Permalink
Faster BIOS flashing
Browse files Browse the repository at this point in the history
Summary:
With this change we are making use of the strong (SHA256) BIOS checksum
calculation introduced in BIC fw 31.04: blocks won't be flashed if the
checksum matches. Upwards of 50% of blocks remain the same between BIOS
version, so this speeds up flashing quite a bit.

We also use larger USB blocks (also introduced in 31.04).

Graceful fallback to non-deduping is provided so this still works
with older BIC version:
if strong checksums are available, then it will perform deduplication by default (can still turn off with DEDUP=0 env variable).
if strong checksums are not available, it will fall back to weak and turn off dedup (can force it with DEDUP=2 if you want to take the risk).

Also provided is ability to turn off verification (with VERIFY=0) - will save a few seconds of flashing, can be useful to speed up dev cycle.

Test Plan:
Baseline: 12m17.122s (P151555168)
With dedup: 3m 38.52s (P151558354)
Without dedup (fallback for older BIC versions): 11m 55.38s (P151557710)

Reviewed By: benwei13

fbshipit-source-id: e68605a95e
  • Loading branch information
rojer9-fb authored and facebook-github-bot committed Dec 8, 2020
1 parent a078a2e commit 08732aa
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ int BiosComponent::update_internal(const std::string &image, bool force) {
me_recovery(slot_id, RECOVERY_MODE);
cerr << "Enabling USB..." << endl;
bic_set_gpio(slot_id, RST_USB_HUB_N, GPIO_HIGH);
sleep(3);
sleep(1);
cerr << "Switching BIOS SPI MUX for update..." << endl;
bic_switch_mux_for_bios_spi(slot_id, MUX_SWITCH_CPLD);
sleep(1);
ret = bic_update_fw(slot_id, fw_comp, (char *)image.c_str(), FORCE_UPDATE_UNSET);
cerr << "Disabling USB..." << endl;
bic_set_gpio(slot_id, RST_USB_HUB_N, GPIO_LOW);
if (ret != 0) {
return -1;
}
Expand All @@ -64,8 +66,6 @@ int BiosComponent::update_internal(const std::string &image, bool force) {
pal_set_server_power(slot_id, SERVER_12V_CYCLE);
sleep(5);
pal_set_server_power(slot_id, SERVER_POWER_ON);
cerr << "Disabling USB..." << endl;
bic_set_gpio(slot_id, RST_USB_HUB_N, GPIO_LOW);
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,42 @@ bic_get_fw_cksum(uint8_t slot_id, uint8_t target, uint32_t offset, uint32_t len,
return ret;
}

struct bic_get_fw_cksum_sha256_req {
uint8_t iana_id[3];
uint8_t target;
uint32_t offset;
uint32_t length;
} __attribute__((packed));

struct bic_get_fw_cksum_sha256_res {
uint8_t iana_id[3];
uint8_t cksum[32];
} __attribute__((packed));

int
bic_get_fw_cksum_sha256(uint8_t slot_id, uint8_t target, uint32_t offset, uint32_t len, uint8_t *cksum) {
int ret;
struct bic_get_fw_cksum_sha256_req req = {
.iana_id = {0x9c, 0x9c, 0x00},
.target = target,
.offset = offset,
.length = len,
};
struct bic_get_fw_cksum_sha256_res res = {0};
uint8_t rlen = sizeof(res);

ret = bic_ipmb_wrapper(slot_id, NETFN_OEM_1S_REQ, BIC_CMD_OEM_FW_CKSUM_SHA256, (uint8_t *) &req, sizeof(req), (uint8_t *) &res, &rlen);
if (ret != 0) {
return -1;
}
if (rlen != sizeof(res)) {
return -2;
}

memcpy(cksum, res.cksum, sizeof(res.cksum));

return 0;
}

static int
verify_bios_image(uint8_t slot_id, int fd, long size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ extern "C" {

int print_configuration(struct libusb_device_handle *hDevice,struct libusb_config_descriptor *config);
int active_config(struct libusb_device *dev,struct libusb_device_handle *handle);
int bic_get_fw_cksum(uint8_t slot_id, uint8_t target, uint32_t offset, uint32_t len, uint8_t *ver);
int bic_get_fw_cksum(uint8_t slot_id, uint8_t target, uint32_t offset, uint32_t len, uint8_t *cksum);
int bic_get_fw_cksum_sha256(uint8_t slot_id, uint8_t target, uint32_t offset, uint32_t len, uint8_t *cksum);
int update_bic_bios(uint8_t slot_id, uint8_t comp, char *image, uint8_t force);
int update_bic_usb_bios(uint8_t slot_id, uint8_t comp, char *image);

Expand Down
Loading

0 comments on commit 08732aa

Please sign in to comment.