Friday, May 15, 2020

Running a macbook without battery ... let's go:


A pandemic: 


During the covid-19 lockdown, like many others, I've used my Macbook 13' mid-2018, quite a lot. And big mistake... it was always plugged in. Was it the cause of the problem or just a faulty battery, we will probably never know, but the battery started swelling badly to the point where it started deforming the case.



As I was using this laptop for my work and on time sensitive projects, no replacement battery available to do it myself, I had to find a solution. Apple was not helping, as they refuse to sell you parts, even in the middle of a lockdown, when you rely on your mac for work, and you cannot leave it 3 to 5 days in the hands of their technical service.

***Please note***: this is probably completely outdated by now, it was originally published in May 2020

Before removing:

First thing to know, the macbook will boot, but Apple decided to limit CPU performances to the bare minimum when running without battery. Some of the things you may need to do, may takes ages to load if they even load.

That's why I think, it is more efficient to do a couple of actions before removing the battery.

  1. Deactivating kernel_task capability to slow down your computer
  • Boot into recovery mode (press command+R at boot) 
  • Open a terminal
  • Deactivate SIP: csrutil disable (keep this disabled as it will be important for restoring normal CPU speeds after)
  • In single mode (command+S)
  • do a backup copy of /System/Library/Extensions/IOPlatformPluginFamily.kext
    • for example:
    • rsync -av /System/Library/Extensions/IOPlatformPluginFamily.kext /Users/Shared/
  • remove the IOPlatformPluginFamily: 
    • sudo rm -rf /System/Library/Extensions/IOPlatformPluginFamily.kext
    • if your system is read only, just do a mount -uw /  and redo the command above
  • Note: you should be able to reactivate csrutil with the following command and still be able to load CPUTune:
    • in recovery mode again:
    • csrutil enable --without kext
  • reboot, download and compile (with XCode)

  If you are having trouble compiling (here are the instructions from Nick-Z0, Thank you!)

Hello everyone, I am also trying to run my macbook without a battery following the tutorial by @christophe-duc in the first post but after spending the whole day on it without any luck, I finally managed to do it on my last try before posting here and asking for a compiled version. I just want to share what helped me to spare other people some time.

I was unable to compile it. I am on MacOS 10.14.6, I had xcode 11.0 that did not work, tried to install SDK for 10.14 as per a commenter on the tutorial post, did not work, installed xcode 10.3 tried again but did not work either (always changing deployment info to 10.14).

In the end I after searching the errors I got, I found this answer on stackoverflow that opening .xcodeproj instead of .xcworkspace will cause some errors. I was trying to compile CPUTuneApp and CPUTuneCore separately, only managing to compile the latter with success.

