Discussion:
Simple platform detection...
(too old to reply)
u***@garethlock.com
2017-11-19 02:36:39 UTC
Permalink
I'm hatching a program that allows the user to tweak RPi config.txt files from the RISC OS desktop.

What I need is something written in BASIC that will, when running on a RPi, return TRUE and for everything else return FALSE.

Can anyone here point me in the right direction?
John Williams (News)
2017-11-19 07:30:20 UTC
Permalink
Post by u***@garethlock.com
I'm hatching a program that allows the user to tweak RPi config.txt files
from the RISC OS desktop.
I already do this with programs called Fat32fs and StrongEd. Of course I
then have to reboot, but I guess you will too.

I don't need to use BASIC to check it's a RPi as I just look at it. I even
name my SD cards individually to reflect their individual sizes as well as
unique identities.

Best wishes,

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
u***@garethlock.com
2017-11-19 14:42:11 UTC
Permalink
This is supposed to be a complete solution that also allows the user to switch between several versions of RISC OS and other stuff by just presenting windows, menus and dialogue boxes. It does the messy job of writing back the CONFIG.TXT file, saving CMOS and copying ROM images in and out of the boot partition. When complete, will even parse in your current CONFIG.TXT to get baseline configuration from the host system.
Bernard Veasey
2017-11-20 07:00:07 UTC
Permalink
Post by u***@garethlock.com
This is supposed to be a complete solution that also allows the user
to switch between several versions of RISC OS and other stuff by just
presenting windows, menus and dialogue boxes. It does the messy job of
writing back the CONFIG.TXT file, saving CMOS and copying ROM images
in and out of the boot partition. When complete, will even parse in
your current CONFIG.TXT to get baseline configuration from the host
system.
This detects the hardware

SYS "OS_Hardware",&403,0,,,,,,,4 TO ,,C%
cpu% = (C%!0)>>16
board% = C%!64
revision% = C%!68

Examples:

Raspberry Pi 1 - cpu%=2 - board%=0 - revision% = 0 to 4
Raspberry Pi 2 - cpu%=2 - board%=0 - revision% = 6 etc
Raspberry Pi 3 - cpu%=4 - board%=-100659864 - revision% = 12 etc

Bernard
--
Contact Me - http://www.bapfish.org.uk/contactme/
Web - http://www.bapfish.org.uk/
Alan Adams
2017-11-20 11:15:16 UTC
Permalink
Post by Bernard Veasey
Post by u***@garethlock.com
This is supposed to be a complete solution that also allows the user
to switch between several versions of RISC OS and other stuff by just
presenting windows, menus and dialogue boxes. It does the messy job of
writing back the CONFIG.TXT file, saving CMOS and copying ROM images
in and out of the boot partition. When complete, will even parse in
your current CONFIG.TXT to get baseline configuration from the host
system.
This detects the hardware
SYS "OS_Hardware",&403,0,,,,,,,4 TO ,,C%
cpu% = (C%!0)>>16
board% = C%!64
revision% = C%!68
Raspberry Pi 1 - cpu%=2 - board%=0 - revision% = 0 to 4
Raspberry Pi 2 - cpu%=2 - board%=0 - revision% = 6 etc
Raspberry Pi 3 - cpu%=4 - board%=-100659864 - revision% = 12 etc
Bernard
For comparison on my ARMX6 I get cpu%=3 board%=0 revision%=1
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
u***@garethlock.com
2017-11-20 11:26:22 UTC
Permalink
That's exactly what I was looking for... I have a an example of something similar from way back, but couldn't figure out how to make it work... Damn thing just stiffed every time. Will check this out.

Thanks Bernard
John Williams (News)
2017-11-20 12:01:39 UTC
Permalink
Post by Bernard Veasey
Raspberry Pi 1 - cpu%=2 - board%=0 - revision% = 0 to 4
Raspberry Pi 2 - cpu%=2 - board%=0 - revision% = 6 etc
Curious, my RPi2 gives:

cpu%=4 - board%=-100657584 - revision%=12

one of 3 which I purchased from old stock having the ARMv7 processor, not
the later RPi3-style processor, and which I run in ARMv7 fast mode.

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Alan Adams
2017-11-20 12:40:54 UTC
Permalink
Post by John Williams (News)
Post by Bernard Veasey
Raspberry Pi 1 - cpu%=2 - board%=0 - revision% = 0 to 4
Raspberry Pi 2 - cpu%=2 - board%=0 - revision% = 6 etc
cpu%=4 - board%=-100657584 - revision%=12
one of 3 which I purchased from old stock having the ARMv7 processor, not
the later RPi3-style processor, and which I run in ARMv7 fast mode.
John
I get the same from 4 rPi's bought in the last couple of months from
RS Components.
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
John Williams (News)
2017-11-21 13:27:10 UTC
Permalink
There seems to be some problem in the Linux world with version reporting:

