<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:14px">I think it's because of the following 2 lines:</span><span style="font-family:arial,sans-serif;font-size:14px"><div> static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6 +101,7<br>@@ static void __init qihoo_c301_setup(void)<br>        u8 tmpmac[ETH_ALEN];<br><br>        ath79_register_m25p80_multi(&flash);<br>+       qihoo_c301_board = 1;<br><div><br></div></div><div><br></div></span><div style="font-family:arial,sans-serif;font-size:14px">BTW,I think it's easier to use a preinit script to erase the partition than erasing the partition in mach-qihoo-c301.c.</div><div style="font-family:arial,sans-serif;font-size:14px">I'll submit mine later.</div><div class="gmail_extra"><br><div class="gmail_quote">2014-09-20 5:00 GMT+08:00 swigger <span dir="ltr"><<a href="mailto:swigger@gmail.com" target="_blank">swigger@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Where? I don't think it's whitespace broken.<br>
Spaces are spaces and tabs are tabs.<br>
<br>
-----邮件原件-----<br>
发件人: Weijie Gao [mailto:<a href="mailto:hackpascal@gmail.com" target="_blank">hackpascal@gmail.com</a>]<br>
发送时间: 2014年9月20日 1:11<br>
收件人: swigger; <a href="mailto:openwrt-devel@lists.openwrt.org" target="_blank">openwrt-devel@lists.openwrt.org</a><br>
主题: Re: [OpenWrt-Devel] [PATCH] [ar71xx] stops qihoo 360 c301 booting into backup firmware<br>
<div><div><br>
Hi,<br>
<br>
It's great. I hope this can be applied.<br>
<br>
However, your patch seems to be whitespace broken. Please fix it and resend.<br>
<br>
Weijie Gao<br>
<br>
On 2014/9/20 0:50, swigger wrote:<br>
> Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support.<br>
> However, this router has a backup firmware in the second flash and the<br>
> current trunk can only boot 3 times before u-boot boots into that<br>
> backup firmware. This is a stratgy for unbricking.<br>
><br>
> This patch makes u-boot happy.<br>
><br>
> Signed-off-by: Xungneg li <swigger at <a href="http://gmail.com" target="_blank">gmail.com</a>><br>
><br>
> ===============================================================<br>
> diff --git<br>
> a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c<br>
> b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c<br>
> index 08a602f..774356f 100644<br>
> --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c<br>
> +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c<br>
> @@ -14,6 +14,8 @@<br>
>  #include <linux/gpio.h><br>
>  #include <linux/platform_device.h><br>
>  #include <linux/ath9k_platform.h><br>
> +#include <linux/crc32.h><br>
> +#include <linux/mtd/mtd.h><br>
><br>
>  #include <asm/mach-ath79/ar71xx_regs.h><br>
><br>
> @@ -79,6 +81,7 @@ static struct gpio_keys_button<br>
> qihoo_c301_gpio_keys[] __initdata = {<br>
>       },<br>
>  };<br>
><br>
> +static int qihoo_c301_board = 0;<br>
>  struct flash_platform_data flash __initdata = {NULL, NULL, 0};<br>
><br>
>  static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6<br>
> +101,7 @@ static void __init qihoo_c301_setup(void)<br>
>       u8 tmpmac[ETH_ALEN];<br>
><br>
>       ath79_register_m25p80_multi(&flash);<br>
> +     qihoo_c301_board = 1;<br>
><br>
>       ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE);<br>
><br>
> @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void)<br>
><br>
>  MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301",<br>
>            qihoo_c301_setup);<br>
> +<br>
> +<br>
> +//the following code stops qihoo's uboot booting into the backup system.<br>
> +static void erase_callback(struct erase_info *erase) {<br>
> +     char * buf = (char*) erase->priv;<br>
> +     int ret;<br>
> +     size_t nb=0;<br>
> +<br>
> +     if (erase->state == MTD_ERASE_DONE)<br>
> +     {<br>
> +             ret = mtd_write(erase->mtd, 0, 0x10000, &nb, buf);<br>
> +     }<br>
> +     kfree(erase);<br>
> +     kfree(buf);<br>
> +}<br>
> +<br>
> +static int qihoo_reset_trynum(void)<br>
> +{<br>
> +     size_t nb = 0;<br>
> +     char *buf=0, *p;<br>
> +     const char * match = "image1trynum=";<br>
> +     size_t matchlen = strlen(match);<br>
> +     struct erase_info *erase;<br>
> +     struct mtd_info * mtd;<br>
> +     unsigned int newcrc;<br>
> +     int ret;<br>
> +<br>
> +     if (! qihoo_c301_board)<br>
> +             return 0;<br>
> +<br>
> +     mtd = get_mtd_device_nm("action_image_config");<br>
> +     if (IS_ERR(mtd))<br>
> +     {<br>
> +             return PTR_ERR(mtd);<br>
> +     }<br>
> +     if (mtd->size!=0x10000)<br>
> +     {<br>
> +             return -1;<br>
> +     }<br>
> +     buf = kzalloc(0x10000+4, GFP_KERNEL);<br>
> +     ret = mtd_read(mtd, 0, 0x10000, &nb, buf);<br>
> +     if (nb != 0x10000)<br>
> +     {<br>
> +             kfree(buf);<br>
> +             return -1;<br>
> +     }<br>
> +     for (p=buf+4; *p; p+=strlen(p)+1)<br>
> +     {<br>
> +             if (strncmp(p, match, matchlen)==0)<br>
> +             {<br>
> +                     p += matchlen;<br>
> +                     while (*p)<br>
> +                             *p++ = '0';<br>
> +                     break;<br>
> +             }<br>
> +     }<br>
> +<br>
> +     newcrc = crc32(~0, buf+4, 0xfffc)^0xffffffff;<br>
> +     memcpy(buf, &newcrc, 4);<br>
> +<br>
> +     erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL);<br>
> +     if (!erase)<br>
> +     {<br>
> +             kfree(buf);<br>
> +             return -1;<br>
> +     }<br>
> +     erase->mtd      = mtd;<br>
> +     erase->callback = erase_callback;<br>
> +     erase->addr     = 0;<br>
> +     erase->len      = 0x10000;<br>
> +     erase->priv     = (u_long) buf;<br>
> +     ret = mtd_erase(mtd, erase);<br>
> +<br>
> +     if (ret) {<br>
> +             kfree(buf);<br>
> +             kfree(erase);<br>
> +             return ret;<br>
> +     }<br>
> +<br>
> +     return 0;<br>
> +}<br>
> +late_initcall(qihoo_reset_trynum);<br>
> _______________________________________________<br>
> openwrt-devel mailing list<br>
> <a href="mailto:openwrt-devel@lists.openwrt.org" target="_blank">openwrt-devel@lists.openwrt.org</a><br>
> <a href="https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel" target="_blank">https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel</a><br>
_______________________________________________<br>
openwrt-devel mailing list<br>
<a href="mailto:openwrt-devel@lists.openwrt.org" target="_blank">openwrt-devel@lists.openwrt.org</a><br>
<a href="https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel" target="_blank">https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel</a><br>
</div></div></blockquote></div><br></div></div>