theHetman
Posts: 88
Joined: Tue Jan 10, 2012 5:42 pm

Detecting the "blob" version and memory split

Sun May 20, 2012 2:51 pm

I'm wondering if there is any way to detect the version number of the GPU code "blob". I'm guessing that the features that the blob will provide will increase over time and it will become necessary for code to detect the version of the blob to see if newer features are available.

Also is to possible to detect the GPU/CPU memory split? I've already seen one post from a user trying to compile the "triangle" demo and it failed to run because he was using the 224MB memory split. If the demo could detect this and notify the user of the problem it would save questions like that in the forum.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5425
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Detecting the "blob" version and memory split

Sun May 20, 2012 4:54 pm

# /opt/vc/bin/vcgencmd version
May 18 2012 18:06:56
Copyright (c) 2012 Broadcom
version 315668 (debug)

The version is a perforce changelist number, so higher means newer. The date is when I built it.

# cat /proc/meminfo | head -1
MemTotal: 125880 kB

(for 128M split). You will get numbers just under 192M and 224M for those splits.

theHetman
Posts: 88
Joined: Tue Jan 10, 2012 5:42 pm

Re: Detecting the "blob" version and memory split

Mon May 21, 2012 7:52 am

Thanks for that Dom. Those are useful for users to quickly check for version number and memory split, but less useful from within an application. I suppose that a program could shell out and parse the output but I was thinking more along the lines of a simple API call. Is there anyway that that could be added?

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4258
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Detecting the "blob" version and memory split

Mon May 21, 2012 8:24 am

It's easy enough to write one at least for the memory size. Just open up the file and parse it.

Code: Select all

int MemorySize()
{
	FILE f;
	int mem;

	f = fopen("/proc/meminfo","r");
	fscanf(f, "MemTotal: %d", &mem);
	fclose(f);

	return mem;
}
For the other, then you do need to shell out, but it isn't difficult...

Code: Select all

int GPUBuildNumber()
{
	FILE f;
	int build;
	char debugp[256];

	f = popen("/opt/vc/bin/vcgencmd version","r");
	while (fscanf(f,"version %d %s\n", &build, &debugp) == 0 && !feof(f))
		;
	pclose(f);

	return build;
}
(All code untested with no error handling)

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Detecting the "blob" version and memory split

Mon May 21, 2012 8:47 am

dom wrote:# /opt/vc/bin/vcgencmd version
May 18 2012 18:06:56
Copyright (c) 2012 Broadcom
version 315668 (debug)

The version is a perforce changelist number, so higher means newer. The date is when I built it.
I know this is going to sound like "nitpicking", but I assume the "it" you are referring to (I.e., the "it" that was built at: May 18 2012 18:06:56) the GPU blob (aka, start.elf), not the "vcgencmd" program. When I first read your post, I thought you were referring to the vcgencmd program, not the blob, but now I've revised my interpretation.

Anyway, it seems like with a little reverse engineering, it should be possible to figure out where that version # is stored in the binary, and ferret it out that way. This seems to be what the OP is hoping for.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5425
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Detecting the "blob" version and memory split

Mon May 21, 2012 9:12 am

vcgencmd sends textual commands to GPU. The version reported is for start.elf.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5425
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Detecting the "blob" version and memory split

Mon May 21, 2012 10:30 am

The gencmd API is exposed throgh bcm_host.h

Code: Select all

char  response[80];
vc_gencmd(response, sizeof response, "version");

theHetman
Posts: 88
Joined: Tue Jan 10, 2012 5:42 pm

Re: Detecting the "blob" version and memory split

Mon May 21, 2012 2:00 pm

Thanks Dom, that's really helpful. vc_gencmd isn't really documented in bcm_host.h. I'm guessing that it return zero if successful like the other commands in the header. Is there any chance of adding a command string to vc_gencmd that returns the amount of RAM that the GPU is using? I would like a robust and future poof method of detecting if a graphics demo can be run and failing elegently if there is not enough space to run.

Also is there a document that lists the commands that can be set using vc_gencmd anywhere?

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5425
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Detecting the "blob" version and memory split

Tue May 22, 2012 9:00 am

vcgencmd commands

User avatar
AndrewS
Posts: 3625
Joined: Sun Apr 22, 2012 4:50 pm
Location: Cambridge, UK
Contact: Website

Re: Detecting the "blob" version and memory split

Tue May 22, 2012 10:48 am

I don't have my own RPi yet, so I can't be 100% certain these are "correct", but they seem to work okay for the versions of start.elf I've downloaded from the firmware repository.

A while ago I wrote a Python script to pull the "version" out of a start.elf file http://www.raspberrypi.org/archives/1097#comment-20968

And I've just written a simple BASH script to "detect" which memory-split is currently being used http://www.andrewscheller.co.uk/get_ram_split

Both my scripts work by looking at files on disk, which may not necessarily be the same as the blobs "in use" if you've changed the files in /boot since you last booted your Pi. But it does mean (after a tiny edit) you can run the scripts "offline" with your SD card inserted into a different PC.

theHetman
Posts: 88
Joined: Tue Jan 10, 2012 5:42 pm

Re: Detecting the "blob" version and memory split

Tue May 22, 2012 4:06 pm

Andrew,

Yes those scripts are nice but for getting the version number there is an API call and vcgencmd is a wrapper on that call. Thanks to Dom I can list the commands that are available but I've no idea what most of them do:

Code: Select all

[email protected]:/opt/vc/bin$ ./vcgencmd commands
commands="vcos, ap_output_control, ap_output_post_processing, pm_set_policy, pm_get_status, pm_show_stats, pm_start_logging, pm_stop_logging, version, commands, set_vll_dir, led_control, set_backlight, set_logging, get_lcd_info, set_bus_arbiter_mode, cache_flush, hdmi_ntsc_freqs, render_bar, disk_notify, inuse_notify, sus_suspend, sus_status, sus_is_enabled, sus_stop_test_thread, egl_platform_switch, file, vctest_memmap, vctest_start, vctest_stop, vctest_set, vctest_get"
It would be nice if there was a command to show the amount of RAM that the GPU was using.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5425
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Detecting the "blob" version and memory split

Tue May 22, 2012 4:15 pm

sudo /opt/vc/bin/vcdbg malloc
sudo /opt/vc/bin/vcdbg reloc

Note: these parse linked lists while GPU is running, so can produce spurious results if mallocs/frees occur while the command is executing.

Also the ARM can't see the GPU's L1 cache, so
/opt/vc/bin/vcgencmd cache_flush
first may help.

Return to “General programming discussion”