Is there a way to get the hardware and software bit length from the pi its-self? For example Pi maybe ARM v7 and 64 bit hardware, but could be running only a (older) 32 bit (length) OS image.
Want to avoid some type of static lookup (data) table to resolve this. So need the following:
1. How to query hardware for bit length
2. How to query OS to get the current bit length
Any help appreciated.
Re: Is there a way to get the hardware and software bit length from the pi its-self?
The hardware for recent Pi's supports both 32 and 64 bits.
Here "uname" shows the kernel is 64-bits and "file" shows the user land is also 64 bits.
Clearly the hardware is running in 64-bit mode.
This Pi4 is running 32 bits:
"uname -m" just gives the architecture name.
Here "uname" shows the kernel is 64-bits and "file" shows the user land is also 64 bits.
Clearly the hardware is running in 64-bit mode.
Code: Select all
$ uname -a
Linux raspberrypi 5.4.50-v8+ #1324 SMP PREEMPT Wed Jul 1 17:13:08 BST 2020 aarch64 GNU/Linux
$ file /bin/ls
/bin/ls: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=9ecc063cc78a0a8c15f950e5e8fc4a6954c734dc, stripped
$
Code: Select all
$ uname -a
Linux pihat 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l GNU/Linux
$ file /bin/ls
/bin/ls: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=67a394390830ea3ab4e83b5811c66fea9784ee69, stripped
$
Pi4 8GB and Pi4 4GB running Raspberry Pi OS 64-bit
Re: Is there a way to get the hardware and software bit length from the pi its-self?
Based on the above I have been using the following in my Python code -
Code: Select all
def GetArchitectureBitSize():
# Returns bit-size of kernel/userland, eg, "32+32", "64+32", "64+64"
s = os.popen("uname -m").read().strip()
if s.lower() == "aarch64" : bitSize = "64+"
else : bitSize = "32+"
s = os.popen("file /bin/ls").read().strip()
if s.find(": ELF 32-bit") >= 0 : bitSize = bitSize + "32"
elif s.find(": ELF 64-bit") >= 0 : bitSize = bitSize + "64"
else : bitSize = bitSize + "??"
return bitSize
print(GetArchitectureBitSize())
-
- Posts: 2510
- Joined: Sat Aug 18, 2012 2:33 pm
Re: Is there a way to get the hardware and software bit length from the pi its-self?
but if your running a 32bit kernel on a 64bit cpu, most interfaces claim its 32bit only
you need to grab the hw revision from /proc/cpuinfo, and decode it as defined in https://www.raspberrypi.org/documentati ... /README.md
then use the processor code to figure out if its a 64bit capable model or not
you need to grab the hw revision from /proc/cpuinfo, and decode it as defined in https://www.raspberrypi.org/documentati ... /README.md
then use the processor code to figure out if its a 64bit capable model or not
Re: Is there a way to get the hardware and software bit length from the pi its-self?
You are right if one wants to know if the SoC is capable of 64-bit, not merely whether it's currently running 64-bit or 32-bit kernel and/or userland.cleverca22 wrote: ↑Mon Jul 13, 2020 7:53 pmthen use the processor code to figure out if its a 64bit capable model or not
Not sure the OP can avoid the "static lookup (data) table" they hoped to avoid
-
- Posts: 2510
- Joined: Sat Aug 18, 2012 2:33 pm
Re: Is there a way to get the hardware and software bit length from the pi its-self?
assuming they never release a new 32bit only cpu, you can do that with just a range check, if processor > 1 then 64bit else 32bit, for examplehippy wrote: ↑Mon Jul 13, 2020 9:35 pmYou are right if one wants to know if the SoC is capable of 64-bit, not merely whether it's currently running 64-bit or 32-bit kernel and/or userland.cleverca22 wrote: ↑Mon Jul 13, 2020 7:53 pmthen use the processor code to figure out if its a 64bit capable model or not
Not sure the OP can avoid the "static lookup (data) table" they hoped to avoid
- davidcoton
- Posts: 5692
- Joined: Mon Sep 01, 2014 2:37 pm
- Location: Cambridge, UK
- Contact: Website
Re: Is there a way to get the hardware and software bit length from the pi its-self?
Not that. Early Pi2B were 32bit only 4core, and there is at least the possibility of a future 64bit single core SOC for an (unlikely) Pi0 upgrade.cleverca22 wrote: ↑Mon Jul 13, 2020 10:47 pmassuming they never release a new 32bit only cpu, you can do that with just a range check, if processor > 1 then 64bit else 32bit, for example
Location: 345th cell on the right of the 210th row of L2 cache
Re: Is there a way to get the hardware and software bit length from the pi its-self?
Thanks everyone, I think getting the revision info and parsing it, is the best method, based on everything I have read, to determine if the given Pi is 64 bit capable. Then of course query the OS to see if it is 32 or 64 bit variant.