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

Cleanup and refactor firmware.sh #549

Merged
merged 21 commits into from
Jun 20, 2024

Conversation

sharpenedblade
Copy link
Contributor

There are minor visual changes and some of the "warnings" about installing packages got removed but most of the logic is exactly the same. 9c427e2 has a gnarly diff but the code changes are actually really small.

docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
@AdityaGarg8
Copy link
Member

Previously it was possible to manually run the python script using python3 firmware.sh. It can be useful in various cases, like having some firmware archive and want to rename it. Iirc, that's why I chose a polyglot script. Will it still be possible?

@AdityaGarg8
Copy link
Member

Also you have removed many intended blank lines from the code. It becomes a pain to read what is written on the terminal without blank lines. Lots of blank lines missing in create_deb, create_rpm and create_arch_package.

@AdityaGarg8
Copy link
Member

Also, the commit history is a pain to review here. Probably commit like

Refactor Install packages.
Refactor loading and unloading of drivers.

Etc.

Squash the commits which are addressing minor mistakes made by you.

Lastly, do the miscellaneous changes like shell check fixes, refactoring the python bit etc.

@AdityaGarg8
Copy link
Member

AdityaGarg8 commented Jun 14, 2024

If you want, you can open a new PR with a proper commit history. Probably shall also fix the intended blank lines, since hunting them shall be difficult.

@sharpenedblade
Copy link
Contributor Author

Previously it was possible to manually run the python script using python3 firmware.sh. It can be useful in various cases, like having some firmware archive and want to rename it. Iirc, that's why I chose a polyglot script. Will it still be possible?

I am going to make the script accept flags to pick a method so I can just add a flag to run the rename function

Also you have removed many intended blank lines from the code. It becomes a pain to read what is written on the terminal without blank lines. Lots of blank lines missing in create_deb, create_rpm and create_arch_package.

All of those were changed in d0c05f8, I can just revert that commit.

Also, the commit history is a pain to review here. Probably commit like

I can squash down some of the commits but its not going to be that much better. Github is messing up the diff, its a lot cleaner if you run git diff master --diff-algorithm minimal.

@sharpenedblade sharpenedblade force-pushed the refactor-firmware branch 2 times, most recently from 31c7ee8 to d2bc828 Compare June 14, 2024 20:40
@AdityaGarg8
Copy link
Member

Last 2 commits are absolutely unnecessary, The only thing that is good is replacing echo with cat and renaming firmware.tar to firmware-raw.tar. And please don't remove logging. It's required for have an idea where the script fails, in case it does. Also, why python_check is there in create_firmware even if it is macOS only check?

@AdityaGarg8
Copy link
Member

				for file in "$mountpoint/brcmfmac4364b2-pcie.txt" \
					    "$mountpoint/brcmfmac4364b2-pcie.txcap_blob"
				do
					if [ -f "$file" ]
					then
						sudo cp ${verbose} "$file" /lib/firmware/brcm
					fi
				done

And why has this been removed?

@AdityaGarg8
Copy link
Member

Also replace == with = in comparisons. IIRC == is bash specific, not POSIX compliant

@sharpenedblade
Copy link
Contributor Author

This isnt the latest version yet, I havent pushed my changes. I will request a review when im done.

@sharpenedblade
Copy link
Contributor Author

And why has this been removed?

Its appended to the tar archive so its not placed in the ESP anymore.

@AdityaGarg8
Copy link
Member

And why has this been removed?

Its appended to the tar archive so its not placed in the ESP anymore.

It's still placed in esp, and should be placed on esp

if [[ (${identifier} = iMac19,1) || (${identifier} = iMac19,2) || (${identifier} = iMacPro1,1) ]]

@AdityaGarg8
Copy link
Member

This isnt the latest version yet, I havent pushed my changes. I will request a review when im done.

Mark it as a draft then

@sharpenedblade
Copy link
Contributor Author

sharpenedblade commented Jun 15, 2024

And why has this been removed?

Its appended to the tar archive so its not placed in the ESP anymore.

It's still placed in esp

The current pushed branch is in a half-fixed state, its in the ESP on my local branch

and should be placed on esp

Why? Its just like the other firmware files, we just need to rename it on macos

@sharpenedblade sharpenedblade marked this pull request as draft June 15, 2024 04:46
@AdityaGarg8
Copy link
Member

And why has this been removed?

Its appended to the tar archive so its not placed in the ESP anymore.

It's still placed in esp

The current pushed branch is in a half-fixed state, its in the ESP on my local branch

and should be placed on esp

Why? Its just like the other firmware files, we just need to rename it on macos

Because ESP files are renamed on Linux, not macOS

@sharpenedblade
Copy link
Contributor Author

sharpenedblade commented Jun 15, 2024

Im not sure exactly what to put in the help output, its a bit unclear right now. Im open to renaming the subcommands too.

@sharpenedblade
Copy link
Contributor Author

Because ESP files are renamed on Linux, not macOS

I put it in the firmware-raw.tar.gz bundle but copy it on linux from the extracted tarball instead of giving it to the python script.

@AdityaGarg8
Copy link
Member

Im not sure exactly what to put in the help output, its a bit unclear right now. Im open to renaming the subcommands too.

I'd rather say add the rename only and get from macOS functionality. It would be better to give options to users rather than doing automatation. I don't think there will be a big gain by just reducing the step of choosing the method by the user. In fact passing these long parameters is a bigger pain.

@AdityaGarg8
Copy link
Member

Get from macOS should be good if you want to add some sort of systemd service which you planned before. Rename only should be good as script is no longer polyglot

