Skip to content

Commit

Permalink
fby3.5: bb: Optimize CPLD update (facebook#268)
Browse files Browse the repository at this point in the history
Summary:
- Modify struct variable name.
- Define delay time.
- Define LSB to MSB function and add explaining comment.

Pull Request resolved: facebook#268

Test Plan:
- Build code: Pass
- Update CPLD: Pass

Log:
1. Check update CPLD is successful.
root@bmc-oob:~# fw-util slot1 --version bb_cpld
BB CPLD Version: 00030E05
BB CPLD Version After activation: 00030E05
root@bmc-oob:~# fw-util slot1 --force --update bb_cpld Y35CBB_E06.rpd
Failed to get board revision ID
slot_id: 1, comp: f, intf: 0, img: Y35CBB_E06.rpd, force: 1
Set fan mode to manual and set PWM to 70%
OnChip Flash Status = 0xFFFFFE00., slot_id 0x1, sectype 0x1, intf: 0x10, read 143360 bytes.
Erase sector SUCCESS.
Erase sector SUCCESS.
updated cpld: 100 %
Elapsed time:  57   sec.
Set fan mode to auto and start fscd
Force upgrade of slot1 : bb_cpld succeeded

root@bmc-oob:~# power-util sled-cycle
packet_write_wait: Connection to 192.168.88.24 port 22: Broken pipe

root@bmc-oob:~# fw-util slot1 --version bb_cpld
BB CPLD Version: 00030E06
BB CPLD Version After activation: 00030E06

Reviewed By: garnermic

Differential Revision: D36076646

Pulled By: GoldenBug

fbshipit-source-id: 931efefe0ccc65a89afb65e2ae09b0a59a0d23d6
  • Loading branch information
SaraLin-wiwynn committed May 11, 2022
1 parent 1ec7239 commit e2bcbeb
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions common/dev/altera.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
#include "hal_i2c.h"

#define MAX_RETRY 3
#define CHECK_ALTERA_STATUS_DELAY_US 100

// Change bit 1010 1010b(0xaa) and 0101 0101b (0x55)
// e.g. 0123 4567 -> 1032 5476
// Change bit 1100 1100b(0xcc) and 0011 0011b(0x33)
// e.g. 1032 5476 -> 3210 7654
// Change bit 1111 0000b(0xf0) and 0000 1111b(0x0f)
// e.g. 3210 7654 -> 7654 3210
#define SWAP_LSB_TO_MSB(x) \
x = (((x & 0xaa) >> 1) | ((x & 0x55) << 1)); \
x = (((x & 0xcc) >> 2) | ((x & 0x33) << 2)); \
x = (((x & 0xf0) >> 4) | ((x & 0x0f) << 4));

static altera_max10_attr altera_max10_config;

Expand Down Expand Up @@ -157,12 +169,7 @@ int cpld_altera_max10_fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg)

// Swap LSB with MSB before write into CFM
for (byte = 0; byte < 4; byte++) {
receive_buffer[byte] = (((receive_buffer[byte] & 0xaa) >> 1) |
((receive_buffer[byte] & 0x55) << 1));
receive_buffer[byte] = (((receive_buffer[byte] & 0xcc) >> 2) |
((receive_buffer[byte] & 0x33) << 2));
receive_buffer[byte] = (((receive_buffer[byte] & 0xf0) >> 4) |
((receive_buffer[byte] & 0x0f) << 4));
SWAP_LSB_TO_MSB(receive_buffer[byte]);
}

// Combine 4 bytes to 1 word before write operation
Expand All @@ -186,7 +193,7 @@ int cpld_altera_max10_fw_update(uint32_t offset, uint16_t msg_len, uint8_t *msg)

} else {
printf("status: %x retry...\n", status);
k_usleep(100);
k_usleep(CHECK_ALTERA_STATUS_DELAY_US);
retry--;
}

Expand Down

0 comments on commit e2bcbeb

Please sign in to comment.