File: cmd_get_system_boot_options.go

package info (click to toggle)
golang-github-bougou-go-ipmi 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,880 kB
  • sloc: makefile: 38
file content (201 lines) | stat: -rw-r--r-- 6,461 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
package ipmi

import (
	"context"
	"fmt"
)

// 28.13 Get System Boot Options Command
type GetSystemBootOptionsParamRequest struct {
	ParamSelector BootOptionParamSelector
	SetSelector   uint8
	BlockSelector uint8
}

// Table 28-14, Boot Option Parameters

type GetSystemBootOptionsParamResponse struct {
	ParameterVersion uint8

	// [7] - 1b = mark parameter invalid / locked
	// 0b = mark parameter valid / unlocked
	ParameterInValid bool
	// [6:0] - boot option parameter selector
	ParamSelector BootOptionParamSelector

	ParamData []byte // origin parameter data
}

func (req *GetSystemBootOptionsParamRequest) Pack() []byte {
	out := make([]byte, 3)
	packUint8(uint8(req.ParamSelector), out, 0)
	packUint8(req.SetSelector, out, 1)
	packUint8(req.BlockSelector, out, 2)
	return out
}

func (req *GetSystemBootOptionsParamRequest) Command() Command {
	return CommandGetSystemBootOptions
}

func (res *GetSystemBootOptionsParamResponse) CompletionCodes() map[uint8]string {
	return map[uint8]string{
		0x80: "parameter not supported",
	}
}

func (res *GetSystemBootOptionsParamResponse) Unpack(msg []byte) error {
	if len(msg) < 3 {
		return ErrUnpackedDataTooShortWith(len(msg), 3)
	}
	res.ParameterVersion, _, _ = unpackUint8(msg, 0)
	b, _, _ := unpackUint8(msg, 1)
	res.ParameterInValid = isBit7Set(b)
	res.ParamSelector = BootOptionParamSelector(b & 0x7f) // clear bit 7

	res.ParamData, _, _ = unpackBytes(msg, 2, len(msg)-2)
	return nil
}

func (res *GetSystemBootOptionsParamResponse) Format() string {

	var paramDataFormatted string

	var param BootOptionParameter

	switch res.ParamSelector {
	case BootOptionParamSelector_SetInProgress:
		param = &BootOptionParam_SetInProgress{}
	case BootOptionParamSelector_ServicePartitionSelector:
		param = &BootOptionParam_ServicePartitionSelector{}
	case BootOptionParamSelector_ServicePartitionScan:
		param = &BootOptionParam_ServicePartitionScan{}
	case BootOptionParamSelector_BMCBootFlagValidBitClear:
		param = &BootOptionParam_BMCBootFlagValidBitClear{}
	case BootOptionParamSelector_BootInfoAcknowledge:
		param = &BootOptionParam_BootInfoAcknowledge{}
	case BootOptionParamSelector_BootFlags:
		param = &BootOptionParam_BootFlags{}
	case BootOptionParamSelector_BootInitiatorInfo:
		param = &BootOptionParam_BootInitiatorInfo{}
	case BootOptionParamSelector_BootInitiatorMailbox:
		param = &BootOptionParam_BootInitiatorMailbox{}
	}

	if param != nil {
		if err := param.Unpack(res.ParamData); err == nil {
			paramDataFormatted = param.Format()
		}
	}

	return "" +
		fmt.Sprintf("Boot parameter version : %d\n", res.ParameterVersion) +
		fmt.Sprintf("Boot parameter %d is %s\n", res.ParamSelector, formatBool(res.ParameterInValid, "invalid/locked", "valid/unlocked")) +
		fmt.Sprintf("Boot parameter data : %02x\n", res.ParamData) +
		fmt.Sprintf("%s : %s\n", res.ParamSelector.String(), paramDataFormatted)
}

func (c *Client) GetSystemBootOptionsParam(ctx context.Context, paramSelector BootOptionParamSelector, setSelector uint8, blockSelector uint8) (response *GetSystemBootOptionsParamResponse, err error) {
	request := &GetSystemBootOptionsParamRequest{
		ParamSelector: paramSelector,
		SetSelector:   setSelector,
		BlockSelector: blockSelector,
	}
	response = &GetSystemBootOptionsParamResponse{}
	err = c.Exchange(ctx, request, response)
	return
}

func (c *Client) GetSystemBootOptionsParamFor(ctx context.Context, param BootOptionParameter) error {
	if isNilBootOptionParameter(param) {
		return nil
	}
	paramSelector, setSelector, blockSelector := param.BootOptionParameter()

	response, err := c.GetSystemBootOptionsParam(ctx, paramSelector, setSelector, blockSelector)
	if err != nil {
		return fmt.Errorf("GetSystemBootOptions for param (%s[%d]) failed, err: %w", paramSelector.String(), paramSelector, err)
	}

	if err := param.Unpack(response.ParamData); err != nil {
		return fmt.Errorf("unpack param (%s[%d]) failed, err: %w", paramSelector.String(), paramSelector, err)
	}

	return nil
}

// GetSystemBootOptionsParams get all parameters of boot options.
func (c *Client) GetSystemBootOptionsParams(ctx context.Context) (*BootOptionsParams, error) {
	bootOptionsParams := &BootOptionsParams{
		SetInProgress:            &BootOptionParam_SetInProgress{},
		ServicePartitionSelector: &BootOptionParam_ServicePartitionSelector{},
		ServicePartitionScan:     &BootOptionParam_ServicePartitionScan{},
		BMCBootFlagValidBitClear: &BootOptionParam_BMCBootFlagValidBitClear{},
		BootInfoAcknowledge:      &BootOptionParam_BootInfoAcknowledge{},
		BootFlags:                &BootOptionParam_BootFlags{},
		BootInitiatorInfo:        &BootOptionParam_BootInitiatorInfo{},
		BootInitiatorMailbox:     &BootOptionParam_BootInitiatorMailbox{},
	}

	if err := c.GetSystemBootOptionsParamsFor(ctx, bootOptionsParams); err != nil {
		return nil, fmt.Errorf("GetBootOptionsFor failed, err: %w", err)
	}

	return bootOptionsParams, nil
}

func (c *Client) GetSystemBootOptionsParamsFor(ctx context.Context, bootOptionsParams *BootOptionsParams) error {
	if bootOptionsParams == nil {
		return nil
	}

	if bootOptionsParams.SetInProgress != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.SetInProgress); err != nil {
			return err
		}
	}

	if bootOptionsParams.ServicePartitionSelector != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.ServicePartitionSelector); err != nil {
			return err
		}
	}

	if bootOptionsParams.ServicePartitionScan != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.ServicePartitionScan); err != nil {
			return err
		}
	}

	if bootOptionsParams.BMCBootFlagValidBitClear != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.BMCBootFlagValidBitClear); err != nil {
			return err
		}
	}

	if bootOptionsParams.BootInfoAcknowledge != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.BootInfoAcknowledge); err != nil {
			return err
		}
	}

	if bootOptionsParams.BootFlags != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.BootFlags); err != nil {
			return err
		}
	}

	if bootOptionsParams.BootInitiatorInfo != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.BootInitiatorInfo); err != nil {
			return err
		}

	}

	if bootOptionsParams.BootInitiatorMailbox != nil {
		if err := c.GetSystemBootOptionsParamFor(ctx, bootOptionsParams.BootInitiatorMailbox); err != nil {
			return err
		}
	}
	return nil
}