Crinit -- Configurable Rootfs Init
machine-id-gen.c File Reference

(2023-08-02, commit: 9434b31)

#include <fcntl.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
Include dependency graph for machine-id-gen.c:

Macros

#define S32G_OCOTP_BASE   0x400a4000uL
 Memory-mapped base address of the S32G OCOTP memory controller. More...
 
#define S32G_OCOTP_OFFSET_UID   0x210uL
 Offset to the unique ID shadow registers (2x32-Bit consecutive) More...
 
#define S32G_SIUL21_BASE   0x44010000uL
 Memory-mapped base address of the S32G SIUL2_1 subsystem. More...
 
#define S32G_SIUL21_OFFSET_MIDR1   0x4uL
 Offset to the SIUL2 MCU ID register 1 (MIDR1). More...
 
#define S32G_SIUL21_MCUID_VAL   0x4C200000uL
 Upper 16-Bit of MIDR1 valid for all S32G models. More...
 
#define S32G_SIUL21_MCUID_MASK   0xFFFF0000uL
 Bitmask of upper 16-Bit (for MIDR1 access). More...
 
#define MID_STR_LEN   36
 Length of a 128-Bit UUIDv4 not including the terminating zero. More...
 
#define KERNEL_CMDLINE_PATH   "/proc/cmdline"
 Where the (pseudo-)file containing the Kernel command line is. More...
 
#define KERNEL_CMDLINE_MAX_LEN   4096
 Maximum length of the Kernel command line options to be read. More...
 
#define KERNEL_CMDLINE_KEY   "systemd.machine_id"
 Kernel command line key to set machine ID. More...
 
#define MACHINE_ID_PATH   "/etc/machine-id"
 Path to the machine-id file to generate. More...
 

Functions

static void crinitPrintUsage (const char *basename)
 
static int crinitGetMidKernelCmdLine (char *mid, size_t n)
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ KERNEL_CMDLINE_KEY

#define KERNEL_CMDLINE_KEY   "systemd.machine_id"

Kernel command line key to set machine ID.

◆ KERNEL_CMDLINE_MAX_LEN

#define KERNEL_CMDLINE_MAX_LEN   4096

Maximum length of the Kernel command line options to be read.

◆ KERNEL_CMDLINE_PATH

#define KERNEL_CMDLINE_PATH   "/proc/cmdline"

Where the (pseudo-)file containing the Kernel command line is.

◆ MACHINE_ID_PATH

#define MACHINE_ID_PATH   "/etc/machine-id"

Path to the machine-id file to generate.

◆ MID_STR_LEN

#define MID_STR_LEN   36

Length of a 128-Bit UUIDv4 not including the terminating zero.

◆ S32G_OCOTP_BASE

#define S32G_OCOTP_BASE   0x400a4000uL

Memory-mapped base address of the S32G OCOTP memory controller.

◆ S32G_OCOTP_OFFSET_UID

#define S32G_OCOTP_OFFSET_UID   0x210uL

Offset to the unique ID shadow registers (2x32-Bit consecutive)

◆ S32G_SIUL21_BASE

#define S32G_SIUL21_BASE   0x44010000uL

Memory-mapped base address of the S32G SIUL2_1 subsystem.

◆ S32G_SIUL21_MCUID_MASK

#define S32G_SIUL21_MCUID_MASK   0xFFFF0000uL

Bitmask of upper 16-Bit (for MIDR1 access).

◆ S32G_SIUL21_MCUID_VAL

#define S32G_SIUL21_MCUID_VAL   0x4C200000uL

Upper 16-Bit of MIDR1 valid for all S32G models.

◆ S32G_SIUL21_OFFSET_MIDR1

#define S32G_SIUL21_OFFSET_MIDR1   0x4uL

Offset to the SIUL2 MCU ID register 1 (MIDR1).

Function Documentation

◆ crinitGetMidKernelCmdLine()

static int crinitGetMidKernelCmdLine ( char *  mid,
size_t  n 
)
static

Tries to get the machine-id from the Kernel command line.

Searches the Kernel command line for a value for KERNEL_CMDLINE_KEY and copies it to mid if found and n is large enough.

Parameters
midReturn pointer for the machine-id UUID string.
nMaximum size of the string that can be returned.
Returns
0 on success, -1 on a general error, and -2 if everything went well but KERNEL_CMDLINE_KEY is not found in the Kernel commandline.

◆ crinitPrintUsage()

static void crinitPrintUsage ( const char *  basename)
static

Print application usage information (to stderr).

Parameters
basenameThe name of this program.

◆ main()

int main ( int  argc,
char *  argv[] 
)