Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/amd/firmware: Wrap PSP and BIOS directories in arrays #367

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

orangecms
Copy link
Collaborator

This allows for returning multiple directories. Up until now, only the first directories
would be returned, while many firmware images contain multiple directories for various
SoC families and models, e.g., for desktop boards where SoCs can be swapped.

Signed-off-by: Daniel Maslowski [email protected]

This allows for returning multiple directories. Up until now, only the first directories
would be returned, while many firmware images contain multiple directories for various
SoC families and models, e.g., for desktop boards where SoCs can be swapped.

Signed-off-by: Daniel Maslowski <[email protected]>
@codecov-commenter
Copy link

Codecov Report

Merging #367 (f581bcd) into master (64c18ae) will decrease coverage by 0.02%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #367      +/-   ##
==========================================
- Coverage   41.74%   41.72%   -0.03%     
==========================================
  Files         110      110              
  Lines        7649     7653       +4     
==========================================
  Hits         3193     3193              
- Misses       3877     3881       +4     
  Partials      579      579              
Impacted Files Coverage Δ
pkg/amd/manifest/firmware.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 64c18ae...f581bcd. Read the comment docs.

@rihter007
Copy link
Collaborator

A slice doesn't provide information about the origin of the element.
It is unclear what element should I use, if I end up having multiple.

@orangecms
Copy link
Collaborator Author

A slice doesn't provide information about the origin of the element. It is unclear what element should I use, if I end up having multiple.

Yea, that is also currently the problem: I don't know what I got, I only got a single directory, and I am missing the other directories. From the code I could understand that I got the first directory that is found. And it could be either from the EmbeddedFirmwareStruct or it could have been found by scanning. When the latter is the case, how would we know the processor family/model range?

To expost that information when we have it, I would suggest adding metadata to the respective directory, such as processor family / model range based on the offset. However, that is a different concern; this PR here is to enable multiple directories for a start. WDYT?

Copy link
Member

@GanShun GanShun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think this needs to be cleaned up long term, descriptors need to be added to differentiate the PSPDirectories, but it's possible this could be placed in the PSPDir struct instead. I'm ok with merging this right now as it doesn't make anything worse, and looking at the code like this actually warns me that there can be multiple PSP directories.

Perhaps a TODO or block comment is in order warning us that only the first one is handled right now?

@rihter007
Copy link
Collaborator

A slice doesn't provide information about the origin of the element. It is unclear what element should I use, if I end up having multiple.

Yea, that is also currently the problem: I don't know what I got, I only got a single directory, and I am missing the other directories. From the code I could understand that I got the first directory that is found. And it could be either from the EmbeddedFirmwareStruct or it could have been found by scanning. When the latter is the case, how would we know the processor family/model range?

To expost that information when we have it, I would suggest adding metadata to the respective directory, such as processor family / model range based on the offset. However, that is a different concern; this PR here is to enable multiple directories for a start. WDYT?

Sorry, for a very long delay. There is a documentation problem, each "directory" has its own purpose. The future code should clearly specify the purpose of each directory. (which we currently can't do)

I agree that the current code assumes, that there could be no more than a single directory in firmware, which could be incorrect.

I propose to leave everything as is, but move "scanning" into a separate function

Copy link
Collaborator

@rihter007 rihter007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a documentation problem, each "directory" has its own purpose. The future code should clearly specify the purpose of each directory. (which we currently can't do)

I agree that the current code assumes, that there could be no more than a single directory in firmware, which could be incorrect.

I propose to leave everything as is, but move "scanning" into a separate function, this will make the behaviour of what directory do we have clear.

@orangecms
Copy link
Collaborator Author

Okay I will create another implementation then. We discussed this in the Fiano sync call, and the proposal is to rework the directory structs, so that they

  • contain the range; it's currently side by side, though belongs to the dir
  • get a source field; can be "scan", "efs". "xxxdir", depending on whether it resulted from seeking or from following references via EFS or possibly a level 1 directory (called pointers here in the code; "xxxdir" would need be more precise of course such as "fam-17h_model-00h-0fh_biosdir" or something)

@orangecms orangecms marked this pull request as draft March 21, 2022 22:19
@orangecms orangecms changed the base branch from master to main September 8, 2022 13:03
}
}
break
}
}

result.BIOSDirectories = []BIOSDir{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand this. you can append to a nil slice. But 112 or 113 seem redundant. But you wanted two elements or ...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough Go, will see about your suggestion.

@orangecms
Copy link
Collaborator Author

orangecms commented Oct 9, 2024

I've been working on this again recently, but in a Rust implementation, based on System76/Jeremey Soller's romulan:
https://github.com/orangecms/romulan/tree/CLI-to-teh-limitz

The current objective is diffing two given images, allowing me to somewhat understand them more.
Up until now, we still don't have much documentation. All I can refer to is other people's reversing, what's in Fiano as of now, and what's in the coreboot docs: https://doc.coreboot.org/soc/amd/psp_integration.html#psp-directory-table-entries

Addendum 1: coreboot refers to NDA docs, so they are not publicly accessible/verifiable.
Addendum 2: coreboot has some AMD CLI tools which can provide some more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants