ITzTravelInTime Posted April 8, 2017 Share Posted April 8, 2017 Hi guys, I ask to the developers of this community, I'm am developing a kext for a pci device for Mac OS and I want to add custom boot args to it to enable a diagnostic mode (it just defines a particular macro when the boot arg is detected) or to add other stuff in the future, can you help me? I'd like to add a boot arg that I want to call -kx_diagnose Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/ Share on other sites More sharing options...
bs0d Posted April 8, 2017 Share Posted April 8, 2017 perhaps look at the source for other kexts that have args to give you a hint ? 3 Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2400551 Share on other sites More sharing options...
Sinetek Posted April 8, 2017 Share Posted April 8, 2017 Instead of doing that you could use the sysctl interfaces to set an integer in your driver. Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2400579 Share on other sites More sharing options...
ITzTravelInTime Posted April 8, 2017 Author Share Posted April 8, 2017 Instead of doing that you could use the sysctl interfaces to set an integer in your driver. i cant't because that system i implemented has to be loaded at driver startup Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2400747 Share on other sites More sharing options...
ITzTravelInTime Posted April 8, 2017 Author Share Posted April 8, 2017 perhaps look at the source for other kexts that have args to give you a hint ? if you can it will be great, I just to want to see how to do that because I don't know Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2400897 Share on other sites More sharing options...
PMheart Posted April 8, 2017 Share Posted April 8, 2017 Hi. What about "pe_parse_boot_argn" interface? Well, can't explain that in short words... I guess @vit9696's Lilu may give you a few hints. 1 Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2400939 Share on other sites More sharing options...
ITzTravelInTime Posted April 9, 2017 Author Share Posted April 9, 2017 Hi. What about "pe_parse_boot_argn" interface? Well, can't explain that in short words... I guess @vit9696's Lilu may give you a few hints. thank you, i have seen that it's very simple, just include #include <IOKit/IOLib.h> #include <IOKit/IORegistryEntry.h> #include <mach/mach_types.h> in the module in witch there is the startup function and then inside that function i have just to call the function you mentioned if (PE_parse_boot_argn("-kx_debug", tmp, sizeof(tmp))){ #define GENERAL_DEBUG debug(DBGCLASS"[%p]::initHardware: debug mode enabled by boot arg -kx_debug\n",this); }else{ #ifdef GENERAL_DEBUG #undef GENERAL_DEBUG #endif } 1 Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2400984 Share on other sites More sharing options...
PMheart Posted April 9, 2017 Share Posted April 9, 2017 thank you, i have seen that it's very simple, just include #include <IOKit/IOLib.h> #include <IOKit/IORegistryEntry.h> #include <mach/mach_types.h> in the module in witch there is the startup function and then inside that function i have just to call the function you mentioned if (PE_parse_boot_argn("-kx_debug", tmp, sizeof(tmp))){ #define GENERAL_DEBUG debug(DBGCLASS"[%p]::initHardware: debug mode enabled by boot arg -kx_debug\n",this); }else{ #ifdef GENERAL_DEBUG #undef GENERAL_DEBUG #endif } Congratulations! Glad to hear that. BTW, I think your code is somewhat complicated, introduce a global macro and define debug logging can be a better solution. (Like Lilu's DBGLOG() ) Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2401032 Share on other sites More sharing options...
ITzTravelInTime Posted April 9, 2017 Author Share Posted April 9, 2017 Congratulations! Glad to hear that. BTW, I think your code is somewhat complicated, introduce a global macro and define debug logging can be a better solution. (Like Lilu's DBGLOG() ) if you mean debug(DBGCLASS"[%p]::initHardware: debug mode enabled by boot arg -kx_debug\n",this); it is a replacement of iolog , that uses also serial and network debugging too, it is custom made 2 Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2401424 Share on other sites More sharing options...
PMheart Posted April 9, 2017 Share Posted April 9, 2017 if you mean debug(DBGCLASS"[%p]::initHardware: debug mode enabled by boot arg -kx_debug\n",this); it is a replacement of iolog , that uses also serial and network debugging too, it is custom made Great. I see. Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2401481 Share on other sites More sharing options...
ITzTravelInTime Posted April 19, 2017 Author Share Posted April 19, 2017 just a quick update, i have seen that using macros does not work that well, so i used some booleans i decided to put more boot args for various stuff. if you ask hw is an instance of a custom class that represents the device that the driver is using and his characteristics and debug stil is what i told before if you are asking and also arg is to count the boot args found only for testing reasons debug(DBGCLASS"[%p]::initHardware: boot args detection started\n",this); //boot args checking char tmp[16]; int arg; arg = 0; if (PE_parse_boot_argn("-kx_debug", tmp, sizeof(tmp))){ hw->nameDebug = true; hw->showBusInName = true; arg++; debug(DBGCLASS"[%p]::initHardware: debug mode enabled by boot arg -kx_debug\n",this); }else{ hw->nameDebug = false; hw->showBusInName = false; } if (PE_parse_boot_argn("-kx_exp_deb", tmp, sizeof(tmp))){ hw->testImputs = true; arg++; debug(DBGCLASS"[%p]::initHardware: debug of experimental features enbled by -kx_exp_deb\n",this); }else{ hw->testImputs = false; } if (PE_parse_boot_argn("-kx_original", tmp, sizeof(tmp))){ hw->disableFixes = true; arg++; debug(DBGCLASS"[%p]::initHardware: fixes of the mod disabled by -kx_original\n",this); }else{ hw->disableFixes = false; } if (arg == 0){ debug(DBGCLASS"[%p]::initHardware: boot args detecting finished, none found\n",this); }else{ debug(DBGCLASS"[%p]::initHardware: boot args detecting finished, [%i] found\n",this, arg); } Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2407313 Share on other sites More sharing options...
matthew. Posted April 23, 2017 Share Posted April 23, 2017 thank you, i have seen that it's very simple, just include #include <IOKit/IOLib.h> #include <IOKit/IORegistryEntry.h> #include <mach/mach_types.h> in the module in witch there is the startup function and then inside that function i have just to call the function you mentioned if (PE_parse_boot_argn("-kx_debug", tmp, sizeof(tmp))){ #define GENERAL_DEBUG debug(DBGCLASS"[%p]::initHardware: debug mode enabled by boot arg -kx_debug\n",this); }else{ #ifdef GENERAL_DEBUG #undef GENERAL_DEBUG #endif } I think that you have misunderstood macros. They are evaluated at compile time, not runtime. Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2410583 Share on other sites More sharing options...
ITzTravelInTime Posted April 28, 2017 Author Share Posted April 28, 2017 I think that you have misunderstood macros. They are evaluated at compile time, not runtime. yes i have seen it, that's why i decided to use some booleans instead 1 Link to comment https://www.insanelymac.com/forum/topic/322629-create-a-new-kext-that-uses-boot-args/#findComment-2413707 Share on other sites More sharing options...
Recommended Posts