184ab085aSmws#!/bin/sh 284ab085aSmws# 384ab085aSmws# CDDL HEADER START 484ab085aSmws# 584ab085aSmws# The contents of this file are subject to the terms of the 684ab085aSmws# Common Development and Distribution License, Version 1.0 only 784ab085aSmws# (the "License"). You may not use this file except in compliance 884ab085aSmws# with the License. 984ab085aSmws# 1084ab085aSmws# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 1184ab085aSmws# or http://www.opensolaris.org/os/licensing. 1284ab085aSmws# See the License for the specific language governing permissions 1384ab085aSmws# and limitations under the License. 1484ab085aSmws# 1584ab085aSmws# When distributing Covered Code, include this CDDL HEADER in each 1684ab085aSmws# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1784ab085aSmws# If applicable, add the following below this CDDL HEADER, with the 1884ab085aSmws# fields enclosed by brackets "[]" replaced with your own identifying 1984ab085aSmws# information: Portions Copyright [yyyy] [name of copyright owner] 2084ab085aSmws# 2184ab085aSmws# CDDL HEADER END 2284ab085aSmws# 2384ab085aSmws# 244e901881SDale Ghent# Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved. 25*174bc649SRobert Mustacchi# Copyright (c) 2018, Joyent, Inc. 2684ab085aSmws# Copyright 2005 Sun Microsystems, Inc. All rights reserved. 2784ab085aSmws# Use is subject to license terms. 2884ab085aSmws# 2984ab085aSmws 3084ab085aSmws# 3184ab085aSmws# The SMBIOS interfaces defined in <sys/smbios.h> include a set of integer-to- 3284ab085aSmws# string conversion routines for the various constants defined in the SMBIOS 3384ab085aSmws# spec. These functions are used by smbios(1M) and prtdiag(1M) and can be 3484ab085aSmws# leveraged by other clients as well. To simplify maintenance of the source 3584ab085aSmws# base, this shell script automatically generates the source code for all of 3684ab085aSmws# these functions from the <sys/smbios.h> header file and its comments. Each 3784ab085aSmws# set of constants should be given a unique #define prefix, listed in the 3884ab085aSmws# tables below. The smbios_*_name() functions return the identifier of the 3984ab085aSmws# cpp define, and the smbios_*_desc() functions return the text of the comment. 4084ab085aSmws# 4184ab085aSmws 4284ab085aSmwsname_funcs=' 4384ab085aSmwsSMB_BBFL_ smbios_bboard_flag_name uint_t 4484ab085aSmwsSMB_BIOSFL_ smbios_bios_flag_name uint64_t 4584ab085aSmwsSMB_BIOSXB1_ smbios_bios_xb1_name uint_t 4684ab085aSmwsSMB_BIOSXB2_ smbios_bios_xb2_name uint_t 4784ab085aSmwsSMB_CAT_ smbios_cache_ctype_name uint_t 4884ab085aSmwsSMB_CAF_ smbios_cache_flag_name uint_t 4984ab085aSmwsSMB_EVFL_ smbios_evlog_flag_name uint_t 5084ab085aSmwsSMB_IPMI_F_ smbios_ipmi_flag_name uint_t 512b9d2074SRobert MustacchiSMB_POWERSUP_F_ smbios_powersup_flag_name uint_t 52*174bc649SRobert MustacchiSMB_MOMC_ smbios_memdevice_op_capab_name uint_t 5384ab085aSmwsSMB_MDF_ smbios_memdevice_flag_name uint_t 544e901881SDale GhentSMB_PRC_ smbios_processor_core_flag_name uint_t 5584ab085aSmwsSMB_TYPE_ smbios_type_name uint_t 5684ab085aSmwsSMB_SLCH1_ smbios_slot_ch1_name uint_t 5784ab085aSmwsSMB_SLCH2_ smbios_slot_ch2_name uint_t 5884ab085aSmws' 5984ab085aSmws 6084ab085aSmwsdesc_funcs=' 6184ab085aSmwsSMB_BBFL_ smbios_bboard_flag_desc uint_t 6284ab085aSmwsSMB_BBT_ smbios_bboard_type_desc uint_t 6384ab085aSmwsSMB_BIOSFL_ smbios_bios_flag_desc uint64_t 6484ab085aSmwsSMB_BIOSXB1_ smbios_bios_xb1_desc uint_t 6584ab085aSmwsSMB_BIOSXB2_ smbios_bios_xb2_desc uint_t 6684ab085aSmwsSMB_BOOT_ smbios_boot_desc uint_t 6784ab085aSmwsSMB_CAA_ smbios_cache_assoc_desc uint_t 6884ab085aSmwsSMB_CAT_ smbios_cache_ctype_desc uint_t 6984ab085aSmwsSMB_CAE_ smbios_cache_ecc_desc uint_t 7084ab085aSmwsSMB_CAF_ smbios_cache_flag_desc uint_t 7184ab085aSmwsSMB_CAL_ smbios_cache_loc_desc uint_t 7284ab085aSmwsSMB_CAG_ smbios_cache_logical_desc uint_t 7384ab085aSmwsSMB_CAM_ smbios_cache_mode_desc uint_t 7484ab085aSmwsSMB_CHST_ smbios_chassis_state_desc uint_t 7584ab085aSmwsSMB_CHT_ smbios_chassis_type_desc uint_t 7645807aa8SRobert MustacchiSMB_COOLDEV_S_ smbios_cooldev_status_desc uint_t 7745807aa8SRobert MustacchiSMB_COOLDEV_T_ smbios_cooldev_type_desc uint_t 7884ab085aSmwsSMB_EVFL_ smbios_evlog_flag_desc uint_t 7984ab085aSmwsSMB_EVHF_ smbios_evlog_format_desc uint_t 8084ab085aSmwsSMB_EVM_ smbios_evlog_method_desc uint_t 8184ab085aSmwsSMB_HWSEC_PS_ smbios_hwsec_desc uint_t 8284ab085aSmwsSMB_IPMI_F_ smbios_ipmi_flag_desc uint_t 8384ab085aSmwsSMB_IPMI_T_ smbios_ipmi_type_desc uint_t 8445807aa8SRobert MustacchiSMB_IPROBE_L_ smbios_iprobe_loc_desc uint_t 8545807aa8SRobert MustacchiSMB_IPROBE_S_ smbios_iprobe_status_desc uint_t 862b9d2074SRobert MustacchiSMB_POWERSUP_F_ smbios_powersup_flag_desc uint_t 872b9d2074SRobert MustacchiSMB_POWERSUP_I_ smbios_powersup_input_desc uint_t 882b9d2074SRobert MustacchiSMB_POWERSUP_S_ smbios_powersup_status_desc uint_t 892b9d2074SRobert MustacchiSMB_POWERSUP_T_ smbios_powersup_type_desc uint_t 9084ab085aSmwsSMB_MAL_ smbios_memarray_loc_desc uint_t 9184ab085aSmwsSMB_MAU_ smbios_memarray_use_desc uint_t 9284ab085aSmwsSMB_MAE_ smbios_memarray_ecc_desc uint_t 9384ab085aSmwsSMB_MDF_ smbios_memdevice_flag_desc uint_t 9484ab085aSmwsSMB_MDFF_ smbios_memdevice_form_desc uint_t 9584ab085aSmwsSMB_MDT_ smbios_memdevice_type_desc uint_t 964e901881SDale GhentSMB_MDR_ smbios_memdevice_rank_desc uint_t 97*174bc649SRobert MustacchiSMB_MTECH_ smbios_memdevice_memtech_desc uint_t 98*174bc649SRobert MustacchiSMB_MOMC_ smbios_memdevice_op_capab_desc uint_t 996734c4b0SRobert MustacchiSMB_OBT_ smbios_onboard_type_desc uint_t 10084ab085aSmwsSMB_POC_ smbios_port_conn_desc uint_t 10184ab085aSmwsSMB_POT_ smbios_port_type_desc uint_t 1024e901881SDale GhentSMB_PRC_ smbios_processor_core_flag_desc uint_t 10384ab085aSmwsSMB_PRF_ smbios_processor_family_desc uint_t 10484ab085aSmwsSMB_PRS_ smbios_processor_status_desc uint_t 10584ab085aSmwsSMB_PRT_ smbios_processor_type_desc uint_t 10684ab085aSmwsSMB_PRU_ smbios_processor_upgrade_desc uint_t 10784ab085aSmwsSMB_SLCH1_ smbios_slot_ch1_desc uint_t 10884ab085aSmwsSMB_SLCH2_ smbios_slot_ch2_desc uint_t 10984ab085aSmwsSMB_SLL_ smbios_slot_length_desc uint_t 11084ab085aSmwsSMB_SLT_ smbios_slot_type_desc uint_t 11184ab085aSmwsSMB_SLU_ smbios_slot_usage_desc uint_t 11284ab085aSmwsSMB_SLW_ smbios_slot_width_desc uint_t 11345807aa8SRobert MustacchiSMB_TPROBE_L_ smbios_tprobe_loc_desc uint_t 11445807aa8SRobert MustacchiSMB_TPROBE_S_ smbios_tprobe_status_desc uint_t 11584ab085aSmwsSMB_TYPE_ smbios_type_desc uint_t 11645807aa8SRobert MustacchiSMB_VPROBE_L_ smbios_vprobe_loc_desc uint_t 11745807aa8SRobert MustacchiSMB_VPROBE_S_ smbios_vprobe_status_desc uint_t 11884ab085aSmwsSMB_WAKEUP_ smbios_system_wakeup_desc uint_t 11984ab085aSmws' 12084ab085aSmws 12184ab085aSmwsif [ $# -ne 1 ]; then 12284ab085aSmws echo "Usage: $0 file.h > file.c" >&2 12384ab085aSmws exit 2 12484ab085aSmwsfi 12584ab085aSmws 12684ab085aSmwsecho "\ 12784ab085aSmws/*\n\ 1284e901881SDale Ghent * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.\n\ 12984ab085aSmws * Copyright 2005 Sun Microsystems, Inc. All rights reserved.\n\ 13084ab085aSmws * Use is subject to license terms.\n\ 13184ab085aSmws */\n\ 13284ab085aSmws\n\ 13384ab085aSmws#include <smbios.h>" 13484ab085aSmws 13584ab085aSmwsecho "$name_funcs" | while read p name type; do 13684ab085aSmws [ -z "$p" ] && continue 13784ab085aSmws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*[A-Z0-9]*.*$" 13884ab085aSmws replace=' case \1: return ("\1");' 13984ab085aSmws 14084ab085aSmws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {" 14184ab085aSmws sed -n "s@$pattern@$replace@p" < $1 || exit 1 14284ab085aSmws echo "\t}\n\treturn (NULL);\n}" 14384ab085aSmwsdone 14484ab085aSmws 14584ab085aSmws# 14684ab085aSmws# Generate the description functions based on the comment next to a #define. 14784ab085aSmws# The transformations for descriptive comments are slightly more complicated 14884ab085aSmws# than those used for the identifier->name functions above: 14984ab085aSmws# 15084ab085aSmws# (1) strip any [RO] suffix from the comment (a header file convention) 15184ab085aSmws# (2) replace any " with \" so it is escaped for the final output string 15284ab085aSmws# (3) replace return (...); with return ("..."); to finish the code 15384ab085aSmws# 15484ab085aSmwsecho "$desc_funcs" | while read p name type; do 15584ab085aSmws [ -z "$p" ] && continue 15684ab085aSmws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*.*/\\* \(.*\) \\*/$" 15784ab085aSmws replace=' case \1: return (\2);' 15884ab085aSmws 15984ab085aSmws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {" 16084ab085aSmws sed -n "s@$pattern@$replace@p" < $1 | sed 's/ ([RO]))/)/' | \ 16184ab085aSmws sed 's/"/\\"/g' | sed 's/(/("/;s/);$/");/' || exit 1 16284ab085aSmws echo "\t}\n\treturn (NULL);\n}" 16384ab085aSmwsdone 16484ab085aSmws 16584ab085aSmwsexit 0 166