source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/arduino/avr/firmwares/wifishield/wifi_dnld/src/flash_fw.c @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 4.0 KB
Line 
1/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
2
3/*! \page License
4 * Copyright (C) 2009, H&D Wireless AB All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. The name of H&D Wireless AB may not be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY H&D WIRELESS AB ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
22 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30#include <avr32/io.h>
31
32#include "printf-stdarg.h"
33#include "wl_fw.h"
34#include "startup.h"
35#include "nor_flash.h"
36#include "gpio.h"
37
38#define GREEN_OFF()             gpio_set_gpio_pin(LED0_GPIO)
39#define GREEN_ON()                      gpio_clr_gpio_pin(LED0_GPIO)
40#define GREEN_BLINK()           gpio_tgl_gpio_pin(LED0_GPIO)
41#define RED_OFF()                       gpio_set_gpio_pin(LED1_GPIO)
42#define RED_ON()                        gpio_clr_gpio_pin(LED1_GPIO)
43#define RED_BLINK()             gpio_tgl_gpio_pin(LED1_GPIO)
44#define BLUE_OFF()                      gpio_set_gpio_pin(LED2_GPIO)
45#define BLUE_ON()                       gpio_clr_gpio_pin(LED2_GPIO)
46#define BLUE_BLINK()            gpio_tgl_gpio_pin(LED2_GPIO)
47
48
49/**
50 *
51 */
52void
53led_init(void)
54{
55        gpio_enable_gpio_pin(LED0_GPIO);
56        gpio_enable_gpio_pin(LED1_GPIO);
57        gpio_enable_gpio_pin(LED2_GPIO);
58        GREEN_OFF();
59        RED_OFF();
60        BLUE_OFF();
61}
62
63
64int main(void)
65{
66        U32 pos, len;
67
68        startup_init();
69        printk("*** HD chip firmware upgrade ver 2.7 ***\n");
70        led_init();
71        flash_init();
72        GREEN_ON();
73        if (at45dbx_mem_check() == OK)
74        {
75                printk("Memory check... [  OK  ]\n");
76        }
77        else
78        {
79                RED_ON();
80                GREEN_OFF();
81                printk("Memory check... [FAIL]\n");
82                return 0;
83        }
84        printk("Writing firmware data to flash\n");
85        pos = 0;
86        while (pos < fw_len) {
87                if (fw_len - pos > SECTOR_SIZE)
88                        len = SECTOR_SIZE;
89                else
90                        len = fw_len - pos;
91               
92                flash_write(pos, fw_buf + pos, len);
93                pos += len;
94        }
95
96        printk("Verifying firmware data\n");
97        pos = 0;
98        while (pos < fw_len) {
99                static U8 page_buf[SECTOR_SIZE];
100                U32 i;
101
102                if (fw_len - pos > SECTOR_SIZE)
103                        len = SECTOR_SIZE;
104                else
105                        len = fw_len - pos;
106               
107                flash_read(pos, page_buf, len);
108
109                for (i = 0; i < len; i++)
110                    if (*(page_buf + i) != *(fw_buf + pos + i)) {
111                        RED_ON();
112                        GREEN_OFF();
113                        printk("Verify failed at byte %d, 0x%02x != 0x%02x\n",
114                               pos + i, *(page_buf + i), *(fw_buf + pos + i));
115                        return 0;
116                    }
117                       
118               
119                pos += len;
120        }
121        GREEN_OFF();
122        BLUE_ON();
123        printk("Firmware successfully stored in flash!\n");
124        return 0;
125}
Note: See TracBrowser for help on using the repository browser.