Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1] 2   Go Down

Author Topic: Setting PowerBook G4 fan speed in open firmware  (Read 17008 times)

Greystash

  • 256 MB
  • *****
  • Posts: 257
  • Tinkerer
    • Mac-Classic.com
Setting PowerBook G4 fan speed in open firmware
« on: March 12, 2019, 01:40:50 AM »

Is there anyone out there with some knowledge on Open Firmware?

I've been playing around with OF recently to try turning the fans on my PowerBook G4 while running OS9. I've hit a roadblock trying to modify values within the 'fan' device, each time I try to modify a property OF returns "no current instance"

I can change values for other devices, the example below turns all LEDs on:

Code: [Select]
dev via-pmu
ledson true

Modifying fan properties example:
Code: [Select]
dev fan
fans-on true

RETURNS
> no current instance

I found this article where somebody enabled the fans on their Pismo, but I haven't been able to get close to this.

Below is a list of the 'words' relevant to the fan device.
Logged

Daniel

  • 256 MB
  • *****
  • Posts: 302
  • Programmer, Hacker, Thinker
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #1 on: March 12, 2019, 04:12:47 AM »

Most OF devices insist that you "open" them and create and instance.

Code: [Select]
" fan" open-dev constant fan-ih
" fans-on" fan-ih $call-method

Once you are done with an opened device, you can close it. It doesn't really matter if you do.
Code: [Select]
fan-ih close-dev
I don't know how to turn on the fan, but the "see" word lets you look inside the OF routines.
Code: [Select]
dev fan
see fan-on
Logged

darthnVader

  • 512 MB
  • *****
  • Posts: 681
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #2 on: March 12, 2019, 11:47:16 AM »

I don't want to hijack the thread, but I figure I'll side track it a little.

Something me and Elliot have been working on, iBooks and Powerbooks with the 7447a boot in dfs-low mode, and because OS 9 has no power management software for the 7447a the CPU runs at 50% under OS 9.

We've been working on fixing this through the Mac OS ROM, but this thread makes me think maybe we could do it with an nvram script, and I've found some things that make me think there is a way to do what we want...

Code: [Select]
Trying 10.1.2.3...
Connected to 10.1.2.3.
Escape character is '^]'.
 ok
0 > dev /cpus/@0  ok
0 > words

set-dfs-high    translate       modify          unmap           map
release         claim           set-dfs-low     set-dfs-high    spd
close           open  ok
0 > spd 140  pll-ratio*2 = 10  HID1 = 80416c80  DelayAACK = 0  GPIO1 = 4 BusClk = 133173712  ok
0 > set-dfs-high  ok
1 > spd 140  pll-ratio*2 = 10  HID1 = 80416c80  DelayAACK = 0  GPIO1 = 4 BusClk = 133173712  ok
1 > modify
STACK UNDERFLOW!
 ok
0 > claim
CLAIM failed
 ok
0 >

set-dfs-high is what we are looking for, but I'm unsure how to use the word?

Seems it would also use the "modify"  or maybe the "claim" word, or "translate"?

Code: [Select]
0 > " /cpus/@0" open-dev constant set-dfs-high  ok
0 > " translate" set-dfs-high $call-method  ok
0 > set-dfs-high close-dev  ok
0 > spd 140  pll-ratio*2 = 10  HID1 = 80416c80  DelayAACK = 0  GPIO1 = 4 BusClk = 133173712  ok
0 >

That didn't work, as we can see from "spd" HID1 bit 9 is still set to true, but I'm really close, and just need a little help getting the correct syntax, Daniel?
Logged

darthnVader

  • 512 MB
  • *****
  • Posts: 681
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #3 on: March 12, 2019, 12:12:26 PM »

Never mind, it couldn't be simpler.

Code: [Select]
Trying 10.1.2.3...
Connected to 10.1.2.3.
Escape character is '^]'.
 ok
0 > dev /cpus/@0  ok
0 > spd 139  pll-ratio*2 = 10  HID1 = 80416c80  DelayAACK = 0  GPIO1 = 4 BusClk = 133173483  ok
0 > set-dfs-high  ok
0 > spd 70  pll-ratio*2 = 20  HID1 = 80015c80  DelayAACK = 0  GPIO1 = 7 BusClk = 133173483  ok
0 >

