Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/SMBiosPatcher/SMBiosPatcher.c

1/*
2 * Copyright 2011 cparm. All rights reserved.
3 */
4#include "boot.h"
5#include "bootstruct.h"
6#include "libsaio.h"
7#include "modules.h"
8#include "Platform.h"
9#include "smbios_patcher.h"
10#include "efi.h"
11
12#ifndef DEBUG_SMBIOS
13#define DEBUG_SMBIOS 0
14#endif
15
16#if DEBUG_SMBIOS==2
17#define DBG(x...)printf(x)
18#elif DEBUG_SMBIOS==1
19#define DBG(x...) msglog(x)
20#else
21#define DBG(x...)
22#endif
23
24#define kEnableSMBIOSPatcher"EnableSMBIOSPatcher"
25
26
27void getSmbiosPatched_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)
28{
29struct SMBEntryPoint *patched_smb = NULL;
30
31 getSmbiosTableStructure(getSmbiosOriginal()); // generate tables entry list for fast table finding
32
33if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS)
34 scan_memory(Platform);
35
36execute_hook("ScanMemory", NULL, NULL, NULL, NULL, NULL, NULL);
37
38patched_smb = getSmbiosPatched(getSmbiosOriginal());
39
40if (patched_smb)
41smbios_p = ((uint64_t)((uint32_t)patched_smb));
42else
43 {
44verbose("Error: Could not get patched SMBIOS, fallback to original SMBIOS !!\n");
45
46 struct SMBEntryPoint *smbios_o = getSmbiosOriginal();
47 smbios_p = ((uint64_t)((uint32_t)smbios_o));
48 }
49
50}
51
52void getProductName_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)
53{
54setupSmbiosConfigFile("SMBIOS.plist");
55int len = 0;
56const char *val = 0;
57
58if (getValueForKey("SMproductname", &val, &len, &bootInfo->smbiosConfig)) {
59gPlatformName = (char *)val;
60} else {
61const char *productName = sm_get_defstr("SMproductname", 0);
62gPlatformName = (char *)productName;
63}
64DBG("SMBIOS Product name: %s\n",productName);
65
66
67}
68
69void is_SMB_Patcher_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){}
70
71void SMBiosPatcher_start()
72{
73 bool enable = true;
74getBoolForKey(kEnableSMBIOSPatcher, &enable, &bootInfo->bootConfig) ;
75
76enable = (execute_hook("isSMBIOSRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS);
77
78if (enable) {
79register_hook_callback("getSmbiosPatched", &getSmbiosPatched_hook);
80register_hook_callback("getProductNamePatched", &getProductName_hook);
81 register_hook_callback("isSMBIOSRegistred", &is_SMB_Patcher_Registred_Hook);
82 }
83}
84

Archive Download this file

Revision: 1119