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

bin/ubuntu-core-initramfs: build the early initrd from installed ucode packages #252

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

Conversation

valentindavid
Copy link
Collaborator

No description provided.

@valentindavid valentindavid force-pushed the valentindavid/ucode branch 2 times, most recently from fdbf8e9 to 22951f8 Compare August 12, 2024 14:29
@valentindavid
Copy link
Collaborator Author

Tested on Intel NUC. Not tested on AMD.

Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of the TODO! I have a couple of questions below.

shutil.copyfileobj(f, output)

def mk_intel_ucode(output_path):
check_call(['iucode_tool', f'--write-to={output_path}', '/lib/firmware/intel-ucode/'])

Choose a reason for hiding this comment

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

Should this call /usr/share/initramfs-tools/hooks/intel_microcode? I know that this is the way that this is done atm by the script in the debian folder but I fear that we become out of sync with the way that the distro creates the microcode bits. For instance I see that the script uses --write-earlyfw but that is not here. We can leave it as a TODO if not too practical.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is weird to use --write-earlyfw since we want to combine the AMD firmware with the Intel firmware in the same early initrd. --write-earlyfw would create the initrd only with Intel ones.

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 have the impression that initramfs-tools chooses what firmware to use dependending on the processor of the current machine. It is a different script for AMD: /usr/share/initramfs-tools/hooks/amd64_microcode

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, those are hooks for initramfs-tools. They are not expected to be run as tools. We would need to provide environment variables to mimic the initramfs-tools API. And I feel it can break easily.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, sounds good

def mk_amd_ucode(output):
for path in glob.glob('/lib/firmware/amd-ucode/*.bin'):
with open(path, 'rb') as f:
shutil.copyfileobj(f, output)

Choose a reason for hiding this comment

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

Similar question to the one for intel about using /usr/share/initramfs-tools/hooks/amd64_microcode

Comment on lines 754 to 758
if os.path.exists('/lib/firmware/amd-ucode'):
with open(os.path.join(microcode_dir, 'AuthenticAMD.bin'), 'wb') as f:
mk_amd_ucode(f)
if os.path.exists('/lib/firmware/intel-ucode'):
mk_intel_ucode(os.path.join(microcode_dir, 'GenuineIntel.bin'))

Choose a reason for hiding this comment

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

We should check that if it the target arch is amd64 both actually exist and error otherwise.

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 had to use dpkg-architecture. Have a look.

@valentindavid valentindavid force-pushed the valentindavid/ucode branch 2 times, most recently from 2bd4d7c to bb9bf48 Compare October 30, 2024 11:27
Copy link
Member

@alfonsosanchezbeato alfonsosanchezbeato left a comment

Choose a reason for hiding this comment

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

Thanks for the changes, I have a question, looks good otherwise

shutil.copyfileobj(f, output)

def mk_intel_ucode(output_path):
check_call(['iucode_tool', f'--write-to={output_path}', '/lib/firmware/intel-ucode/'])
Copy link
Member

Choose a reason for hiding this comment

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

Ok, sounds good

with open(os.path.join(microcode_dir, 'AuthenticAMD.bin'), 'wb') as f:
mk_amd_ucode(f)
mk_intel_ucode(os.path.join(microcode_dir, 'GenuineIntel.bin'))
reset_time(d)
Copy link
Member

Choose a reason for hiding this comment

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

Why is this reset of the files time needed? Adding a comment would be good.

@alfonsosanchezbeato
Copy link
Member

An additional thing, it looks like rootfs is not being considered so this would fail if args.root is used.

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.

2 participants