Skip to content

Commit

Permalink
pkg/compression: Set correct brotli settings for edk2
Browse files Browse the repository at this point in the history
With these settings a recompiled OVMF with linuxboot booted

The scratch buffer size needs to be tuned. We don't know what the
system tool uses. Maybe we can know when the go library compresses

Signed-off-by: Ian Goegebuer <[email protected]>
  • Loading branch information
iangoegebuer authored and orangecms committed Jan 29, 2024
1 parent 9578087 commit 0ad88a5
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/compression/systembrotli.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c *SystemBROTLI) Decode(encodedData []byte) ([]byte, error) {

// Encode encodes a byte slice with BROTLI.
func (c *SystemBROTLI) Encode(decodedData []byte) ([]byte, error) {
cmd := exec.Command(c.brotliPath, "--stdout")
cmd := exec.Command(c.brotliPath, "--stdout", "-q", "9")
cmd.Stdin = bytes.NewBuffer(decodedData)

encodedData, err := cmd.Output()
Expand All @@ -47,15 +47,16 @@ func (c *SystemBROTLI) Encode(decodedData []byte) ([]byte, error) {
}

// Generate the size of the decoded data for the header
buf := &bytes.Buffer{}
if err := binary.Write(buf, binary.LittleEndian, uint64(len(decodedData))); err != nil {
decodedSize := &bytes.Buffer{}
if err := binary.Write(decodedSize, binary.LittleEndian, uint64(len(decodedData))); err != nil {
return nil, err
}

// This seems to be the buffer size needed by the UEFI decompressor
header := []byte{0x00, 0x00, 0x00, 0x02, 0, 0, 0, 0}

header = append(buf.Bytes(), header...)
// 0x03000000 should suffice. The EDK2 base tools generates this header
// using Brotli internals. This needs to be tuned somehow
scratchBufferSize := []byte{0x00, 0x00, 0x00, 0x03, 0, 0, 0, 0}
header := append(decodedSize.Bytes(), scratchBufferSize...)

encodedData = append(header, encodedData...)

Expand Down

0 comments on commit 0ad88a5

Please sign in to comment.