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*2b9d2074SRobert Mustacchi# Copyright (c) 2017, 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 51*2b9d2074SRobert MustacchiSMB_POWERSUP_F_ smbios_powersup_flag_name uint_t 5284ab085aSmwsSMB_MDF_ smbios_memdevice_flag_name uint_t 534e901881SDale GhentSMB_PRC_ smbios_processor_core_flag_name uint_t 5484ab085aSmwsSMB_TYPE_ smbios_type_name uint_t 5584ab085aSmwsSMB_SLCH1_ smbios_slot_ch1_name uint_t 5684ab085aSmwsSMB_SLCH2_ smbios_slot_ch2_name uint_t 5784ab085aSmws' 5884ab085aSmws 5984ab085aSmwsdesc_funcs=' 6084ab085aSmwsSMB_BBFL_ smbios_bboard_flag_desc uint_t 6184ab085aSmwsSMB_BBT_ smbios_bboard_type_desc uint_t 6284ab085aSmwsSMB_BIOSFL_ smbios_bios_flag_desc uint64_t 6384ab085aSmwsSMB_BIOSXB1_ smbios_bios_xb1_desc uint_t 6484ab085aSmwsSMB_BIOSXB2_ smbios_bios_xb2_desc uint_t 6584ab085aSmwsSMB_BOOT_ smbios_boot_desc uint_t 6684ab085aSmwsSMB_CAA_ smbios_cache_assoc_desc uint_t 6784ab085aSmwsSMB_CAT_ smbios_cache_ctype_desc uint_t 6884ab085aSmwsSMB_CAE_ smbios_cache_ecc_desc uint_t 6984ab085aSmwsSMB_CAF_ smbios_cache_flag_desc uint_t 7084ab085aSmwsSMB_CAL_ smbios_cache_loc_desc uint_t 7184ab085aSmwsSMB_CAG_ smbios_cache_logical_desc uint_t 7284ab085aSmwsSMB_CAM_ smbios_cache_mode_desc uint_t 7384ab085aSmwsSMB_CHST_ smbios_chassis_state_desc uint_t 7484ab085aSmwsSMB_CHT_ smbios_chassis_type_desc uint_t 7584ab085aSmwsSMB_EVFL_ smbios_evlog_flag_desc uint_t 7684ab085aSmwsSMB_EVHF_ smbios_evlog_format_desc uint_t 7784ab085aSmwsSMB_EVM_ smbios_evlog_method_desc uint_t 7884ab085aSmwsSMB_HWSEC_PS_ smbios_hwsec_desc uint_t 7984ab085aSmwsSMB_IPMI_F_ smbios_ipmi_flag_desc uint_t 8084ab085aSmwsSMB_IPMI_T_ smbios_ipmi_type_desc uint_t 81*2b9d2074SRobert MustacchiSMB_POWERSUP_F_ smbios_powersup_flag_desc uint_t 82*2b9d2074SRobert MustacchiSMB_POWERSUP_I_ smbios_powersup_input_desc uint_t 83*2b9d2074SRobert MustacchiSMB_POWERSUP_S_ smbios_powersup_status_desc uint_t 84*2b9d2074SRobert MustacchiSMB_POWERSUP_T_ smbios_powersup_type_desc uint_t 8584ab085aSmwsSMB_MAL_ smbios_memarray_loc_desc uint_t 8684ab085aSmwsSMB_MAU_ smbios_memarray_use_desc uint_t 8784ab085aSmwsSMB_MAE_ smbios_memarray_ecc_desc uint_t 8884ab085aSmwsSMB_MDF_ smbios_memdevice_flag_desc uint_t 8984ab085aSmwsSMB_MDFF_ smbios_memdevice_form_desc uint_t 9084ab085aSmwsSMB_MDT_ smbios_memdevice_type_desc uint_t 914e901881SDale GhentSMB_MDR_ smbios_memdevice_rank_desc uint_t 926734c4b0SRobert MustacchiSMB_OBT_ smbios_onboard_type_desc uint_t 9384ab085aSmwsSMB_POC_ smbios_port_conn_desc uint_t 9484ab085aSmwsSMB_POT_ smbios_port_type_desc uint_t 954e901881SDale GhentSMB_PRC_ smbios_processor_core_flag_desc uint_t 9684ab085aSmwsSMB_PRF_ smbios_processor_family_desc uint_t 9784ab085aSmwsSMB_PRS_ smbios_processor_status_desc uint_t 9884ab085aSmwsSMB_PRT_ smbios_processor_type_desc uint_t 9984ab085aSmwsSMB_PRU_ smbios_processor_upgrade_desc uint_t 10084ab085aSmwsSMB_SLCH1_ smbios_slot_ch1_desc uint_t 10184ab085aSmwsSMB_SLCH2_ smbios_slot_ch2_desc uint_t 10284ab085aSmwsSMB_SLL_ smbios_slot_length_desc uint_t 10384ab085aSmwsSMB_SLT_ smbios_slot_type_desc uint_t 10484ab085aSmwsSMB_SLU_ smbios_slot_usage_desc uint_t 10584ab085aSmwsSMB_SLW_ smbios_slot_width_desc uint_t 10684ab085aSmwsSMB_TYPE_ smbios_type_desc uint_t 10784ab085aSmwsSMB_WAKEUP_ smbios_system_wakeup_desc uint_t 10884ab085aSmws' 10984ab085aSmws 11084ab085aSmwsif [ $# -ne 1 ]; then 11184ab085aSmws echo "Usage: $0 file.h > file.c" >&2 11284ab085aSmws exit 2 11384ab085aSmwsfi 11484ab085aSmws 11584ab085aSmwsecho "\ 11684ab085aSmws/*\n\ 1174e901881SDale Ghent * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.\n\ 11884ab085aSmws * Copyright 2005 Sun Microsystems, Inc. All rights reserved.\n\ 11984ab085aSmws * Use is subject to license terms.\n\ 12084ab085aSmws */\n\ 12184ab085aSmws\n\ 12284ab085aSmws#include <smbios.h>" 12384ab085aSmws 12484ab085aSmwsecho "$name_funcs" | while read p name type; do 12584ab085aSmws [ -z "$p" ] && continue 12684ab085aSmws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*[A-Z0-9]*.*$" 12784ab085aSmws replace=' case \1: return ("\1");' 12884ab085aSmws 12984ab085aSmws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {" 13084ab085aSmws sed -n "s@$pattern@$replace@p" < $1 || exit 1 13184ab085aSmws echo "\t}\n\treturn (NULL);\n}" 13284ab085aSmwsdone 13384ab085aSmws 13484ab085aSmws# 13584ab085aSmws# Generate the description functions based on the comment next to a #define. 13684ab085aSmws# The transformations for descriptive comments are slightly more complicated 13784ab085aSmws# than those used for the identifier->name functions above: 13884ab085aSmws# 13984ab085aSmws# (1) strip any [RO] suffix from the comment (a header file convention) 14084ab085aSmws# (2) replace any " with \" so it is escaped for the final output string 14184ab085aSmws# (3) replace return (...); with return ("..."); to finish the code 14284ab085aSmws# 14384ab085aSmwsecho "$desc_funcs" | while read p name type; do 14484ab085aSmws [ -z "$p" ] && continue 14584ab085aSmws pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*.*/\\* \(.*\) \\*/$" 14684ab085aSmws replace=' case \1: return (\2);' 14784ab085aSmws 14884ab085aSmws echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {" 14984ab085aSmws sed -n "s@$pattern@$replace@p" < $1 | sed 's/ ([RO]))/)/' | \ 15084ab085aSmws sed 's/"/\\"/g' | sed 's/(/("/;s/);$/");/' || exit 1 15184ab085aSmws echo "\t}\n\treturn (NULL);\n}" 15284ab085aSmwsdone 15384ab085aSmws 15484ab085aSmwsexit 0 155