Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/native/native_sim/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ host libC (:kconfig:option:`CONFIG_EXTERNAL_LIBC`):
FUSE, :ref:`Host based filesystem access <native_fuse_flash>`, :kconfig:option:`CONFIG_FUSE_FS_ACCESS`, All
GPIO, GPIO emulator, :kconfig:option:`CONFIG_GPIO_EMUL`, All
GPIO, SDL GPIO emulator, :kconfig:option:`CONFIG_GPIO_EMUL_SDL`, All
HWINFO, :kconfig:option:`CONFIG_HWINFO_NATIVE`, All
I2C, I2C emulator, :kconfig:option:`CONFIG_I2C_EMUL`, All
Input, Input SDL touch, :kconfig:option:`CONFIG_INPUT_SDL_TOUCH`, All
Input, Linux evdev, :kconfig:option:`CONFIG_NATIVE_LINUX_EVDEV`, All
Expand Down
1 change: 1 addition & 0 deletions boards/native/native_sim/native_sim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ supported:
- spi
- gpio
- rtc
- hwinfo
testing:
default: true
vendor: zephyr
1 change: 1 addition & 0 deletions boards/native/native_sim/native_sim_native_64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ supported:
- adc
- gpio
- rtc
- hwinfo
vendor: zephyr
10 changes: 10 additions & 0 deletions drivers/hwinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ zephyr_library_sources_ifdef(CONFIG_HWINFO_SILABS_S2 hwinfo_silabs_series2.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_SMARTBOND hwinfo_smartbond.c)
zephyr_library_sources_ifdef(CONFIG_HWINFO_STM32 hwinfo_stm32.c)
# zephyr-keep-sorted-stop

if(CONFIG_HWINFO_NATIVE)
if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Linux)
zephyr_library_sources(hwinfo_native.c)

target_sources(native_simulator INTERFACE hwinfo_native_bottom.c)
else()
message(FATAL_ERROR "CONFIG_HWINFO_NATIVE is only available on Linux")
endif()
endif()
1 change: 1 addition & 0 deletions drivers/hwinfo/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rsource "Kconfig.mcux_src"
rsource "Kconfig.mcux_src_rev2"
rsource "Kconfig.mcux_syscon"
rsource "Kconfig.mspm0"
rsource "Kconfig.native"
rsource "Kconfig.nrf"
rsource "Kconfig.numaker"
rsource "Kconfig.numaker_rmc"
Expand Down
10 changes: 10 additions & 0 deletions drivers/hwinfo/Kconfig.native
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.
63 changes: 63 additions & 0 deletions drivers/hwinfo/hwinfo_native.c
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);
16 changes: 16 additions & 0 deletions drivers/hwinfo/hwinfo_native_bottom.c
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();
}
11 changes: 11 additions & 0 deletions drivers/hwinfo/hwinfo_native_bottom.h
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 */