I wonder if it’s possbile to use a given portion of ConfigBlock to save and read back custom parameter.
I think to important parameters that must not modified (i.e. a custom S/N for the complete device, some calibration parametres, …)
I wonder if it’s possbile to use a given portion of ConfigBlock to save and read back custom parameter.
I think to important parameters that must not modified (i.e. a custom S/N for the complete device, some calibration parametres, …)
Dear @vix
It is possible to store user defined data in the ConfigBlock. However, you will neither have a user interface in the bootloader, nor be able to use the ConfigBlock Editor to modify the data.
Each section in the ConfigBlock is stored as a simple structure starting with an ID tag identifying the section. All you need to do is choosing any unused ID to store your binary block of data.
Notes:
ConfigBlock parameters can be accessed through calls to KernelIoControl()
. The following code snippet shows the required definitions and function calls:
#include <windows.h>
// function prototype to call into the kernel
BOOL KernelIoControl(DWORD dwIoControlCode,
LPVOID lpInBuf, DWORD nInBufSize,
LPVOID lpOutBuf, DWORD nOutBufSize,
LPDWORD lpBytesReturned);
// IOCTL definitions
#define FILE_DEVICE_HAL 0x00000101
#define METHOD_BUFFERED 0
#define FILE_ANY_ACCESS 0
#define CTL_CODE( DeviceType, Function, Method, Access ) (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
#define IOCTL_HAL_FLASHPARAMGET (DWORD)(CTL_CODE(FILE_DEVICE_HAL, 2058, METHOD_BUFFERED, FILE_ANY_ACCESS))
#define IOCTL_HAL_FLASHPARAMSET (DWORD)(CTL_CODE(FILE_DEVICE_HAL, 2059, METHOD_BUFFERED, FILE_ANY_ACCESS))
#define IOCTL_HAL_FLASHPARAMCLEAR (DWORD)(CTL_CODE(FILE_DEVICE_HAL, 2060, METHOD_BUFFERED, FILE_ANY_ACCESS))
// ID to store the user section in the config block (0x1000 <= ID_USER <= 0x7fff).
#define ID_USER 0x1000
// required data structures to read/write the config block.
typedef struct {
DWORD id;
void* pBuf;
DWORD len;
} FLASHPARAMSETPARAMS;
typedef struct {
DWORD id;
} FLASHPARAMGETPARAMS;
int main()
{
DWORD bytesReturned = 0;
DWORD sampleWriteBuffer[3] = {0x11223344, 0x55667788, 0x99aabbcc};
DWORD sampleReadBuffer[3] = {0};
FLASHPARAMSETPARAMS fps;
FLASHPARAMGETPARAMS fpg;
// write user data
fps.id = ID_USER;
fps.pBuf = &sampleWriteBuffer;
fps.len = sizeof(sampleWriteBuffer);
ASSERT(KernelIoControl(IOCTL_HAL_FLASHPARAMSET,
&fps, sizeof(FLASHPARAMSETPARAMS),
NULL, 0,
&result));
printf("\nSample Write Data 0x%08x 0x%08x 0x%08x :", sampleWriteBuffer[0],
sampleWriteBuffer[1],
sampleWriteBuffer[2]);
//read user data
fpg.id = ID_USER;
ASSERT(KernelIoControl(IOCTL_HAL_FLASHPARAMGET,
&fpg, sizeof(FLASHPARAMGETPARAMS),
&sampleReadBuffer, sizeof(sampleReadBuffer),
&bytesReturned));
printf("\nSample Read Data 0x%08x 0x%08x 0x%08x :", sampleReadBuffer[0],
sampleReadBuffer[1],
sampleReadBuffer[2]);
}
Regards,
Andy
Hi @andy.tx
thank you very much for your detailed explanation.
I think you’re right and, probably, it’s not the best location for a S/N.
I don’t want to re-invent the wheel (if possible), so is there any “special” flash storage section that can be used for this purpose?
Or should I save my custom info in the filesystem?
Hi @vix
There’s no special flash section for this kind of information. The storage options you have are basically
For all storage locations, you will need an individual step for each end device to program the specific serial number.
Compared to file system and registry, the config block is kind of hidden (no standard tools to read or modify it). This can be an advantage or disadvantage.
An additional thing you could do is to keep a database in your company to match the Toradex serial number (which corresponds to the MAC address) with your own serial number. This allows to recover your serial number for a device, in case it got lost.
Regards, Andy