Logged

Greystash

  • 256 MB
  • *****
  • Posts: 257
  • Tinkerer
    • Mac-Classic.com
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #4 on: March 13, 2019, 12:57:13 AM »

Most OF devices insist that you "open" them and create and instance.

Code: [Select]
" fan" open-dev constant fan-ih
" fans-on" fan-ih $call-method

Once you are done with an opened device, you can close it. It doesn't really matter if you do.
Code: [Select]
fan-ih close-dev
I don't know how to turn on the fan, but the "see" word lets you look inside the OF routines.
Code: [Select]
dev fan
see fan-on


Thanks Daniel! Your code turns the fans on at full speed which is a fantastic start!

However, I can't figure out how to work with any of the routines. There's a lot of options that look like they can be modified but it's a matter of figuring out the correct syntax to overwrite the default values. For example 'set-speed' and '.set-speed' give very different output when using the 'see' method and don't give much indication on what can be edited:

Code: [Select]
> see .speed
1 read-speed cr " TACH1 = " type .d 2 read-speed cr " TACH2 = " type .d 3 read-speed cr " TACH3 = " type .d 4 read-speed cr " TACH4 = type .d ; ok

Code: [Select]
> see set-speed
>r 40 dup read-reg 8 andc write-reg case
    1 of
      5c dup read-reg e0 or write-reg 30 r> write-reg
      endof
    2 of
      5d dup read-reg e0 or write-reg 31 r> write-reg
      endof
    3 of
      5e dup read-reg e0 or write-reg 32 r> write-reg
      endof
    dup of
      5e dup read-reg e0 or write-reg 32 r> write-reg
      endof
  endcase
; ok

Code: [Select]
> see set-speeds
1 over set-speed 2 over set-speed 3 swap set-speed

I'll keep mucking around with it but if anyone can offer any hints it would be greatly appreciated!
Logged

Daniel

  • 256 MB
  • *****
  • Posts: 302
  • Programmer, Hacker, Thinker
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #5 on: March 13, 2019, 03:35:27 PM »

Looks like 'set-speed' takes an index of what speed to set and the number to set the speed to.
Code: [Select]
1 2a " set-speed" fan-ih $call-method
That would set speed variable 1 to the value 0x2a (42 in decimal). There seem to be 3 speed variables. Who knows what they do?

I would suggest turning the fan on, then using '.speed' to see what the different speed values are. Then try using set-speed to change one of the values with one that is close to it. If the fan noise changes, you have found out something.

That stuff with 'case' and 'of' and 'endof' and 'endcase' is a switch statement.
Code: [Select]
: test-switch case
0 of ." 0 selected" cr endof
1 of ." 1 selected" cr endof
dup of ." something else selected" cr endof
endcase
;
0 test-switch
1 test-switch
51F244 test-switch
'dup of' is a tricky way to match any possible value in the switch statement.

'>r' puts a value onto the return stack and 'r>' moves it back to the data stack. It is a simple way to leapfrog data over a bunch of code. It can mess up loops and function returns if used incorrectly, so beware.

I think that should be enough for you to figure out what is happening. If all else fails, make small test functions that contain just the things you want to figure out. Mess with them and see what happens.
Logged

Greystash

  • 256 MB
  • *****
  • Posts: 257
  • Tinkerer
    • Mac-Classic.com
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #6 on: March 13, 2019, 06:07:31 PM »

Looks like 'set-speed' takes an index of what speed to set and the number to set the speed to.
Code: [Select]
1 2a " set-speed" fan-ih $call-method
That would set speed variable 1 to the value 0x2a (42 in decimal). There seem to be 3 speed variables. Who knows what they do?

I would suggest turning the fan on, then using '.speed' to see what the different speed values are. Then try using set-speed to change one of the values with one that is close to it. If the fan noise changes, you have found out something.

That stuff with 'case' and 'of' and 'endof' and 'endcase' is a switch statement.
Code: [Select]
: test-switch case
0 of ." 0 selected" cr endof
1 of ." 1 selected" cr endof
dup of ." something else selected" cr endof
endcase
;
0 test-switch
1 test-switch
51F244 test-switch
'dup of' is a tricky way to match any possible value in the switch statement.