These URLs discuss false reporting of RPi3 processor versions with the
Linux reporting call.

https://www.raspberrypi.org/forums/viewtopic.php?t=140572

https://www.element14.com/community/community/raspberry-pi/blog/2016/02/29/the-most-comprehensive-raspberry-pi-comparison-benchmark-ever

I don't know if this is relevant to our case at all, but I think its worth
being aware of.

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Alan Adams
2017-11-21 14:50:22 UTC
Permalink
Post by John Williams (News)
These URLs discuss false reporting of RPi3 processor versions with the
Linux reporting call.
https://www.raspberrypi.org/forums/viewtopic.php?t=140572
I think the important bit here is that the Pi3 is running in 32-bit
more. It would not be unreasonable for the chip to report itself as a
Pi2 in this case, which is roughly what happens.

The other possibility is that the reporting software is converting
numeric IDs to text using a lookup table, and the table is out of
date. I feel this is the less likely option.
Post by John Williams (News)
https://www.element14.com/community/community/raspberry-pi/blog/2016/0
2/29/the-most-comprehensive-raspberry-pi-comparison-benchmark-ever
I don't know if this is relevant to our case at all, but I think its worth
being aware of.
John
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
John Williams (News)
2017-11-21 21:03:14 UTC
Permalink
Post by Alan Adams
I think the important bit here is that the Pi3 is running in 32-bit
more. It would not be unreasonable for the chip to report itself as a
Pi2 in this case, which is roughly what happens.
The other possibility is that the reporting software is converting
numeric IDs to text using a lookup table, and the table is out of
date. I feel this is the less likely option.
OK - so there is a table of info, but it, in Linux, depends on the OS
running to interpret it.

Our platform shows the raw data, but we also need an up-to-date look-up
table.

Is that a reasonable summary, or do you mean that RISC OS (32-bit) will
continue to report the Pi3 as a Pi2? And why the differing results for our
Armv7 Pi2s?

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
u***@garethlock.com
2017-11-21 21:11:51 UTC
Permalink
Wow!!! I really opened up a right can O' worms here, didn't I??
John Williams (News)
2017-11-21 21:29:36 UTC
Permalink
Post by u***@garethlock.com
Wow!!! I really opened up a right can O' worms here, didn't I??
And I said - just look at it - if it's a RPi you can tell!

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Bernard Veasey
2017-11-20 13:01:45 UTC
Permalink
Post by John Williams (News)
Post by Bernard Veasey
Raspberry Pi 1 - cpu%=2 - board%=0 - revision% = 0 to 4
Raspberry Pi 2 - cpu%=2 - board%=0 - revision% = 6 etc
cpu%=4 - board%=-100657584 - revision%=12
one of 3 which I purchased from old stock having the ARMv7 processor, not
the later RPi3-style processor, and which I run in ARMv7 fast mode.
John
You've probably got the later Pi2 version 1.2 which is more like
a Pi3. My Pi2 is an early Pi2 hence the difference.

Bernard
--
Contact Me - http://www.bapfish.org.uk/contactme/
Web - http://www.bapfish.org.uk/
John Williams (News)
2017-11-20 14:04:40 UTC
Permalink
Post by Bernard Veasey
You've probably got the later Pi2 version 1.2 which is more like
a Pi3. My Pi2 is an early Pi2 hence the difference.
I deliberately bought the original Pi2, and that it is one is, I believe,
is evidenced by the fact that Configure > CPU only offers the two ARMv7
options of strict and fast mode.

My Pi3 is running Linux ATM, but I'm tempted to put a RISC OS card in it to
check!

Google seems to confirm that the Pi3 is ARMv8.

Wikipedia states:

The earlier models of Raspberry Pi 2 use a Broadcom BCM2836 SoC
with a 900 MHz 32-bit quad-core ARM Cortex-A7 processor, with
256 KB shared L2 cache.[24] The Raspberry Pi 2 V1.2 was upgraded
to a Broadcom BCM2837 SoC with a 1.2 GHz 64-bit quad-core ARM
Cortex-A53 processor,[25] the same SoC which is used on the
Raspberry Pi 3.
The Raspberry Pi 3 uses a Broadcom BCM2837 SoC with a 1.2 GHz
64-bit quad-core ARM Cortex-A53 processor, with 512 KB shared L2
cache.

