openwrt/target/linux/ar71xx/files/arch/mips/ath79/nvram.c
Serg Studzinskii b7cc661615 ar71xx: add support for TP-Link TL-WR942N v1
TP-Link TL-WR942N v1 is a 2.4 GHz single-band N450 router, based on
Qualcomm/Atheros QCA9561.

Specification:

- 775/650/258 MHz (CPU/DDR/AHB)
- 128 MB of RAM (DDR2)
- 16 MB of FLASH (SPI NOR)
- 3T3R 2.4 GHz
- 5x 10/100 Mbps Ethernet
- 2x USB 2.0
- 11x LED (most are controlled by 74HC595)
- 2x button
- UART header on PCB*

* Serial console is disabled in OEM non-beta firmwares and corresponding
  GPIO pins 14 and 15 are assigned to control USB1 and USB2 LEDs by
  production (non-beta) U-Boot and firmware.

Currently not working:

1. USB1 and USB2 LEDs if UART RX and TX pins are assigned to their GPIOs
   by some U-Boot versions.

Flash instruction under vendor GUI:

1. Download "lede-ar71xx-generic-tl-wr942n-v1-squashfs-factory.bin".
2. Go to WEB interface and perform usual firmware upgrade.

FLash instruction under U-Boot recovery mode (doesn't work in beta
firmware):

1. Setup PC with static IP "192.168.0.66/24" and tftp server.
2. Change "*-factory" image filename to "WR942v1_recovery.bin" and make
   it available to download from your tftp server.
3. Press "reset" button and power up the router, wait till "WPS" LED
   turns on.

Flash instruction under U-Boot, using UART (can be done only with
preinstalled UART-enabled U-Boot version!):

1. Use "tpl" to stop autobooting and obtain U-Boot CLI access.
2. Setup ip addresses for U-Boot and your tftp server.
3. Issue below commands:
   tftp 0x81000000 lede-ar71xx-generic-tl-wr942n-v1-sysupgrade.bin
   erase 0x9f020000 +$filesize
   cp.b 0x81000000 0x9f020000 $filesize
   reset

Signed-off-by: Serg Studzinskii <serguzhg@gmail.com>
[minor code style fixes, extended commit message]
Signed-off-by: Piotr Dymacz <pepe2k@gmail.com>
2017-06-11 21:32:17 +02:00

86 lines
1.8 KiB
C

/*
* Atheros AR71xx minimal nvram support
*
* Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#include <linux/kernel.h>
#include <linux/vmalloc.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/string.h>
#include <linux/etherdevice.h>
#include "nvram.h"
char *ath79_nvram_find_var(const char *name, const char *buf, unsigned buf_len)
{
unsigned len = strlen(name);
char *cur, *last;
if (buf_len == 0 || len == 0)
return NULL;
if (buf_len < len)
return NULL;
if (len == 1)
return memchr(buf, (int) *name, buf_len);
last = (char *) buf + buf_len - len;
for (cur = (char *) buf; cur <= last; cur++)
if (cur[0] == name[0] && memcmp(cur, name, len) == 0)
return cur + len;
return NULL;
}
int ath79_nvram_parse_mac_addr(const char *nvram, unsigned nvram_len,
const char *name, char *mac)
{
char *buf;
char *mac_str;
int ret;
int t;
buf = vmalloc(nvram_len);
if (!buf)
return -ENOMEM;
memcpy(buf, nvram, nvram_len);
buf[nvram_len - 1] = '\0';
mac_str = ath79_nvram_find_var(name, buf, nvram_len);
if (!mac_str) {
ret = -EINVAL;
goto free;
}
if (strlen(mac_str) == 19 && mac_str[0] == '"' && mac_str[18] == '"') {
mac_str[18] = 0;
mac_str++;
}
t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if (t != ETH_ALEN)
t = sscanf(mac_str, "%02hhx-%02hhx-%02hhx-%02hhx-%02hhx-%02hhx",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if (t != ETH_ALEN) {
ret = -EINVAL;
goto free;
}
ret = 0;
free:
vfree(buf);
return ret;
}