-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: firmware: scmi: add optional crc #86347
base: main
Are you sure you want to change the base?
drivers: firmware: scmi: add optional crc #86347
Conversation
Hello @AndreHeinemans-NXP, and thank you very much for your first pull request to the Zephyr project! |
de53e5e
to
2a78a31
Compare
c4326d1
to
0d87b9d
Compare
@@ -17,6 +17,7 @@ CONFIG_CONSOLE=y | |||
CONFIG_MBOX=y | |||
CONFIG_MBOX_INIT_PRIORITY=0 | |||
CONFIG_ARM_SCMI=y | |||
CONFIG_ARM_SCMI_SHMEM_USE_CRC=y | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will enable mandatory CRC validation for all applications on imx95_m7 using ddr config. So this will break any application which doesn't encode the CRC.
e.g sound open firmware: https://github.com/thesofproject/sof/blob/main/app/boards/imx95_evk_mimx9596_m7_ddr.conf
I don't think we should add this kind of checks in the scmi core itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default the imx-sm does enable CRC, hence this PR to make Zephyr actually work with the "Hello world" example.
See imx-sm source
https://github.com/nxp-imx/imx-sm/blob/a07928b4a69e092667c3c2dc61adc36b5eaaf836/configs/mx95evk.cfg#L335
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not mandatory since you can override this setting in the application. All applications who do not need it only have to add 'CONFIG_ARM_SCMI_SHMEM_USE_CRC=n' to their config.
The reason that I enabled it by default on the imx95_evk is that system-manager (imx-sm) also has it enabled by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's unreasonable to ask applications to know about CONFIG_ARM_SCMI_SHMEM_USE_CRC and disable it.
I think your particular application should explicitly enable it.
AFAIK I understand your first end goal is to make default "Hello World" sample to work on M7 with the default imx-sm config.
Looks like we have a conflict here. Allow me some time to better understand the context and then decide on a solution that works for everyone.
PRs are blocked for 4.2 so we do have some time until we can merge this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enabling CRC by default in Zephyr effectively breaks all upstream applications counting on the fact that it's disabled (e.g: SOF, CC: @yangbolu1991 this might affect you as well). Apart from that, you're enabling a feature which you arguably don't need for your application.
IMO this can be solved by updating the documentation (i.e: https://docs.zephyrproject.org/latest/boards/nxp/imx95_evk/doc/index.html) to tell people which configuration requires CRC and which doesn't. I can just as fine run "Hello, world" using ALT config without changing anything on Zephyr-side.
drivers/firmware/scmi/shmem.c
Outdated
@@ -96,6 +97,14 @@ int scmi_shmem_read_message(const struct device *shmem, struct scmi_message *msg | |||
return -EINVAL; | |||
} | |||
|
|||
#ifdef CONFIG_ARM_SCMI_SHMEM_USE_CRC | |||
/* crc match? */ | |||
if (layout->res1[1] != crc32_ieee((const uint8_t *)&layout->msg_hdr, layout->len)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't introduce vendor-specific processing inside the SCMI core. If you need to do some additional processing inside the shared memory read/write functions I'd suggest adding 2 new functions: scmi_shmem_vendor_write_message()
and scmi_shmem_vendor_read_message()
and calling them from the core. If the vendor needs extra processing they should implement those functions in drivers/firmware/scmi/vendor/<vendor_name>/shmem.c
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saying but it was never working to begin with.......
Does this even get actively tested with CI at all?
Also recompiling imx-sm is a bit of pain anyhow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LaurentiuM1234
I added the nxp specific code in the driver/firmware/scmi/nxp/shmem.c file which only contains the functions scmi_shmem_vendor_validate_message() and scmi_shmem_vendor_prepare_message(). This file will only be built when CONFIG_ARM_SCMI_SHMEM_VENDOR_NXP is configured and will override the existing empty functions.
For i.mx95, crc was disabled in mx95alt.cfg, which used for m7 tests. But I'm not sure if there are any cases requiring CRC. If so, I think it should be documented. |
0d87b9d
to
4eada1f
Compare
21efab8
to
dea3547
Compare
@AndreHeinemans-NXP @PetervdPerk-NXP Would this work for you? Looks like CRC is disabled with newer configurations. |
dea3547
to
51d08a8
Compare
@dbaluta, @LaurentiuM1234 , |
In principle, I agree with this PR. It is clean enough to not touch the SCMI core and by default the check is disabled and only activated in specific scenarios. Will need to get an Ack from @LaurentiuM1234 and we can merge it. |
Thanks this patch allows me to use Zephyr on the IMX95-EVK, I tried before but couldn't even get hello world to show up till this patch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually NXP uses two of the SCMI SMT “implementation defined” words, it is res1[2] in the code, the first one holds the status that indicate if CRC is being used and which algorithm is used, and the second one is the CRC. so we need to check first word firstly and then decide use CRC or not, and also decide which CRC algorithm is used. so that the driver will be compatible for all SM firmware with CRC enabled or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as @JiafeiPan pointed out, res1[0]
holds the CRC type (algorithm) used and if CRC is enabled. We can use this to dynamically check if CRC is enabled/disabled and which algorithm to use. This way, we can have the CRC NXP vendor extension enabled by default, thus allowing people to use whatever SM configuration they want.
drivers/firmware/scmi/nxp/shmem.c
Outdated
|
||
LOG_MODULE_REGISTER(arm_scmi_shmem_nxp); | ||
|
||
int scmi_shmem_vendor_validate_message(const struct scmi_shmem_layout *layout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can use a more generic name for these functions? e.g: scmi_shmem_vendor_write_message
and scmi_shmem_vendor_read_message
. We don't really know what other vendors do with the implementation-defined bits.
drivers/firmware/scmi/nxp/shmem.c
Outdated
void scmi_shmem_vendor_prepare_message(struct scmi_shmem_layout *layout) | ||
{ | ||
#ifdef CONFIG_ARM_SCMI_SHMEM_USE_CRC | ||
layout->res1[1] = crc32_ieee((const uint8_t *)&layout->msg_hdr, layout->len); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRC32 is one of the CRCs supported by SM. You'll most likely have to check the value of res1[0]
to see which CRC type SM expects.
Only supporting CRC32 right now is alright but at least check the value of res1[0]
and return an error code if SM expects an unsupported CRC type?
drivers/firmware/scmi/Kconfig
Outdated
help | ||
When enabled, additional SCMI features specific to NXP will be available | ||
|
||
config ARM_SCMI_SHMEM_USE_CRC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe put vendor-specific configurations inside their own Kconfigs? e.g: drivers/firmware/scmi/nxp/Kconfig
drivers/firmware/scmi/Kconfig
Outdated
@@ -48,6 +48,19 @@ config ARM_SCMI_SHMEM_INIT_PRIORITY | |||
help | |||
SCMI SHMEM driver device initialization priority. | |||
|
|||
config ARM_SCMI_SHMEM_VENDOR_NXP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest making this more generic: CONFIG_ARM_SCMI_NXP_VENDOR_EXTENSIONS
. Using this, we can have a distributed approach with our Kconfig and CMakeLists.txt files (i.e: each vendor can have its own Kconfig with their own vendor-specific configurations and a CMakeLists.txt file for adding source files based on their own configurations).
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
struct scmi_shmem_layout { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this whole header file can probably be moved to ./include/zephyr/drivers/firmware/scmi/shmem.h
. This way, we can avoid introducing another header.
An option is added to allow vendor specific processing at scmi_shmem_write_message() and scmi_shmem_read_message(). Additionally code has been added specific to NXP which has some extended validation features. Signed-off-by: Andre Heinemans <andre.heinemans@nxp.com>
01c58ac
51d08a8
to
01c58ac
Compare
Thanks for pointing this out. It's a perfect solution. I reworked all the comments. |
An option is added to validate incomming and outgoing SCMI messages on shared memory.
This is needed especially for the imx95_evk/mimx9596/m7 which is used in combination with imx-sm on the M33 core. The imx-sm software uses CRC on SCMI by default. It will be easier to start with this target because it works with the sdcard image that comes with the evk.