NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    9259 libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Revert "NEX-16819 loader UEFI support"
This reverts commit ec06b9fc617b99234e538bf2e7e4d02a24993e0c.
Reverting due to failures in the zfs-tests and the sharefs-tests
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
   1 /*      $NetBSD: ufs.c,v 1.20 1998/03/01 07:15:39 ross Exp $    */
   2 
   3 /*-
   4  * Copyright (c) 2002 Networks Associates Technology, Inc.
   5  * All rights reserved.
   6  *
   7  * This software was developed for the FreeBSD Project by Marshall
   8  * Kirk McKusick and Network Associates Laboratories, the Security
   9  * Research Division of Network Associates, Inc. under DARPA/SPAWAR
  10  * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
  11  * research program
  12  *
  13  * Copyright (c) 1982, 1989, 1993
  14  *      The Regents of the University of California.  All rights reserved.
  15  *
  16  * This code is derived from software contributed to Berkeley by
  17  * The Mach Operating System project at Carnegie-Mellon University.
  18  *
  19  * Redistribution and use in source and binary forms, with or without
  20  * modification, are permitted provided that the following conditions
  21  * are met:
  22  * 1. Redistributions of source code must retain the above copyright
  23  *    notice, this list of conditions and the following disclaimer.
  66  * any improvements or extensions that they make and grant Carnegie the
  67  * rights to redistribute these changes.
  68  */
  69 
  70 #include <sys/cdefs.h>
  71 
  72 /*
  73  *      Stand-alone file reading package.
  74  */
  75 
  76 #include <sys/param.h>
  77 #include <sys/disklabel.h>
  78 #include <sys/time.h>
  79 #include <ufs/ufs/dinode.h>
  80 #include <ufs/ufs/dir.h>
  81 #include <ufs/ffs/fs.h>
  82 #include "stand.h"
  83 #include "string.h"
  84 
  85 static int      ufs_open(const char *path, struct open_file *f);
  86 static int      ufs_write(struct open_file *f, void *buf, size_t size, size_t *resid);
  87 static int      ufs_close(struct open_file *f);
  88 static int      ufs_read(struct open_file *f, void *buf, size_t size, size_t *resid);
  89 static off_t    ufs_seek(struct open_file *f, off_t offset, int where);
  90 static int      ufs_stat(struct open_file *f, struct stat *sb);
  91 static int      ufs_readdir(struct open_file *f, struct dirent *d);
  92 
  93 struct fs_ops ufs_fsops = {
  94         "ufs",
  95         ufs_open,
  96         ufs_close,
  97         ufs_read,
  98         ufs_write,
  99         ufs_seek,
 100         ufs_stat,
 101         ufs_readdir
 102 };
 103 
 104 /*
 105  * In-core open file.
 106  */
 113         }               f_di;           /* copy of on-disk inode */
 114         int             f_nindir[NIADDR];
 115                                         /* number of blocks mapped by
 116                                            indirect block at level i */
 117         char            *f_blk[NIADDR]; /* buffer for indirect block at
 118                                            level i */
 119         size_t          f_blksize[NIADDR];
 120                                         /* size of buffer */
 121         ufs2_daddr_t    f_blkno[NIADDR];/* disk address of block in buffer */
 122         ufs2_daddr_t    f_buf_blkno;    /* block number of data block */
 123         char            *f_buf;         /* buffer for data block */
 124         size_t          f_buf_size;     /* size of data block */
 125 };
 126 #define DIP(fp, field) \
 127         ((fp)->f_fs->fs_magic == FS_UFS1_MAGIC ? \
 128         (fp)->f_di.di1.field : (fp)->f_di.di2.field)
 129 
 130 static int      read_inode(ino_t, struct open_file *);
 131 static int      block_map(struct open_file *, ufs2_daddr_t, ufs2_daddr_t *);
 132 static int      buf_read_file(struct open_file *, char **, size_t *);
 133 static int      buf_write_file(struct open_file *, char *, size_t *);
 134 static int      search_directory(char *, struct open_file *, ino_t *);
 135 
 136 /*
 137  * Read a new inode into a file structure.
 138  */
 139 static int
 140 read_inode(inumber, f)
 141         ino_t inumber;
 142         struct open_file *f;
 143 {
 144         struct file *fp = (struct file *)f->f_fsdata;
 145         struct fs *fs = fp->f_fs;
 146         char *buf;
 147         size_t rsize;
 148         int rc;
 149 
 150         if (fs == NULL)
 151             panic("fs == NULL");
 152 
 153         /*
 283                 } else
 284                         idx = file_block;
 285 
 286                 if (fp->f_fs->fs_magic == FS_UFS1_MAGIC)
 287                         ind_block_num = ((ufs1_daddr_t *)fp->f_blk[level])[idx];
 288                 else
 289                         ind_block_num = ((ufs2_daddr_t *)fp->f_blk[level])[idx];
 290         }
 291 
 292         *disk_block_p = ind_block_num;
 293 
 294         return (0);
 295 }
 296 
 297 /*
 298  * Write a portion of a file from an internal buffer.
 299  */
 300 static int
 301 buf_write_file(f, buf_p, size_p)
 302         struct open_file *f;
 303         char *buf_p;
 304         size_t *size_p;         /* out */
 305 {
 306         struct file *fp = (struct file *)f->f_fsdata;
 307         struct fs *fs = fp->f_fs;
 308         long off;
 309         ufs_lbn_t file_block;
 310         ufs2_daddr_t disk_block;
 311         size_t block_size;
 312         int rc;
 313 
 314         /*
 315          * Calculate the starting block address and offset.
 316          */
 317         off = blkoff(fs, fp->f_seekp);
 318         file_block = lblkno(fs, fp->f_seekp);
 319         block_size = sblksize(fs, DIP(fp, di_size), file_block);
 320 
 321         rc = block_map(f, file_block, &disk_block);
 322         if (rc)
 323                 return (rc);
741 742 bcopy(buf, addr, csize); 743 744 fp->f_seekp += csize; 745 addr += csize; 746 size -= csize; 747 } 748 if (resid) 749 *resid = size; 750 return (rc); 751 } 752 753 /* 754 * Write to a portion of an already allocated file. 755 * Cross block boundaries when necessary. Can not 756 * extend the file. 757 */ 758 static int 759 ufs_write(f, start, size, resid) 760 struct open_file *f; 761 void *start; 762 size_t size; 763 size_t *resid; /* out */ 764 { 765 struct file *fp = (struct file *)f->f_fsdata; 766 size_t csize; 767 int rc = 0; 768 char *addr = start; 769 770 csize = size; 771 while ((size != 0) && (csize != 0)) { 772 if (fp->f_seekp >= DIP(fp, di_size)) 773 break; 774 775 if (csize >= 512) csize = 512; /* XXX */ 776 777 rc = buf_write_file(f, addr, &csize); 778 if (rc) 779 break; 780 781 fp->f_seekp += csize; 782 addr += csize; 783 size -= csize; 784 } 785 if (resid) 786 *resid = size; 787 return (rc); 788 }  | 
   1 /*      $NetBSD: ufs.c,v 1.20 1998/03/01 07:15:39 ross Exp $    */
   2 
   3 /*
   4  * Copyright (c) 2002 Networks Associates Technology, Inc.
   5  * All rights reserved.
   6  *
   7  * This software was developed for the FreeBSD Project by Marshall
   8  * Kirk McKusick and Network Associates Laboratories, the Security
   9  * Research Division of Network Associates, Inc. under DARPA/SPAWAR
  10  * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
  11  * research program
  12  *
  13  * Copyright (c) 1982, 1989, 1993
  14  *      The Regents of the University of California.  All rights reserved.
  15  *
  16  * This code is derived from software contributed to Berkeley by
  17  * The Mach Operating System project at Carnegie-Mellon University.
  18  *
  19  * Redistribution and use in source and binary forms, with or without
  20  * modification, are permitted provided that the following conditions
  21  * are met:
  22  * 1. Redistributions of source code must retain the above copyright
  23  *    notice, this list of conditions and the following disclaimer.
66 * any improvements or extensions that they make and grant Carnegie the 67 * rights to redistribute these changes. 68 */ 69 70 #include <sys/cdefs.h> 71 72 /* 73 * Stand-alone file reading package. 74 */ 75 76 #include <sys/param.h> 77 #include <sys/disklabel.h> 78 #include <sys/time.h> 79 #include <ufs/ufs/dinode.h> 80 #include <ufs/ufs/dir.h> 81 #include <ufs/ffs/fs.h> 82 #include "stand.h" 83 #include "string.h" 84 85 static int ufs_open(const char *path, struct open_file *f); 86 static int ufs_write(struct open_file *f, const void *buf, size_t size, 87 size_t *resid); 88 static int ufs_close(struct open_file *f); 89 static int ufs_read(struct open_file *f, void *buf, size_t size, size_t *resid); 90 static off_t ufs_seek(struct open_file *f, off_t offset, int where); 91 static int ufs_stat(struct open_file *f, struct stat *sb); 92 static int ufs_readdir(struct open_file *f, struct dirent *d); 93 94 struct fs_ops ufs_fsops = { 95 "ufs", 96 ufs_open, 97 ufs_close, 98 ufs_read, 99 ufs_write, 100 ufs_seek, 101 ufs_stat, 102 ufs_readdir 103 }; 104 105 /* 106 * In-core open file. 107 */ 
 114         }               f_di;           /* copy of on-disk inode */
 115         int             f_nindir[NIADDR];
 116                                         /* number of blocks mapped by
 117                                            indirect block at level i */
 118         char            *f_blk[NIADDR]; /* buffer for indirect block at
 119                                            level i */
 120         size_t          f_blksize[NIADDR];
 121                                         /* size of buffer */
 122         ufs2_daddr_t    f_blkno[NIADDR];/* disk address of block in buffer */
 123         ufs2_daddr_t    f_buf_blkno;    /* block number of data block */
 124         char            *f_buf;         /* buffer for data block */
 125         size_t          f_buf_size;     /* size of data block */
 126 };
 127 #define DIP(fp, field) \
 128         ((fp)->f_fs->fs_magic == FS_UFS1_MAGIC ? \
 129         (fp)->f_di.di1.field : (fp)->f_di.di2.field)
 130 
 131 static int      read_inode(ino_t, struct open_file *);
 132 static int      block_map(struct open_file *, ufs2_daddr_t, ufs2_daddr_t *);
 133 static int      buf_read_file(struct open_file *, char **, size_t *);
 134 static int      buf_write_file(struct open_file *, const char *, size_t *);
 135 static int      search_directory(char *, struct open_file *, ino_t *);
 136 
 137 /*
 138  * Read a new inode into a file structure.
 139  */
 140 static int
 141 read_inode(inumber, f)
 142         ino_t inumber;
 143         struct open_file *f;
 144 {
 145         struct file *fp = (struct file *)f->f_fsdata;
 146         struct fs *fs = fp->f_fs;
 147         char *buf;
 148         size_t rsize;
 149         int rc;
 150 
 151         if (fs == NULL)
 152             panic("fs == NULL");
 153 
 154         /*
 284                 } else
 285                         idx = file_block;
 286 
 287                 if (fp->f_fs->fs_magic == FS_UFS1_MAGIC)
 288                         ind_block_num = ((ufs1_daddr_t *)fp->f_blk[level])[idx];
 289                 else
 290                         ind_block_num = ((ufs2_daddr_t *)fp->f_blk[level])[idx];
 291         }
 292 
 293         *disk_block_p = ind_block_num;
 294 
 295         return (0);
 296 }
 297 
 298 /*
 299  * Write a portion of a file from an internal buffer.
 300  */
 301 static int
 302 buf_write_file(f, buf_p, size_p)
 303         struct open_file *f;
 304         const char *buf_p;
 305         size_t *size_p;         /* out */
 306 {
 307         struct file *fp = (struct file *)f->f_fsdata;
 308         struct fs *fs = fp->f_fs;
 309         long off;
 310         ufs_lbn_t file_block;
 311         ufs2_daddr_t disk_block;
 312         size_t block_size;
 313         int rc;
 314 
 315         /*
 316          * Calculate the starting block address and offset.
 317          */
 318         off = blkoff(fs, fp->f_seekp);
 319         file_block = lblkno(fs, fp->f_seekp);
 320         block_size = sblksize(fs, DIP(fp, di_size), file_block);
 321 
 322         rc = block_map(f, file_block, &disk_block);
 323         if (rc)
 324                 return (rc);
742 743 bcopy(buf, addr, csize); 744 745 fp->f_seekp += csize; 746 addr += csize; 747 size -= csize; 748 } 749 if (resid) 750 *resid = size; 751 return (rc); 752 } 753 754 /* 755 * Write to a portion of an already allocated file. 756 * Cross block boundaries when necessary. Can not 757 * extend the file. 758 */ 759 static int 760 ufs_write(f, start, size, resid) 761 struct open_file *f; 762 const void *start; 763 size_t size; 764 size_t *resid; /* out */ 765 { 766 struct file *fp = (struct file *)f->f_fsdata; 767 size_t csize; 768 int rc = 0; 769 const char *addr = start; 770 771 csize = size; 772 while ((size != 0) && (csize != 0)) { 773 if (fp->f_seekp >= DIP(fp, di_size)) 774 break; 775 776 if (csize >= 512) csize = 512; /* XXX */ 777 778 rc = buf_write_file(f, addr, &csize); 779 if (rc) 780 break; 781 782 fp->f_seekp += csize; 783 addr += csize; 784 size -= csize; 785 } 786 if (resid) 787 *resid = size; 788 return (rc); 789 }  |