-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: hwinfo: add HWINFO driver for native_sim #95437
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
Merged
henrikbrixandersen
merged 1 commit into
zephyrproject-rtos:main
from
henrikbrixandersen:native_hwinfo
Sep 6, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ supported: | |
| - spi | ||
| - gpio | ||
| - rtc | ||
| - hwinfo | ||
| testing: | ||
| default: true | ||
| vendor: zephyr | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,4 +20,5 @@ supported: | |
| - adc | ||
| - gpio | ||
| - rtc | ||
| - hwinfo | ||
| vendor: zephyr | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # Copyright (c) 2025 Henrik Brix Andersen <henrik@brixandersen.dk> | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config HWINFO_NATIVE | ||
| bool "HWINFO driver for native_sim" | ||
| default y | ||
| depends on ARCH_POSIX | ||
| select HWINFO_HAS_DRIVER | ||
| help | ||
| Enable native_sim HWINFO driver. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright (c) 2025 Henrik Brix Andersen <henrik@brixandersen.dk> | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <cmdline.h> | ||
| #include <posix_native_task.h> | ||
| #include <string.h> | ||
| #include <zephyr/drivers/hwinfo.h> | ||
| #include <zephyr/sys/byteorder.h> | ||
|
|
||
| #include "hwinfo_native_bottom.h" | ||
|
|
||
| static uint32_t native_hwinfo_device_id; | ||
| static bool native_hwinfo_device_id_set; | ||
|
|
||
| ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length) | ||
| { | ||
|
|
||
| if (length > sizeof(native_hwinfo_device_id)) { | ||
| length = sizeof(native_hwinfo_device_id); | ||
| } | ||
|
|
||
| sys_put_be(buffer, &native_hwinfo_device_id, length); | ||
|
|
||
| return length; | ||
| } | ||
|
|
||
| static void native_hwinfo_gethostid(void) | ||
| { | ||
| if (!native_hwinfo_device_id_set) { | ||
| native_hwinfo_device_id = native_hwinfo_gethostid_bottom(); | ||
| } | ||
| } | ||
|
|
||
| static void native_hwinfo_device_id_was_set(char *argv, int offset) | ||
| { | ||
| ARG_UNUSED(argv); | ||
| ARG_UNUSED(offset); | ||
|
|
||
| native_hwinfo_device_id_set = true; | ||
| } | ||
|
|
||
| static void native_hwinfo_add_options(void) | ||
| { | ||
| static struct args_struct_t native_hwinfo_options[] = { | ||
| { | ||
| .option = "device_id", | ||
| .name = "id", | ||
| .type = 'u', | ||
| .dest = (void *)&native_hwinfo_device_id, | ||
| .call_when_found = native_hwinfo_device_id_was_set, | ||
| .descript = "A 32-bit integer value to use as HWINFO device ID. " | ||
| "If not set, the host gethostid() output will be used.", | ||
| }, | ||
| ARG_TABLE_ENDMARKER, | ||
| }; | ||
|
|
||
| native_add_command_line_opts(native_hwinfo_options); | ||
| } | ||
|
|
||
| NATIVE_TASK(native_hwinfo_add_options, PRE_BOOT_1, 10); | ||
| NATIVE_TASK(native_hwinfo_gethostid, PRE_BOOT_2, 10); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| * Copyright (c) 2025 Henrik Brix Andersen <henrik@brixandersen.dk> | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #undef _XOPEN_SOURCE | ||
| #define _XOPEN_SOURCE 500 | ||
|
|
||
| #include <unistd.h> | ||
|
|
||
| #include "hwinfo_native_bottom.h" | ||
|
|
||
| long native_hwinfo_gethostid_bottom(void) | ||
| { | ||
| return gethostid(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| * Copyright (c) 2025 Henrik Brix Andersen <henrik@brixandersen.dk> | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #ifndef DRIVERS_HWINFO_NATIVE_BOTTOM_H | ||
| #define DRIVERS_HWINFO_NATIVE_BOTTOM_H | ||
|
|
||
| long native_hwinfo_gethostid_bottom(void); | ||
|
|
||
| #endif /* DRIVERS_HWINFO_NATIVE_BOTTOM_H */ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.