xref: /aosp_15_r20/external/coreboot/src/vendorcode/cavium/bdk/libdram/dram-env.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /***********************license start***********************************
2 * Copyright (c) 2003-2017  Cavium Inc. ([email protected]). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 *   * Redistributions of source code must retain the above copyright
11 *     notice, this list of conditions and the following disclaimer.
12 *
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 *
18 *   * Neither the name of Cavium Inc. nor the names of
19 *     its contributors may be used to endorse or promote products
20 *     derived from this software without specific prior written
21 *     permission.
22 *
23 * This Software, including technical data, may be subject to U.S. export
24 * control laws, including the U.S. Export Administration Act and its
25 * associated regulations, and may be subject to export or import
26 * regulations in other countries.
27 *
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
31 * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
32 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
33 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
34 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
35 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
36 * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK
37 * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39 #include <bdk.h>
40 #include "dram-internal.h"
41 
42 #include <string.h>
43 #include <lame_string.h>
44 
lookup_env_parameter(const char * format,...)45 const char* lookup_env_parameter(const char *format, ...)
46 {
47     const char *s;
48     unsigned long value;
49     va_list args;
50     char buffer[64];
51 
52     va_start(args, format);
53     vsnprintf(buffer, sizeof(buffer)-1, format, args);
54     buffer[sizeof(buffer)-1] = '\0';
55     va_end(args);
56 
57     if ((s = getenv(buffer)) != NULL)
58     {
59         value = strtoul(s, NULL, 0);
60         error_print("Parameter found in environment: %s = \"%s\" 0x%lx (%ld)\n",
61                     buffer, s, value, value);
62     }
63     return s;
64 }
65 
lookup_env_parameter_ull(const char * format,...)66 const char* lookup_env_parameter_ull(const char *format, ...)
67 {
68     const char *s;
69     unsigned long long value;
70     va_list args;
71     char buffer[64];
72 
73     va_start(args, format);
74     vsnprintf(buffer, sizeof(buffer)-1, format, args);
75     buffer[sizeof(buffer)-1] = '\0';
76     va_end(args);
77 
78     if ((s = getenv(buffer)) != NULL)
79     {
80         value = strtoull(s, NULL, 0);
81         error_print("Parameter found in environment: %s = 0x%016llx\n",
82                     buffer, value);
83     }
84     return s;
85 }
86 
87