@AdityaGarg8
Copy link
Member

Try to make things simple.

@AdityaGarg8
Copy link
Member

Because ESP files are renamed on Linux, not macOS

I put it in the firmware-raw.tar.gz bundle but copy it on linux from the extracted tarball instead of giving it to the python script.

Change was absolutely unnecessary, but it's fine if it works.

@sharpenedblade
Copy link
Contributor Author

I don't think there will be a big gain by just reducing the step of choosing the method by the user.
In fact passing these long parameters is a bigger pain.

There is no UX change if you run the script without any subcommands. If you dont pass anything then it uses the old code which interactively prompts the user.

I'd rather say add the rename only and get from macOS functionality.

rename_only is the same as running the old script with python3. get_from_macos is just method 4 from before.

Change was absolutely unnecessary, but it's fine if it works.

The idea was to add just firmware.tar.gz to the ESP in the future with renamed files in it.

@sharpenedblade
Copy link
Contributor Author

Try to make things simple.

In the script in general or just the argument parsing code? Argument parsing in bash is a PITA, especially without gnu-isms. Im not sure how much simpler it can be.

@sharpenedblade
Copy link
Contributor Author

Everything is working now. I think the logs are fixed too.

@sharpenedblade sharpenedblade marked this pull request as ready for review June 17, 2024 19:36
docs/tools/firmware.sh Show resolved Hide resolved
then
dmg2img -v BaseSystem.dmg fw.img
else
dmg2img -s BaseSystem.dmg fw.img
fi
rm BaseSystem.dmg
Copy link
Member

Choose a reason for hiding this comment

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

rm ${verbose}

Copy link
Member

Choose a reason for hiding this comment

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

Btw in cleanup_dmg function, workdir gets removed, which also has the dmg, so I wonder what's the actual advantage of specifically removing it here, since the next step before cleanup is simply firmware extraction and reloading drivers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tmpfs is usually in ram, if you are running low on ram the script crashes. The DMG is almost 2GB so this saves a lot of ram space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to overwrite BaseSystem.dmg with fw.img without using extra space, but I dont know how to do that

Copy link
Member

Choose a reason for hiding this comment

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

tmpfs is usually in ram, if you are running low on ram the script crashes. The DMG is almost 2GB so this saves a lot of ram space.

But it is not removed unless img is made, so what's the benefit here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I was testing the script it would crash a lot here and complain about low disk space, but once I added the rm it usually worked.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Im going to move the dmg dir to somewhere on disk.

docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
docs/tools/firmware.sh Outdated Show resolved Hide resolved
@AdityaGarg8
Copy link
Member

Don't squash the commit addressing these changes.

@AdityaGarg8
Copy link
Member

AdityaGarg8 commented Jun 18, 2024

nvram_txcap_quirk is broken in Method 1 (I haven't tested other methods yet). Cause is quite evident by the code itself. You are making a firmware-raw.tar.gz for the main firmware and firmware-raw.tar for extra firmware. After that you are only extracting firmware-raw.tar.gz on Linux and firmware-raw.tar is untouched.

Screenshot 2024-06-18 at 10 43 25 PM

I don’t understand how you moved the extra files to workdir on Linux as well.

Please test whatever you change.

@AdityaGarg8
Copy link
Member

Also, separate out python_check for macOS in a separate function like it was in the older version. There is not need to unnecessarily complicate the create_firmware_archive

@AdityaGarg8
Copy link
Member

No need to squash the commits btw.

@sharpenedblade
Copy link
Contributor Author

I don’t understand how you moved the extra files to workdir on Linux as well.

Once I add those files to the right archive it will work. When the tarfile is extracted those files will be in $PWD, which is $workdir

Please test whatever you change.

I dont have a mac where that code is used.

Also, separate out python_check for macOS in a separate function like it was in the older version. There is not need to unnecessarily complicate the create_firmware_archive

Ok

@AdityaGarg8
Copy link
Member

I don’t understand how you moved the extra files to workdir on Linux as well.

Once I add those files to the right archive it will work. When the tarfile is extracted those files will be in $PWD, which is $workdir

Please test whatever you change.

I dont have a mac where that code is used.

You can change the model identifier to your Mac and path to the firmware folder to your chip. That's how I test on my Mac.

Also, separate out python_check for macOS in a separate function like it was in the older version. There is not need to unnecessarily complicate the create_firmware_archive

Ok

@AdityaGarg8
Copy link
Member

What are you adding python_check in create_firmware_archive? Just put it in macOS specific code.

@sharpenedblade
Copy link
Contributor Author

What are you adding python_check in create_firmware_archive? Just put it in macOS specific code.

I moved it

@AdityaGarg8
Copy link
Member

Script looks good to me now, I've tested it on Ubuntu as well as Arch. I wonder if there could be a way to use /tmp if storage in RAM is sufficient. I would prefer not to write much on the SSD for such tasks.

@sharpenedblade
Copy link
Contributor Author

I wonder if there could be a way to use /tmp if storage in RAM is sufficient.

I think its better to use the disk since a lot of macs only have 8Gb of RAM and if you have swap enabled its going to write to disk anyways.

I would prefer not to write much on the SSD for such tasks.

It shouldn't be a problem, a lot of things write more than this to disk. SSD wear only matters if you write large amounts of data regularly, a user will probably only run this script once.

docs/tools/firmware.sh Outdated Show resolved Hide resolved
@AdityaGarg8 AdityaGarg8 merged commit d11ad47 into t2linux:master Jun 20, 2024
1 check passed
@sharpenedblade sharpenedblade deleted the refactor-firmware branch June 20, 2024 18:19
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