'>r' puts a value onto the return stack and 'r>' moves it back to the data stack. It is a simple way to leapfrog data over a bunch of code. It can mess up loops and function returns if used incorrectly, so beware.

I think that should be enough for you to figure out what is happening. If all else fails, make small test functions that contain just the things you want to figure out. Mess with them and see what happens.


Thanks so much Daniel! I can change the fan speed by changing the hex value which is exactly what I want. I've tried adding the configuration I want to an NVRAM script with nvedit and use-nvramrc, and it sort of works when the PB is turned on but the fans stop as soon as it starts looking for the system. I'm guessing this is because the instance is no longer open/running when the PB has finished with Open Firmware?

Is there any way to get these settings to persist through boot?

This is my script:

Code: [Select]
nvedit

dev /cpus/PowerPC,G4@0
80010201 encode-int " cpu-version" property
device-end

dev fan
" fan" open-dev constant fan-ih
1 384 " set-speed" fan-ih $call-method
2 384 " set-speed" fan-ih $call-method
device-end

Exit with ctrl+c

Code: [Select]
nvstore
setenv use-nvramrc? true
reset-all

I've also tried specifying each 'fan' alias as it's full path but that doesn't work.

If I run the commands outside of the nvram editor and run `mac-boot` the fans continue to run at the speed I've specified
« Last Edit: March 13, 2019, 07:02:56 PM by Greystash »
Logged

Greystash

  • 256 MB
  • *****
  • Posts: 257
  • Tinkerer
    • Mac-Classic.com
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #7 on: March 13, 2019, 09:59:37 PM »

Since I haven't been able to get the fan speeds to work within the nvram properly I've just written a script with everything I need, and this is easier than typing the fan config each boot.

Code: [Select]
\ comment
cr
dev fan
" fan" open-dev constant fan-ih
1 384 " set-speed" fan-ih $call-method
2 384 " set-speed" fan-ih $call-method
cr
dev /cpus/PowerPC,G4@0
80010201 encode-int " cpu-version" property
device-end
mac-boot

Each time I want the fans to run when I'm using the PB I need to boot into OF, then execute the script ('fans' which was written in SimpleText):
Code: [Select]
boot hd:\fans
Is there a way to either force Open Firmware to load each boot, or to get this code working within the nvram?
Logged

Daniel

  • 256 MB
  • *****
  • Posts: 302
  • Programmer, Hacker, Thinker
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #8 on: March 14, 2019, 12:51:37 PM »

Since I haven't been able to get the fan speeds to work within the nvram properly I've just written a script with everything I need, and this is easier than typing the fan config each boot.

Code: [Select]
\ comment
cr
dev fan
" fan" open-dev constant fan-ih
1 384 " set-speed" fan-ih $call-method
2 384 " set-speed" fan-ih $call-method
cr
dev /cpus/PowerPC,G4@0
80010201 encode-int " cpu-version" property
device-end
mac-boot

Each time I want the fans to run when I'm using the PB I need to boot into OF, then execute the script ('fans' which was written in SimpleText):
Code: [Select]
boot hd:\fans
Is there a way to either force Open Firmware to load each boot, or to get this code working within the nvram?

The boot-device nvram variable can be used to boot from a file.
Code: [Select]
setenv boot-device hd:\fansIt is recommended that you make the boot script boot to the previous boot device (likely "hd:,\\:tbxi"). Just putting 'mac-boot' at the end would make it boot itself again and again and again if it was set as the boot-device.

As for getting it to work in nvram, I suspect that something resets the fans once the boot starts. Maybe make a function in nvram that starts the fans, and then call that function in the boot command?
Code: [Select]
nvedit

dev /cpus/PowerPC,G4@0
80010201 encode-int " cpu-version" property
device-end

0 value fan-ih
: activate-fans
" fan" open-dev to fan-ih
1 384 " set-speed" fan-ih $call-method
2 384 " set-speed" fan-ih $call-method
;
Then change the boot-command nvram variable so activate-fans is called.
Code: [Select]
setenv boot-command activate-fans mac-boot
There are other ways of doing it, like building ELN's NewWorld-rom repo and adding your code to the boot script.

