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-09-13 13:42:50 +0200
commit66bbf2611a41a6dc3c550d365add8f579bd48211 (patch)
treee31047af50f9273f4a1e5b45d69f6104a5087031
parent3bac025eb7a081f7f1598fdb5e7cb0c25912bdf0 (diff)
aboot: set local-mac-address in DTSrelease/LA.BR.1.1.2-02210-8x16.0+sdboot
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> (cherry picked from commit c0026dd80f0cb26a0b32169e66837ea30796f218)
-rw-r--r--app/aboot/aboot.c59
-rw-r--r--platform/msm_shared/dev_tree.c20
-rw-r--r--platform/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 7661680c..cc8b1921 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -579,6 +579,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,
@@ -587,6 +641,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));
@@ -600,8 +655,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 52aa420e..0142c049 100644
--- a/platform/msm_shared/dev_tree.c
+++ b/platform/msm_shared/dev_tree.c
@@ -1220,7 +1220,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;
@@ -1298,6 +1298,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 a6534c00..a8055e03 100644
--- a/platform/msm_shared/include/dev_tree.h
+++ b/platform/msm_shared/include/dev_tree.h
@@ -138,7 +138,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