amrbekhit
Posts: 21
Joined: Wed Apr 16, 2014 11:02 am

Why does /proc/cpuinfo always show the same serial number?

Fri May 12, 2017 1:10 pm

I'm using a raspberry pi 3 and working on a Buildroot-based rootfs using kernel 4.9.17-v7 downloaded from the raspberry github. What I've noticed is that when running cat /proc/cpuinfo, Serial is always the same, even if I load the system from a different raspberry pi. In contrast, Raspbian doesn't have this problem and reads a different Serial for each device. I initially thought that this might be related to the kernel, so I transferred the Raspbian kernel to my Buildroot system but surprisingly, that didn't fix the problem. When I examine the contents of the SD card on a normal PC, the /proc directory is empty, so I know that I'm not just reading a static text file! Any thoughts as to why this would be? When comparing the contents of /proc/cpuinfo between the two systems, they are identical, with just the Serial being different.

Edit: I've used the configs kernel module to dump the .config files for each kernel and compare them and other than a couple of extra device drivers in the Raspbian kernel (sound, sensors etc), the configurations are identical.

User avatar
DougieLawson
Posts: 35581
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Why does /proc/cpuinfo always show the same serial numbe

Fri May 12, 2017 1:22 pm

/proc is a virtual filesystem created by the Linux kernel, it doesn't exist on your SDCard other than as a mount point.

The serial number in there is written by the kernel driver based on the info it reads from the VC processor. Each Raspberry has a 32-bit number for the serial number that comes from OTP storage.

So what you're reporting doesn't make any sense.

Try building the code at: https://github.com/AndrewFromMelbourne/ ... rialnumber and running that.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

amrbekhit
Posts: 21
Joined: Wed Apr 16, 2014 11:02 am

Re: Why does /proc/cpuinfo always show the same serial numbe

Fri May 12, 2017 2:03 pm

DougieLawson wrote:/proc is a virtual filesystem created by the Linux kernel, it doesn't exist on your SDCard other than as a mount point.
....
So what you're reporting doesn't make any sense.
I know! It's confused me as well. I've compiled the github project you suggested and tried it out. On the Raspbian system, all three programs output the same serial number, as expected.

However, when I run it on my buildroot system, this is what I get:

Code: Select all

# ./serialnumber_cpuinfo
serial: 00000000107e0f15    <-- this is the same serial number reported by /proc/cpuinfo regardless of hardware
# ./serialnumber_mailbox
serial: 00000000a230c5c4    <--- This is the correct serial number!
# ./serialnumber_vcgencmd
./serialnumber_vcgencmd: error while loading shared libraries: libbcm_host.so: cannot open shared object file: No such file or directory
Clearly, there seems to be something wrong with the /proc/cpuinfo interface, but what? I noticed that the last program required some missing libraries, so I copied the /opt/vc folder from Raspbian to my buildroot system and then it worked and output the same serial number as serialnumber_mailbox. The presence of /opt/vc didn't change the output of /proc/cpuinfo (as expected really, the kernel shouldn't need an external userspace library). Very weird!

amrbekhit
Posts: 21
Joined: Wed Apr 16, 2014 11:02 am

Re: Why does /proc/cpuinfo always show the same serial numbe

Fri May 12, 2017 2:18 pm

I had a closer look at the serialnumber_mailbox program. This led me to this page. As I understand it, the serial number is actually retrieved from the VideoCore, is that correct? It appears that the program is sending the Get board serial command and parsing the response.

Code: Select all

Get board serial

Tag: 0x00010004
Request:
Length: 0
Response:
Length: 8
Value:
u64: board serial
If so, then presumably the kernel also needs to communicate with the VC in order to retrieve the serial number.

One thing I've just noticed is this - I'm actually using u-boot to boot the Linux kernel, so the first stage bootloader is loading u-boot, which then loads the kernel. If I boot the kernel directly from the first stage bootloader, /proc/cpuinfo now shows the correct info!

My guess is as follows - the VC always writes the responses to a specific address in memory relative to the kernel's start address. The kernel is probably reading the response relative to its own start address, but since the kernel's start address has now changed, it's reading the wrong value. The VC, on the other hand, is still writing the responses to the same address.

