summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Dechesne <nicolas.dechesne@linaro.org>2016-06-17 15:06:01 +0300
committerNicolas Dechesne <nicolas.dechesne@linaro.org>2016-06-17 16:15:30 +0300
commitc0026dd80f0cb26a0b32169e66837ea30796f218 (patch)
treea6d2538ffc5ae4567e6053509f6dd5565fbf086e
parent2740fc8aeb78bb2e012f63f6d500f3133139c504 (diff)
Set local-mac-address for the WCNSS node, if not set already. To set it, we rely on the unique SN provided the target library (typicall the eMMC CID). The SN is formatted as an 8-char number with leading zero's if needed. The MAC address is formed by adding '20:00' in front of the SN number to make sure that we use a MAC address from the locally adminstrated pool. Signed-off-by: Nicolas Dechesne <nicolas.dechesne@linaro.org>
-rw-r--r--app/aboot/aboot.c59
-rwxr-xr-xplatform/msm_shared/dev_tree.c20
-rwxr-xr-xplatform/msm_shared/include/dev_tree.h2
3 files changed, 78 insertions, 3 deletions
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 2927aeed..3ae60429 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -585,6 +585,60 @@ void generate_atags(unsigned *ptr, const char *cmdline,
ptr = atag_end(ptr);
}
+/* todo: give lk strtoul and nuke this */
+static unsigned hex2unsigned(const char *x)
+{
+ unsigned n = 0;
+
+ while(*x) {
+ switch(*x) {
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ n = (n << 4) | (*x - '0');
+ break;
+ case 'a': case 'b': case 'c':
+ case 'd': case 'e': case 'f':
+ n = (n << 4) | (*x - 'a' + 10);
+ break;
+ case 'A': case 'B': case 'C':
+ case 'D': case 'E': case 'F':
+ n = (n << 4) | (*x - 'A' + 10);
+ break;
+ default:
+ return n;
+ }
+ x++;
+ }
+
+ return n;
+}
+
+/* generate a unique locally administrated MAC */
+unsigned char* generate_mac_address()
+{
+ int len, i;
+ char sn[] = "00000000";
+ unsigned char * mac;
+
+ /* make sure we have exactly 8 char for serialno */
+ len = MIN(strlen(sn_buf), 8);
+ memcpy(&sn[8-len], sn_buf, len);
+
+ mac = (unsigned char*) malloc(6*sizeof(unsigned char));
+ ASSERT(mac != NULL);
+
+ /* fill in the mac with serialno, use locally adminstrated pool */
+ mac[0] = 0x02;
+ mac[1] = 00;
+ for (i = 3 ; i >= 0; i--)
+ {
+ mac[i+2] = hex2unsigned(&sn[2*i]);
+ sn[2*i]=0;
+ }
+
+ return mac;
+}
+
typedef void entry_func_ptr(unsigned, unsigned, unsigned*);
void boot_linux(void *kernel, unsigned *tags,
const char *cmdline, unsigned machtype,
@@ -593,6 +647,7 @@ void boot_linux(void *kernel, unsigned *tags,
unsigned char *final_cmdline;
#if DEVICE_TREE
int ret = 0;
+ unsigned char* mac;
#endif
void (*entry)(unsigned, unsigned, unsigned*) = (entry_func_ptr*)(PA((addr_t)kernel));
@@ -606,8 +661,10 @@ void boot_linux(void *kernel, unsigned *tags,
#if DEVICE_TREE
dprintf(INFO, "Updating device tree: start\n");
+ mac = generate_mac_address();
+
/* Update the Device Tree */
- ret = update_device_tree((void *)tags, final_cmdline, ramdisk, ramdisk_size);
+ ret = update_device_tree((void *)tags, final_cmdline, ramdisk, ramdisk_size, mac);
if(ret)
{
dprintf(CRITICAL, "ERROR: Updating Device Tree Failed \n");
diff --git a/platform/msm_shared/dev_tree.c b/platform/msm_shared/dev_tree.c
index 29176142..37a9d1c7 100755
--- a/platform/msm_shared/dev_tree.c
+++ b/platform/msm_shared/dev_tree.c
@@ -1247,7 +1247,7 @@ int dev_tree_add_mem_info(void *fdt, uint32_t offset, uint64_t addr, uint64_t si
/* Top level function that updates the device tree. */
int update_device_tree(void *fdt, const char *cmdline,
- void *ramdisk, uint32_t ramdisk_size)
+ void *ramdisk, uint32_t ramdisk_size, unsigned char* mac)
{
int ret = 0;
uint32_t offset;
@@ -1325,6 +1325,24 @@ int update_device_tree(void *fdt, const char *cmdline,
}
}
+ /* make sure local-mac-address is set for WCN device */
+ offset = fdt_node_offset_by_compatible(fdt, -1, "qcom,wcnss-wlan");
+
+ if (mac != NULL && offset != -FDT_ERR_NOTFOUND)
+ {
+ if (fdt_getprop(fdt, offset, "local-mac-address", NULL) == NULL)
+ {
+ dprintf(INFO, "Setting mac address in DT: %x:%x:%x:%x:%x:%x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+ ret = fdt_setprop(fdt, offset, "local-mac-address", mac, 6);
+ if (ret)
+ {
+ dprintf(CRITICAL, "ERROR: cannot set local-mac-address\n");
+ return ret;
+ }
+ }
+ }
+
fdt_pack(fdt);
return ret;
diff --git a/platform/msm_shared/include/dev_tree.h b/platform/msm_shared/include/dev_tree.h
index 04ce64d3..33d38e44 100755
--- a/platform/msm_shared/include/dev_tree.h
+++ b/platform/msm_shared/include/dev_tree.h
@@ -140,7 +140,7 @@ typedef struct dt_entry_node {
int dev_tree_validate(struct dt_table *table, unsigned int page_size, uint32_t *dt_hdr_size);
int dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info);
-int update_device_tree(void *fdt, const char *, void *, unsigned);
+int update_device_tree(void *fdt, const char *, void *, unsigned, unsigned char*);
int dev_tree_add_mem_info(void *fdt, uint32_t offset, uint64_t size, uint64_t addr);
void *dev_tree_appended(void *kernel, uint32_t kernel_size, void *tags);
#endif