summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/framework/rule/prdrLoadChipCache.C
blob: a23e286aabd8f5a036c6100d7131ccd37f50e069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/framework/rule/prdrLoadChipCache.C $ */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2006,2012              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#ifndef __HOSTBOOT_MODULE

#include <utilreg.H> // for UtilReg

#endif


#include <string.h>                // for strncat
#include <prdrLoadChipCache.H>
#include <utilfile.H>
#include <prdfTrace.H>

namespace Prdr
{
    // Declare private member instance.
    LoadChipCache::Cache_t LoadChipCache::cv_cache;

    //---------------------------------------------------------------------
    void LoadChipCache::flushCache()
    {
        // Delete all objects within the cache.
        for (Cache_t::iterator i = cv_cache.begin();
             i != cv_cache.end();
             ++i)
        {
            if (NULL != i->second)
                delete (PrdrChip*)i->second;
        }

        // Clear map.
        cv_cache.clear();
    };
    //---------------------------------------------------------------------

    //---------------------------------------------------------------------
    errlHndl_t LoadChipCache::loadChip(const char * i_file,
                                       PrdrChip ** o_chip)
    {
        errlHndl_t l_errl = NULL;
        *o_chip = NULL;

        Cache_t::iterator i = cv_cache.find(i_file);

        if (cv_cache.end() != i) // Found object in cache.
        {
            (*o_chip) = (PrdrChip*)(*i).second;
            l_errl = NULL;
        }
        else
        {
            (*o_chip) = new PrdrChip;

            do
            {
                // NOTE: to patch PRF files require rebuilding
                // entire Hostboot image and put in a special
                // location on FSP /nfs mount.
                // FIXME: if we need to patch prf files directly
                // on Hostboot, need to discuss with Patrick
                // about a possibility of creating a new PNOR
                // partition outside of the cryptographically
                // signed area just for PRD.

#ifdef __HOSTBOOT_MODULE

                char* l_filePathName;
                size_t l_filePathSize = strlen(i_file) + 4 + 1; // 4 is for ".prf"
                l_filePathName = new char[l_filePathSize];
                strcpy(l_filePathName, i_file);
                strncat(l_filePathName, ".prf", l_filePathSize-1);

                UtilFile l_ruleFile(l_filePathName);
                if (!l_ruleFile.exists())
                {
                    // FIXME: do we need to log and commit an error here?
                    PRDF_ERR("LoadChipCache::loadChip() failed to find %s", l_filePathName);
                }
                else
                {
                    l_ruleFile.Open("r");
                }

                delete[] l_filePathName;

#else

                 // Read the correct directory path for flash.
                size_t l_rootPathSize = 256;
                char l_rootPath[256] = { '\0' };
                l_errl = UtilReg::read("fstp/RO_Root",
                                       (void *) l_rootPath,
                                       l_rootPathSize);
                strncat(l_rootPath, "prdf/", 255);
                strncat(l_rootPath, i_file, 255);
                strncat(l_rootPath, ".prf", 255);

                if (NULL != l_errl) break;

                // Read /nfs/data/... directory path
                size_t l_nfsPathSize = 256;
                char l_nfsPath[256] = { '\0' };
                l_errl = UtilReg::read("fstp/NFS_Root",
                                       (void *) l_nfsPath,
                                       l_nfsPathSize);

                strncat(l_nfsPath, "prdf/", 255);
                strncat(l_nfsPath, i_file, 255);
                strncat(l_nfsPath, ".prf", 255);

                if (NULL != l_errl) break;

                // Open File to read chip.
                UtilFile l_ruleFile(l_nfsPath);
                if (!l_ruleFile.exists())        // check for NFS file.
                {
                    l_ruleFile.Open(l_rootPath, "r");
                }
                else
                {
                    l_ruleFile.Open("r");
                }

#endif
                // Load chip object.
                l_errl = Prdr::prdrLoadChip(l_ruleFile, *(*o_chip));

            } while (0);

            if (NULL == l_errl)
            {
                // Add chip object to the cache.
                cv_cache[i_file] = *o_chip;
            }
            else
            {
                PRDF_ERR("LoadChipCache::loadChip() l_errl is not null!");
                delete *o_chip;
                (*o_chip) = NULL;
            }

        }

        return l_errl;

    };
    //---------------------------------------------------------------------
}
OpenPOWER on IntegriCloud