Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:58

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2008.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #include <bsp.h>
0030 
0031 /*
0032  * If the BSP variant does not have UBoot, then disable all contents
0033  * of this file.
0034  */
0035 #if defined(HAS_UBOOT)
0036 
0037 #include <stdint.h>
0038 #include <string.h>
0039 
0040 /* Assumed to be provided by BSP */
0041 extern const uint8_t *uboot_environment;
0042 extern const size_t uboot_environment_size;
0043 
0044 /*
0045  * The U-Boot source code appears to use the CRC32 code from zlib.
0046  * But I cannot find a way to get the crc32() in zlib code to
0047  * generate the CRC found in the Flash on the Icecube board.
0048  * So for now, always return TRUE.
0049  */
0050 static int bsp_uboot_environ_check_crc(void)
0051 {
0052 #if 0
0053   unsigned long crc;
0054   unsigned long max;
0055 
0056   for (max=0 ; max <= 0x20000 ; max+=4 ) {
0057     crc = crc32( 0, NULL, 0 );
0058     crc = crc32( crc, &uboot_environment[4], max);
0059     printk( "crc=0x%08lx need %0x max=%d\n", crc,
0060             *(int *)uboot_environment, max  );
0061   }
0062 #endif
0063   return 1;
0064 }
0065 
0066 const char *bsp_uboot_getenv(
0067   const char *name
0068 )
0069 {
0070   char   lhs[64];
0071   size_t i, j;
0072 
0073   if ( !bsp_uboot_environ_check_crc() )
0074     return NULL;
0075 
0076   for ( i=4 ; i<uboot_environment_size ; i++ ) {
0077     memset( lhs, '\0', sizeof(lhs) );
0078     for( j=0 ; uboot_environment[i] != '=' && j<sizeof(lhs) ; i++, j++ ) {
0079       lhs[j] = uboot_environment[i];
0080     }
0081     if ( !strncmp( name, lhs, sizeof(lhs) ) ) {
0082       return (const char *)&uboot_environment[i+1];
0083     }
0084 
0085     for ( i++ ; uboot_environment[i] && i<uboot_environment_size ; i++ )
0086       ;
0087     if ( !uboot_environment[i+1] )
0088       return NULL;
0089   }
0090   return NULL;
0091 }
0092 
0093 #endif /* defined(HAS_UBOOT) */