So the proper way to compile it is:

  1. Use correct version of Xcode that has SDK for your OS.
  2. Open ONLY CPUTune.xworkspace
  3. Change deployment to match your OS (click blue icon on the left CPUTuneCore, select Build Settings, Levels, and then set everything in macOS Deployment target to your OS. Then on the second list directly left of the Deployment target, select the other files and also change Deployment target. Finally, select the other blue icon CPUTuneApp and repeat the steps to change deployment target for everything.
  4. Click Play icon/Compile and hopefully you will get build succeeded message.

After removing:

Boot normally your macbook (it is going to be a very slow boot as the processor is going to be forced by Apple to run at the lowest speed possible)

How Apple is doing this, is by setting the BD_PROCHOT signal on the Intel CPU, which indicates that the CPUs are running hot (but they are not!) and disabling frequency stepping.

Disabling BD_PROCHOT is done at your own risk, as you are effectively disabling the thermal protections of your CPUs

CPUTune will solve this for you:
  • It will deactivate the turboboost (recommended so you don't overheat your CPUs) 
    • Note: it should be possible to run with turboboost as BD_PROCHOT does not impact the capabilities of the CPU to send its own PROCHOT signal and cool down when needed. So far my tests all get a forced reset when I deactivate BD_PROCHOT and Turboboost is enable. If you experience something different please let me know in the comment or post on CPUTune github. So far I think it's just Apple screwing with us, there should be a way to restore normal functionalities even without a battery...
  • Deactivate the BD_PROCHOT signal
  • Reactivate frequency stepping if needed
Once compiled, XCode will provide the CPUTune package in the Product directory in the XCode project interface. You can use 'Show in Finder' to copy the package into a directory of your choice.

  • change ownership on the package:
    • sudo chown -R root:wheel CPUTune.kext
  • Load the kext into memory (remember csrutil should be set to disable for this to work, as the kext is not signed)
    • sudo kextutil -v CPUTune.kext
  • kextutil will show an error that the kext is unsigned, but it should load it anyway if csrutil is disabled, you can then check if it's loaded using
    • kextstat
  • You can also check in /var/log/cputune.kext.log
CPUTune @ CPUInfo: cpu model: 0x8e
CPUTune @ cpu-tune-panic not existed in NVRAM property
CPUTune @ CPUInfo: cpu model: 0x8e
CPUTune @ init: successed!
CPUTune @ disableTurboBoost: change 0x850089 to 0x4000850089 in MSR_IA32_MISC_ENABLE(0x1a0)
CPUTune @ disableProcHot: change 0x64005f to 0x64005e in MSR_IA32_POWERCTL(0x1fc)
CPUTune @ enableSpeedShift: change 0x0 to 0x1 in MSR_IA32_PM_ENABLE(0x770)
CPUTune @ start: RegisterService

And voila! Your CPUs should now be freely moving frequency between min and max and you should have restored usability to your mac.

If you want to have CPUTune activated automatically at boot, just copy CPUTune.kext to /Library/Extensions/. Don't forget to make sure that the owner is correctly set:

sudo chown -R root:wheel /Library/Extensions/CPUTune.kext

Tested on May 2020 with a macbook pro 13' mid-2018 and running Catalina.

Additional note: if you are noticing shutdowns when high CPU programs are running, it seems that it is caused due to interference from the tailspind and spindump daemon.

You can check this by opening console and looking into the diagnotistic reports and you will see cpu_resource.diag files being generated when the shutdown happened

You can disable those daemons by issuing the following commands:
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.tailspind.plist
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.spindump.plist
If you want to permanently remove those services, remove the plist or move it to another name. You might need to boot into single user-mode for that (Command+S at boot) and remount the file system in read-write with mount -uw /

After disabling those, I have been able to use my macbook pro even on CPU intensive tasks without any issues. 

Additional note 2: if you want to restore Fans to normal behavior you can use Macs Fan Control it is available here: https://crystalidea.com/macs-fan-control/download

Thursday, March 3, 2016

How to integrate Shearwater information in Final Cut Pro X

After my video at 108 meters with Trimix (see here Youtube), there was a lot of interest on how i managed to put the shearwater information on the screen


To those who think this can be done automatically, no such luck. Everything is manual and it is a very repetitive process.

First, we need to extract the data of the dive. 

Go into Shearwater Desktop, select your dive and go into File->Export Dive->CSV


Shearwater will ask you for a directory to save the data to. In that directory you will find a csv file that you can open either with a text editor or excel.

Here are the columns that I used for the video:

Time (seconds), the shearwater internally save the data every 10 seconds, on the display the TIME is in minutes.
Depth: This translates directly into the DEPTH field
FirstStopDepth: translates to STOP
TTS Mins: translates to TTS field
Average PPO2: translates to the Gas PO2 field
Current NDL: translates to the NDL field
Fraction O2/FractionHe: permit to reconstruct the gas and the O2/HE field


In Final Cut pro, I created 2 titles that mimics the shearwater display (available here), Why 2, because the shearwater will change the color of the gas, when there is a better gas that can be used.

Now the boring part:
You have to sync the data that you have in the excel with the movie. What I do is that I use the moment I look at my shearwater in the dive to sync it the excel data. When this is done you  can go backward and forward from that point with the excel data.

I do a title every 10 seconds that is overlaid on top of the video, in each title, I look in the excel to find the corresponding data from the timestamp and I update one by one every title.



Have fun!