If you really want to mess with stuff, try putting your code into a 'Apple_Driver_OpenFirmware' partition. If a filesystem is accessed from OF, the '/packages/mac-parts' package will look for a Apple Partition Map partition of type 'Apple_Driver_OpenFirmware' on the device. If it finds one, it will treat the contents of the partition as either raw forth or fcode and try to run it. It expects the code to properly create a device package which can be passed the device accesses, but it can be used to just run arbitrary code when the disk is first used. Try sticking fan code there  ;D
Logged

Greystash

  • 256 MB
  • *****
  • Posts: 257
  • Tinkerer
    • Mac-Classic.com
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #9 on: March 15, 2019, 02:01:33 AM »

Thanks so much Daniel!! For now I went with the boot from file method and that's working perfectly :D
I'll take a look at adding this to a ROM file and experiment with the 'Apple_Driver_OpenFirmware' partition method. I'll post an update once I've sorted experimented with all of the options.

Once again thank you so much for the help it's much appreciated! :)
Logged

Daniel

  • 256 MB
  • *****
  • Posts: 302
  • Programmer, Hacker, Thinker
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #10 on: March 15, 2019, 01:48:21 PM »

No problem. It's very fun :)

Logged

LarsG5

  • 16 MB
  • ***
  • Posts: 25
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #11 on: June 16, 2020, 01:32:22 PM »

Hello,
Any updates? I have recently picked up an iBook G4 1.2GHz and well, it runs hot. Like really really hot...
Have you found a permanent solution to triggering fans that could be added as an nvram parameter to work after every reboot?

Thanks in advance.
Logged

Greystash

  • 256 MB
  • *****
  • Posts: 257
  • Tinkerer
    • Mac-Classic.com
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #12 on: June 16, 2020, 03:25:03 PM »

I haven't had a chance to dig into editing the Mac OS ROM, but here's the script I run from Open Firmware. This has been a permanent fix for me since I have working batteries and the unit never loses power. I don't have my machine on hand at the moment to double check but this should be correct.

bootscript (SimpleText file which is located in the HDD root directory)
Code: [Select]
\ comment
cr
dev /cpus/PowerPC,G4@0
80010201 encode-int " cpu-version" property
device-end
" fan" open-dev constant fan-ih
1 340 " set-speeds" fan-ih $call-method
boot hd:,\\:tbxi

Description:
Lines 1 - 2: Scripts must begin with a 'comment' and a carriage return (cr)
Lines 3 - 5: Changes the CPU version to enable OS9 booting on unsupported machines
Line 6: Opens/creates an instance of the 'fan' device
Line 7: Sets the speed for both fans. '340' is the speed, which may need to be altered to best suit your machine/preference.
Line 8: Continue booting the system

To run this script on every boot you need to boot into Open Firmware and do this once:
Open the NVRAMRC editor
Code: [Select]
nvedit
Set the boot device to your bootscript
Code: [Select]
setenv boot-device hd:\bootscriptClose the NVRAMRC editor by pressing CTRL + C
Run the following commands
Code: [Select]
nvstore
setenv use-nvramrc? true
reset all

If your machine looses power you will need to run these commands again
Logged

LarsG5

  • 16 MB
  • ***
  • Posts: 25
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #13 on: June 16, 2020, 04:37:08 PM »

Hi, thanks for your answer!
I have actually found the same solution online, but I thought there's been a better way discovered. The script method is good enough for now, though - still much better than nothing.

Btw, I have tried using the same method on my 12" 867MHz Powerbook, but well, it looks like it requires a different solution - do you know how to perform the same trick on a 7455 cpu?
Logged

LarsG5

  • 16 MB
  • ***
  • Posts: 25
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #14 on: June 17, 2020, 03:28:25 PM »


Code: [Select]
\ comment
cr
dev /cpus/PowerPC,G4@0
80010201 encode-int " cpu-version" property
device-end
" fan" open-dev constant fan-ih
1 340 " set-speeds" fan-ih $call-method
boot hd:,\\:tbxi

Btw, since the last line forces Mac to boot from the first available boot partition (rendering Startup Disk control panel non-working) I wonder if there is a command to finish this script with that wouldn't direct to a one, fixed boot partition?

I switch between OS9 and OS X quite often, many times simply staying on OS X for several days straight, thus I heavily rely on Startup Disk control panel (OS9) and Startup Disk setting (OS X), that's why I ask.

