ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Understanding the mailbox property interface

Wed Jul 18, 2018 10:14 am

Hello,
I am really confused about this documentation: https://github.com/raspberrypi/firmware ... -interface
For example: it says "concatenated tags" in there. That does mean the complete tags are placed in that buffer, not the pointers to them, doesn't it? (cause using pointers it'd be a lot easier to implement IMO)

Next, when I want to find out the VideoCore firmware revision for example: the property tag would look like this, wouldn't it?

Code: Select all

struct {
	uint32_t id = 0x00000001;	// ID 1 = get VC firmware revision
	uint32_t vbuffer_size = 0;	// no request value, so the value buffer size is 0
	uint32_t req_resp_code = 0;	// bit 31 clear = request
} p_tag_t;
(no real C i know)

But where does the return value go then? does the GPU shift the whole property request by 4 bytes in order to fit its response (the firmware revision) into the value buffer? (seems highly unlikely)
Or do I have to include a value buffer large enough for the return values?

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24139
Joined: Sat Jul 30, 2011 7:41 pm

Re: Understanding the mailbox property interface

Wed Jul 18, 2018 10:31 am

I've started writing a more comprehensive mailbox document, the work in [progress is here

https://github.com/raspberrypi/document ... /mailboxes

Does that help?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

ardera
Posts: 10
Joined: Wed Jul 18, 2018 9:49 am

Re: Understanding the mailbox property interface

Wed Jul 18, 2018 12:44 pm

Yep, now I understand. Thanks!

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

Re: Understanding the mailbox property interface

Wed Jul 18, 2018 1:25 pm

jamesh wrote:
Wed Jul 18, 2018 10:31 am
I've started writing a more comprehensive mailbox document, the work in [progress is here

https://github.com/raspberrypi/document ... /mailboxes

Does that help?
In your article can you include a simple sample C program that anyone can cut'n'paste and get running. Do something naff like reading the CPU serial with a mailbox call.

