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