I realize you can press Option button on power up to switch between boot partitions, but it's not that convenient and I'd have to do that every single time I'd like to use OS X. Small inconvienience, but still - do you know if there is a way to fix it?

Thanks in advance!
Logged

macarone

  • 64 MB
  • ****
  • Posts: 108
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #15 on: June 18, 2020, 05:59:00 AM »

I realize you can press Option button on power up to switch between boot partitions, but it's not that convenient and I'd have to do that every single time I'd like to use OS X. Small inconvienience, but still - do you know if there is a way to fix it?

I have the same question.

In different words how can one get "Boot Manager: (Option key) and  "Startup disk" (Prefernce Pane/Control  Panel) in synch.

The contribution  I can make is that when  using "Boot Manager",  you can save some waiting time once the partition you want appears, by clicking the Mouse once and then Command-Period.
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4680
  • just a number
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #16 on: June 18, 2020, 07:05:00 AM »

there are many ways how to boot into a particular system but none of them is as easy as holding a key after start.

like macarone says you can pause the search on boot manager (unlinke in the controlpanel before rebooting) but it still includes waiting time, several clicks, and the risk that you sometimes choose the wrong OS by accident.

a reboot command, no matter how it is triggered (keyboard, finder menu, apple script, console...), will always boot into the currently chosen startup folder as set per PRAM.

for most people rebooting from X to X is the lesser case compared to rebooting from 9 to 9, so your best bet is to always choose your (main, if you have many) 9 folder as startup folder and then remember, that if you want to boot (or reboot) into OSX or linux, you have to go via the boot manager.

OS9 = default case, OSX = hold alt. easy to remember.

now what you could do when your machines doesnt support the boot manager or when you want to control a reboot by remote, no idea. :)

(some machines will also support holding D to boot from the very first partition. or to hold X to boot from the first partition with OSX. but which one is that? ... and it can easily stop working when your disks and volumes setup changes.)

what would be a neat solution to easily choose 1 out of 2 systems would be that you

1. always had the list of currently available boot folders ready somewhere

2. then it should show up somewhere in the finder menu
extras
/restart from disk 1 folder 1
/restart from disk 1 folder 2

but what would you save? now the search for current bootable systems happens everytime when the finder is loaded.

Logged
insert arbitrary signature here

LarsG5

  • 16 MB
  • ***
  • Posts: 25
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #17 on: June 18, 2020, 09:25:16 AM »


a reboot command, no matter how it is triggered (keyboard, finder menu, apple script, console...), will always boot into the currently chosen startup folder as set per PRAM.

Exactly, that's the issue: how to make it boot into partition chosen by Startup Disk (regardless if under OS 9 or X) and not the very first bootable one, as forced by boot tbxi command? Is there an OF command that makes mac boot without specifying a fixed boot partition?
Logged

Daniel

  • 256 MB
  • *****
  • Posts: 302
  • Programmer, Hacker, Thinker
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #18 on: July 19, 2020, 07:49:26 AM »

I wrote a little NVRAM script for you. It will make sure that the fan script is always booted first, regardless of what the boot device actually is.

Code: [Select]
' mac-boot @ constant saved-word

: fake-mac-boot
  saved-word ' mac-boot code!
  boot hd:42,\path\to\fan\script.of
;

' mac-boot ' fake-mac-boot brpatch

Stick this in NVRAM. The first call to mac-boot (done by the system) will boot the fan script. The second call to mac-boot (which you should put at the end of the fan script) will go and boot whatever mac-boot would normally boot.w

As long as nvram isn't disturbed, the fan script will always be run first.
Logged

LarsG5

  • 16 MB
  • ***
  • Posts: 25
  • New Member
Re: Setting PowerBook G4 fan speed in open firmware
« Reply #19 on: July 23, 2020, 02:04:38 PM »

Code: [Select]
' mac-boot ' fake-mac-boot brpatch

The second call to mac-boot (which you should put at the end of the fan script) will go and boot whatever mac-boot would normally boot.

So this will basically re-enable the Startup Disk utility and let me boot to whichever partition I chose in Startup Disk (regardless if on os9 or x)?
Thanks, I'll try this as soon as possible :)
Logged
Pages: [1] 2   Go Up

Recent Topics