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 | ␊ |
27 | void getSmbiosPatched_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
28 | {␉␊ |
29 | ␉struct SMBEntryPoint *patched_smb = NULL;␊ |
30 | ␉␊ |
31 | getSmbiosTableStructure(getSmbiosOriginal()); // generate tables entry list for fast table finding␊ |
32 | ␊ |
33 | ␉if (execute_hook("isMemoryRegistred", NULL, NULL, NULL, NULL, NULL, NULL) == EFI_SUCCESS) ␊ |
34 | scan_memory(Platform);␊ |
35 | ␊ |
36 | ␉execute_hook("ScanMemory", NULL, NULL, NULL, NULL, NULL, NULL);␉␊ |
37 | ␉␊ |
38 | ␉patched_smb = getSmbiosPatched(getSmbiosOriginal());␊ |
39 | ␉␊ |
40 | ␉if (patched_smb)␊ |
41 | ␉␉smbios_p = ((uint64_t)((uint32_t)patched_smb)); ␊ |
42 | ␉else␊ |
43 | {␊ |
44 | ␉␉verbose("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 | ␊ |
52 | void getProductName_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
53 | {␉␊ |
54 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
55 | ␉int len = 0;␊ |
56 | ␉const char *val = 0;␊ |
57 | ␉␊ |
58 | ␉if (getValueForKey("SMproductname", &val, &len, &bootInfo->smbiosConfig)) {␊ |
59 | ␉␉gPlatformName = (char *)val;␊ |
60 | ␉} else {␊ |
61 | ␉␉const char *productName = sm_get_defstr("SMproductname", 0);␉␊ |
62 | ␉␉gPlatformName = (char *)productName;␊ |
63 | ␉}␉␊ |
64 | ␉DBG("SMBIOS Product name: %s\n",productName);␊ |
65 | ␊ |
66 | ␉␊ |
67 | }␊ |
68 | ␊ |
69 | void getboardproduct_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
70 | {␉␊ |
71 | ␉setupSmbiosConfigFile("SMBIOS.plist");␊ |
72 | ␉int len = 0;␊ |
73 | ␉const char *val = 0;␊ |
74 | ␉␊ |
75 | ␉if (getValueForKey("SMboardproduct", &val, &len, &bootInfo->smbiosConfig)) {␊ |
76 | ␉␉gboardproduct = (char *)val;␊ |
77 | ␉} else {␊ |
78 | const char *productBoard = sm_get_defstr("SMboardproduct", 0);␉␊ |
79 | ␉␉gboardproduct = (char *)productBoard;␊ |
80 | ␉}␉␊ |
81 | ␉␊ |
82 | }␊ |
83 | ␊ |
84 | void is_SMB_Patcher_Registred_Hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6){}␊ |
85 | ␊ |
86 | void SMBiosPatcher_start()␊ |
87 | {␉␊ |
88 | bool enable = true;␊ |
89 | ␉getBoolForKey(kEnableSMBIOSPatcher, &enable, &bootInfo->bootConfig) ;␊ |
90 | ␉␊ |
91 | ␉enable = (execute_hook("isSMBIOSRegistred", NULL, NULL, NULL, NULL, NULL, NULL) != EFI_SUCCESS);␊ |
92 | ␊ |
93 | ␉if (enable) {␊ |
94 | ␉register_hook_callback("getSmbiosPatched", &getSmbiosPatched_hook);␉␊ |
95 | ␉register_hook_callback("getProductNamePatched", &getProductName_hook);␊ |
96 | register_hook_callback("getboardproductPatched", &getboardproduct_hook);␊ |
97 | register_hook_callback("isSMBIOSRegistred", &is_SMB_Patcher_Registred_Hook);␊ |
98 | }␊ |
99 | }␊ |
100 | |