Page 1 of 1

Is there a way to get the hardware and software bit length from the pi its-self?

Posted: Mon Jul 13, 2020 3:37 pm
by Schorschi
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?

Posted: Mon Jul 13, 2020 5:38 pm
by jahboater
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.

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
$ 
This Pi4 is running 32 bits:

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
$ 
"uname -m" just gives the architecture name.

Re: Is there a way to get the hardware and software bit length from the pi its-self?

Posted: Mon Jul 13, 2020 6:47 pm
by hippy
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())

Re: Is there a way to get the hardware and software bit length from the pi its-self?

Posted: Mon Jul 13, 2020 7:53 pm
by cleverca22
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

Re: Is there a way to get the hardware and software bit length from the pi its-self?

Posted: Mon Jul 13, 2020 9:35 pm
by hippy
cleverca22 wrote:
Mon Jul 13, 2020 7:53 pm
then use the processor code to figure out if its a 64bit capable model or not
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.

Not sure the OP can avoid the "static lookup (data) table" they hoped to avoid

Re: Is there a way to get the hardware and software bit length from the pi its-self?

Posted: Mon Jul 13, 2020 10:47 pm
by cleverca22
hippy wrote:
Mon Jul 13, 2020 9:35 pm
cleverca22 wrote:
Mon Jul 13, 2020 7:53 pm
then use the processor code to figure out if its a 64bit capable model or not
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.

Not sure the OP can avoid the "static lookup (data) table" they hoped to avoid
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 example

Re: Is there a way to get the hardware and software bit length from the pi its-self?

Posted: Mon Jul 13, 2020 11:05 pm
by davidcoton
cleverca22 wrote:
Mon Jul 13, 2020 10:47 pm
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 example
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.

Re: Is there a way to get the hardware and software bit length from the pi its-self?

Posted: Wed Jul 15, 2020 12:59 pm
by Schorschi
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.