summaryrefslogtreecommitdiff
path: root/sys/boot/common/module.c
Commit message (Collapse)AuthorAgeFilesLines
* Move sys/boot to stand. Fix all references to new locationWarner Losh2017-11-141-1095/+0
| | | | | | | Sponsored by: Netflix Notes: svn path=/head/; revision=325834
* loader/multiboot: fix multiboot loadingRoger Pau Monné2017-04-131-0/+16
| | | | | | | | | | | | | | | | | | | | The current multiboot loader code doesn't clean the metadata added to the kernel after the bi_load64 dry run, which breaks accounting of the required memory for the metadata. This issue didn't show itself before because all the metadata items where small (8bytes), but after r316343 there's a big blob in the metadata, which triggers this. Fix it by cleaning the metadata added to the kernel after the bi_load64 dry run. Also add a comment describing the memory layout when booting using multiboot (Xen Dom0). This unbreaks booting a FreeBSD/Xen Dom0 after r316343. MFC after: 3 weeks Sponsored by: Citrix Systems R&D Notes: svn path=/head/; revision=316754
* sys/boot/common: Make geli(4) support optional in MI sourcesEnji Cooper2017-03-281-0/+2
| | | | | | | | | | | This saves a negligible amount of memory for non-geli enabled bootloaders. MFC after: 1 week Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=316076
* Loader paged/pageable data is not always paged.Toomas Soome2016-11-081-6/+12
| | | | | | | | | | | | | | | | | | | This change does modify devsw dv_print() to return the int value, enabling walkers to interrupt the walk on non zero value from dv_print(). This will allow the pager_print actually to stop displaying data on user input, and additionally pager is used in various *dev_print callbacks, where it was missing. For test, lsdev [-v] command should display data by screenfuls and should stop when the key 'q' is pressed on pager prompt. Reviewed by: allanjude Approved by: allanjude (mentor) Differential Revision: https://reviews.freebsd.org/D5461 Notes: svn path=/head/; revision=308434
* loader is filling fixed length command_errbuf with sprintf() and is trustingToomas Soome2016-08-201-17/+30
| | | | | | | | | | | | | | strings provided by user/config files. This update is replacing sprintf with snprintf for cases the command_errbuf is built from dynamic content. PR: 211958 Reported by: ecturt@gmail.com Reviewed by: imp, allanjude Approved by: imp (mentor), allanjude (mentor) Differential Revision: https://reviews.freebsd.org/D7563 Notes: svn path=/head/; revision=304532
* Fix several instances where the boot loader ignored pager_outputWarner Losh2016-05-181-4/+7
| | | | | | | | | | return value when it could return 1 (indicating we should stop). Fix a few instances of pager_open() / pager_close() not being called. Actually use these routines for the environment variable printing code I just committed. Notes: svn path=/head/; revision=300117
* sys/boot/common: use of spaces vs. TAB.Pedro F. Giffuni2016-05-121-8/+8
| | | | | | | No functional change. Notes: svn path=/head/; revision=299499
* sys: use our roundup2/rounddown2() macros when param.h is available.Pedro F. Giffuni2016-04-211-1/+1
| | | | | | | | | | | | | rounddown2 tends to produce longer lines than the original code and when the code has a high indentation level it was not really advantageous to do the replacement. This tries to strike a balance between readability using the macros and flexibility of having the expressions, so not everything is converted. Notes: svn path=/head/; revision=298433
* A new implementation of the loader block cacheAllan Jude2016-04-181-3/+3
| | | | | | | | | | | | | | | | | | | | The block cache implementation in loader has proven to be almost useless, and in worst case even slowing down the disk reads due to insufficient cache size and extra memory copy. Also the current cache implementation does not cache reads from CDs, or work with zfs built on top of multiple disks. Instead of an LRU, this code uses a simple hash (O(1) read from cache), and instead of a single global cache, a separate cache per block device. The cache also implements limited read-ahead to increase performance. To simplify read ahead management, the read ahead will not wrap over bcache end, so in worst case, single block physical read will be performed to fill the last block in bcache. Booting from a virtual CD over IPMI: 0ms latency, before: 27 second, after: 7 seconds 60ms latency, before: over 12 minutes, after: under 5 minutes. Submitted by: Toomas Soome <tsoome@me.com> Reviewed by: delphij (previous version), emaste (previous version) Relnotes: yes Differential Revision: https://reviews.freebsd.org/D4713 Notes: svn path=/head/; revision=298230
* Make common boot file_loadraw name parameter constSteven Hartland2016-01-151-7/+6
| | | | | | | | | | | | | Fix compiler warnings about dropping const qualifier by changing file_loadraw name param to const, and updating method to make that the case (it was abusing the variable). MFC after: 2 weeks X-MFC-With: r293268 Sponsored by: Multiplay Notes: svn path=/head/; revision=294058
* Improve non-interactive forth cmd error reportingSteven Hartland2016-01-131-9/+22
| | | | | | | | | | | | | | | | | | | | | | Non-interactive forth command errors where silent even for critical issues e.g. failing to load a required kernel module or mfs_root. This resulted in later unexplained and hard to trace errors such as mount root failures. This introduces additional command return codes that are treated appropriately by the non-interactive command processor (bf_command). * CMD_CRIT = print error * CMD_FATAL = panic Also fix minor style(9) issues with command_load return codes. MFC after: 2 weeks X-MFC-With: r293268 Sponsored by: Multiplay Notes: svn path=/head/; revision=293835
* Enable warnings in EFI boot codeSteven Hartland2016-01-121-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Set WARNS if not set for EFI boot code and fix the issues highlighted by setting it. Most components are set to WARNS level 6 with few being left at lower levels due to the amount of changes needed to fix at higher levels. Error types fixed: * Missing / invalid casts * Missing inner structs * Unused vars * Missing static for internal only funcs * Missing prototypes * Alignment changes * Use of uninitialised vars * Unknown pragma (intrinsic) * Missing types etc due to missing includes * printf formatting types Reviewed by: emaste (in part) MFC after: 2 weeks X-MFC-With: r293268 Sponsored by: Multiplay Differential Revision: https://reviews.freebsd.org/D4839 Notes: svn path=/head/; revision=293724
* Fix a problem which made loader(8) load non-kld files twice.Edward Tomasz Napierala2015-08-031-0/+8
| | | | | | | | | | | | | | | | | | For example, without this patch, the following three lines in /boot/loader.conf would result in /boot/root.img being preloaded twice, and two md(4) devices - md0 and md1 - being created. initmd_load="YES" initmd_type="md_image" initmd_name="/boot/root.img" Reviewed by: marcel@ MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D3204 Notes: svn path=/head/; revision=286234
* loader: implement multiboot support for Xen Dom0Roger Pau Monné2015-01-151-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Implement a subset of the multiboot specification in order to boot Xen and a FreeBSD Dom0 from the FreeBSD bootloader. This multiboot implementation is tailored to boot Xen and FreeBSD Dom0, and it will most surely fail to boot any other multiboot compilant kernel. In order to detect and boot the Xen microkernel, two new file formats are added to the bootloader, multiboot and multiboot_obj. Multiboot support must be tested before regular ELF support, since Xen is a multiboot kernel that also uses ELF. After a multiboot kernel is detected, all the other loaded kernels/modules are parsed by the multiboot_obj format. The layout of the loaded objects in memory is the following; first the Xen kernel is loaded as a 32bit ELF into memory (Xen will switch to long mode by itself), after that the FreeBSD kernel is loaded as a RAW file (Xen will parse and load it using it's internal ELF loader), and finally the metadata and the modules are loaded using the native FreeBSD way. After everything is loaded we jump into Xen's entry point using a small trampoline. The order of the multiboot modules passed to Xen is the following, the first module is the RAW FreeBSD kernel, and the second module is the metadata and the FreeBSD modules. Since Xen will relocate the memory position of the second multiboot module (the one that contains the metadata and native FreeBSD modules), we need to stash the original modulep address inside of the metadata itself in order to recalculate its position once booted. This also means the metadata must come before the loaded modules, so after loading the FreeBSD kernel a portion of memory is reserved in order to place the metadata before booting. In order to tell the loader to boot Xen and then the FreeBSD kernel the following has to be added to the /boot/loader.conf file: xen_cmdline="dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga" xen_kernel="/boot/xen" The first argument contains the command line that will be passed to the Xen kernel, while the second argument is the path to the Xen kernel itself. This can also be done manually from the loader command line, by for example typing the following set of commands: OK unload OK load /boot/xen dom0_mem=1024M dom0_max_vcpus=2 dom0pvh=1 console=com1,vga OK load kernel OK load zfs OK load if_tap OK load ... OK boot Sponsored by: Citrix Systems R&D Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D517 For the Forth bits: Submitted by: Julien Grall <julien.grall AT citrix.com> Notes: svn path=/head/; revision=277215
* The current limit of 100k for the linker hints file is getting a bitWarner Losh2014-11-291-1/+1
| | | | | | | | | | | crowded as we now are at about 70k. Bump the limit to 1MB instead which is still quite a reasonable limit and allows for future growth of this file and possible future expansion to additional data. MFC After: 2 weeks Notes: svn path=/head/; revision=275261
* When built with FDT support, add /boot/dtb to the list of search directories.Ian Lepore2014-09-031-0/+5
| | | | Notes: svn path=/head/; revision=271054
* Rename command_unload() to unload() and re-implement command_unload()Marcel Moolenaar2014-08-061-6/+12
| | | | | | | | | | in terms of unload() This allows unloading all files by the loader itself. Obtained from: Juniper Networks, Inc. Notes: svn path=/head/; revision=269618
* In command_lsmod() prevent overrunning lbuf due to long pathMarcel Moolenaar2014-08-051-2/+4
| | | | | | | | | names. Call pager_output() separately for the module name. Obtained from: Juniper Networks, Inc. Notes: svn path=/head/; revision=269616
* In file_loadraw() print the name of the file as well as its sizeMarcel Moolenaar2014-08-051-1/+6
| | | | | | | | | so that we know what file is being loaded and how big the file is once complete. This has ELF modules and disk images emit the same output. Notes: svn path=/head/; revision=269614
* Change file_loadraw() from static to public. Change the order of itsIan Lepore2014-02-221-10/+9
| | | | | | | | | arguments from type,filename to filename,type to be consistant with other public file_whatever() functions, and change it to return a pointer to the preloaded_file struct describing the file. Adjust existing callers. Notes: svn path=/head/; revision=262345
* Since we didn't break the loop, we should set i to -1 to start from theAndrey V. Elsukov2013-04-211-1/+2
| | | | | | | | | | beginning. Submitted by: Steven Hartland MFC after: 1 week Notes: svn path=/head/; revision=249719
* Fix the bug I introduced in r247045.Tim Kientzle2013-02-251-36/+0
| | | | | | | | | | | | | | | | | | | After digging through more carefully, it looks like there's no real need to have the DTB in the module directory. So we can simplify a lot: Just copy DTB into local heap for "fdt addr" and U-Boot integration, drop all the extra COPYIN() calls. I've left one final COPYIN() to update the in-kernel DTB for consistency with how this code used to work, but I'm no longer convinced it's appropriate here. I've also remove the mem_load_raw() utility that I added to boot/common/module.c with r247045 since it's no longer necessary. Notes: svn path=/head/; revision=247250
* Add mem_load_raw() for loading data from another location in memory.Tim Kientzle2013-02-181-0/+37
| | | | | | | | | This will be used by some upcoming changes to loader(8) FDT handling to allow it to use an FDT provided by an earlier boot stage the same as an FDT loaded from disk. Notes: svn path=/head/; revision=246953
* Fix the style.Andrey V. Elsukov2012-09-301-4/+4
| | | | Notes: svn path=/head/; revision=241070
* Remember the file format of the last loaded module and try to use it forAndrey V. Elsukov2012-09-301-2/+9
| | | | | | | next files. Notes: svn path=/head/; revision=241069
* boot: file_loadraw should strdup name argumentAndriy Gapon2012-09-111-1/+1
| | | | | | | | | ... the same way it's done for type argument. MFC after: 2 weeks Notes: svn path=/head/; revision=240342
* Fix a long standing bug where file_load() passes down the global loadaddrMarcel Moolenaar2011-04-041-1/+1
| | | | | | | | | | | to the l_load() method in the file_formats structure, while being passed an address as an argument (dest). With file_load() calling arch_loadaddr() now, this bug is a little bit more significant. Spotted by: nyan@ (nice catch!) Notes: svn path=/head/; revision=220332
* Add 2 new archsw interfaces:Marcel Moolenaar2011-04-031-19/+6
| | | | | | | | | | | | | | | | | 1. arch_loadaddr - used by platform code to adjust the address at which the object gets loaded. Implement PC98 using this new interface instead of using conditional compilation. For ELF objects the ELF header is passed as the data pointer. For raw files it's the filename. Note that ELF objects are first considered as raw files. 2. arch_loadseg - used by platform code to keep track of actual segments, so that (instruction) caches can be flushed or translations can be created. Both the ELF header as well as the program header are passed to allow platform code to treat the kernel proper differently from any additional modules and to have all the relevant details of the loaded segment (e.g. protection). Notes: svn path=/head/; revision=220311
* Formatting nitWarner Losh2010-05-101-1/+2
| | | | Notes: svn path=/head/; revision=207854
* Don't use 15M-16M area on pc98. It's reserved for some devices.Yoshihiro Takahashi2009-12-311-0/+19
| | | | | | | MFC after: 2 week Notes: svn path=/head/; revision=201340
* Add a helper function for loading geli keys from the loader.Andrew Thompson2009-02-161-0/+38
| | | | Notes: svn path=/head/; revision=188666
* Also boot *.debug if everything else fails.David E. O'Brien2007-10-041-0/+1
| | | | | | | Approved by: re(gnn) Notes: svn path=/head/; revision=172445
* In moduledir_readhints() cast the value returned by sizeof() to ssize_tMarius Strobl2006-01-121-1/+2
| | | | | | | | | | | | | | when checking whether it's greater than a struct stat st_size in order to also catch the case when st_size is -1. Previously this check didn't trigger on sparc64 when st_size is -1 (as it's the case for a file on a bzipfs, TFTP server etc.), causing the content of the linker hints file to be copied to memory referenced by a null-pointer. PR: 91231 MFC after: 1 week Notes: svn path=/head/; revision=154257
* Use __FBSDID().David E. O'Brien2003-08-251-2/+3
| | | | | | | Also some minor style cleanups. Notes: svn path=/head/; revision=119483
* FreeBSD 5.0 has stopped shipping /modules 2.5 years ago. CatchRuslan Ermilov2003-03-031-1/+1
| | | | | | | | up with this further by excluding /modules from the (default) kern.module_path. Notes: svn path=/head/; revision=111852
* Bandaid for a buffer overrun in the module searching code. When breakingPeter Wemm2002-04-111-0/+2
| | | | | | | | | | | up the module_path string, we would walk one past the end of the buffer. This hurting ia64 originally, but it was probably also happening on i386 occasionally as well. The effects were usually harmless, it would add bogus "binary" search directories to the places it actually looked for files. Notes: svn path=/head/; revision=94419
* Fix a number of misspellings of "dependency" and "dependencies" inIan Dowse2001-11-161-3/+3
| | | | | | | | | | comments and function names. PR: kern/8589 Submitted by: Rajesh Vaidheeswarran <rv@fore.com> Notes: svn path=/head/; revision=86469
* Implement the long-awaited module->file cache database. A userlandPeter Wemm2001-09-111-84/+399
| | | | | | | | | | tool (kldxref(8)) keeps a cache of what modules and versions are inside what .ko files. I have tested this on both Alpha and i386. Submitted by: bp Notes: svn path=/head/; revision=83321
* Fix a minor style bug in the last commit.Jesper Skriver2001-06-101-1/+1
| | | | | | | | Submitted by: Adrian Steinmann <ast@marabu.ch> MFC after: 2 days Notes: svn path=/head/; revision=77971
* In sys/boot/common/module.c, near line 105 a request for a rawJesper Skriver2001-05-271-1/+1
| | | | | | | | | | | | | | | | | | | | file is processed by passing its name in argv[1]: return(mod_loadobj(typestr, argv[1])); however, it is not tested to see if argv[1] actually is defined. At best, mod_loadobj() near line 244 returns an error like "can't find 'garbage'" but if the "filename" entered is sufficiently long, some buffer gets overrun. Of course, "load -t filename" is actually a typo because we meant to type "load -t mfs_root filename"; nevertheless, a hung machine seems like too harsh a punishment for such a small typo... PR: i386/27693 Submitted by: Adrian Steinmann <ast@marabu.ch> MFC after: 1 week Notes: svn path=/head/; revision=77285
* The default search path for kernel and modules was bogus. It makes noDaniel C. Sobral2000-09-161-1/+1
| | | | | | | sense for /boot/kernel to come last. Notes: svn path=/head/; revision=65940
* Fix autoboot. Now autoboot *always* show the correct kernel name. ItDaniel C. Sobral2000-09-081-0/+1
| | | | | | | | | | | | | | | | | | | | | gets the name from the environment variable kernelname, which is set when a kernel is loaded. For this reason, autoboot will _first_ try to load a kernel, and only proceed with the wait prompt after that succeeds. If it fails, it will abort immediately. While I understand some may think this behavior undesirable, I think it is, overall, the best thing to do, even if we do not consider the aesthetic issue. Notice that anyone using the default loader.rc already has the kernel loaded before autoboot. On unload, unset kernelname. Separate the code that tries to load a kernel from the list of options to the function loadakernel(). It is used by both boot() and autoboot(). Notes: svn path=/head/; revision=65613
* The kernel is now known as `kernel.ko' and it and its matching modulesDavid E. O'Brien2000-09-051-1/+1
| | | | | | | live in ``/boot/kernel/''. Notes: svn path=/head/; revision=65501
* Cleanup warnings. Most of these are signed/unsigned warnings, as well asJohn Baldwin2000-08-031-2/+2
| | | | | | | some added const's. Notes: svn path=/head/; revision=64187
* Update loader logic to distinguish modules vs. files.Boris Popov2000-05-011-202/+261
| | | | | | | | | | Add support for module metadata. The old way of dependancy handling will be supported for a while. Reviewed by: peter Notes: svn path=/head/; revision=59854
* Fix the loader to handle module dependencies properly. More fixesBoris Popov2000-02-251-70/+74
| | | | | | | | | | will be provided after modmetadata appears in the kernel. Reviewed by: msmith Approved by: jkh Notes: svn path=/head/; revision=57468
* Close a file descriptor leak in the code which loads file objects.Mike Smith2000-02-171-0/+2
| | | | | | | | Submitted by: Paul Saab <paul@mu.org> Approved by: jkh Notes: svn path=/head/; revision=57269
* Add fairings. Do not depend on user actually supplying the argumentsDaniel C. Sobral1999-12-011-0/+4
| | | | | | | he is supposed to supply. Notes: svn path=/head/; revision=53993
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50477
* Fix a number of memory leaks and other memory-related disorders.Daniel C. Sobral1999-03-081-4/+6
| | | | | | | | | | | | | | | | | | Also, unbreak the breakage introduced at the last revision of module.c. This changes the semantics of mod_searchfile() (and mod_searchmodule()) to make the caller's responsibility freeing the buffer returned. This is different from other functions in loader's code, and was done as a fix for kern/9631. If someone wants to revert this to the original behavior, don't forget to fix kern/9631 in another way. This should also fix bin/10462, which was introduced as a result of the first try at kern/9631 (module.c last revision). PR: bin/10462 Submitted by: Takanori Saneto <sanewo@ba2.so-net.ne.jp> Notes: svn path=/head/; revision=44570