Re: [OpenWrt-Devel] On support status of OpenWrt for Qihoo C301
I think they are in parallel connection, you can have a look at the circuit. On Wed, Sep 24, 2014 at 10:57 AM, Yousong Zhou wrote: > On 23 September 2014 23:54, Weijie Gao wrote: >> Hi, >> >> The gap is not used in official firmware, so it is okay not to keep the gap. >> > > Yeah, I checked the content of that segment when using OEM firmware > with "md 0x9ff7" and found it was almost all filled with 0xff. > >> The seama header of factory firmware contains the whole firmware. So after >> openwrt created the rootfs_data partition, the MD5 digest is corrupted. >> Instead, the seama header of sysupgrade firmware only contains the kernel, >> the MD5 digest will not be corrupted. >> > > Wow, I see. 0xdeadc0de will be erased in the first boot. Shame on me > not thinking further on that. This should be fixed. > >> The three ethernet LEDs are directly configured in mach-qihoo-c301.c, so it >> is not necessary to defined as GPIO LEDs. >> >> BTW, there are two status LEDs in the front, one is green and another one is >> red. > > Well, is it possible that they are actually 4 leds that can be > controlled by 4 separate GPIOs? 2 groups of leds each controlled by 1 > GPIO just to increase the brightness so that it can seen from outside > the case? > >> >> Weijie Gao. >> > >yousong > ___ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] 答复: 答复: [PATCH] ar71xx: qihoo-c301: reset imageNtrynum after each successful boot.
I reflashed a whole new binary and it worked. 发件人: Yousong Zhou [mailto:yszhou4t...@gmail.com] 发送时间: 2014年9月22日 22:36 收件人: swigger 抄送: Weijie Gao; OpenWrt Development List; gch981...@gmail.com; blo...@openwrt.org 主题: Re: 答复: [PATCH] ar71xx: qihoo-c301: reset imageNtrynum after each successful boot. hi, swigger On Sep 22, 2014 10:04 PM, "swigger" wrote: > > It does NOT run on my router. > > root@OpenWrt:~# cat /etc/config/ubootenv > config ubootenv > option dev '/dev/mtd9' > option offset '0x0' > option envsize '0x1' > option secsize '0x1' > root@OpenWrt:~# fw_printenv > Cannot parse config file: No such file or directory > > What's wrong? i am not sure. if /e/c/ubootenv was generated, so should be /etc/fw_env.config. was this ubootenv created by you manually or generated by script in uci-defaults during first boot after the fresh installation? anyway, it should work if /etc/fw_env.config was created correctly. regards yousong > > > -邮件原件- > 发件人: Yousong Zhou [mailto:yszhou4t...@gmail.com] > 发送时间: 2014年9月14日 8:28 > 收件人: blo...@openwrt.org > 抄送: swig...@gmail.com; hackpas...@gmail.com; gch981...@gmail.com; > openwrt-devel@lists.openwrt.org; Yousong Zhou > 主题: [PATCH] ar71xx: qihoo-c301: reset imageNtrynum after each successful > boot. > > Qihoo C301 has 2 flash chips of which one is used as primary and the other > is used as backup. OEM U-Boot will try to boot an activeregion N with > imageNstatus=0 and imageNtrynum <= imagemaxtry. If such a region is found, > bootloader will try to increment imageNtrynum and boot it. > > This patch tries to reset imageNtrynum after each successful boot (if the > boot process reaches the execution of /etc/init.d/done). > > root@OpenWrt:/# hexdump -C -n 128 /dev/mtdblock9 > 9e f3 63 91 61 63 74 69 76 65 72 65 67 69 6f 6e > |..c.activeregion| > 0010 3d 31 00 69 6d 61 67 65 31 73 74 61 74 75 73 3d > |=1.image1status=| > 0020 30 00 69 6d 61 67 65 32 73 74 61 74 75 73 3d 30 > |0.image2status=0| > 0030 00 69 6d 61 67 65 32 74 72 79 6e 75 6d 3d 30 00 > |.image2trynum=0.| > 0040 69 6d 61 67 65 6d 61 78 74 72 79 3d 33 00 69 6d > |imagemaxtry=3.im| > 0050 61 67 65 31 74 72 79 6e 75 6d 3d 30 00 00 00 00 > |age1trynum=0| > 0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > || > > Signed-off-by: Yousong Zhou > --- > package/boot/uboot-envtools/files/ar71xx |3 +++ > target/linux/ar71xx/base-files/etc/diag.sh |6 ++ > 2 files changed, 9 insertions(+) > > diff --git a/package/boot/uboot-envtools/files/ar71xx > b/package/boot/uboot-envtools/files/ar71xx > index 5deed9c..f660883 100644 > --- a/package/boot/uboot-envtools/files/ar71xx > +++ b/package/boot/uboot-envtools/files/ar71xx > @@ -41,6 +41,9 @@ om2p-lc) > wzr-hp-ag300h) > ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x1" "0x1" > ;; > +qihoo-c301) > + ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x1" "0x1" > + ;; > esac > > config_load ubootenv > diff --git a/target/linux/ar71xx/base-files/etc/diag.sh > b/target/linux/ar71xx/base-files/etc/diag.sh > index ac7e20d..c7c6233 100755 > --- a/target/linux/ar71xx/base-files/etc/diag.sh > +++ b/target/linux/ar71xx/base-files/etc/diag.sh > @@ -294,6 +294,12 @@ set_state() { > ;; > done) > status_led_on > + case $(ar71xx_board_name) in > + qihoo-c301) > + local n=$(fw_printenv activeregion | cut -d = -f 2) > + fw_setenv "image${n}trynum" 0 > + ;; > + esac > ;; > esac > } > -- > 1.7.10.4 > > ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] 答复: [PATCH] ar71xx: qihoo-c301: reset imageNtrynum after each successful boot.
It does NOT run on my router. root@OpenWrt:~# cat /etc/config/ubootenv config ubootenv option dev '/dev/mtd9' option offset '0x0' option envsize '0x1' option secsize '0x1' root@OpenWrt:~# fw_printenv Cannot parse config file: No such file or directory What's wrong? -邮件原件- 发件人: Yousong Zhou [mailto:yszhou4t...@gmail.com] 发送时间: 2014年9月14日 8:28 收件人: blo...@openwrt.org 抄送: swig...@gmail.com; hackpas...@gmail.com; gch981...@gmail.com; openwrt-devel@lists.openwrt.org; Yousong Zhou 主题: [PATCH] ar71xx: qihoo-c301: reset imageNtrynum after each successful boot. Qihoo C301 has 2 flash chips of which one is used as primary and the other is used as backup. OEM U-Boot will try to boot an activeregion N with imageNstatus=0 and imageNtrynum <= imagemaxtry. If such a region is found, bootloader will try to increment imageNtrynum and boot it. This patch tries to reset imageNtrynum after each successful boot (if the boot process reaches the execution of /etc/init.d/done). root@OpenWrt:/# hexdump -C -n 128 /dev/mtdblock9 9e f3 63 91 61 63 74 69 76 65 72 65 67 69 6f 6e |..c.activeregion| 0010 3d 31 00 69 6d 61 67 65 31 73 74 61 74 75 73 3d |=1.image1status=| 0020 30 00 69 6d 61 67 65 32 73 74 61 74 75 73 3d 30 |0.image2status=0| 0030 00 69 6d 61 67 65 32 74 72 79 6e 75 6d 3d 30 00 |.image2trynum=0.| 0040 69 6d 61 67 65 6d 61 78 74 72 79 3d 33 00 69 6d |imagemaxtry=3.im| 0050 61 67 65 31 74 72 79 6e 75 6d 3d 30 00 00 00 00 |age1trynum=0| 0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 || Signed-off-by: Yousong Zhou --- package/boot/uboot-envtools/files/ar71xx |3 +++ target/linux/ar71xx/base-files/etc/diag.sh |6 ++ 2 files changed, 9 insertions(+) diff --git a/package/boot/uboot-envtools/files/ar71xx b/package/boot/uboot-envtools/files/ar71xx index 5deed9c..f660883 100644 --- a/package/boot/uboot-envtools/files/ar71xx +++ b/package/boot/uboot-envtools/files/ar71xx @@ -41,6 +41,9 @@ om2p-lc) wzr-hp-ag300h) ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x1" "0x1" ;; +qihoo-c301) + ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x1" "0x1" + ;; esac config_load ubootenv diff --git a/target/linux/ar71xx/base-files/etc/diag.sh b/target/linux/ar71xx/base-files/etc/diag.sh index ac7e20d..c7c6233 100755 --- a/target/linux/ar71xx/base-files/etc/diag.sh +++ b/target/linux/ar71xx/base-files/etc/diag.sh @@ -294,6 +294,12 @@ set_state() { ;; done) status_led_on + case $(ar71xx_board_name) in + qihoo-c301) + local n=$(fw_printenv activeregion | cut -d = -f 2) + fw_setenv "image${n}trynum" 0 + ;; + esac ;; esac } -- 1.7.10.4 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH][RESEND.3] ar71xx:stops qihoo c301 booting into backup firmware
Flashing back to OEM through OpenWrt's sysupgrade process is also OK, but you should cut-off extra seama header from the decrypted OEM firmware. then just run: mtd -r write your-decrypted-oem-firmware firmware On Mon, Sep 22, 2014 at 4:10 PM, Yousong Zhou wrote: > Just got the device... Wow > > On 22 September 2014 15:47, swigger wrote: >> Well, it's a good idea. >> But I don't know how to create a wiki page. >> >> QIhoo 360 C301 (http://luyou.360.cn/parameter.html, Simplified Chinese >> ONLY), has two 16M flash. >> The first flash is full functional, and the second has just a backup >> firmware. >> U-boot will boot into the second flash when it believes firmware on >> the first is broken. >> > > Yeah, when (image1trynum > imagemaxtry) with imagemaxtry defaults to > 3, and in this case, image1status would be set to 1 to mark it as not > viable. > >> To flash openwrt, disconnect power source, hold down the reset button >> and power on, keep holding reset button for about 20 seconds. >> Go to http://192.168.1.1 and upload the openwrt firmware to flash. >> > > Good. > >> To flash back to OEM firmware from openwrt, use the same instructions >> above and upload a decrypted OEM firmware which can be founded >> somewhere by a search engine. >> > > How about flashing back through OpenWrt's sysupgrade process? > >> There is also some tools for decrypting OEM firmware (no tool for >> encrypting yet), but they are not part of openwrt, so it is not >> necessary to discuss here. > > You mean seama? That code is already in OpenWrt. > > I think I have a better patch for working with this U-Boot. Please > hold on for a moment. > > Regards > >yousong ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH][RESEND.3] ar71xx:stops qihoo c301 booting into backup firmware
NO, not seama. Seama is only a container, not an encrypted format. The original OEM firmware is encrypted by AES ECB mode and have a RSA-1024 signuature. The aes key is base64_decode("lbhySwdj31NGnuebNn9FmQ=="); The oem's upgrade firmware web page ONLY allows encrypted firmware while the u-boot allows only decrypted. There is a program in OEM firwmare whose path is /usr/sbin/rom_decrypt to decrypt OEM firmware. Encrypted OEM firmware can be downloaded at http://luyou.360.cn/rom.html (Simplified Chinese Only). On Mon, Sep 22, 2014 at 4:10 PM, Yousong Zhou wrote: > Just got the device... Wow > > On 22 September 2014 15:47, swigger wrote: >> Well, it's a good idea. >> But I don't know how to create a wiki page. >> >> QIhoo 360 C301 (http://luyou.360.cn/parameter.html, Simplified Chinese >> ONLY), has two 16M flash. >> The first flash is full functional, and the second has just a backup >> firmware. >> U-boot will boot into the second flash when it believes firmware on >> the first is broken. >> > > Yeah, when (image1trynum > imagemaxtry) with imagemaxtry defaults to > 3, and in this case, image1status would be set to 1 to mark it as not > viable. > >> To flash openwrt, disconnect power source, hold down the reset button >> and power on, keep holding reset button for about 20 seconds. >> Go to http://192.168.1.1 and upload the openwrt firmware to flash. >> > > Good. > >> To flash back to OEM firmware from openwrt, use the same instructions >> above and upload a decrypted OEM firmware which can be founded >> somewhere by a search engine. >> > > How about flashing back through OpenWrt's sysupgrade process? > >> There is also some tools for decrypting OEM firmware (no tool for >> encrypting yet), but they are not part of openwrt, so it is not >> necessary to discuss here. > > You mean seama? That code is already in OpenWrt. > > I think I have a better patch for working with this U-Boot. Please > hold on for a moment. > > Regards > >yousong ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH][RESEND.3] ar71xx:stops qihoo c301 booting into backup firmware
Well, it's a good idea. But I don't know how to create a wiki page. QIhoo 360 C301 (http://luyou.360.cn/parameter.html, Simplified Chinese ONLY), has two 16M flash. The first flash is full functional, and the second has just a backup firmware. U-boot will boot into the second flash when it believes firmware on the first is broken. To flash openwrt, disconnect power source, hold down the reset button and power on, keep holding reset button for about 20 seconds. Go to http://192.168.1.1 and upload the openwrt firmware to flash. To flash back to OEM firmware from openwrt, use the same instructions above and upload a decrypted OEM firmware which can be founded somewhere by a search engine. There is also some tools for decrypting OEM firmware (no tool for encrypting yet), but they are not part of openwrt, so it is not necessary to discuss here. On Mon, Sep 22, 2014 at 2:01 PM, Yousong Zhou wrote: >>> On 2014/9/20 17:18, swigger wrote: >>>> Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. >>>> However, this router has a backup firmware in the second flash and the >>>> current trunk can only boot 3 times before u-boot boots into that backup >>>> firmware. This is a stratgy for unbricking. >>>> >>>> This patch makes u-boot happy. >>>> > > I do not have a device of this, but looks like it has some quirks that > needs to be taken care of. How about creating a wiki page for this > and documenting your findings about the backup firmware, instructions > on how to flash OpenWrt from OEM and to restore to OEM firmware, etc? > > > Regards. > >yousong ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH][RESEND.3] ar71xx:stops qihoo c301 booting into backup firmware
thanks. I have done. On Sat, Sep 20, 2014 at 5:39 PM, Weijie Gao wrote: > Hi, > > You need to register a account at patchwork.openwrt.org, and mark your > previous patches Superseded. > > Weijie Gao > > > On 2014/9/20 17:18, swigger wrote: >> Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. >> However, this router has a backup firmware in the second flash and the >> current trunk can only boot 3 times before u-boot boots into that backup >> firmware. This is a stratgy for unbricking. >> >> This patch makes u-boot happy. >> >> Signed-off-by: Xungneg li >> --- >> .../ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c | 87 >> >> 1 file changed, 87 insertions(+) >> >> diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c >> b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c >> index 08a602f..816a433 100644 >> --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c >> +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c >> @@ -14,6 +14,8 @@ >> #include >> #include >> #include >> +#include >> +#include >> >> #include >> >> @@ -79,6 +81,7 @@ static struct gpio_keys_button qihoo_c301_gpio_keys[] >> __initdata = { >> }, >> }; >> >> +static int qihoo_c301_board = 0; >> struct flash_platform_data flash __initdata = {NULL, NULL, 0}; >> >> static void qihoo_c301_get_mac(const char *name, char *mac) >> @@ -98,6 +101,7 @@ static void __init qihoo_c301_setup(void) >> u8 tmpmac[ETH_ALEN]; >> >> ath79_register_m25p80_multi(&flash); >> + qihoo_c301_board = 1; >> >> ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); >> >> @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void) >> >> MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301", >>qihoo_c301_setup); >> + >> + >> +//the following code stops qihoo's uboot booting into the backup system. >> +static void erase_callback(struct erase_info *erase) >> +{ >> + char * buf = (char*) erase->priv; >> + int ret; >> + size_t nb=0; >> + >> + if (erase->state == MTD_ERASE_DONE) >> + { >> + ret = mtd_write(erase->mtd, 0, 0x1, &nb, buf); >> + } >> + kfree(erase); >> + kfree(buf); >> +} >> + >> +static int qihoo_reset_trynum(void) >> +{ >> + size_t nb = 0; >> + char *buf=0, *p; >> + const char * match = "image1trynum="; >> + size_t matchlen = strlen(match); >> + struct erase_info *erase; >> + struct mtd_info * mtd; >> + unsigned int newcrc; >> + int ret; >> + >> + if (! qihoo_c301_board) >> + return 0; >> + >> + mtd = get_mtd_device_nm("action_image_config"); >> + if (IS_ERR(mtd)) >> + { >> + return PTR_ERR(mtd); >> + } >> + if (mtd->size!=0x1) >> + { >> + return -1; >> + } >> + buf = kzalloc(0x1+4, GFP_KERNEL); >> + ret = mtd_read(mtd, 0, 0x1, &nb, buf); >> + if (nb != 0x1) >> + { >> + kfree(buf); >> + return -1; >> + } >> + for (p=buf+4; *p; p+=strlen(p)+1) >> + { >> + if (strncmp(p, match, matchlen)==0) >> + { >> + p += matchlen; >> + while (*p) >> + *p++ = '0'; >> + break; >> + } >> + } >> + >> + newcrc = crc32(~0, buf+4, 0xfffc)^0x; >> + memcpy(buf, &newcrc, 4); >> + >> + erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL); >> + if (!erase) >> + { >> + kfree(buf); >> + return -1; >> + } >> + erase->mtd = mtd; >> + erase->callback = erase_callback; >> + erase->addr = 0; >> + erase->len = 0x1; >> + erase->priv = (u_long) buf; >> + ret = mtd_erase(mtd, erase); >> + >> + if (ret) { >> + kfree(buf); >> + kfree(erase); >> + return ret; >> + } >> + >> + return 0; >> +} >> +late_initcall(qihoo_reset_trynum); > ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH][RESEND.3] ar71xx:stops qihoo c301 booting into backup firmware
Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. However, this router has a backup firmware in the second flash and the current trunk can only boot 3 times before u-boot boots into that backup firmware. This is a stratgy for unbricking. This patch makes u-boot happy. Signed-off-by: Xungneg li --- .../ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c | 87 1 file changed, 87 insertions(+) diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c index 08a602f..816a433 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include @@ -79,6 +81,7 @@ static struct gpio_keys_button qihoo_c301_gpio_keys[] __initdata = { }, }; +static int qihoo_c301_board = 0; struct flash_platform_data flash __initdata = {NULL, NULL, 0}; static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6 +101,7 @@ static void __init qihoo_c301_setup(void) u8 tmpmac[ETH_ALEN]; ath79_register_m25p80_multi(&flash); + qihoo_c301_board = 1; ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void) MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301", qihoo_c301_setup); + + +//the following code stops qihoo's uboot booting into the backup system. +static void erase_callback(struct erase_info *erase) +{ + char * buf = (char*) erase->priv; + int ret; + size_t nb=0; + + if (erase->state == MTD_ERASE_DONE) + { + ret = mtd_write(erase->mtd, 0, 0x1, &nb, buf); + } + kfree(erase); + kfree(buf); +} + +static int qihoo_reset_trynum(void) +{ + size_t nb = 0; + char *buf=0, *p; + const char * match = "image1trynum="; + size_t matchlen = strlen(match); + struct erase_info *erase; + struct mtd_info * mtd; + unsigned int newcrc; + int ret; + + if (! qihoo_c301_board) + return 0; + + mtd = get_mtd_device_nm("action_image_config"); + if (IS_ERR(mtd)) + { + return PTR_ERR(mtd); + } + if (mtd->size!=0x1) + { + return -1; + } + buf = kzalloc(0x1+4, GFP_KERNEL); + ret = mtd_read(mtd, 0, 0x1, &nb, buf); + if (nb != 0x1) + { + kfree(buf); + return -1; + } + for (p=buf+4; *p; p+=strlen(p)+1) + { + if (strncmp(p, match, matchlen)==0) + { + p += matchlen; + while (*p) + *p++ = '0'; + break; + } + } + + newcrc = crc32(~0, buf+4, 0xfffc)^0x; + memcpy(buf, &newcrc, 4); + + erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL); + if (!erase) + { + kfree(buf); + return -1; + } + erase->mtd = mtd; + erase->callback = erase_callback; + erase->addr = 0; + erase->len = 0x1; + erase->priv = (u_long) buf; + ret = mtd_erase(mtd, erase); + + if (ret) { + kfree(buf); + kfree(erase); + return ret; + } + + return 0; +} +late_initcall(qihoo_reset_trynum); -- 1.7.10.4 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] [resend.2] [ar71xx] stops qihoo 360 c301 booting into backup firmware
Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. However, this router has a backup firmware in the second flash and the current trunk can only boot 3 times before u-boot boots into that backup firmware. This is a stratgy for unbricking. This patch makes u-boot happy. Signed-off-by: Xungneg li === diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c index 08a602f..774356f 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include @@ -79,6 +81,7 @@ static struct gpio_keys_button qihoo_c301_gpio_keys[] __initdata = { }, }; +static int qihoo_c301_board = 0; struct flash_platform_data flash __initdata = {NULL, NULL, 0}; static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6 +101,7 @@ static void __init qihoo_c301_setup(void) u8 tmpmac[ETH_ALEN]; ath79_register_m25p80_multi(&flash); + qihoo_c301_board = 1; ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void) MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301", qihoo_c301_setup); + + +//the following code stops qihoo's uboot booting into the backup system. +static void erase_callback(struct erase_info *erase) +{ + char * buf = (char*) erase->priv; + int ret; + size_t nb=0; + + if (erase->state == MTD_ERASE_DONE) + { + ret = mtd_write(erase->mtd, 0, 0x1, &nb, buf); + } + kfree(erase); + kfree(buf); +} + +static int qihoo_reset_trynum(void) +{ + size_t nb = 0; + char *buf=0, *p; + const char * match = "image1trynum="; + size_t matchlen = strlen(match); + struct erase_info *erase; + struct mtd_info * mtd; + unsigned int newcrc; + int ret; + + if (! qihoo_c301_board) + return 0; + + mtd = get_mtd_device_nm("action_image_config"); + if (IS_ERR(mtd)) + { + return PTR_ERR(mtd); + } + if (mtd->size!=0x1) + { + return -1; + } + buf = kzalloc(0x1+4, GFP_KERNEL); + ret = mtd_read(mtd, 0, 0x1, &nb, buf); + if (nb != 0x1) + { + kfree(buf); + return -1; + } + for (p=buf+4; *p; p+=strlen(p)+1) + { + if (strncmp(p, match, matchlen)==0) + { + p += matchlen; + while (*p) + *p++ = '0'; + break; + } + } + + newcrc = crc32(~0, buf+4, 0xfffc)^0x; + memcpy(buf, &newcrc, 4); + + erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL); + if (!erase) + { + kfree(buf); + return -1; + } + erase->mtd = mtd; + erase->callback = erase_callback; + erase->addr = 0; + erase->len = 0x1; + erase->priv = (u_long) buf; + ret = mtd_erase(mtd, erase); + + if (ret) { + kfree(buf); + kfree(erase); + return ret; + } + + return 0; +} +late_initcall(qihoo_reset_trynum); ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] 答复: [PATCH] [resend] [ar71xx] stops qihoo 360 c301 booting into backup firmware
I'm sorry it is still whitespace broken. -邮件原件- 发件人: swigger [mailto:swig...@gmail.com] 发送时间: 2014年9月20日 11:34 收件人: 'openwrt-devel@lists.openwrt.org' 主题: [PATCH] [resend] [ar71xx] stops qihoo 360 c301 booting into backup firmware Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. However, this router has a backup firmware in the second flash and the current trunk can only boot 3 times before u-boot boots into that backup firmware. This is a stratgy for unbricking. This patch makes u-boot happy. Signed-off-by: Xungneg li === diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c index 08a602f..774356f 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include @@ -79,6 +81,7 @@ static struct gpio_keys_button qihoo_c301_gpio_keys[] __initdata = { }, }; +static int qihoo_c301_board = 0; struct flash_platform_data flash __initdata = {NULL, NULL, 0}; static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6 +101,7 @@ static void __init qihoo_c301_setup(void) u8 tmpmac[ETH_ALEN]; ath79_register_m25p80_multi(&flash); + qihoo_c301_board = 1; ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void) MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301", qihoo_c301_setup); + + +//the following code stops qihoo's uboot booting into the backup system. +static void erase_callback(struct erase_info *erase) { + char * buf = (char*) erase->priv; + int ret; + size_t nb=0; + + if (erase->state == MTD_ERASE_DONE) + { + ret = mtd_write(erase->mtd, 0, 0x1, &nb, buf); + } + kfree(erase); + kfree(buf); +} + +static int qihoo_reset_trynum(void) +{ + size_t nb = 0; + char *buf=0, *p; + const char * match = "image1trynum="; + size_t matchlen = strlen(match); + struct erase_info *erase; + struct mtd_info * mtd; + unsigned int newcrc; + int ret; + + if (! qihoo_c301_board) + return 0; + + mtd = get_mtd_device_nm("action_image_config"); + if (IS_ERR(mtd)) + { + return PTR_ERR(mtd); + } + if (mtd->size!=0x1) + { + return -1; + } + buf = kzalloc(0x1+4, GFP_KERNEL); + ret = mtd_read(mtd, 0, 0x1, &nb, buf); + if (nb != 0x1) + { + kfree(buf); + return -1; + } + for (p=buf+4; *p; p+=strlen(p)+1) + { + if (strncmp(p, match, matchlen)==0) + { + p += matchlen; + while (*p) + *p++ = '0'; + break; + } + } + + newcrc = crc32(~0, buf+4, 0xfffc)^0x; + memcpy(buf, &newcrc, 4); + + erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL); + if (!erase) + { + kfree(buf); + return -1; + } + erase->mtd = mtd; + erase->callback = erase_callback; + erase->addr = 0; + erase->len = 0x1; + erase->priv = (u_long) buf; + ret = mtd_erase(mtd, erase); + + if (ret) { + kfree(buf); + kfree(erase); + return ret; + } + + return 0; +} +late_initcall(qihoo_reset_trynum); ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] [resend] [ar71xx] stops qihoo 360 c301 booting into backup firmware
Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. However, this router has a backup firmware in the second flash and the current trunk can only boot 3 times before u-boot boots into that backup firmware. This is a stratgy for unbricking. This patch makes u-boot happy. Signed-off-by: Xungneg li === diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c index 08a602f..774356f 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include @@ -79,6 +81,7 @@ static struct gpio_keys_button qihoo_c301_gpio_keys[] __initdata = { }, }; +static int qihoo_c301_board = 0; struct flash_platform_data flash __initdata = {NULL, NULL, 0}; static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6 +101,7 @@ static void __init qihoo_c301_setup(void) u8 tmpmac[ETH_ALEN]; ath79_register_m25p80_multi(&flash); + qihoo_c301_board = 1; ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void) MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301", qihoo_c301_setup); + + +//the following code stops qihoo's uboot booting into the backup system. +static void erase_callback(struct erase_info *erase) +{ + char * buf = (char*) erase->priv; + int ret; + size_t nb=0; + + if (erase->state == MTD_ERASE_DONE) + { + ret = mtd_write(erase->mtd, 0, 0x1, &nb, buf); + } + kfree(erase); + kfree(buf); +} + +static int qihoo_reset_trynum(void) +{ + size_t nb = 0; + char *buf=0, *p; + const char * match = "image1trynum="; + size_t matchlen = strlen(match); + struct erase_info *erase; + struct mtd_info * mtd; + unsigned int newcrc; + int ret; + + if (! qihoo_c301_board) + return 0; + + mtd = get_mtd_device_nm("action_image_config"); + if (IS_ERR(mtd)) + { + return PTR_ERR(mtd); + } + if (mtd->size!=0x1) + { + return -1; + } + buf = kzalloc(0x1+4, GFP_KERNEL); + ret = mtd_read(mtd, 0, 0x1, &nb, buf); + if (nb != 0x1) + { + kfree(buf); + return -1; + } + for (p=buf+4; *p; p+=strlen(p)+1) + { + if (strncmp(p, match, matchlen)==0) + { + p += matchlen; + while (*p) + *p++ = '0'; + break; + } + } + + newcrc = crc32(~0, buf+4, 0xfffc)^0x; + memcpy(buf, &newcrc, 4); + + erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL); + if (!erase) + { + kfree(buf); + return -1; + } + erase->mtd = mtd; + erase->callback = erase_callback; + erase->addr = 0; + erase->len = 0x1; + erase->priv = (u_long) buf; + ret = mtd_erase(mtd, erase); + + if (ret) { + kfree(buf); + kfree(erase); + return ret; + } + + return 0; +} +late_initcall(qihoo_reset_trynum); ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] 答复: [PATCH] [ar71xx] stops qihoo 360 c301 booting into backup firmware
Where? I don't think it's whitespace broken. Spaces are spaces and tabs are tabs. -邮件原件- 发件人: Weijie Gao [mailto:hackpas...@gmail.com] 发送时间: 2014年9月20日 1:11 收件人: swigger; openwrt-devel@lists.openwrt.org 主题: Re: [OpenWrt-Devel] [PATCH] [ar71xx] stops qihoo 360 c301 booting into backup firmware Hi, It's great. I hope this can be applied. However, your patch seems to be whitespace broken. Please fix it and resend. Weijie Gao On 2014/9/20 0:50, swigger wrote: > Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. > However, this router has a backup firmware in the second flash and the > current trunk can only boot 3 times before u-boot boots into that > backup firmware. This is a stratgy for unbricking. > > This patch makes u-boot happy. > > Signed-off-by: Xungneg li > > === > diff --git > a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c > b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c > index 08a602f..774356f 100644 > --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c > +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c > @@ -14,6 +14,8 @@ > #include > #include > #include > +#include > +#include > > #include > > @@ -79,6 +81,7 @@ static struct gpio_keys_button > qihoo_c301_gpio_keys[] __initdata = { > }, > }; > > +static int qihoo_c301_board = 0; > struct flash_platform_data flash __initdata = {NULL, NULL, 0}; > > static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6 > +101,7 @@ static void __init qihoo_c301_setup(void) > u8 tmpmac[ETH_ALEN]; > > ath79_register_m25p80_multi(&flash); > + qihoo_c301_board = 1; > > ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); > > @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void) > > MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301", >qihoo_c301_setup); > + > + > +//the following code stops qihoo's uboot booting into the backup system. > +static void erase_callback(struct erase_info *erase) { > + char * buf = (char*) erase->priv; > + int ret; > + size_t nb=0; > + > + if (erase->state == MTD_ERASE_DONE) > + { > + ret = mtd_write(erase->mtd, 0, 0x1, &nb, buf); > + } > + kfree(erase); > + kfree(buf); > +} > + > +static int qihoo_reset_trynum(void) > +{ > + size_t nb = 0; > + char *buf=0, *p; > + const char * match = "image1trynum="; > + size_t matchlen = strlen(match); > + struct erase_info *erase; > + struct mtd_info * mtd; > + unsigned int newcrc; > + int ret; > + > + if (! qihoo_c301_board) > + return 0; > + > + mtd = get_mtd_device_nm("action_image_config"); > + if (IS_ERR(mtd)) > + { > + return PTR_ERR(mtd); > + } > + if (mtd->size!=0x1) > + { > + return -1; > + } > + buf = kzalloc(0x1+4, GFP_KERNEL); > + ret = mtd_read(mtd, 0, 0x1, &nb, buf); > + if (nb != 0x1) > + { > + kfree(buf); > + return -1; > + } > + for (p=buf+4; *p; p+=strlen(p)+1) > + { > + if (strncmp(p, match, matchlen)==0) > + { > + p += matchlen; > + while (*p) > + *p++ = '0'; > + break; > + } > + } > + > + newcrc = crc32(~0, buf+4, 0xfffc)^0x; > + memcpy(buf, &newcrc, 4); > + > + erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL); > + if (!erase) > + { > + kfree(buf); > + return -1; > + } > + erase->mtd = mtd; > + erase->callback = erase_callback; > + erase->addr = 0; > + erase->len = 0x1; > + erase->priv = (u_long) buf; > + ret = mtd_erase(mtd, erase); > + > + if (ret) { > + kfree(buf); > + kfree(erase); > + return ret; > + } > + > + return 0; > +} > +late_initcall(qihoo_reset_trynum); > ___ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] [ar71xx] stops qihoo 360 c301 booting into backup firmware
Openwrt recently adds Qihoo [NYSE:QIHU] C301 router support. However, this router has a backup firmware in the second flash and the current trunk can only boot 3 times before u-boot boots into that backup firmware. This is a stratgy for unbricking. This patch makes u-boot happy. Signed-off-by: Xungneg li === diff --git a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c index 08a602f..774356f 100644 --- a/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c +++ b/target/linux/ar71xx/files/arch/mips/ath79/mach-qihoo-c301.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include @@ -79,6 +81,7 @@ static struct gpio_keys_button qihoo_c301_gpio_keys[] __initdata = { }, }; +static int qihoo_c301_board = 0; struct flash_platform_data flash __initdata = {NULL, NULL, 0}; static void qihoo_c301_get_mac(const char *name, char *mac) @@ -98,6 +101,7 @@ static void __init qihoo_c301_setup(void) u8 tmpmac[ETH_ALEN]; ath79_register_m25p80_multi(&flash); + qihoo_c301_board = 1; ath79_gpio_function_enable(AR934X_GPIO_FUNC_JTAG_DISABLE); @@ -164,3 +168,86 @@ static void __init qihoo_c301_setup(void) MIPS_MACHINE(ATH79_MACH_QIHOO_C301, "QIHOO-C301", "Qihoo 360 C301", qihoo_c301_setup); + + +//the following code stops qihoo's uboot booting into the backup system. +static void erase_callback(struct erase_info *erase) { + char * buf = (char*) erase->priv; + int ret; + size_t nb=0; + + if (erase->state == MTD_ERASE_DONE) + { + ret = mtd_write(erase->mtd, 0, 0x1, &nb, buf); + } + kfree(erase); + kfree(buf); +} + +static int qihoo_reset_trynum(void) +{ + size_t nb = 0; + char *buf=0, *p; + const char * match = "image1trynum="; + size_t matchlen = strlen(match); + struct erase_info *erase; + struct mtd_info * mtd; + unsigned int newcrc; + int ret; + + if (! qihoo_c301_board) + return 0; + + mtd = get_mtd_device_nm("action_image_config"); + if (IS_ERR(mtd)) + { + return PTR_ERR(mtd); + } + if (mtd->size!=0x1) + { + return -1; + } + buf = kzalloc(0x1+4, GFP_KERNEL); + ret = mtd_read(mtd, 0, 0x1, &nb, buf); + if (nb != 0x1) + { + kfree(buf); + return -1; + } + for (p=buf+4; *p; p+=strlen(p)+1) + { + if (strncmp(p, match, matchlen)==0) + { + p += matchlen; + while (*p) + *p++ = '0'; + break; + } + } + + newcrc = crc32(~0, buf+4, 0xfffc)^0x; + memcpy(buf, &newcrc, 4); + + erase = kzalloc(sizeof(struct erase_info), GFP_KERNEL); + if (!erase) + { + kfree(buf); + return -1; + } + erase->mtd = mtd; + erase->callback = erase_callback; + erase->addr = 0; + erase->len = 0x1; + erase->priv = (u_long) buf; + ret = mtd_erase(mtd, erase); + + if (ret) { + kfree(buf); + kfree(erase); + return ret; + } + + return 0; +} +late_initcall(qihoo_reset_trynum); ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel