Skip to content

Commit

Permalink
added serial number detection
Browse files Browse the repository at this point in the history
  • Loading branch information
tangrs committed Oct 20, 2012
1 parent 82bfdf8 commit 7509fda
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
3 changes: 3 additions & 0 deletions atag.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ int atag_build() {
ATAG(ATAG_INITRD2, settings.ramdisk.addr, settings.ramdisk.size);
if (settings.kernel_ramdisk_size)
ATAG(ATAG_RAMDISK, 0, settings.kernel_ramdisk_size, 0);

ATAG(ATAG_SERIAL, settings.serialnr[0], settings.serialnr[1]);
ATAG(ATAG_REVISION, settings.rev);
/*
End list. Stop here
*/
Expand Down
1 change: 1 addition & 0 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void dump_settings(char * ignored __attribute__((unused))) {
FOOTER_LEVEL0();

DUMP_LEVEL0(settings, machine_id);
DUMP_LEVEL0(settings, rev);
DUMP_LEVEL0(settings, kernel_ramdisk_size);
DUMP_LEVEL0(settings, ramdisk_loaded);
DUMP_LEVEL0(settings, kernel_loaded);
Expand Down
1 change: 1 addition & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ struct params {
int machine_id;

unsigned serialnr[2];
unsigned rev;
unsigned kernel_ramdisk_size;

unsigned ramdisk_loaded:1;
Expand Down
32 changes: 31 additions & 1 deletion mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdint.h>

#include "common.h"
#include "macros.h"

Expand Down Expand Up @@ -87,4 +89,32 @@ int detect_machine() {
return -1;
}
return 0;
}
}

/*
Detect serial number and revision and write it
return negative value for error
*/
#define ADD_BITS(v,r,x,y) do { \
unsigned len = ((y)-(x)+1); \
v <<= len; \
v |= ((r)>>(x)) & ~(~0<<len); \
} while (0)
static int __attribute__((unused)) _detect_serialnr_assert[sizeof(uint64_t)>=8?1:-1];
int detect_serialnr() {
uint64_t serial = 0, raw_serial = *(uint64_t*)0x900A0028;

ADD_BITS(serial, raw_serial, 33, 55);
ADD_BITS(serial, raw_serial, 17, 31);
ADD_BITS(serial, raw_serial, 9, 15);
ADD_BITS(serial, raw_serial, 5, 7);
ADD_BITS(serial, raw_serial, 3, 3);

settings.serialnr[0] = (unsigned)serial;
settings.serialnr[1] = (unsigned)(serial>>32);
settings.rev = (raw_serial>>58) & 0x1F;

return 0;
}
#undef ADD_BITS
1 change: 1 addition & 0 deletions mach.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
int detect_machine();
int detect_memory();
void force_guess_memory();
int detect_serialnr();

#endif
7 changes: 7 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ int main(int argc, char *argv[]) {
printl("Physical memory at: 0x%p-0x%p\n",
settings.phys.start, (void*)((char*)settings.phys.start + settings.phys.size));

if (detect_serialnr())
printl("Warning: Could not get serial number!\n");
else
printl("Serial number: %x%x rev%d (%s)\n",
settings.serialnr[1], settings.serialnr[0], settings.rev,
settings.rev?"CAS":"Non-CAS");

if (argc > 1) {
FILE *script = fopen(argv[1], "r");
if (!script) {
Expand Down

0 comments on commit 7509fda

Please sign in to comment.