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

Zephyr: examples: add hello #129

Merged
merged 11 commits into from
Jul 28, 2023
Merged

Zephyr: examples: add hello #129

merged 11 commits into from
Jul 28, 2023

Conversation

szczys
Copy link
Contributor

@szczys szczys commented Jul 19, 2023

  • add samples common support for hardcoded credentials
  • add samples common support for default configuration
  • select common symbols by default when building with zephyr port
  • add symbols to select between PSK and certificate auth
  • add the hello sample

@github-actions
Copy link

github-actions bot commented Jul 19, 2023

Visit the preview URL for this PR (updated for commit 9f9c43c):

https://golioth-firmware-sdk-doxygen-dev--pr129-szczys-zephyr-x726rk3c.web.app

(expires Fri, 04 Aug 2023 16:29:44 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: a9993e61697a3983f3479e468bcb0b616f9a0578

@szczys szczys marked this pull request as draft July 19, 2023 16:40
@szczys szczys force-pushed the szczys/zephyr-samples-add-hello branch 5 times, most recently from cac7bca to 1ba6838 Compare July 20, 2023 14:11
@szczys szczys marked this pull request as ready for review July 20, 2023 14:34
@szczys szczys force-pushed the szczys/zephyr-samples-add-hello branch from 1ba6838 to d10685c Compare July 20, 2023 15:56
@szczys szczys changed the title Szczys/zephyr samples add hello Zephyr: examples: add hello Jul 24, 2023
@szczys szczys force-pushed the szczys/zephyr-samples-add-hello branch 4 times, most recently from 09c668c to 60168c2 Compare July 24, 2023 22:36
port/zephyr/CMakeLists.txt Outdated Show resolved Hide resolved
Comment on lines +9 to +18
select MBEDTLS
select MBEDTLS_DTLS if MBEDTLS_BUILTIN
select NET_SOCKETS
select NET_UDP
select ZCBOR
imply DNS_RESOLVER if NET_NATIVE
imply NET_SOCKETS_SOCKOPT_TLS
imply NET_SOCKETS_ENABLE_DTLS
help
Enable library for communication with Golioth cloud.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe let's remove those symbols from examples/zephyr/golioth_basics and actually see how much this simplifies prj.conf.

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 have done so by adding this commit:
b9048cb

I was trying to keep golioth_basics as a more verbose example. Combining the default symbols from this commit with the common/Kconfig.defconfig committed later in this PR makes for nearly-empty prj.conf files in the more simplified samples.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be really just a single way how to configure examples. Otherwise such inconsistency is confusing to people wanting to compare those samples (e.g. "what does it take to configure more services at once, just like in golioth_basics sample").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think it would be better to leave this commit out and move this set of symbol selection to the common/Kconfig.defconfig file for samples?

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 discussed with @sam-golioth and have left these symbols as is for now.

port/zephyr/Kconfig Outdated Show resolved Hide resolved
port/zephyr/Kconfig Outdated Show resolved Hide resolved
examples/zephyr/hello/README.md Outdated Show resolved Hide resolved
@szczys szczys force-pushed the szczys/zephyr-samples-add-hello branch from 60168c2 to 2939c17 Compare July 25, 2023 22:27
examples/zephyr/common/Kconfig Outdated Show resolved Hide resolved
examples/zephyr/common/Kconfig Show resolved Hide resolved
examples/zephyr/common/Kconfig Outdated Show resolved Hide resolved
examples/zephyr/common/hardcoded_credentials.c Outdated Show resolved Hide resolved
examples/zephyr/golioth_basics/Kconfig Outdated Show resolved Hide resolved
examples/zephyr/hello/README.md Outdated Show resolved Hide resolved
examples/zephyr/common/Kconfig Outdated Show resolved Hide resolved
examples/zephyr/hello/scripts/generate-keys.py Outdated Show resolved Hide resolved
@szczys szczys force-pushed the szczys/zephyr-samples-add-hello branch 4 times, most recently from 27ab152 to 750d9d6 Compare July 26, 2023 21:18
Use absolute path when sourcing other Kconfig files.

Signed-off-by: Mike Szczys <[email protected]>
* Add GOLIOTH_SAMPLE_COMMON
* Add the `hardcoded_credentials` samples common helper from the Golioth
  Zephyr SDK.
* add `hardcoded_credentials_get()` to return a `golioth_client_config_t`
  used to create a Golioth client
* PSK or PKI (certificate auth) are returned automatically based on the
  `CONFIG_GOLIOTH_AUTH_METHOD_CERT` symbol
* PKI is not yet implemented in the port. Placeholder code must be
  updated/replace when support is available

Signed-off-by: Mike Szczys <[email protected]>
Use the GOLIOTH_SAMPLE_CONFIG symbol to conditionally include the common
library files in the build.

Signed-off-by: Mike Szczys <[email protected]>
automatically select necessary symbols when Golioth is enabled in a build:

* MBEDTLS
* MBEDTLS_DTLS
* NET_SOCKETS
* NET_UDP
* ZCBOR
* DNS_RESOLVER
* NET_SOCKETS_SOCKOPT_TLS
* NET_SOCKETS_ENABLE_DTLS

Signed-off-by: Mike Szczys <[email protected]>
* port/zephyr/Kconfig: add symbols to select either certificate or PSK auth
* port/zephyr/Kconfig: add symbols to configure mbedtls based on auth type
* examples/zephyr/common/Kconfig: add symbols to define PSK/PSK-ID and
  certificate symbols

Signed-off-by: Mike Szczys <[email protected]>
@szczys szczys force-pushed the szczys/zephyr-samples-add-hello branch from 750d9d6 to fdc33ca Compare July 26, 2023 21:23
@szczys szczys requested a review from mniestroj July 26, 2023 21:43
@szczys szczys requested a review from sam-golioth July 26, 2023 21:43
rsource '../../src/Kconfig'
rsource '${ZEPHYR_GOLIOTH_FIRMWARE_SDK_MODULE_DIR}/src/Kconfig'

config GOLIOTH_CIPHERSUITES
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think is being used anywhere, let's remove it.

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 think we might need this. When I remove it I get this:

warning: the int symbol GOLIOTH_ZEPHYR_THREAD_STACK_SIZE (defined at /home/mike/golioth-compile/golioth-firmware-sdk/modules/lib/golioth-firmware-sdk/port/zephyr/Kconfig:121) has a non-int default GOLIOTH_COAP_THREAD_STACK_SIZE (undefined)

And I see that's in src/Kconfig:

➜ grep GOLIOTH_COAP_THREAD_STACK_SIZE ../../../src/Kconfig -A4
config GOLIOTH_COAP_THREAD_STACK_SIZE
    int "Golioth CoAP thread stack size"
    default 6144
    help
        Thread stack size of the Golioth CoAP thread, in bytes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, it doesn't seem like removing GOLIOTH_CIPHERSUITES should cause that particular error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sam-golioth I was confused by what you were commenting on. I thought you were asking to remove the rsource line.

Sorry that I merged before reading this comment. I can make a new PR to remove this block.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries! We're an agile team 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, looking into this I remember why I added it. It's a value used in the twister testing:

sample.golioth.hello.psk.fast.ccm_8:
platform_allow: >
nrf52840dk_nrf52840
qemu_x86
extra_configs:
- CONFIG_MBEDTLS_CIPHER_GCM_ENABLED=n
- CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y
- CONFIG_MBEDTLS_CIPHER_MODE_CBC_ENABLED=n
- CONFIG_GOLIOTH_CIPHERSUITES="TLS_PSK_WITH_AES_128_CCM_8"

Do want me to remove the GOLIOTH_CIPHERSUITES along with that test?

default 2048 if MINIMAL_LIBC

config LOG_PROCESS_THREAD_STACK_SIZE
default 2048 if LOG_BACKEND_GOLIOTH
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no Golioth log backend yet, so we don't need this. Are there other settings in this file that go beyond what we need for these samples?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good point. I've removed everything form defconfig that wasn't directly used in the current state of golioth_basics.

@sam-golioth sam-golioth self-requested a review July 27, 2023 21:30
CONFIG_FLASH=y
CONFIG_FLASH_MAP=y
CONFIG_STREAM_FLASH=y
CONFIG_IMG_MANAGER=y
Copy link
Contributor

@sam-golioth sam-golioth Jul 27, 2023

Choose a reason for hiding this comment

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

Why do we need these flash and image symbols for a "hello" sample?

Copy link
Contributor Author

@szczys szczys Jul 28, 2023

Choose a reason for hiding this comment

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

It seems like the DFU portions of the SDK are built automatically and I don't see a way to turn them off (the Zephyr SDK has a CONFIG_GOLIOTH_FW symbol for this).

In file included from /home/mike/golioth-compile/golioth-firmware-sdk/modules/lib/golioth-firmware-sdk/port/zephyr/golioth_fw_zephyr.c:1:
/home/mike/golioth-compile/golioth-firmware-sdk/zephyr/include/zephyr/dfu/flash_img.h:33:21: error: 'CONFIG_IMG_BLOCK_BUF_SIZE' undeclared here (not in a function); did you mean 'CONFIG_ISR_STACK_SIZE'?
   33 |         uint8_t buf[CONFIG_IMG_BLOCK_BUF_SIZE];
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                     CONFIG_ISR_STACK_SIZE

These symbols are necessary to complete the build. But I don't think they should be part of the default config. I've left them here to be removed later when building DFU components is configurable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me! Can you file a ticket to make DFU configurable?

CONFIG_DNS_RESOLVER=y
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_NET_SOCKETS_ENABLE_DTLS=y

# TLS configuration
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=10240
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these TLS options are enabled by GOLIOTH_AUTH_PSK_MBEDTLS_DEPS in port/zephyr/Kconfig so we don't need to set them here.

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've pared this prj.conf down to only the necessary symbols.

add symbols needed by all samples as the default when the common library is
enabled.

Signed-off-by: Mike Szczys <[email protected]>
Source the examples/zephyr/common/Kconfig from the main Zephyr port Kconfig
file. All symbols in the common Kconfig are guarded and will only be built
when `GOLIOTH_SAMPLE_COMMON` is selected.

Signed-off-by: Mike Szczys <[email protected]>
Add the ciphersuites Kconfig options. These are used during Twister
testing.

Signed-off-by: Mike Szczys <[email protected]>
Remove the symbols that are now selected by default. This commit also
changes the name of the symbol used for PSK/PSK-ID from CONFIG_GOLIOTH_* to
CONFIG_GOLIOTH_SAMPLE_*.

Signed-off-by: Mike Szczys <[email protected]>
Add a sample that sends "hello world" style message to Golioth. Includes
support for qemu_x86 and nrf52840dk_nrf52840.

Signed-off-by: Mike Szczys <[email protected]>
ignore hidden .cache directories created by vim

Signed-off-by: Mike Szczys <[email protected]>
@szczys szczys force-pushed the szczys/zephyr-samples-add-hello branch from fdc33ca to 9f9c43c Compare July 28, 2023 16:28
@szczys szczys merged commit 8a0825b into develop Jul 28, 2023
12 checks passed
@szczys szczys deleted the szczys/zephyr-samples-add-hello branch July 28, 2023 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants