Change to storing Pi CMOS settings
Chris Evans (457) 1614 posts |
It appears that current Pi builds are not only reading CMOS defaults from the end of the ROM image file but that they are also being stored there! This strikes me as being a bad idea. 1. The most critical file on the SD card is being written to and just when people might be pulling the power. Have I missed something and other people think it the best idea since sliced bread? |
Jeffrey Lee (213) 6048 posts |
This isn’t a recent change – it’s been like it ever since the CMOS code was implemented on the Pi (i.e. over a year ago). Obviously it’s not an ideal solution, but at the time I think it was the only one we had available (or at least the only one which could be implemented in the required timeframe). However things have moved on by now, and it looks like the firmware now allows you to specify an extra file to load on startup. This is intended to be a Linux initramfs image, but I can’t see any reason why we can’t use it to load a CMOS file. So if nobody objects, it should be pretty straightforward for me to modify the ROM to use a CMOS file on the SD card instead of stashing it in the ROM image. If only you’d had the foresight to include a 256+ byte CMOS chip in your RTC modules! |
Chris Evans (457) 1614 posts |
We did consider putting an EEPROM on the Pi RTC module but there were various technical issues, the use of a CMOS file was already in place, we knew that not all RISC OS users would have one of our modules and we knew some systems like Pandora can’t ever have an EEPROM added and hopefully there will be more ports to other hardware that can’t have an EEPROM. The main market for the RTC modules is price sensitive. |
Dave Higton (1515) 3526 posts |
I really, really believe that a hardware solution is the wrong one, and a file on the SD card is the right one. It has zero marginal cost to everybody, and it has no size limit (within reason). |
Rick Murray (539) 13840 posts |
Depends upon your outlook. Sure, a CMOS file on SD makes sense… …but if you need a hardware solution in order to have an RTC, then why not have a hardware solution for CMOS as well? |
Martin Bazley (331) 379 posts |
…because RTC needs to be updated when the machine is switched off, and CMOS doesn’t? Hardware CMOS is a legacy of the days when a RISC OS machine was expected to boot up with no storage devices whatsoever. It essentially does exactly the same job as a hard disc, or SD card or whatever. A Pi requires an SD card to be inserted in order to run RISC OS in the first place, so there’s zero advantage to any additional hardware. |
Dave Higton (1515) 3526 posts |
There are other snags associated with hardware “CMOS”. Usually we would use an EEPROM. Sadly, they don’t write as easily as RAM; you have to write a page at a time. And here’s the snag: there is no way to read back the page size. You just have to know the device involved. Writes wrap within the page. So if, for example, you have a device with a 32 byte page size (I have one that I’m using for something entirely unrelated, that has 32 byte pages – yes, really!), and you attempt to write past the page boundary, it wraps back to the first byte within the page. What you end up writing, and where you end up writing it, may not be what and where you expected. [I scratched my head for a long time when I saw the symptoms. It didn’t occur to me that anyone would create a large-ish EEPROM with such a tiny page size. They did, though. When I finally resorted to the data sheet, all became clear.] Again: please, please, let’s keep the “CMOS” as a file on the SD card. |
Rick Murray (539) 13840 posts |
…except the Pi has no RTC so something additional is already required. FWIW, I think the CMOS on the RTC module is around 64 bytes, so it would need to be a file on disc. Just saying there is already a need for some hardware…
This is why it is good to read the data sheet first – all sorts of word things become clear, like the weird clocking the original xx86 processors required… |
Steve Pampling (1551) 8170 posts |
As they always say, as a last resort read the manual. |
Theo Markettos (89) 919 posts |
That sounds like a good idea, with one caveat. On current systems, if the ROM is upgraded the CMOS is reset to defaults. Which is annoying, but at least the machine boots. Have to consider the case that the ROM doesn’t notice the CMOS is outdated and some critical module is unplugged. Does power-on-delete work on a USB keyboard, and will people remember to do it? I wonder if it’s possible to put some kind of ROM id in the file so the OS knows that the ROM has been changed and the CMOS hasn’t? This would make it feasible to deal with upgrades, though I’m not completely sure at what point something could be called to fixup the CMOS between different ROM versions. It would have to know about the layout of all previous versions too, which would be awkward. |
Theo Markettos (89) 919 posts |
Some further thought indicates it’s even worse than this. Consider:
There is a way to get out of that hole by deleting the CMOS file on the SD card, but you need another machine to do it. You could delete it in the upgrade process, but you need to be really careful that your running OS (if you’re doing this from RISC OS) won’t re-write it. (My post above is itself slightly wrong. In the current scheme, if you upgrade the ROM and just kill the power, you get the CMOS from the new ROM. If you shutdown, you get the new ROM with its CMOS overwritten with the old ROM’s settings. Which just goes to show how tricky this is to get right) I think it’s high time we moved to a text-based CMOS system (with a translation layer for ‘traditional’ CMOS RAM) because this problem means upgrading your system has a moderate risk of rendering it broken. It was enough of a headache to write something to fix up the CMOS between RC6 and RC8, and this requirement is only going to get worse as more ROM versions appear. Could we use the NVRAM modules that exist from the NC work? They have key/value support already and did for CMOS on NCs which didn’t have the I2C clock+CMOS chip. |
Colin (478) 2433 posts |
unplug has lots of problems with testing and softloading on an Iyonix too. If you want to record debug output during the initialisation of the rom adding the dadebug module early in the romlist changes what is unplugged. Softloading just makes the cmos entries entries for a different rom. Do usb keyboards work during boot my Iyonix always says ‘keyboard not found – autobooting’. The only solution I can see is fix the module that a bit represents in CMOS but that doesn’t help if you go back to earlier versions of the OS. |
Chris Evans (457) 1614 posts |
Might this work? Two negatives I can think of: All of this hassle reinforces the advantages of having the CMOS settings as text parameters as Dave Higton suggested |
Steffen Huber (91) 1953 posts |
Is there a valid case for unplugging modules anyway? I would just reinstate all modules after an OS ROM change. |
Rick Murray (539) 13840 posts |
What he said. I am aware of two specific instances where modules were unplugged:
Certainly, in the case of modern RISC OS – is there a need to unplug stuff?
What occurs to me – when looking at the point of view of RISC OS booting itself up… how do you tell the difference between an OS ROM change and any other boot up? Maybe some sort of ID in the CMOS data itself? Like the last two bytes of the build date (depending on how many bytes are spare)? |
Steffen Huber (91) 1953 posts |
Toolbox modules were never unplugged, but replaced early in boot with the latest versions. There was one situation where unplugging CDFSSoftATAPI was a good idea to reduce boot time by 30 seconds. Other than that, I cannot remember a need to unplug since RISC OS 3.1. |
Steffen Huber (91) 1953 posts |
I think a build ID for ROMs is necessary to identify when CMOS Unplug state should be reinstated to default. ROMs could even know when incompatible changes to CMOS have been made and migrate CMOS content. |