github.com/linuxboot/fiano@v1.2.0/cmds/fspinfo/main_test.go (about)

     1  // Copyright 2017-2018 the LinuxBoot Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"os"
    10  	"testing"
    11  
    12  	"github.com/linuxboot/fiano/pkg/fsp"
    13  )
    14  
    15  const (
    16  	// From https://github.com/IntelFsp/FSP/blob/master/ApolloLakeFspBinPkg/FspBin/Fsp.fd
    17  	// under the FSP license. See README.md under `test_blobs`.
    18  	FSPTestFile = "test_blobs/ApolloLakeFspBinPkg/Fsp.fd"
    19  )
    20  
    21  func TestNewInfoHeaderRealFile(t *testing.T) {
    22  	buf, err := os.ReadFile(FSPTestFile)
    23  	if err != nil {
    24  		t.Errorf("Error opening test file %s: %v", FSPTestFile, err)
    25  	}
    26  	// in the ApolloLake FSP, the FSP header starts at byte 148. This can be
    27  	// extracted by parsing it as uefi.FirmwareVolume, but it's not relevant for
    28  	// this test, so let's go with raw offsets.
    29  	hdr, err := fsp.NewInfoHeader(buf[148 : 148+fsp.HeaderV3Length])
    30  	if err != nil {
    31  		t.Errorf("NewInfoHeader failed to parse FSP file %s: %v", FSPTestFile, err)
    32  	}
    33  	if hdr.Signature != fsp.Signature {
    34  		t.Errorf("Invalid signature %v; want %v", hdr.Signature, fsp.Signature)
    35  	}
    36  	if hdr.HeaderLength != fsp.HeaderV3Length {
    37  		t.Errorf("Invalid header length %d; want %d", hdr.HeaderLength, fsp.HeaderV3Length)
    38  	}
    39  	if hdr.SpecVersion != fsp.SpecVersion(0x20) {
    40  		t.Errorf("Invalid spec version %s; want %s", hdr.SpecVersion, fsp.SpecVersion(0x20))
    41  	}
    42  	if hdr.HeaderRevision != 3 {
    43  		t.Errorf("Invalid header revision %d; want %d", hdr.HeaderRevision, 3)
    44  	}
    45  	if hdr.ImageRevision != fsp.ImageRevision(0x0001000400030001) {
    46  		t.Errorf("Invalid image revision %s; want %s", hdr.ImageRevision, fsp.ImageRevision(0x0001000400030001))
    47  	}
    48  	if !bytes.Equal(hdr.ImageID[:], []byte("$APLFSP$")) {
    49  		t.Errorf("Invalid image ID %s; want %s", hdr.ImageID, "$APLFSP$")
    50  	}
    51  	if hdr.ImageSize != 0x2a000 {
    52  		t.Errorf("Invalid image size %#x; want %#x", hdr.ImageSize, 0x2a000)
    53  	}
    54  	if hdr.ImageBase != 0x200000 {
    55  		t.Errorf("Invalid image base %#x; want %#x", hdr.ImageSize, 0x200000)
    56  	}
    57  	if hdr.ImageAttribute != 0x1 {
    58  		t.Errorf("Invalid image attribute %#x; want %#x", hdr.ImageAttribute, 0x1)
    59  	}
    60  	if hdr.ComponentAttribute != 0x3003 {
    61  		t.Errorf("Invalid component attribute %#x; want %#x", hdr.ComponentAttribute, 0x3003)
    62  	}
    63  	if hdr.CfgRegionOffset != 0x124 {
    64  		t.Errorf("Invalid cfg region offset %#x; want %#x", hdr.CfgRegionOffset, 0x124)
    65  	}
    66  	if hdr.CfgRegionSize != 0x3b0 {
    67  		t.Errorf("Invalid cfg region size %#x; want %#x", hdr.CfgRegionSize, 0x3b0)
    68  	}
    69  	if hdr.TempRAMInitEntryOffset != 0x0 {
    70  		t.Errorf("Invalid temp RAM init entry offset %#x; want %#x", hdr.TempRAMInitEntryOffset, 0x0)
    71  	}
    72  	if hdr.NotifyPhaseEntryOffset != 0x580 {
    73  		t.Errorf("Invalid notify phase entry offset %#x; want %#x", hdr.NotifyPhaseEntryOffset, 0x580)
    74  	}
    75  	if hdr.FSPMemoryInitEntryOffset != 0x0 {
    76  		t.Errorf("Invalid FSP memory init entry offset %#x; want %#x", hdr.FSPMemoryInitEntryOffset, 0x0)
    77  	}
    78  	if hdr.TempRAMInitEntryOffset != 0x0 {
    79  		t.Errorf("Invalid temp RAM init entry offset %#x; want %#x", hdr.TempRAMInitEntryOffset, 0x0)
    80  	}
    81  	if hdr.FSPSiliconInitEntryOffset != 0x58a {
    82  		t.Errorf("Invalid FSP silicon init entry offset %#x; want %#x", hdr.FSPSiliconInitEntryOffset, 0x58a)
    83  	}
    84  }