读取芯片UUID的方法

Version 1.03

例程:

#include < fcntl.h >
#include < stdio.h >
#include < ctype.h >
#include < sys/ioctl.h >
#include < sys/types.h >
#include < stdlib.h >
#include < string.h>
#define MSYS_IOCTL_MAGIC 'S'
#define IOCTL_MSYS_GET_UDID _IO(MSYS_IOCTL_MAGIC, 0x32)

typedef struct
{
unsigned int VerChk_Version;
unsigned long long udid;
unsigned int VerChk_Size;
} attribute((packed)) MSYS_UDID_INFO;

int main(int argc, char* argv[])
{
int sysFd = 0;
MSYS_UDID_INFO udfo;
memset(&udfo,0,sizeof(MSYS_UDID_INFO));
sysFd = open("/dev/msys", O_RDWR);
if(sysFd<0){
printf("open /dev/msys fail!\n");
return 0;
}
udfo.VerChk_Version = 0x4d530100;
udfo.VerChk_Size = sizeof(MSYS_UDID_INFO);
if(ioctl(sysFd,IOCTL_MSYS_GET_UDID, &udfo)!=0){
printf("ioctl fail!\n");
}
printf("The version is 0x%x, The uuid=%lld, the size=%d\n", udfo.VerChk_Version, udfo.udid, udfo.VerChk_Size);
close(sysFd);
return 0;
}

uuid是烧写在EFUSE,通过读取bank 0x20 offset 0x16/17/18。

命令行用riu_r工具读取方式:

riu_r 20 16 (低16位) riu_r 20 1717 (中16位) riu_r 20 1818 (高16位)

三个16位寄存器值组成48bit UUID。

提供Ispahan 在uboot下读取uuid的代码(比如把以下加在lib/display_iptions.c/dislay_options()):

#include "asm/arch/mach/io.h"
#include "asm/arch/mach/ms_types.h"
#include "asm/arch/mach/platform.h"

unsigned long long udid=0;
CLRREG16(0x1f00400c, BIT8);
udid = (u64)INREG16(0x1F004058) | ((u64)(INREG16(0x1F00405c))<<16) | ((u64)(INREG16(0x1F004060)) << 32);

printf(" uuid=%llx\n",udid);