(Yes I know I can write that, I'm thinking about the newbies.)

Edit: Or just steal https://github.com/AndrewFromMelbourne/ ... _mailbox.c
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.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24139
Joined: Sat Jul 30, 2011 7:41 pm

Re: Understanding the mailbox property interface

Wed Jul 18, 2018 3:44 pm

DougieLawson wrote:
Wed Jul 18, 2018 1:25 pm
jamesh wrote:
Wed Jul 18, 2018 10:31 am
I've started writing a more comprehensive mailbox document, the work in [progress is here

https://github.com/raspberrypi/document ... /mailboxes

Does that help?
In your article can you include a simple sample C program that anyone can cut'n'paste and get running. Do something naff like reading the CPU serial with a mailbox call.

(Yes I know I can write that, I'm thinking about the newbies.)

Edit: Or just steal https://github.com/AndrewFromMelbourne/ ... _mailbox.c
Yes, don't see why not. Similar to the linked code, but with comments to explain everything. I'll add it to the list.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24139
Joined: Sat Jul 30, 2011 7:41 pm

Re: Understanding the mailbox property interface

Wed Jul 18, 2018 4:26 pm

Turns out we already had a link to our own example source code on the first page, but I have also added a link to the example linked above, as that is pretty clear and simple.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

bzt
Posts: 393
Joined: Sat Oct 14, 2017 9:57 pm

Re: Understanding the mailbox property interface

Wed Jul 18, 2018 4:42 pm

Considering this question was asked under Bare Metal, I suppose opening "/dev/vcio" (as in the example linked above) is not really an option. I think this example would be more appropriate (also MIT licensed):
https://github.com/bztsrc/raspi3-tutori ... xes/main.c
Just a sidenote, because of the varying number of tags, I have used an uint32_t array instead of a struct. Although if you don't plan to take advantage of more tags in a single query you can use your struct as well.

Cheers,
bzt

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 3:53 pm

Maybe I should start a new thread, but my question seems closely related to this one.

I want to use the mailbox interface to get mac address. I'm getting something back that can be "nibble swapped" to match the mac address I get by doing:

Code: Select all

[email protected]:/ $ cat /sys/class/net/wlan0/address
b8:27:eb:c9:d8:3b

The array of 32 bit integers has two words that seem to contain the mac address (after changing by order and nibble swapping some bytes):

word 4: 0x9ceb27b8
word 5: 0x6e8d

Ignoring the first byte, word 4 looks like a Little Endian representation of 0xb827be??. But, the ?? is nibble swapped (0x9c versus 0xc9).

One of the bytes in word 5 are nibble swapped 0x8d versus 0xd8. I see no way to warp 0x6e into 0x3b.

I'd like to understand what's going on. I understand byte swapping required for LE to BE conversion, but there seems to be more than that going on. Maybe related to how the 6 byte Mac address is aligned in the 32 bit words. But, I can't put it together.

Can anyone help?

Here's the array used for the ioctl::

Code: Select all

    uint32_t property[9] =
    {
        0x00000000,
        0x00000000,
        0x00010003,
        0x00000010,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000,
        0x00000000
    };
Here are the returned words:

Code: Select all

"28"
"80000000"
"10003"
"10"
"80000006"
"9ceb27b8"
"6e8d"
"0"
"0"

LdB
Posts: 1315
Joined: Wed Dec 07, 2016 2:29 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 4:31 pm

The return is 6bytes MAC address in network byte order

https://en.wikipedia.org/wiki/Endianness
Big-endian is the most common format in data networking; fields in the protocols of the Internet protocol suite, such as IPv4, IPv6, TCP, and UDP, are transmitted in big-endian order.
For this reason, big-endian byte order is also referred to as network byte order.
The arm is little endian spin the 6 bytes

Now that all said that mac address is usually put on the main LAN there are other mac addresses for the wireless etc that are pseudo randomly generated from that if the wifi chip doesn't have a set mac. Look at the linux driver for the wifi it will show where they get the mac from.

So on linux I would expect that main mac to be on

Code: Select all

/sys/class/net/eth0/address

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 4:59 pm

It's not just byte swapping. Note the nibble swapping. 0xb8 versus 0x8b. 0x27 versus 0x72, etc.

Normally, it's just the bytes that are swapped, not the nibbles.

Maybe if I had the memory layout (which bytes were at each address), I could figure it out.

This rpi has no eth0 (it's an rpi3A+). That's why I pasted the wlan0 MAC address in the first post.

LdB
Posts: 1315
Joined: Wed Dec 07, 2016 2:29 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:08 pm

You posted the WLAN mac

You retreived the Ethernet MAC

They aren't allowed to match :-)

The mailbox command uses this
https://github.com/raspberrypi/firmware ... -interface
Get board MAC address

Tag: 0x00010003
Request:
Length: 0
Response:
Length: 6
Value:
u8...: MAC address in network byte order
THAT IS THE BOARD MAC ..... NOT THE WIFI MAC

As I said open up /sys/class/net/eth0/address I am sure it will match

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:16 pm

Again, there is no eth0
[email protected]:~/HeatTracker $ cat /sys/class/net/eth0/address
cat: /sys/class/net/eth0/address: No such file or directory
[email protected]:~/HeatTracker $
RPI3A+ does not have ethernet.

LdB
Posts: 1315
Joined: Wed Dec 07, 2016 2:29 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:22 pm

Still unlikely they would stick the BOARD MAC onto the WIFI as that would cause driver issues on models that do have ethernet.

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:24 pm

I don't see anything in the mailbox interface documentation referenced in this thread where an interface can be passed for the mac address request.

How is that done? How would I map something like wlan0 to an interface (integer, I assme)?
THAT IS THE BOARD MAC ..... NOT THE WIFI MAC

What is "THE BOARD MAC"? What could I use to compare against what I get from the IOCTL.

Again, there is no eth0 interface.

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

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:31 pm

The onboard ethernet MAC (for boards with that hardware) is low 24-bits of the serial or'ed with high 48-bits 0xb827eb000000.

The onboard WiFi MAC is low 24-bits of the serial XOR'ed with 0x555555 then or'ed with 0xb827eb000000.

Example 3B:
Serial: 00000000dc2525db
eth0 MAC: b8:27:eb:25:25:db
wlan0 MAC: b8:27:eb:70:70:8e

Example 3A+:
Serial: 00000000cb95b0ba
wlan0 MAC: b8:27:eb:c0:e5:ef
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.

LdB
Posts: 1315
Joined: Wed Dec 07, 2016 2:29 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:34 pm

Thanks dougie I guessed it was a crypto crunch from the main board MAC but was too lazy to look up the linix driver and there he has his answer.

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:35 pm

Thanks!!

Never would have figured it out on my own.

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:37 pm

Just to clarify...

The only MAC on an RPI3A+ is the wifi MAC, correct?

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:38 pm

When I do:

Code: Select all

[email protected]:~/HeatTracker $ ls /sys/class/net/*/address
/sys/class/net/lo/address    /sys/class/net/uap0/address
/sys/class/net/tun0/address  /sys/class/net/wlan0/address
You can see the interfaces.

The uap0 and wlan0 have the b8:27:eb:c9:d8:3b address:

Code: Select all

[email protected]:/ $ cat /sys/class/net/*/address
00:00:00:00:00:00

b8:27:eb:c9:d8:3b
b8:27:eb:c9:d8:3b

LdB
Posts: 1315
Joined: Wed Dec 07, 2016 2:29 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:48 pm

We get there is only one the wifi and no ethernet for you but understand there is one wifi driver and it must work with or without the board ethernet.

So the wifi driver is crunching a crypto number from the main board mac so it doesn't ever clash when the ethernet is there.
The driver will do that crunch everytime it loads and it doesn't care or probably even look to see if the main board has an ethernet.

So what you have is the same wifi driver will work on your RPI3A+ with no ethernet or it will still work on a Pi board with the ethernet the process of how it derives the MAC remains unchanged.

Basically XOR the last 3 bytes with 0x55 and you will get the answer on any model :-)

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 5:59 pm

I can confirm what DougieLawson posted for getting the mac address works.

There's no "wrong interface", there's only one on an rpi3A+.

You get an (lightly) encrytped version of wlan0 on an rpi3A+.

For my purpose, I really don't care whether I get the eth0 or wlan0 when the code runs on a 3B+. But, I think you said I'd get the eth0 mac, not the wlan0 with the array of bytes I was passing.

So, how does one indicate which interface the request was for?

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 6:02 pm

Actually, I guess there's no point in getting the mac address at all. Just get the serial an calculate it for the interface of interest?

LdB
Posts: 1315
Joined: Wed Dec 07, 2016 2:29 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 6:06 pm

Serial number comes thru the mailbox the same way so it really doesn't change anything.

Change 0x00010003 to 0x00010004 on your code above and you get it
Get board serial

Tag: 0x00010004
Request:
Length: 0
Response:
Length: 8
Value:
u64: board serial
I am guessing they end up with the VC4 fetching the same data just one it adds the 3 fixed characters the other it doesn't

davethomaspilot
Posts: 107
Joined: Tue Apr 29, 2014 6:18 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 6:21 pm

Yes, I'm already getting the board serial using that interface.

So, when you referred to BOARD MAC, you meant serial number. Makes more sense.

I was going to construct a unique hardware identifier by combining an (obfuscated) combination of the serial number and wlan mac address.

But there's no point. Getting a MAC address that can be calculated from the serial number adds nothing.

Thanks for the replies!

LdB
Posts: 1315
Joined: Wed Dec 07, 2016 2:29 pm

Re: Understanding the mailbox property interface

Fri Mar 29, 2019 6:34 pm

There is

Get board model Tag: 0x00010001
Get board revision Tag: 0x00010002

Which would mix it up more

Return to “Bare metal, Assembly language”