Commit 3ef4e7d2 authored by Mikhail Karpenko's avatar Mikhail Karpenko

Merge branch 'master' of https://github.com/Elphel/linux-elphel

parents fc8b39fe 2bc79fbd
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#define SYSFS_READONLY 0444 #define SYSFS_READONLY 0444
#define SYSFS_WRITEONLY 0222 #define SYSFS_WRITEONLY 0222
#define NAND_FLASH_OTP_PAGE_OFFSET 4*2048 #define NAND_FLASH_OTP_PAGE_OFFSET 0*2048
/* /*
* Read and parse bootargs parameter in the device tree * Read and parse bootargs parameter in the device tree
...@@ -149,12 +149,12 @@ static ssize_t set_boardinfo(struct device *dev, struct device_attribute *attr, ...@@ -149,12 +149,12 @@ static ssize_t set_boardinfo(struct device *dev, struct device_attribute *attr,
size_t retlen; size_t retlen;
char wbuf[2048]; char wbuf[2048];
memset(wbuf,0xff,2048);
if (IS_ERR(mtd)){ if (IS_ERR(mtd)){
pr_err("Get MTD device error, code:%d\n",-(u32)mtd); pr_err("Get MTD device error, code:%d\n",-(u32)mtd);
return -ENODEV; return -ENODEV;
} }
memset(wbuf,0xff,2048);
//too much of a trouble to read from flash again //too much of a trouble to read from flash again
if(!strnstr(boardinfo,"<board>",sizeof(boardinfo))){ if(!strnstr(boardinfo,"<board>",sizeof(boardinfo))){
pr_info("Factory Info record is clean.\n"); pr_info("Factory Info record is clean.\n");
...@@ -162,28 +162,26 @@ static ssize_t set_boardinfo(struct device *dev, struct device_attribute *attr, ...@@ -162,28 +162,26 @@ static ssize_t set_boardinfo(struct device *dev, struct device_attribute *attr,
// I got some buf, unknown size- should be limited to 2048? ok // I got some buf, unknown size- should be limited to 2048? ok
if (strlen(buf)>2048) { if (strlen(buf)>2048) {
pr_err("Data > 2KiB. Abort.\n"); pr_err("Data > 2KiB. Abort.\n");
return -1; return -EFBIG;
} }
// Not too strict check, just look for opening tags. // Not too strict check, just look for opening tags.
if(!strnstr(buf,"<board>",2048)||!strnstr(buf,"<serial>",2048)||!strnstr(buf,"<rev>",2048)){ if(!strnstr(buf,"<board>",2048)||!strnstr(buf,"<serial>",2048)||!strnstr(buf,"<rev>",2048)){
pr_err("Bad data format\n"); pr_err("Bad data format\n");
return -2; return -EINVAL;
} }
//tmp disabled.
//ret = mtd_write_user_prot_reg(mtd, *ppos+4*2048, 2048, &retlen, buf);
//copy to buf //copy to buf
strncpy(wbuf,buf,strlen(buf)); strncpy(wbuf,buf,strlen(buf));
pr_info("BUFFER: %s\n",wbuf); //pr_info("BUFFER: %s\n",wbuf);
ret = mtd_write_user_prot_reg(mtd, NAND_FLASH_OTP_PAGE_OFFSET, 2048, &retlen, wbuf); ret = mtd_write_user_prot_reg(mtd, NAND_FLASH_OTP_PAGE_OFFSET, 2048, &retlen, wbuf);
if (ret){ if (ret){
pr_err("Flash page write, code %d",ret); pr_err("Flash page write, code %d",ret);
return ret; return ret;
} }
pr_info("Data is successfully written and cannot be overwritten anymore, record size: %d B\n",strlen(wbuf)); pr_info("Data is successfully written and cannot be overwritten anymore\n");
get_factory_info(); get_factory_info();
}else{ }else{
pr_info("Factory Info record (serial='%s' revision='%s') can not be overwritten\n",serial,revision); pr_err("Factory Info record (serial='%s' revision='%s') can not be overwritten\n",serial,revision);
return -EPERM;
} }
return count; return count;
} }
...@@ -284,13 +282,10 @@ static int elphel393_init_probe(struct platform_device *pdev) ...@@ -284,13 +282,10 @@ static int elphel393_init_probe(struct platform_device *pdev)
} }
static int get_factory_info(void){ static int get_factory_info(void){
//char regvalh[5];
//char regvall[9];
char regvalh[]="0000"; char regvalh[]="0000";
char regvall[]="00000000"; char regvall[]="00000000";
u16 hwaddrh; u16 hwaddrh0, hwaddrh1;
u32 hwaddrl; u32 hwaddrl0, hwaddrl1;
size_t retlen; size_t retlen;
//size of nand flash page //size of nand flash page
...@@ -299,23 +294,36 @@ static int get_factory_info(void){ ...@@ -299,23 +294,36 @@ static int get_factory_info(void){
int ret; int ret;
char *ps,*pe; char *ps,*pe;
// const u8 *mac_address;
struct device_node *node; struct device_node *node;
struct property *newproperty; struct property *newproperty;
u32 *mac32; // = (u32*) mac_address; u32 *mac32; // = (u32*) mac_address;
u8 *macaddr; u8 *macaddr;
// I expected to have null terminated strings u8 block_factory_mac = 0;
// but cannot get it from the declaration. Don't know.
//memset(regvalh,0x00,5); node = of_find_node_by_name(NULL, "ps7-ethernet");
//memset(regvall,0x00,9); if (!node){
pr_err("Device tree node 'ps7-ethernet' not found.");
return -ENODEV;
}
// check if MAC address was overridden in u-boot
mac32 = (u32 *) of_get_mac_address(node);
hwaddrl0 = cpu_to_le32(mac32[0]);
hwaddrh0 = cpu_to_le16(mac32[1]);
if ((hwaddrh0!=0x0000)||(hwaddrl0!=0x10640E00)){
block_factory_mac = 1;
}
ret = mtd_read_user_prot_reg(mtd, NAND_FLASH_OTP_PAGE_OFFSET, size, &retlen, kbuf); ret = mtd_read_user_prot_reg(mtd, NAND_FLASH_OTP_PAGE_OFFSET, size, &retlen, kbuf);
if (ret){ if (ret){
pr_err("Flash page read, code %d",ret); pr_err("Flash page read, code %d",ret);
return ret; return ret;
} }
pr_debug("buf: %s\n",kbuf);
// do whatever we like with the kbuf // do whatever we like with the kbuf
// search for "<board>" // search for "<board>"
// expecting to find it somewhere... // expecting to find it somewhere...
...@@ -329,19 +337,13 @@ static int get_factory_info(void){ ...@@ -329,19 +337,13 @@ static int get_factory_info(void){
strncpy(regvall,serial+4,8); strncpy(regvall,serial+4,8);
//there is kstrtou64 but it doesn't work? //there is kstrtou64 but it doesn't work?
kstrtou16(regvalh,16,&hwaddrh); kstrtou16(regvalh,16,&hwaddrh1);
kstrtou32(regvall,16,&hwaddrl); kstrtou32(regvall,16,&hwaddrl1);
node = of_find_node_by_name(NULL, "ps7-ethernet");
if (!node){
pr_err("Device tree node 'ps7-ethernet' not found.");
return -ENODEV;
}
pr_debug("MAC from flash: %02x:%02x:%02x:%02x:%02x:%02x\n", pr_debug("MAC from flash: %02x:%02x:%02x:%02x:%02x:%02x\n",
(hwaddrl & 0xff), ((hwaddrl >> 8) & 0xff), (hwaddrl1 & 0xff), ((hwaddrl1 >> 8) & 0xff),
((hwaddrl >> 16) & 0xff), (hwaddrl >> 24), ((hwaddrl1 >> 16) & 0xff), (hwaddrl1 >> 24),
(hwaddrh & 0xff), (hwaddrh >> 8)); (hwaddrh1 & 0xff), (hwaddrh1 >> 8));
newproperty = kzalloc(sizeof(*newproperty) + 6, GFP_KERNEL); newproperty = kzalloc(sizeof(*newproperty) + 6, GFP_KERNEL);
if (!newproperty) if (!newproperty)
...@@ -354,23 +356,28 @@ static int get_factory_info(void){ ...@@ -354,23 +356,28 @@ static int get_factory_info(void){
return -ENOMEM; return -ENOMEM;
} }
macaddr = newproperty->value; macaddr = newproperty->value;
macaddr[0] = (hwaddrh >> 8) & 0xff; macaddr[0] = (hwaddrh1 >> 8) & 0xff;
macaddr[1] = hwaddrh & 0xff; macaddr[1] = hwaddrh1 & 0xff;
macaddr[2] = (hwaddrl >> 24) & 0xff; macaddr[2] = (hwaddrl1 >> 24) & 0xff;
macaddr[3] = (hwaddrl >> 16) & 0xff; macaddr[3] = (hwaddrl1 >> 16) & 0xff;
macaddr[4] = (hwaddrl >> 8) & 0xff; macaddr[4] = (hwaddrl1 >> 8) & 0xff;
macaddr[5] = hwaddrl & 0xff; macaddr[5] = hwaddrl1 & 0xff;
if (!block_factory_mac)
of_update_property(node,newproperty); of_update_property(node,newproperty);
else
pr_info("Factory MAC: %02x:%02x:%02x:%02x:%02x:%02x, u-boot overridden MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
(hwaddrl1 & 0xff),((hwaddrl1 >> 8) & 0xff),((hwaddrl1 >> 16) & 0xff),(hwaddrl1 >> 24),(hwaddrh1 & 0xff),(hwaddrh1 >> 8),
(hwaddrl0 & 0xff),((hwaddrl0 >> 8) & 0xff),((hwaddrl0 >> 16) & 0xff),(hwaddrl0 >> 24),(hwaddrh0 & 0xff),(hwaddrh0 >> 8));
mac32 = (u32 *) of_get_mac_address(node); mac32 = (u32 *) of_get_mac_address(node);
hwaddrl = cpu_to_le32(mac32[0]); hwaddrl1 = cpu_to_le32(mac32[0]);
hwaddrh = cpu_to_le16(mac32[1]); hwaddrh1 = cpu_to_le16(mac32[1]);
pr_debug("MAC from device tree: %02x:%02x:%02x:%02x:%02x:%02x\n", pr_debug("new MAC from device tree: %02x:%02x:%02x:%02x:%02x:%02x\n",
(hwaddrl & 0xff), ((hwaddrl >> 8) & 0xff), (hwaddrl1 & 0xff), ((hwaddrl1 >> 8) & 0xff),
((hwaddrl >> 16) & 0xff), (hwaddrl >> 24), ((hwaddrl1 >> 16) & 0xff), (hwaddrl1 >> 24),
(hwaddrh & 0xff), (hwaddrh >> 8)); (hwaddrh1 & 0xff), (hwaddrh1 >> 8));
//write hwaddr to zynq reg //write hwaddr to zynq reg
//kstrtou16(serial,16,&regvalh); //kstrtou16(serial,16,&regvalh);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment