boot2.c (183635) | boot2.c (183636) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2008 John Hay 3 * Copyright (c) 2006 Warner Losh |
|
2 * Copyright (c) 1998 Robert Nordier 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are freely 6 * permitted provided that the above copyright notice and this 7 * paragraph and the following disclaimer are duplicated in all 8 * such forms. 9 * 10 * This software is provided "AS IS" and without any express or 11 * implied warranties, including, without limitation, the implied 12 * warranties of merchantability and fitness for a particular 13 * purpose. 14 */ 15 16#include <sys/cdefs.h> | 4 * Copyright (c) 1998 Robert Nordier 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms are freely 8 * permitted provided that the above copyright notice and this 9 * paragraph and the following disclaimer are duplicated in all 10 * such forms. 11 * 12 * This software is provided "AS IS" and without any express or 13 * implied warranties, including, without limitation, the implied 14 * warranties of merchantability and fitness for a particular 15 * purpose. 16 */ 17 18#include <sys/cdefs.h> |
17__FBSDID("$FreeBSD: head/sys/boot/arm/at91/boot2/boot2.c 183635 2008-10-05 23:39:28Z imp $"); | 19__FBSDID("$FreeBSD: head/sys/boot/arm/at91/boot2/boot2.c 183636 2008-10-05 23:59:52Z imp $"); |
18 19#include <sys/param.h> 20#include <sys/disklabel.h> 21#include <sys/diskmbr.h> 22#include <sys/dirent.h> 23#include <sys/reboot.h> 24 25#include <machine/elf.h> --- 20 unchanged lines hidden (view full) --- 46/* 0xe is reserved for log2(RB_POWEROFF). */ 47#define RBX_GDB 0xf /* -g */ 48/* #define RBX_MUTE 0x10 -m */ 49/* 0x11 is reserved for log2(RB_SELFTEST). */ 50/* 0x12 is reserved for boot programs. */ 51/* 0x13 is reserved for boot programs. */ 52/* #define RBX_PAUSE 0x14 -p */ 53/* #define RBX_QUIET 0x15 -q */ | 20 21#include <sys/param.h> 22#include <sys/disklabel.h> 23#include <sys/diskmbr.h> 24#include <sys/dirent.h> 25#include <sys/reboot.h> 26 27#include <machine/elf.h> --- 20 unchanged lines hidden (view full) --- 48/* 0xe is reserved for log2(RB_POWEROFF). */ 49#define RBX_GDB 0xf /* -g */ 50/* #define RBX_MUTE 0x10 -m */ 51/* 0x11 is reserved for log2(RB_SELFTEST). */ 52/* 0x12 is reserved for boot programs. */ 53/* 0x13 is reserved for boot programs. */ 54/* #define RBX_PAUSE 0x14 -p */ 55/* #define RBX_QUIET 0x15 -q */ |
54/* #define RBX_NOINTR 0x1c -n */ | 56#define RBX_NOINTR 0x1c /* -n */ |
55/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ 56/* #define RBX_DUAL 0x1d -D */ 57/* 0x1f is reserved for log2(RB_BOOTINFO). */ 58 59/* pass: -a, -s, -r, -v, -g */ 60#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ 61 OPT_SET(RBX_DFLTROOT) | \ 62 OPT_SET(RBX_VERBOSE) | \ 63 OPT_SET(RBX_GDB)) 64 65#define PATH_CONFIG "/boot.config" 66//#define PATH_KERNEL "/boot/kernel/kernel" 67#define PATH_KERNEL "/boot/kernel/kernel.gz.tramp" 68 | 57/* 0x1d is reserved for log2(RB_MULTIPLE) and is just misnamed here. */ 58/* #define RBX_DUAL 0x1d -D */ 59/* 0x1f is reserved for log2(RB_BOOTINFO). */ 60 61/* pass: -a, -s, -r, -v, -g */ 62#define RBX_MASK (OPT_SET(RBX_ASKNAME) | OPT_SET(RBX_SINGLE) | \ 63 OPT_SET(RBX_DFLTROOT) | \ 64 OPT_SET(RBX_VERBOSE) | \ 65 OPT_SET(RBX_GDB)) 66 67#define PATH_CONFIG "/boot.config" 68//#define PATH_KERNEL "/boot/kernel/kernel" 69#define PATH_KERNEL "/boot/kernel/kernel.gz.tramp" 70 |
69#define NOPT 5 | 71extern uint32_t _end; |
70 | 72 |
73#define NOPT 6 74 |
|
71#define OPT_SET(opt) (1 << (opt)) 72#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) 73 | 75#define OPT_SET(opt) (1 << (opt)) 76#define OPT_CHECK(opt) ((opts) & OPT_SET(opt)) 77 |
74extern uint32_t _end; 75 76static const char optstr[NOPT] = "agrsv"; | 78static const char optstr[NOPT] = "agnrsv"; |
77static const unsigned char flags[NOPT] = { | 79static const unsigned char flags[NOPT] = { |
78 RBX_ASKNAME, 79 RBX_GDB, 80 RBX_DFLTROOT, 81 RBX_SINGLE, 82 RBX_VERBOSE | 80 RBX_ASKNAME, 81 RBX_GDB, 82 RBX_NOINTR, 83 RBX_DFLTROOT, 84 RBX_SINGLE, 85 RBX_VERBOSE |
83}; 84 85unsigned dsk_start; 86static char cmd[512]; 87static char kname[1024]; 88static uint32_t opts; 89static int dsk_meta; 90 91static void load(void); 92static int parse(void); 93static int xfsread(ino_t, void *, size_t); 94static int dskread(void *, unsigned, unsigned); 95 96#define UFS_SMALL_CGBASE 97#include "ufsread.c" 98 | 86}; 87 88unsigned dsk_start; 89static char cmd[512]; 90static char kname[1024]; 91static uint32_t opts; 92static int dsk_meta; 93 94static void load(void); 95static int parse(void); 96static int xfsread(ino_t, void *, size_t); 97static int dskread(void *, unsigned, unsigned); 98 99#define UFS_SMALL_CGBASE 100#include "ufsread.c" 101 |
102#ifdef DEBUG 103#define DPRINTF(fmt, ...) printf(fmt, __VA_ARGS__) 104#else 105#define DPRINTF(fmt, ...) 106#endif 107 |
|
99static inline int 100xfsread(ino_t inode, void *buf, size_t nbyte) 101{ 102 if ((size_t)fsread(inode, buf, nbyte) != nbyte) 103 return -1; 104 return 0; 105} 106 --- 30 unchanged lines hidden (view full) --- 137} 138 139int 140main(void) 141{ 142 int autoboot, c = 0; 143 ino_t ino; 144 | 108static inline int 109xfsread(ino_t inode, void *buf, size_t nbyte) 110{ 111 if ((size_t)fsread(inode, buf, nbyte) != nbyte) 112 return -1; 113 return 0; 114} 115 --- 30 unchanged lines hidden (view full) --- 146} 147 148int 149main(void) 150{ 151 int autoboot, c = 0; 152 ino_t ino; 153 |
154 dmadat = (void *)(0x20000000 + (16 << 20)); |
|
145 board_init(); 146 | 155 board_init(); 156 |
147 dmadat = (void *)(0x20000000 + (16 << 20)); 148 /* Process configuration file */ 149 | |
150 autoboot = 1; 151 | 157 autoboot = 1; 158 |
159 /* Process configuration file */ |
|
152 if ((ino = lookup(PATH_CONFIG))) 153 fsread(ino, cmd, sizeof(cmd)); 154 155 if (*cmd) { 156 if (parse()) 157 autoboot = 0; | 160 if ((ino = lookup(PATH_CONFIG))) 161 fsread(ino, cmd, sizeof(cmd)); 162 163 if (*cmd) { 164 if (parse()) 165 autoboot = 0; |
158 printf("%s: %s", PATH_CONFIG, cmd); | 166 printf("%s: %s\n", PATH_CONFIG, cmd); |
159 /* Do not process this command twice */ 160 *cmd = 0; 161 } 162 | 167 /* Do not process this command twice */ 168 *cmd = 0; 169 } 170 |
163 /* Present the user with the boot2 prompt. */ 164 | |
165 if (*kname == '\0') 166 strcpy(kname, PATH_KERNEL); | 171 if (*kname == '\0') 172 strcpy(kname, PATH_KERNEL); |
173 174 /* Present the user with the boot2 prompt. */ |
|
167 for (;;) { 168 printf("\nDefault: %s\nboot: ", kname); | 175 for (;;) { 176 printf("\nDefault: %s\nboot: ", kname); |
169 if (!autoboot || (c = getc(2)) != -1) | 177 if (!autoboot || 178 (OPT_CHECK(RBX_NOINTR) == 0 && (c = getc(2)) != 0)) |
170 getstr(c); 171 xputchar('\n'); 172 autoboot = 0; 173 c = 0; 174 if (parse()) 175 xputchar('\a'); 176 else 177 load(); --- 120 unchanged lines hidden --- | 179 getstr(c); 180 xputchar('\n'); 181 autoboot = 0; 182 c = 0; 183 if (parse()) 184 xputchar('\a'); 185 else 186 load(); --- 120 unchanged lines hidden --- |