The specific ARM Cortex-A7 page states:

implementing the ARMv7-A architecture ...

which is what I believe I've got!

Which is why I posted.

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Alan Adams
2017-11-20 15:22:30 UTC
Permalink
Post by John Williams (News)
Post by Bernard Veasey
You've probably got the later Pi2 version 1.2 which is more like
a Pi3. My Pi2 is an early Pi2 hence the difference.
I deliberately bought the original Pi2, and that it is one is, I believe,
is evidenced by the fact that Configure > CPU only offers the two ARMv7
options of strict and fast mode.
My Pi3 is running Linux ATM, but I'm tempted to put a RISC OS card in it to
check!
Google seems to confirm that the Pi3 is ARMv8.
The earlier models of Raspberry Pi 2 use a Broadcom BCM2836 SoC
with a 900 MHz 32-bit quad-core ARM Cortex-A7 processor, with
256 KB shared L2 cache.[24] The Raspberry Pi 2 V1.2 was upgraded
to a Broadcom BCM2837 SoC with a 1.2 GHz 64-bit quad-core ARM
Cortex-A53 processor,[25] the same SoC which is used on the
Raspberry Pi 3.
The Raspberry Pi 3 uses a Broadcom BCM2837 SoC with a 1.2 GHz
64-bit quad-core ARM Cortex-A53 processor, with 512 KB shared L2
cache.
implementing the ARMv7-A architecture ...
which is what I believe I've got!
Which is why I posted.
John
Here on rPi2 I get

cpu%=4 board%=-100657584 revision%=12

A brute-force scan of devices shows in part the following. The
significant bit to me is the BC2835

"BCM2835 VDU device"
"Arasan SD host controller"
"VCHIQ audio service mixer"
"BCM283x CPU clock controller"
"VCHIQ audio service mixer"
"VCHIQ"
"BCM2835 SPI0 controller"
"FT5406 Touch Panel Controller"
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
John Williams (News)
2017-11-20 16:14:17 UTC
Permalink
Post by Alan Adams
A brute-force scan of devices shows in part the following. The
significant bit to me is the BC2835
"BCM2835 VDU device"
The official site
(https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836/README.md) says:

BCM2836

The Broadcom chip used in the Raspberry Pi 2 Model B

The underlying architecture in BCM2836 is identical to BCM2835. The
only significant difference is the removal of the ARM1176JZF-S
processor and replacement with a quad-core Cortex-A7 cluster.

What the significance of all this is, I don't know, but it definitely says
Cortex-A7 processor at start-up!

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
druck
2017-11-20 20:03:59 UTC
Permalink
Post by John Williams (News)
What the significance of all this is, I don't know, but it definitely says
Cortex-A7 processor at start-up!
That's entirely dependent on what cores the OS recognises and can name,
not what it is actually running on.

---druck
John Williams (News)
2017-11-20 20:25:41 UTC
Permalink
Post by druck
That's entirely dependent on what cores the OS recognises and can name,
not what it is actually running on.
Could you elaborate on that for our elucidation?

Have I been duped into buying a counterfeit RPi2 original?

Should I be seeking legal redress? Mis-sold legislation springs to mind as
a remedy!

What do you know that we don't?#

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
u***@garethlock.com
2017-11-21 02:17:43 UTC
Permalink
Thanks for all the help... Can anyone point me to a full list of return values and their associated hardware combinations. If there is indeed such a list.
Rick Murray
2017-12-05 22:06:53 UTC
Permalink
On Sun, 19 Nov 2017 07:30:20 +0000 (GMT), "John Williams (News)"
Post by John Williams (News)
I don't need to use BASIC to check it's a RPi as I just look at it.
How does a program "look" at the machine? ;-)

The way I use is to look for something specific in the OS for the
machine I want to check - so for a RaspberryPi, I'd ask OS_Module to
look up "BCMVideo". If it exists, it's a Pi. If it doesn't, it is
not. And if some future Pi revision doesn't have that module, the
machine is probably therefore different enough that it can be counted
as something else.
--
Best wishes,

