Exemple #1
0
char *prom_getenv(char *envname)
{
#if defined (CONFIG_MIPS_AVALANCHE_PSPBOOT) /* PSP Boot related code. */
	int index;
        for (index = 0; index < sizeof(env_adam2_alias)/sizeof(env_adam2_alias[0]); index++) {
                if (strcmp(env_adam2_alias[index].nm, envname) == 0) {
                        return sys_getenv(env_adam2_alias[index].new_nm);
                }
        }
	return sys_getenv(envname);
#else		
	/*
	 * Return a pointer to the given environment variable.
	 * In 64-bit mode: we're using 64-bit pointers, but all pointers
	 * in the PROM structures are only 32-bit, so we need some
	 * workarounds, if we are running in 64-bit mode.
	 */
	int i, index=0;

	i = strlen(envname);

	while (prom_envp(index)) {
		if(strncmp(envname, prom_envp(index), i) == 0) {
			return(prom_envp(index+1));
		}
		index += 2;
	}

	return NULL;
#endif
}
Exemple #2
0
char *sys_username (char *buf, size_t length)
{
#ifdef _WIN32
	char	ts [UNLEN + 1];
	DWORD	len = sizeof (ts);

	if (!GetUserNameA (ts, &len))
		fatal_printf ("sys_username(): GetUserNameA() returned error!");

	if (len >= length)
		fatal_printf ("sys_username(): buffer too short!");

	memcpy (buf, ts, len);
	buf [len] = '\0';
#else
	const char	*cp = getlogin ();

	if (!cp)
		cp = sys_getenv ("LOGNAME");
	if (!cp)
		return (NULL);

	if (strlen (cp) >= length) {
		memcpy (buf, cp, length - 1);
		buf [length - 1] = '\0';
		warn_printf ("sys_username(): login name too long ('%s')!", cp);
	}
	else
		strcpy (buf, cp);
#endif
	return (buf);
}
Exemple #3
0
int EnvInit(void)
{
#ifdef _STANDALONE
#ifdef PERMANENT_VARIABLES
    unsigned int index = 0;
    char *env_name;
#endif
#endif
    static char after_init = 0;
    
    if( after_init )
      return SBL_SUCCESS;
    else
      after_init = 1;  

    env_size = psbl_rec->env_size;
    env_base = psbl_rec->env_base;

    MaxEnvVarsNum = (env_size)/(ENV_CELL_SIZE) - 1; /* Ignore the header */
    
    if(strcmp(( char *)env_base, envVersion) != 0) 
    {
        FormatEnvBlock();            
    } 
#if 0
    else 
    {
        /* TODO: Visit each environment variable and calculate the checksum. 
         * If incorrect, mark as garbage
         */   
    }
#endif

#ifdef _STANDALONE
#ifdef PERMANENT_VARIABLES

    /* Initialize permanent variables section */
    __sys_initpermenv();
    
    /* Hai: Copy variables from permanent to temporary storage */
    while( ( env_name = ( char *) __sys_getpermenvname( index ) ) != NULL )
    {
      if( __sys_setenv( env_name, __sys_getpermenvval( index ), TRUE ) == SBL_ERESCRUNCH )
      {
        sys_printf( "\nUnable to copy variable %s", env_name );
      }
      
      index++;
    }
    
    if( index == 0 )
    {       
      /* No permanent variables were found, check if PSPBoot was upgraded. if so,
         copy the backed up permanent variables back to their place */
      for(index = 0; index < MaxEnvVarsNum; index++) 
      {
        ENV_VAR* pVar;
        char *pName, *pValue;
        
        if( !(pVar = GetEnvBlockByNumber( index )) )
          break;

        GetNameAndValueFromEnvVar(pVar, &pName, &pValue);        

        if( !pName )
          continue;

        if( IsEnvPerm( pVar ) )
        {
          /* This is a permanent variable */
          sys_setpermenv( ( char *)pName, ( char *)pValue );
        }
      }    
    }  
#endif
    if( sys_getenv( "BUILD_OPS" ) == 0 )
    {
      unsigned int flag;
      char buf[ 16 ];
      
      flag =
#ifdef FFS
      BLDOPS_FFS |
#endif

#ifdef INCLUDE_LZMA
      BLDOPS_LZMA |
#endif

#ifdef INCLUDE_7ZIP
      BLDOPS_7ZIP |
#endif

#ifdef INCLUDE_GZIP
      BLDOPS_GZIP |
#endif

#ifdef FTP
      BLDOPS_FTP |
#endif

#ifdef TFTP
      BLDOPS_TFTP |
#endif

#ifdef DUAL_IMAGE_SUPPORT
      BLDOPS_DUAL_IMAGE |
#endif

#ifdef TFTP_FAILOVER_SUPPROT
      BLDOPS_TFTP_FAILOVER |
#endif

#ifdef DHCP_SUPPORT
      BLDOPS_DHCP |
#endif

#ifdef FTP_SERVER_SUPPORT
      BLDOPS_PCAPP |
#endif

#ifdef TIBINARY_SUPPORT
      BLDOPS_TI_BINARY |
#endif

#ifdef ELF_SUPPORT
      BLDOPS_ELF |
#endif
      0;
      
      sys_sprintf( buf, "0x%x", flag );
      
      sys_setenv( "BUILD_OPS", buf );
    }
#endif
    
    return SBL_SUCCESS;        
}