Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ func (c *Client) setBootParam(param uint8, data ...uint8) error {
// SetBootDevice is a wrapper around SetSystemBootOptionsRequest to configure the BootDevice
// per section 28.12 - table 28
func (c *Client) SetBootDevice(dev BootDevice) error {
return c.setBootDevice(dev, false)
}

// SetBootDeviceEFI is to support EFI boot option
func (c *Client) SetBootDeviceEFI(dev BootDevice) error {
return c.setBootDevice(dev, true)
}

func (c *Client) setBootDevice(dev BootDevice, efi bool) error {
useProgress := true
// set set-in-progress flag
err := c.setBootParam(BootParamSetInProgress, 0x01)
Expand All @@ -93,7 +102,11 @@ func (c *Client) SetBootDevice(dev BootDevice) error {
return err
}

err = c.setBootParam(BootParamBootFlags, 0x80, uint8(dev), 0x00, 0x00, 0x00)
flag := uint8(0x80)
if efi {
flag = flag | 0x20
}
err = c.setBootParam(BootParamBootFlags, flag, uint8(dev), 0x00, 0x00, 0x00)
if err == nil {
if useProgress {
// set-in-progress = commit-write
Expand Down
37 changes: 37 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func TestClient(t *testing.T) {
err = client.Open()
assert.NoError(t, err)

s.SetHandler(NetworkFunctionChassis, CommandSetSystemBootOptions, func(msg *Message) Response {
if msg.Data[0] == BootParamBootFlags {
assert.Equal(t, []byte{0x05, 0x80, 0x04, 0x00, 0x00, 0x00}, msg.Data)
}
return &SetSystemBootOptionsResponse{
CompletionCode: CommandCompleted,
}
})

err = client.SetBootDevice(BootDevicePxe)
assert.NoError(t, err)

Expand Down Expand Up @@ -75,3 +84,31 @@ func TestDeviceID(t *testing.T) {
assert.NoError(t, err)
s.Stop()
}

func TestBootDevEFI(t *testing.T) {
s := NewSimulator(net.UDPAddr{Port: 0})
err := s.Run()
assert.NoError(t, err)

client, err := NewClient(s.NewConnection())
assert.NoError(t, err)

err = client.Open()
assert.NoError(t, err)

s.SetHandler(NetworkFunctionChassis, CommandSetSystemBootOptions, func(msg *Message) Response {
if msg.Data[0] == BootParamBootFlags {
assert.Equal(t, []byte{0x05, 0xa0, 0x04, 0x00, 0x00, 0x00}, msg.Data)
}
return &SetSystemBootOptionsResponse{
CompletionCode: CommandCompleted,
}
})

err = client.SetBootDeviceEFI(BootDevicePxe)
assert.NoError(t, err)

err = client.Close()
assert.NoError(t, err)
s.Stop()
}