Any thoughts?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7026
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Why does /proc/cpuinfo always show the same serial numbe

Fri May 12, 2017 2:35 pm

The firmware uses device tree to pass the serial number. Look at /proc/device-tree/serial-number.
Part of the kernel initialisation looks there for the serial number http://elixir.free-electrons.com/linux/ ... tup.c#L929

At a guess u-boot is messing with the device tree that the firmware is passing, so that's likely to mess up ethernet MAC addresses too.

http://elixir.free-electrons.com/linux/ ... up.c#L1273 is the block of code that will be called when reading /proc/cpuinfo.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

amrbekhit
Posts: 21
Joined: Wed Apr 16, 2014 11:02 am

Re: Why does /proc/cpuinfo always show the same serial numbe

Sat May 13, 2017 6:19 pm

Ah thanks for explaining. Interestingly enough, the current version of u-boot for the raspberry pi has been written to not modify the device tree at all, thus allowing us to benefit from the device tree manipulation that is done by the first stage bootloader. The first stage bootloader writes the device tree to a specific address in memory, which u-boot exposes via an environment variable, thus allowing the kernel to be booted using the previously prepared device tree. However, as you said, it is possible that something is going wrong and u-boot is knowingly or unknowingly making some changes. I'll have a look at the u-boot code and examine the in-memory device tree to see what's going on.

notro
Posts: 695
Joined: Tue Oct 16, 2012 6:21 pm
Location: Drammen, Norway

Re: Why does /proc/cpuinfo always show the same serial numbe

Sat May 13, 2017 8:03 pm

The serial number is present in 2 places in the device tree handed over by the videocore bootloader.
First we had /system/linux,serial, which the downstream kernel still uses. See bcm2835_init() https://github.com/raspberrypi/linux/bl ... 2835.c#L27
Later mainline Linux added support for /serial-number.

Revision is not set in this output because I'm running a mainline kernel booted directly by the vc bootloader (no u-boot):

Code: Select all

$ cat /proc/cpuinfo
processor       : 0
model name      : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS        : 697.95
Features        : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xb76
CPU revision    : 7

Hardware        : BCM2835
Revision        : 0000
Serial          : 00000000a1725dd1

$ hexdump /proc/device-tree/system/linux,serial
0000000 0000 0000 72a1 d15d
0000008

$ hexdump -C /proc/device-tree/serial-number
00000000  30 30 30 30 30 30 30 30  61 31 37 32 35 64 64 31  |00000000a1725dd1|
00000010  00                                                |.|
00000011

amrbekhit
Posts: 21
Joined: Wed Apr 16, 2014 11:02 am

Re: Why does /proc/cpuinfo always show the same serial numbe

Mon May 15, 2017 7:49 am

Hi all,

Thanks for your help. It turns out that u-boot is indeed modifying the "serial-number" entry in the device tree. In U-boot, the function set_serial_number in rpi.c is responsible for using the mailbox interface to retrieve the serial number from the VC, but appears to be retrieving the wrong serial number and then using that to overwrite serial-number at lines 202-209 in fdt_support.c.

I've sent an email to Stephen Warren (who I believe is the maintainer for the Raspberry Pi port), hopefully the issue can be fixed.

For now, I've simply commented out lines 202-209 in fdt_support.c, since I'm relying on the fdt composed by the first stage bootloader.

swarren
Posts: 45
Joined: Tue Mar 01, 2016 5:56 am

Re: Why does /proc/cpuinfo always show the same serial numbe

Thu May 25, 2017 7:52 pm

I believe U-Boot's serial number is actually correct here, but serialnumber_mailbox.c is wrong.

https://github.com/raspberrypi/firmware ... -interface states that the response from the "get board serial" mailbox function is a 64-bit serial number. However, serialnumber_mailbox.c only extracts a 32-bit number from the mailbox response message.

That is unless the documentation is wrong, in which case U-Boot can be updated once the documentation is fixed.

Return to “Advanced users”