Commit bd1726df authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

Merge branch 'adam-monimod' into 'master'

monimod fantray support

See merge request !3
parents c15c7481 70cd1c1a
Pipeline #3945 passed with stage
in 42 minutes and 31 seconds
......@@ -83,7 +83,7 @@ index 15f95dd4488c..2d9fef5c5300 100644
}
static const struct i2c_device_id monimod_id[] = {
@@ -62,6 +90,134 @@ static struct i2c_driver monimod_driver = {
@@ -62,6 +90,133 @@ static struct i2c_driver monimod_driver = {
module_i2c_driver(monimod_driver);
......@@ -105,14 +105,13 @@ index 15f95dd4488c..2d9fef5c5300 100644
+ NULL, "%llx\n");
+
+
+static int monimod_debugfs_get_dword(void *data, u64 *val)
+static int monimod_debugfs_get_block_dword(void *data, u64 *val)
+{
+ int rc;
+ struct pmbus_debugfs_entry *entry = data;
+ u8 tmp[4];
+
+ rc = i2c_smbus_read_i2c_block_data(entry->client, entry->reg,
+ sizeof(tmp), tmp);
+ rc = i2c_smbus_read_block_data(entry->client, entry->reg, tmp);
+ if (rc < 0)
+ return rc;
+
......@@ -120,8 +119,8 @@ index 15f95dd4488c..2d9fef5c5300 100644
+
+ return 0;
+}
+DEFINE_DEBUGFS_ATTRIBUTE(monimod_debugfs_ops_get_dword,
+ monimod_debugfs_get_dword, NULL, "%lld\n");
+DEFINE_DEBUGFS_ATTRIBUTE(monimod_debugfs_ops_get_block_dword,
+ monimod_debugfs_get_block_dword, NULL, "%lld\n");
+
+static ssize_t monimod_debugfs_get_fw_type(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
......@@ -189,14 +188,14 @@ index 15f95dd4488c..2d9fef5c5300 100644
+ entries[idx].reg = MONIMOD_REG_UPTIME_SECS;
+ debugfs_create_file("uptime_secs", 0444, monimod_dir,
+ &entries[idx++],
+ &monimod_debugfs_ops_get_dword);
+ &monimod_debugfs_ops_get_block_dword);
+
+ /* Create debugfs entry for tmr_error_cnt */
+ entries[idx].client = client;
+ entries[idx].reg = MONIMOD_REG_TMR_ERROR_CNT;
+ debugfs_create_file("tmr_error_cnt", 0444, monimod_dir,
+ &entries[idx++],
+ &monimod_debugfs_ops_get_dword);
+ &monimod_debugfs_ops_get_block_dword);
+
+ /* Create debugfs entry for use_pec */
+ entries[idx].client = client;
......
From a0662987d13c464ba98f1cc5582a4d4657a8740c Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Mon, 4 Jul 2022 19:43:07 +0200
Subject: [PATCH] hwmon: (monimod) check PMBUS_MFR_MODEL at load
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
drivers/hwmon/pmbus/monimod.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/drivers/hwmon/pmbus/monimod.c b/drivers/hwmon/pmbus/monimod.c
index 7cf7430b0998..501bfdea5145 100644
--- a/drivers/hwmon/pmbus/monimod.c
+++ b/drivers/hwmon/pmbus/monimod.c
@@ -25,6 +25,8 @@
#define MONIMOD_FW_TYPE_BOOTLOADER 1
#define MONIMOD_FW_TYPE_MAIN 2
+#define MONIMOD_MFR_MODEL_MAIN_FW "DI/OT MoniMod"
+#define MONIMOD_MFR_MODEL_BOOTLOADER "DI/OT MoniMod (bl)"
#define MONIMOD_REG_BOOT_NEW_FW 0xD5
#define MONIMOD_REG_UPTIME_SECS 0xD7
@@ -59,15 +61,44 @@ static int monimod_probe(struct i2c_client *client,
{
int ret;
int probe_ret;
+ u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
probe_ret = pmbus_do_probe(client, id, &monimod_info);
+
+ ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer);
+ if (ret < 0) {
+ dev_err(&client->dev, "Failed to read Manufacturer MODEL\n");
+ return ret;
+ }
+
+ block_buffer[ret] = '\0';
+ /* Check first if the monimod is in bootloader mode, to give more
+ * descriptive information */
+ if (!strcmp(block_buffer, MONIMOD_MFR_MODEL_BOOTLOADER)) {
+ dev_err(&client->dev, "Monimod in the bootloader mode, refuse "
+ "to register. Please switch to main mode.\n");
+ return -ENODEV;
+ }
+
+ /* In bootloader mode, STATUS_BYTE does not exists. Give a hint about
+ * bootloader mode (above) before failing. */
if (probe_ret < 0)
return probe_ret;
+ /* Check first if MFR model match */
+ if (ret != strlen(MONIMOD_MFR_MODEL_MAIN_FW)
+ || strcmp(block_buffer, MONIMOD_MFR_MODEL_MAIN_FW)) {
+ dev_err(&client->dev, "Unsupported Manufacturer Model. "
+ "Read %s, Expected %s\n", block_buffer,
+ MONIMOD_MFR_MODEL_MAIN_FW);
+ return -ENODEV;
+ }
ret = monimod_debugfs(client);
if (ret)
dev_warn(&client->dev, "Failed to register debugfs\n");
+ dev_info(&client->dev, "Registered Monimod\n");
+
return probe_ret;
}
--
2.17.1
From 40e05200593af06633f64ab0effff052eee6f076 Mon Sep 17 00:00:00 2001
From: Mans Rullgard <mans@mansr.com>
Date: Sat, 13 Jun 2020 11:41:09 +0100
Subject: [PATCH] i2c: core: check returned size of emulated smbus block read
If the i2c bus driver ignores the I2C_M_RECV_LEN flag (as some of
them do), it is possible for an I2C_SMBUS_BLOCK_DATA read issued
on some random device to return an arbitrary value in the first
byte (and nothing else). When this happens, i2c_smbus_xfer_emulated()
will happily write past the end of the supplied data buffer, thus
causing Bad Things to happen. To prevent this, check the size
before copying the data block and return an error if it is too large.
Fixes: 209d27c3b167 ("i2c: Emulate SMBus block read over I2C")
Signed-off-by: Mans Rullgard <mans@mansr.com>
[wsa: use better errno]
Signed-off-by: Wolfram Sang <wsa@kernel.org>
---
drivers/i2c/i2c-core-smbus.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/i2c/i2c-core-smbus.c b/drivers/i2c/i2c-core-smbus.c
index 56bb840142e3..f5c9787992e9 100644
--- a/drivers/i2c/i2c-core-smbus.c
+++ b/drivers/i2c/i2c-core-smbus.c
@@ -495,6 +495,13 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter *adapter, u16 addr,
break;
case I2C_SMBUS_BLOCK_DATA:
case I2C_SMBUS_BLOCK_PROC_CALL:
+ if (msg[1].buf[0] > I2C_SMBUS_BLOCK_MAX) {
+ dev_err(&adapter->dev,
+ "Invalid block size returned: %d\n",
+ msg[1].buf[0]);
+ status = -EPROTO;
+ goto cleanup;
+ }
for (i = 0; i < msg[1].buf[0] + 1; i++)
data->block[i] = msg[1].buf[i];
break;
--
2.17.1
From 314e1aae7a9ec863dc09e0529ff1c5f1f7bc20b0 Mon Sep 17 00:00:00 2001
From: Adam Wujek <dev_public@wujek.eu>
Date: Fri, 1 Jul 2022 01:31:07 +0200
Subject: [PATCH] fdt_support: add uboot version to FDT
Under /chosen/uboot_version
Signed-off-by: Adam Wujek <dev_public@wujek.eu>
---
common/fdt_support.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 2b3f811bbd..630fe3ebc5 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -16,6 +16,7 @@
#include <fdt_support.h>
#include <exports.h>
#include <fdtdec.h>
+#include <version.h>
/**
* fdt_getprop_u32_default_node - Return a node's property or a default
@@ -332,6 +333,14 @@ int fdt_chosen(void *fdt)
}
}
+ err = fdt_setprop(fdt, nodeoffset, "uboot_version", PLAIN_VERSION,
+ strlen(PLAIN_VERSION) + 1);
+ if (err < 0) {
+ printf("WARNING: could not set uboot_version %s.\n",
+ fdt_strerror(err));
+ return err;
+ }
+
return fdt_fixup_stdout(fdt, nodeoffset);
}
--
2.17.1
......@@ -34,6 +34,7 @@
#define DTB_MODEBOOT_FILE "/sys/firmware/devicetree/base/chosen/modeboot"
#define DTB_UIMAGE_SOURCE_FILE "/sys/firmware/devicetree/base/chosen/uimage_source"
#define DTB_RESET_REASON_FILE "/sys/firmware/devicetree/base/chosen/reset_reason"
#define DTB_UBOOT_VERSION_FILE "/sys/firmware/devicetree/base/chosen/uboot_version"
#define READLINE_PROMPT "diot_util> "
......@@ -113,12 +114,15 @@ int cmd_help(char *params)
int cmd_version(char *params)
{
char buff[100];
printf("diot_util version information:\n");
printf("HW version: %d\n", SB_VER);
printf("GIT commit id: %s\n", __GIT_VER__);
printf("Build date: %s\n", __DATE__);
printf("Build time: %s\n", __TIME__);
printf("Built by: %s\n", __GIT_USR__);
printf("Uboot version: %s\n", get_file_content(DTB_UBOOT_VERSION_FILE, buff, sizeof(buff)));
return 0;
}
......
......@@ -28,6 +28,8 @@
#include "util.h"
#define FANTRAY_FW_MAX_SIZE 0x3E000
#define UC_RESET_MAGIC 0x5A
#define BOOT_NEW_FW_MAGIC 0xAD
static int cmd_fantray_status(char *params);
static int cmd_fantray_reset(char *params);
......@@ -113,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);
......@@ -124,7 +127,21 @@ static int fantray_i2c_reset(void)
goto out;
}
ret = i2c_smbus_write_byte_data(i2c_file, FANTRAY_I2C_REG_RESET, 1);
/* 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);
out:
close(i2c_file);
......@@ -512,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();
......@@ -581,14 +599,34 @@ 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,
1);
BOOT_NEW_FW_MAGIC);
if (ret < 0) {
printf("Error: unable to set boot mode of the Fantray!\n");
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 */
......@@ -616,7 +654,8 @@ static int cmd_fantray_load_fw(char *params)
printf("Switching Fantray to main firmware mode\n");
/* Switch to main firmware */
ret = i2c_smbus_write_byte_data(i2c_file, FANTRAY_I2C_REG_BOOT_NEW_FW, 1);
ret = i2c_smbus_write_byte_data(i2c_file, FANTRAY_I2C_REG_BOOT_NEW_FW,
BOOT_NEW_FW_MAGIC);
if (ret < 0) {
printf("Error: unable to set the boot mode of the Fantray!\n");
goto close_i2c;
......
......@@ -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
......
# Remove run-time dependency of python3-pycparser on cpp and cpp-symlinks
#
# python3-pytest depends on python3-attrs->python3-cryptography->python3-pycparser
# but features used in pytest do not need cpp nor cpp-symlinks.
# This reduces the size of rootfs image by ~8MB
RDEPENDS_${PN}_remove = "cpp cpp-symlinks "
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