Rick (heyrick one nine seven three at yahoo dot co dot uk)
John Williams (News)
2017-12-08 12:03:30 UTC
Permalink
Post by Rick Murray
The way I use is to look for something specific in the OS for the
machine I want to check - so for a RaspberryPi, I'd ask OS_Module to
look up "BCMVideo". If it exists, it's a Pi. If it doesn't, it is
not. And if some future Pi revision doesn't have that module, the
machine is probably therefore different enough that it can be counted
as something else.
So Rick has now finally definitively answered your question posed at the
start of this thread.

So you can now get your program to throw up its hands and say "This is NOT
a Raspberry Pi, you nitwit!" and fail gracefully if anyone is foolish
enough to expect it to do something useful on a non-RPi machine.

Now I can see what your program is intending to do, I can possibly be more
helpful with some configuration options.

For example, as I take my Pi abroad where I don't have a HDMI monitor but
use a VGA adapter on the monitor I keep there, I can point out that, to
change the audio from HDMI to 3.5mm jack output, the line to add, or in
this case uncomment, is, from my own master CONFIG.TXT file:

#
# AUDIO
# This line =1 pretends all audio formats are unsupported by the display.
# This means ALSA will default to analogue, sound out via headphone socket.
# hdmi_ignore_edid_audio=1
#

This has changed from earlier where a different method was recommended, but
no longer works.

Also you might have missed the apparently-undocumented monitor sleep-mode
option briefly chronicled in the forum thread cited in the REMark:

#
# Undocumented blanking option for DPMS - puts HD monitor into sleep mode
# https://www.riscosopen.org/forum/forums/2/topics/6788
hdmi_blanking=1
#

I also include the screen rotation commands myself, tho' I haven't used
them in anger yet:

#
# Rotate values: 0, normal; 1, 90°; 2, 180°; 3, 270°;
# 0x10000, horizontal flip; 0x20000, vertical flip
display_rotate=0
#

I keep them in just to save having to look them up should I find I need
them.

Is this sort of thing helpful? I have attempted to e-mail you privately on
a related matter.

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Rick Murray
2018-01-02 11:23:23 UTC
Permalink
Post by John Williams (News)
Is this sort of thing helpful? I have attempted to e-mail you privately
on a related matter.
You have?
--
___
/__/ o __ /_
/ \ / /__ / \ (heyrick one nine seven three at yahoo dot co dot uk)
John Williams (News)
2018-01-02 11:34:07 UTC
Permalink
Post by Rick Murray
I have attempted to e-mail you privately on a related matter.
You have?
Yes, but not you! You just wrote the bit I quoted in your capacity as
solver of the OPs original problem.

It was, of course, the OP I was addressing there, from whom I have had no
response to my helpful e-mail.

En consequent, I've lost interest during the intervening 3½ weeks.

Happy New Year!

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
John Williams (News)
2017-11-19 08:06:35 UTC
Permalink
Post by u***@garethlock.com
What I need is something written in BASIC that will, when running on a
RPi, return TRUE and for everything else return FALSE.
Why not get your user to confirm initially that it's a RPi, and, if so,
create a file in the DOS partition called, say, RPi.

You could then check for its presence from BASIC using something like:

:
DEF FN_objectpresent(fullpath$)
SYS"OS_File",23,fullpath$ TO present%,,,,,,objftype%
=present%
REM case present% of 0=absent 1=file 2=directory 3=image file
:

where fullpath$="SDFS::0.$.!Boot.Loader.RPi", the FN returning 1 if it's a
Pi and the file is present.

Your file RPi could also contain other useful information about the
specifics of the RPi boot system to be read by your program.

Or, easier still, you could just check for the presence of SDFS - that's
only present on the RPi running RISCOS, isn't it? Modules SDFS and
SDFSFiler, though it would be easier to do that with an OS command like
RMEnsure:

RMEnsure SDFS Echo This is NOT a RPi
Set IsThis$APi TRUE
RMEnsure SDFS Set IsThis$APi FALSE

Then test the system variable from BASIC. I can provide examples of how to
do this, including an elegant one from John Kortink I've kept a note of.

Both of these seem to meet your brief as described.

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Steve Fryatt
2017-11-19 09:47:08 UTC
Permalink
On 19 Nov, "John Williams (News)" wrote in message
Post by John Williams (News)
Or, easier still, you could just check for the presence of SDFS - that's
only present on the RPi running RISCOS, isn't it? Modules SDFS and
SDFSFiler, though it would be easier to do that with an OS command like
RMEnsure SDFS Echo This is NOT a RPi
Set IsThis$APi TRUE
RMEnsure SDFS Set IsThis$APi FALSE
Then test the system variable from BASIC.
SDFS is present on all -- or at least most -- RISC OS 5 systems, so this
won't work.
--
Steve Fryatt - Leeds, England

