Skip to content
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

MCUmgr and SMP Client support #56934

Merged
merged 3 commits into from Jul 27, 2023

Conversation

jheiskan81
Copy link
Contributor

@jheiskan81 jheiskan81 commented Apr 17, 2023

MCUmgr client

MCUmgr client basic implementation for support Image and OS group commands.

Image Group:
* Image state read/write
* Image Upload secondary slot
* Image Erase secondary slot

OS group:
* Reset
* Echo service, disabled by default

Operation's are blocked call and can't call inside worker queue.
IMG and OS needs SMP client object for transport.

SMP update

SMP client:

  • SMP buffer allocation
  • SMP object init for selected SMP transport
  • SMP client support for generate request and handling response message.

SMP transport:

Updated SMP transport for trigger client packets.
API for register SMP transport object.

Unit test

Unit test for MCUmgr & SMP client.

@nordicjm nordicjm added this to In progress in mcumgr via automation Apr 17, 2023
@jheiskan81
Copy link
Contributor Author

@SeppoTakalo Please review

@jheiskan81 jheiskan81 force-pushed the mcumgr_client branch 2 times, most recently from 0580e2d to acd829b Compare April 17, 2023 10:40
include/zephyr/mgmt/mcumgr/smp/smp.h Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/smp/smp_client.h Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/transport/smp.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left few remarks

include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/transport/smp.h Outdated Show resolved Hide resolved
@SeppoTakalo
Copy link
Collaborator

Now MCUMGR client and its OS/Image operations are bundled under one module.

I wonder if it makes sense to have the generic McuMGR as a single file, then optionally enable OS, Image or some other functionality.

@jheiskan81
Copy link
Contributor Author

Now MCUMGR client and its OS/Image operations are bundled under one module.

I wonder if it makes sense to have the generic McuMGR as a single file, then optionally enable OS, Image or some other functionality.

OS Reset and Echo are used now. RESET is mandatory. I can replace echo command from Recovery mode by Read Image list command.

include/zephyr/mgmt/mcumgr/smp/smp.h Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/grp/img_mgmt/src/img_mgmt_state.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
@jheiskan81
Copy link
Contributor Author

@SeppoTakalo and @nordicjm I removed Canonical fix commit. I have updated SMP and MCUMGR client commits missing headers doxygen comment's.

@jheiskan81 jheiskan81 force-pushed the mcumgr_client branch 4 times, most recently from 9c64380 to a547fcd Compare April 19, 2023 13:15
include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
include/zephyr/mgmt/mcumgr/smp/mcumgr_client.h Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/smp.c Outdated Show resolved Hide resolved
subsys/mgmt/mcumgr/smp/src/mcumgr_client.c Outdated Show resolved Hide resolved
@jheiskan81 jheiskan81 force-pushed the mcumgr_client branch 2 times, most recently from cc1f3fc to 66f6f93 Compare April 20, 2023 11:48
@jheiskan81
Copy link
Contributor Author

jheiskan81 commented Apr 20, 2023

I have been fixed now raised item's:
SMP:

  • SMP CLIENT retry logic is updated now more dynamic and retry schedule is using exact timestamp to next retry send
  • SMP client base retry is 500ms and send operation give a total timeout now in seconds

MCUmgr client:

  • Updated Image group state read response IMAGE list parser.
  • Hash and Version size used already defined definition from image group header
  • Removed rsn unused cased
  • Removed magic number usages and optimize cbor state count's

Thanks for good feedback @nordicjm and @de-nordic.

@jheiskan81
Copy link
Contributor Author

MCUmgr client file can be splitted to own seprated groups file but I want to review main functionality first.

@jheiskan81 jheiskan81 changed the title MCUMGR and SMP Client support MCUmgr and SMP Client support Apr 20, 2023
Copy link
Collaborator

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isssues found in test:

  • Client must not respond to packets with error responses, it needs to ignore corrupt packets and handle them i.e. with retransmissions
  • Client is not removing the data from the packet and it then tries to look at an invalid packet
  • Upload does not set the image status to 0, therefore it always fails because it always has the default value of EINVAL

@nordicjm
Copy link
Collaborator

Also logging does not work, instead of having:

#define LOG_MODULE_NAME smp_client
LOG_MODULE_REGISTER(smp_client);

Use:

LOG_MODULE_REGISTER(mcumgr_client, <log_level_here_from_Kconfig>);

@jheiskan81 jheiskan81 force-pushed the mcumgr_client branch 4 times, most recently from f4ad187 to d6dcbad Compare July 26, 2023 09:03
@jheiskan81
Copy link
Contributor Author

@nordicjm Thanks for testing and reporting issues. I have fixed issues and also fix logging.

@jheiskan81
Copy link
Contributor Author

Fixed Compliance checks

Copy link
Collaborator

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 minor nits then ready for approval, thanks!

if MCUMGR_GRP_OS_CLIENT

config MCUMGR_GRP_OS_CLIENT_ECHO
default y
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No indenting in Kconfig files for if... blocks

}

smp_read_hdr(nb, &smp_header);
if (nb->len > sizeof(smp_header)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would flip this to error out if there is not at least sizeof(smp_header) to send, as that would not be valid, then the part below can be part of the main flow as it will only send packets of a minimum valid length

Juha Heiskanen added 3 commits July 27, 2023 10:35
SMP client support for generate request and handling
response message.

Updated SMP transport for send request.

Added API for register SMP transport.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
MCUmgr client basic implementation for support Image and OS grpup
commands.

Image Group:
* Image state read/write
* Image Upload secondary slot
* Image Erase secondary slot

OS group:
* Reset
* Echo service, disabled by default

Opeartion's are blocked call and cant't call inside worker queue.
IMG and OS need to be SMP client object for transport.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
Added unit test for testing IMG and OS group component's.

Added Unit test for SMP Client.

Signed-off-by: Juha Heiskanen <juha.heiskanen@nordicsemi.no>
@jheiskan81
Copy link
Contributor Author

@nordicjm Thanks for review. I fixed those raised case.

Copy link
Collaborator

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK, thanks!

void smp_client_transport_register(struct smp_client_transport_entry *entry)
{
if (smp_client_transport_get(entry->smpt_type)) {
/* Already in list */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably have some warning here, as a LOG_DBG, as this would be strange behavior when certain transport type is registered twice; this also checks type only so it does not distinguish between different handler being registered for the same type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add that no problem.

@carlescufi carlescufi merged commit 9a06ce1 into zephyrproject-rtos:main Jul 27, 2023
17 checks passed
mcumgr automation moved this from In progress to Done in release 3.5 Jul 27, 2023
@kartben
Copy link
Collaborator

kartben commented Aug 10, 2023

Is there a plan to add documentation and/or a sample for this? It would really help with making sure people are aware this now exists. Apologies if there is already an open issue or PR for this and I just missed it. @nordicjm @jheiskan81

@nordicjm nordicjm moved this from Done in release 3.5 to Done in mcumgr Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

9 participants