From owner-freebsd-questions Wed Apr 3 13: 0:15 2002 Delivered-To: freebsd-questions@freebsd.org Received: from snipe.prod.itd.earthlink.net (snipe.mail.pas.earthlink.net [207.217.120.62]) by hub.freebsd.org (Postfix) with ESMTP id 631C837B41B; Wed, 3 Apr 2002 12:59:53 -0800 (PST) Received: from pool0355.cvx40-bradley.dialup.earthlink.net ([216.244.43.100] helo=mindspring.com) by snipe.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16srrD-0001Ef-00; Wed, 03 Apr 2002 12:59:52 -0800 Message-ID: <3CAB6D30.7CDAFB80@mindspring.com> Date: Wed, 03 Apr 2002 12:59:28 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: "Kreider, Carl" Cc: freebsd-questions@freebsd.org, freebsd-hackers@freebsd.org Subject: Re: read a file from a driver References: <20020403101614.A12363@indy.doctordesign.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG "Kreider, Carl" wrote: > I am working on an embedded project running FreeBSD, and my driver > for our custom card needs to load an FPGA with code. I know I can > compile the code in as data, but for ease of development, I would > rather fetch the FPGA code from a file. With a driver in kernel > space. Really. > > Can it be done? If so, how? open() and read() are obviously in libc > which rules them out. Do I have to write my own in assembler? For drivers which must be active in the boot path, it is generally necessary to embed the firmware in the driver as data. This is what FreeBSD does for the Adaptec SCSI drivers. For drivers that need to be active after boot time, but before the mi_startup() is complete, you can load the data in a module that contains the data. THis is similar to compiling the data into the kernel, but puts it at a minor level of abstraction. For drivers that only need to be there before the rc files start executing or the other CPUs have been started, you can do kernel level file I/O. THis was discussed in some detail over the past year on the FreeBSD-current mailing list. THis is not recommended, since FreeBSD has porr support for kernel level file I/O compared to other OSs (e.g. AIX has excellent kernel interfaces for almost all system calls, since it puts its abstraction barriers in the right places). For most drivers which are not accessed until some way into the user space bot process, or some time after the system is up, the general model is to open the driver and to push the data down into the kernel via an ioctl(). THis is, in fact, how the LKM system worked to load loadable kernel modules: it pushed the modules over the user/kernel boundary into allocated memory, a chunk at a time. It really depends on *when* in the boot process the driver *must* be functional and available, as to which approach you should use. Using the "kernel file I/O" approach has an incredibly narrow window of utility, and since it's hard to do anyway... my recommendation is to pick another option. -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message