http://www.stevefryatt.org.uk/
News
2017-11-19 16:41:16 UTC
Permalink
Post by u***@garethlock.com
I'm hatching a program that allows the user to tweak RPi config.txt files from the RISC OS desktop.
What I need is something written in BASIC that will, when running
on a RPi, return TRUE and for everything else return FALSE.
Can anyone here point me in the right direction?
It is not entirely clear from your other post whether you just need
to detect RaPi hardware, or the various types of RaPi.

Whatever, it is likely you will need to probe the machine at a
relative low level.

One possibility is to use the SWI "OS_Hardware" (SWI 0x7a), with
reason codes in R8 of 4 or 5 (enumerate HAL devices in reverse or
chronological order). Probing the GPIO Comms device will return an
identifying string which contains reference to the hardware type.

You can check for example for IMX6, OMAP3, OMAP4, OMAP5, and BCM28nn
for RaPis. The ROOL wiki has details of this call.

All my code (used in CPUClock) is in C, which is not what you want,
although you are welcome to see it.
--
Chris Johnson
Theo Markettos
2017-11-21 22:18:13 UTC
Permalink
Post by u***@garethlock.com
I'm hatching a program that allows the user to tweak RPi config.txt files
from the RISC OS desktop.
What I need is something written in BASIC that will, when running on a
RPi, return TRUE and for everything else return FALSE.
DEF FNis_a_pi
LOCAL f%
f%=OPENIN("Boot:Loader.CONFIG/TXT")
IF f% CLOSE#f%
=(f% != 0)
Post by u***@garethlock.com
Can anyone here point me in the right direction?
As this thread suggests, machine detection is a tricky business and it's
always susceptible to the risk that the next machine released won't obey the
logic.

The usual Acorn mantra was to check for the feature you actually want, don't
try and second guess that from the machine type. Which is very sensible,
given it originated in 1980s and has been proved true numerous times since
then.

So if you're making a tool to manipulate config.txt files, check for their
existence. If you don't have one, you can't manipulate it.
If the OS is shipping a Boot:Loader.CONFIG/TXT but not using it, that might
be a problem - but I see no likelihood of that happening.

Theo
j***@gmail.com
2017-11-22 11:33:21 UTC
Permalink
Post by Theo Markettos
f%=OPENIN("Boot:Loader.CONFIG/TXT")
FWIW my Rpi doesn't have that file as I built my own SD card that is correctly partitioned - ie it has a Filecore partition and a FAT partition with no overlap.
u***@garethlock.com
2017-11-22 14:05:03 UTC
Permalink
How does RISC OS "See" your FAT partition then, or does it??
j***@gmail.com
2017-11-22 14:25:02 UTC
Permalink
Post by u***@garethlock.com
How does RISC OS "See" your FAT partition then, or does it??
It doesn't. If I really need to see it then I can mount it with fat32fs.
u***@garethlock.com
2017-11-22 14:42:15 UTC
Permalink
Ok... I'm using OS_File calls here rather than arbitrary OPENIN operations because I find them more reliable. So we first look for !Boot:Loader existing, using OS_File 17, then, also with OS _File 17, we check if it's filetype is &fc8. If so we look inside it for a file called CONFIG/TXT.

rpi_detected%=FALSE
target$="SDFS::0.$.!Boot.Loader"
IF FNfs_found(target$,3) THEN
IF FNfs_filetype(target$)=&fc8 THEN
IF FNfs_found(target$+".CONFIG/TXT",1) THEN
rpi_detected%=TRUE
ENDIF
ENDIF
ENDIF

FNfs_found() and FNfs_filetype() both use OS_File 17 to return the requested info.

Can anyone think of any caveats to this approach?
j***@mdfs.net
2017-12-01 12:22:40 UTC
Permalink
Post by u***@garethlock.com
target$="SDFS::0.$.!Boot.Loader"
IF FNfs_found(target$,3) THEN
IF FNfs_filetype(target$)=&fc8 THEN
I think you can do found and filetype in one call, so you
can optimise this a bit, but the logic looks fine.
Post by u***@garethlock.com
IF FNfs_found(target$+".CONFIG/TXT",1) THEN
rpi_detected%=TRUE
Loading...