check_flash.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2009-2010, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
37 #include <string.h>
38 #include <cstdio>
39 #include <cstdlib>
40 #include <cstring>
41 #include <cassert>
42 #include <unistd.h>
43 
44 int main(int argc, char** argv)
45 {
46  if (argc != 2 || !strcmp(argv[1], "--help")) {
47  fprintf(stderr, "Usage: %s <camera_url>\n", argv[0]);
48  fprintf(stderr, "Writes a test sequence to unused portions of the flash to check for\n");
49  fprintf(stderr, "proper operation. It is very improbable that you need this tool in\n");
50  fprintf(stderr, "normal use of the camera.\n");
51  return -1;
52  }
53  char* camera_url = argv[1];
54 
55  // Find the camera matching the URL
56  IpCamList camera;
57  const char *errmsg;
58  int outval = wge100FindByUrl(camera_url, &camera, SEC_TO_USEC(0.1), &errmsg);
59  if (outval)
60  {
61  fprintf(stderr, "Matching URL %s : %s\n", camera_url, errmsg);
62  return -1;
63  }
64 
65  // Configure the camera with its IP address, wait up to 500ms for completion
66  int retval = wge100Configure(&camera, camera.ip_str, SEC_TO_USEC(0.5));
67  if (retval != 0) {
68  if (retval == ERR_CONFIG_ARPFAIL) {
69  fprintf(stderr, "Unable to create ARP entry (are you root?), continuing anyway\n");
70  } else {
71  fprintf(stderr, "IP address configuration failed\n");
72  return -1;
73  }
74  }
75 
76 #define FLASH_SIZE_LONG ((FLASH_PAGE_SIZE + 3) / 4)
77  uint32_t buffer[FLASH_SIZE_LONG];
78  uint32_t buffer2[FLASH_PAGE_SIZE];
79 
80  fprintf(stderr, "\n*************************************************************************\n");
81  fprintf(stderr, "Warning, this will overwrite potentially important flash memory contents.\n");
82  fprintf(stderr, "You have 5 seconds to press CTRL+C to abort this operation.\n");
83  fprintf(stderr, "*************************************************************************\n");
84 
85  sleep(5);
86 
87  uint32_t incr = 282475249;
88  uint32_t pattern = 0;
89  for (int i = FLASH_MAX_PAGENO / 2; i <= FLASH_MAX_PAGENO - 10; i++)
90  {
91  if (i % 100 == 0)
92  {
93  fprintf(stderr, ".");
94  fflush(stderr);
95  }
96  for (int j = 0; j < FLASH_SIZE_LONG; j++)
97  buffer[j] = pattern += incr;
98 
99  if (wge100ReliableFlashWrite(&camera, i, (uint8_t*) buffer, NULL) != 0) {
100  fprintf(stderr, "\nFlash write error\n");
101  return -1;
102  }
103  }
104  printf("\n");
105 
106  int errcount = 0;
107  pattern = 0;
108  for (int i = FLASH_MAX_PAGENO / 2; i <= FLASH_MAX_PAGENO - 10; i++)
109  {
110  if (i % 100 == 0)
111  {
112  fprintf(stderr, ".");
113  fflush(stderr);
114  }
115  for (int j = 0; j < FLASH_SIZE_LONG; j++)
116  buffer[j] = pattern += incr;
117 
118  if (wge100ReliableFlashRead(&camera, i, (uint8_t*) buffer2, NULL) != 0) {
119  fprintf(stderr, "\nFlash read error\n");
120  return -1;
121  }
122 
123  if (memcmp(buffer, buffer2, FLASH_PAGE_SIZE))
124  {
125  errcount++;
126  fprintf(stderr, "Mismatch in page %i\n.", i);
127  }
128  }
129 
130  fprintf(stderr, "\nCheck completed, %i errors.\n", errcount);
131 
132  return 0;
133 }
#define FLASH_PAGE_SIZE
Definition: ipcam_packet.h:60
int wge100ReliableFlashRead(const IpCamList *camInfo, uint32_t address, uint8_t *pageDataOut, int *retries)
Definition: wge100lib.c:906
int wge100ReliableFlashWrite(const IpCamList *camInfo, uint32_t address, const uint8_t *pageDataIn, int *retries)
Definition: wge100lib.c:1014
int wge100Configure(IpCamList *camInfo, const char *ipAddress, unsigned wait_us)
Definition: wge100lib.c:532
#define ERR_CONFIG_ARPFAIL
Definition: wge100lib.h:116
#define FLASH_SIZE_LONG
#define SEC_TO_USEC(sec)
Definition: host_netutil.h:65
int wge100FindByUrl(const char *url, IpCamList *camera, unsigned wait_us, const char **errmsg)
Definition: wge100lib.c:94
char ip_str[16]
Definition: list.h:296
int main(int argc, char **argv)
Definition: check_flash.cpp:44
#define FLASH_MAX_PAGENO
Definition: ipcam_packet.h:59


wge100_camera
Author(s): Blaise Gassend, Patrick Mihelich, Eric MacIntosh, David Palchak
autogenerated on Mon Jun 10 2019 15:44:15