source: rtems/c/src/lib/libbsp/powerpc/shared/uboot_getenv.c @ bc98089

4.104.115
Last change on this file since bc98089 was a060e34, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/08 at 19:13:22

2008-07-01 Joel Sherrill <joel.sherrill@…>

  • shared/uboot_getenv.c: New file.
  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2008.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <stdint.h>
13#include <string.h>
14
15/* Assumed to be provided by BSP */
16extern const uint8_t *uboot_environment;
17extern const size_t uboot_environment_size;
18
19/*
20 * The U-Boot source code appears to use the CRC32 code from zlib.
21 * But I cannot find a way to get the crc32() in zlib code to
22 * generate the CRC found in the Flash on the Icecube board.
23 * So for now, always return TRUE.
24 */
25static int bsp_uboot_environ_check_crc(void)
26{
27#if 0
28  unsigned long crc;
29  unsigned long max;
30
31  for (max=0 ; max <= 0x20000 ; max+=4 ) {
32    crc = crc32( 0, NULL, 0 );
33    crc = crc32( crc, &uboot_environment[4], max);
34    printk( "crc=0x%08lx need %0x max=%d\n", crc,
35            *(int *)uboot_environment, max  );
36  }
37#endif
38  return 1;
39}
40
41const char *bsp_uboot_getenv(
42  const char *name
43)
44{
45  char   lhs[64];
46  size_t i, j;
47
48  if ( !bsp_uboot_environ_check_crc() )
49    return NULL;
50
51  for ( i=4 ; i<uboot_environment_size ; i++ ) {
52    memset( lhs, '\0', sizeof(lhs) );   
53    for( j=0 ; uboot_environment[i] != '=' && j<sizeof(lhs) ; i++, j++ ) {
54      lhs[j] = uboot_environment[i];
55    }
56    if ( !strncmp( name, lhs, sizeof(lhs) ) ) {
57      return (const char *)&uboot_environment[i+1];
58    }
59
60    for ( i++ ; uboot_environment[i] && i<uboot_environment_size ; i++ )
61      ;
62    if ( !uboot_environment[i+1] )
63      return NULL;
64  }
65  return NULL;
66}
67
68
Note: See TracBrowser for help on using the repository browser.