Commit 1a673a47 authored by Adam Wujek's avatar Adam Wujek

sw/petalinux/diot-util: use PEC for monimod if enabled

Signed-off-by: 's avatarAdam Wujek <dev_public@wujek.eu>
parent e6e095b3
......@@ -115,6 +115,7 @@ static int fantray_i2c_reset(void)
{
int i2cbus, i2c_file;
int ret = 0;
int use_pec;
i2cbus = atoi(FANTRAY_I2C);
i2c_file = open_i2c_dev(i2cbus);
......@@ -126,6 +127,19 @@ static int fantray_i2c_reset(void)
goto out;
}
/* If PEC is used by Monimod, it has to be used here too, otherwise writes
* are silently rejected */
/* Read PEC */
use_pec = i2c_smbus_read_byte_data(i2c_file, FANTRAY_I2C_REG_PEC);
if (use_pec > 0) {
/* PEC enabled, use it */
if (ioctl(i2c_file, I2C_PEC, 1) < 0) {
printf("Error: Could not set PEC: %s\n", strerror(errno));
} else {
printf("Using PEC\n");
}
}
ret = i2c_smbus_write_byte_data(i2c_file, FANTRAY_I2C_REG_RESET,
UC_RESET_MAGIC);
......@@ -515,6 +529,7 @@ static int cmd_fantray_load_fw(char *params)
char *p;
FILE *fw_file = NULL;
int errno_local;
int use_pec;
diot_error_clear();
......@@ -584,6 +599,20 @@ static int cmd_fantray_load_fw(char *params)
if (ret == FANTRAY_FW_TYPE_MAIN) {
printf("Fantray in main mode. Switching to bootloader mode\n");
/* If PEC is used by Monimod, it has to be used here too otherwise
* writes are silently rejected */
/* Read PEC */
use_pec = i2c_smbus_read_byte_data(i2c_file, FANTRAY_I2C_REG_PEC);
if (use_pec > 0) {
/* PEC enabled, use it */
if (ioctl(i2c_file, I2C_PEC, 1) < 0) {
printf("Error: Could not set PEC: %s\n", strerror(errno));
use_pec = 0;
} else {
printf("Using PEC\n");
}
}
/* Switch to boot loader */
ret = i2c_smbus_write_byte_data(i2c_file, FANTRAY_I2C_REG_BOOT_NEW_FW,
BOOT_NEW_FW_MAGIC);
......@@ -592,6 +621,12 @@ static int cmd_fantray_load_fw(char *params)
goto close_i2c;
}
/* Disable PEC if was enabled */
if (use_pec > 0 && ioctl(i2c_file, I2C_PEC, 0) < 0) {
printf("Error: Could not set PEC: %s\n", strerror(errno));
use_pec = 0;
}
/* Let the bootloader to start */
sleep(2);
/* Confirm that bootloader is started */
......
......@@ -36,6 +36,7 @@
#define FANTRAY_I2C_REG_LOCAL_FW_CHKSUM 0xD4
#define FANTRAY_I2C_REG_BOOT_NEW_FW 0xD5
#define FANTRAY_I2C_REG_RESET 0xD6
#define FANTRAY_I2C_REG_PEC 0xD9
#define FANTRAY_FW_TYPE_BOOTLOADER 0x1
#define FANTRAY_FW_TYPE_MAIN 0x2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment