Generating device-specific files as part of a package

Hello all,

I'm modifying an OpenWrt package where I need the package to generate a device-specific file using the DEVICE_NAME variable and install this file into the rootfs. However, it looks like the DEVICE_NAME variable is not populated at the time of Package/install. I can't just simply pre-create the file and include it in the base-files directory for my target as the file needs to be generated based on some other configuration variables.

How can I achieve this in the Openwrt build system?

Could you pull it from board.json at runtime or similar? Without knowing what you want to achieve exactly it is hard to comment.

1 Like

mac address ?

Not an expert, but given the lack of replies from them -- would package variants be usable as workarounds? Something like this: ?

Thanks for the replies everyone. For further clarification, basically at build time a package needs to know the device name that we're building the Openwrt image for, as it needs to generate some device-specific files that get installed into the read-only rootfs. Doing it at runtime on the device is not practical as it would involve installing some extra tools onto the rootfs that are only needed to generate these files.

As mentioned in the original post, the DEVICE_NAME variable is not populated in Package/Install.

@stangri : This seems like a good workaround, I'll look into it.

Just as a follow up, it looks like the VARIANT solution adds extra options in menuconfig that the user then needs to be manually select, which unfortunately is not desired.

Basically, I'm integrating the Mender OTA update system into my image. As part of this, I need to generate what's called a "bootstrap artifact", which is basically an empty update image that is included in the rootfs that contains metadata about the current software version. Mender uses this to populate its database initially with the current software information. To generate this file, I use the mender-artifact tool and need to pass it the software version as well as the device name. I'm using DEVICE_NAME to serve as the unique identifier for the hardware type.

I've managed to come to the following solution:

The information I need is already stored in the CONFIG_TARGET_PROFILE variable, but needs to be sanitised, similar to how it's done in to produce the PROFILE_SANITIZED variable:

  • Remove quotes
  • Replace spaces with dashes
  • Remove the DEVICE_ prefix
  • Convert to lower case.
  • A final step that needs to be added is to replace underscores with a comma.

So in the package Makefile, I can do something like this:

$(eval PROFILE_SANITIZED := $(call tolower,$(subst _,$(comma),$(subst DEVICE_,,$(subst $(space),-,$(call qstrip,$(CONFIG_TARGET_PROFILE)))))))

I can then use PROFILE_SANITIZED in the rest of the Makefile.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.