Schorschi
Posts: 245
Joined: Thu Nov 22, 2012 9:38 pm

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

Mon Jul 13, 2020 3:37 pm

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.

User avatar
jahboater
Posts: 6274
Joined: Wed Feb 04, 2015 6:38 pm
Location: Wonderful West Dorset

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

Mon Jul 13, 2020 5:38 pm

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.
Pi4 8GB running PIOS64 Lite

hippy
Posts: 8522
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

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

Mon Jul 13, 2020 6:47 pm

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())

cleverca22
Posts: 1867
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?

Mon Jul 13, 2020 7:53 pm

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

hippy
Posts: 8522
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

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

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

cleverca22
Posts: 1867
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?

Mon Jul 13, 2020 10:47 pm

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

User avatar
davidcoton
Posts: 5494
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?

Mon Jul 13, 2020 11:05 pm

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.
Location: 345th cell on the right of the 210th row of L2 cache

Schorschi
Posts: 245
Joined: Thu Nov 22, 2012 9:38 pm

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

Wed Jul 15, 2020 12:59 pm

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.

Return to “General discussion”