Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
misc:acpi_patch [2025/04/25 15:11] – created h3artbl33dmisc:acpi_patch [2025/06/29 00:26] (current) 92.40.32.213
Line 1: Line 1:
-Patch to fix the ACPI weirdness on some models - TODO!!+====== The Dreaded ACPI Timeout Bug ====== 
 + 
 +Some models can experience really, really long boot times with OpenBSD. This bug has been known for a while and seems to have appeared around OpenBSD 7.6. It has [[https://bsd.network/@brynet/114322673716285788|featured]] [[https://old.reddit.com/r/openbsd/comments/1ixz0bn/macbook_2015/|in]] [[https://marc.info/?l=openbsd-bugs&m=173855804823166&w=2|a lot of]] [[https://marc.info/?l=openbsd-misc&m=174438934730598&w=2|discussions]], and resolving it caused so much unbridled joy that it prompted the creation of this entire wiki. 
 + 
 +===== The Symptoms ===== 
 +Booting the stock installer or kernel will cause the boot procedure to hang quite early on, usually after identifying the hard disks: 
 + 
 +{{ :misc:acpi-bug-macbook-12-1.jpg?direct&640 |}} 
 + 
 +As @brynet@bsd.network pointed out, it is caused by "some kind of regression that triggers a weird ACPI firmware bug on this machine."  
 + 
 +The machine **will** boot, eventually, if you leave it long enough, usually 2+ hours. However, without applying a simple patch to the kernel, it will do the same thing every single time you boot the machine. 
 + 
 +===== Affected Models ===== 
 +  * [[:A1502]] Early 2015 Macbook Pro 
 +  * Maybe others? 
 + 
 +==== Patch to fix the ACPI bug ====
  
 <code> <code>
Line 20: Line 37:
  int  int
 </code> </code>
 +
 +==== How to patch ====
 +
 +You have two options: build a custom installer and install your system with a patched kernel, or going the "slow way" and wait out the long boot time on booting the installer; installing the system; waiting out the first boot; then patching the kernel for the machine you are on.
 +
 +Before you start, give the following manual pages a good read, you will have a much clearer understanding of what's going on:
 +  * [[https://www.openbsd.org/anoncvs.html|Getting sources from the OpenBSD CVS]]
 +  * [[https://man.openbsd.org/release|RELEASE(8) Manual Page]]
 +  * [[https://www.openbsd.org/faq/faq5.html|OpenBSD FAQ - Building the System from Source]]
 +  * If going the "Custom installer" route, [[https://www.openbsd.org/faq/faq4.html#MkInsMedia|OpenBSD FAQ - Creating Install Media ]]
 +
 +=== I. The Slow Boot Way ===
 +Waiting out the slow boot times is probably a little bit easier, and it doesn't require you to have another working OpenBSD install that you can use to compile a custom kernel and create a custom installer image.
 +
 +So after you have downloaded the latest ''installXX.img'', flashed it to a USB drive or whatever, plugged it in, booted up the Mac by holding down Option until you see the bootloader screen, selected the USB drive ("EFI BOOT" usually), started the installer, waited / slept / went for a walk until it got over the ACPI nonsense, installed, rebooted, waited / slept / went for a walk until it got over the ACPI nonsense again, and logged in...
 +
 +== 0. Setting some ENV variables ==
 +It makes your life easier if you set the $CVSROOT env variable in your ''%%~/.profile%%'' or ''%%~/.kshrc%%'' or preferred place that will get sourced on login.
 +
 +First, pick a server close to you from the list at the bottom of the [[https://www.openbsd.org/anoncvs.html|OpenBSD Anonymous CVS]] page
 +
 +Then add to your dotfile of choice the below:
 +<code>
 +export CVSROOT=anoncvs@url-to-your-cvs-server-of-cho.ice:/cvs
 +</code> 
 +And source it:
 +<code>
 +$ . ~/.my-favourite-dotfile
 +</code>
 +
 +== 1. Add your user to the source groups ==
 +You need to be a member of ''wsrc'' and ''wobj'' groups. As root, therefore, run:
 +<code>
 +# usermod -G wsrc,wobj $YOURUSERNAME
 +</code>
 +
 +== 2. CVS Checkout the Tree of the Sauce ==
 +It is important that you get the sources for the branch you follow. Check the instructions under **"Getting an Initial Tree"** on the [[https://www.openbsd.org/anoncvs.html|OpenBSD Anonymous CVS]] page.
 +
 +If you are on ''-current'', it's advised you make sure you are on the latest snapshot before downloading the source tree, by running ''%%# sysupgrade -s%%'' first.
 +
 +First checkout takes a while, but once done, you should have the source tree in ''/usr/src''.
 +
 +== 3. Patch / Edit the appropriate files ==
 +Paste the contents of the Patch above into a new file (let's call it <del>best-patch-ever.diff</del> ''mac_acpi_patch.diff'' for our purposes), and then run:
 +<code>
 +$ patch < mac_acpi_patch.diff
 +</code>
 +
 +You can of course simply comment out the two (!) affected lines manually; [[https://old.reddit.com/r/openbsd/comments/1ixz0bn/macbook_2015/|you need to delete / comment out two lines]] in ''/usr/src/sys/dev/acpi/acpi.c''. (In OpenBSD 7.7 they start at :823).
 +
 +== 4. Compiling ==
 +Follow the ''release(8)'' man page closely here. 
 +As root, first, change directories to the appropriate directory in ''/sys''. Make sure you are in the right folder because ''/usr/src/sys'' follows the same directory structure, but if you compile from there, you won't get the right results. This was a lesson learned //The Hard Way//™. So to be on the safe side do exactly as the manpage says, and run:
 +<code>
 +$ doas -s
 +# cd /sys/arch/amd64/compile/GENERIC.MP
 +</code>
 +
 +Then proceed as the manual suggests, with root privileges - otherwise "make install" will fail. This is another lesson learned //The Hard Way//™. 
 +<code>
 +# make obj
 +# make config
 +# make && make install
 +</code>
 +
 +After you reboot, the new kernel should be the one in use. It will be easy to tell whether the patch worked, because if your system boots "normally", it worked, if you are back at waiting for 2+ hours at "sd0", it failed and you need to check over whether you did everything correctly.
 +
 +
 +----
 +
 +
 +===== Updating the patched system =====
 +If you want to avoid having to wait 2+ hours again TWICE everytime you have to update your system, there is, fortunately, a much quicker way to do it. Basically the less painfully slow update method is a hybrid of manual and automatic installation with custom-compiling the kernel. Credits go to [[https://marc.info/?l=openbsd-tech&m=175031825008339&w=2|Stuart Henderson]] for pointing out this possibility.
 +
 +The below will be a walkthrough that follows ''-current'', a few commands will be different for ''-stable'', these will be indicated.
 +
 +==== 0. Preparation ====
 +=== 0.a. READ UP. Seriously. ===
 +Read through the [[https://www.openbsd.org/faq/upgrade77.html#NoInstKern|OpenBSD Manual Installation howto in the FAQ]] first as well as the man pages linked above, if you have not done so. They will make your life much much easier.
 +
 +=== 0.b. Preparation ===
 +Follow the "Preparation" steps on the Manual Upgrade page: especially on becoming root "properly" and installing the boot blocks. Make sure you install the boot blocks to the appropriate drive, do not just go with "sd0" as it was in the tutorial, if, say your root is on e.g. sd3.
 +
 +==== 1. Get the upgrade files ====
 +Fetch the updates and move them to a new location. When you run ''sysupgrade'' the installer files are stored in ''/home/_sysupgrade'', and two extra files are created, ''/bsd.update'' and ''/auto_upgrade.conf''. You want to copy the installer files from ''/home/_sysupgrade'' somewhere else, and delete the auto-update files.
 +<code>
 +# sysupgrade -ns
 +# mkdir /usr/update
 +# mv /home/_sysupgrade/* /usr/update/
 +# rm /{bsd.update,auto_upgrade.conf}
 +</code>
 +**NB**: On ''-stable'' you want to run ''sysupgrade -n''.
 +
 +==== 2. Update the source tree ====
 +Follow the **Anonymous CVS** guides for updating the source tree to the latest version. 
 +☛ **ASIDE** - What to do if acpi.c changes drastically and the patch doesn't work anymore? ((The file we have been patching, ''/usr/src/sys/dev/acpi/acpi.c'', might change in the future. It is good to check the CVS logs, or keep an eye on the [[https://github.com/openbsd/src/commits/master/sys/dev/acpi/acpi.c|acpi.c on GitHub's CVS mirror]].  If you would see that the lines we have been working with have changed in the source or new features have been introduced, then you need to revert your local modifications to the CVS version. To do this, you need to run,
 +<code>
 +$ cd /usr/src/sys/dev/acpi/
 +$ cvs update -C acpi.c
 +</code>
 +CVS will tell you where it stashed the previous file, it usually starts with ".#" or similar. You can then run ''diff'' and see what the changes were, decide whether you need to find the lines that were previously around :823 and automatically or manually patch again, or not.))
 +
 +To update the source tree on ''-current'', run:
 +<code>
 +$ cd /usr/src
 +$ cvs -q up -Pd -A
 +</code>
 +**NB**: On ''-stable'' you want to use '' -rOPENBSD_7_7'' as the last parameter instead of "-A"
 +
 +==== 3. Re-compile the GENERIC.MP Kernel ====
 +See above, but run ''# make clean'' before compiling and **do not** run ''# make install'' at the end:
 +<code>
 +# cd /sys/arch/amd64/compile/GENERIC.MP/
 +# make clean
 +# make obj
 +# make config
 +# make
 +</code>
 +Your newly compiled kernel file, ''bsd.gdb'' will be in the symlinked ''obj'' directory. The symlink points to ''/usr/obj/sys/arch/amd64/compile/GENERIC.MP/bsd.gdb''.
 +
 +Now we have:
 +  * The latest update files stored away safely 
 +  * The latest kernel, compiled with our own patch
 +
 +So it is time to move on to the installation.
 +
 +==== 4. Manual installation ====
 +This follows closely the official [[https://www.openbsd.org/faq/upgrade77.html#NoInstKern|manual installation guide]], but diverges for the installation of the kernel.
 +
 +=== 4.a. Make sure you have done all the preparation in the official guide ===
 +Did you?
 +
 +=== 4.b Install the newly compiled kernel ===
 +We did not run ''make install'' after compiling because we are going to do this little dance as suggested:
 +<code>
 +# cd /usr/update
 +# ln -f /bsd /obsd 
 +# cp /usr/obj/sys/arch/amd64/compile/GENERIC.MP/bsd.gdb /nbsd && mv /nbsd /bsd
 +# cp bsd.rd /
 +# cp bsd /bsd.sp # You might not even have this file, relatively safe to skip this last one if you do not intend to run in single-processor mode
 +</code>
 +
 +=== 4.c follow the rest of the Manual Install Process ===
 +Follow closely the linked manual installation guide, and continue the process: Enable KARL; Install new userland. Reboot. Run MAKEDEV,  update the boot loader, run ''sysmerge'' and ''fw_update''.
 +
 +DONE!
 +