summaryrefslogtreecommitdiffstats
path: root/sys/boot/arm
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2008-10-05 23:37:03 +0000
committerimp <imp@FreeBSD.org>2008-10-05 23:37:03 +0000
commit7baf73d142217a09b612d86006b4db8171a60cbc (patch)
treeed3c78d9ec6faa41c139f956d92d885e9a5a7ac3 /sys/boot/arm
parent29849f1e076f89f4cba9bef1160d442ed84d3667 (diff)
downloadFreeBSD-src-7baf73d142217a09b612d86006b4db8171a60cbc.zip
FreeBSD-src-7baf73d142217a09b612d86006b4db8171a60cbc.tar.gz
Indent with 8-space tabs. This reduces the diffs to the newer ixp425
boot2 and may make it easier to merge these files in the future...
Diffstat (limited to 'sys/boot/arm')
-rw-r--r--sys/boot/arm/at91/boot2/boot2.c334
1 files changed, 169 insertions, 165 deletions
diff --git a/sys/boot/arm/at91/boot2/boot2.c b/sys/boot/arm/at91/boot2/boot2.c
index fb2bcfe..e0e88ea 100644
--- a/sys/boot/arm/at91/boot2/boot2.c
+++ b/sys/boot/arm/at91/boot2/boot2.c
@@ -99,199 +99,203 @@ static int dskread(void *, unsigned, unsigned);
static inline int
xfsread(ino_t inode, void *buf, size_t nbyte)
{
- if ((size_t)fsread(inode, buf, nbyte) != nbyte)
- return -1;
- return 0;
+ if ((size_t)fsread(inode, buf, nbyte) != nbyte)
+ return -1;
+ return 0;
}
static inline void
getstr(int c)
{
- char *s;
-
- s = cmd;
- if (c == 0)
- c = getc(10000);
- for (;;) {
- switch (c) {
- case 0:
- break;
- case '\177':
- case '\b':
- if (s > cmd) {
- s--;
- printf("\b \b");
- }
- break;
- case '\n':
- case '\r':
- *s = 0;
- return;
- default:
- if (s - cmd < sizeof(cmd) - 1)
- *s++ = c;
- xputchar(c);
+ char *s;
+
+ s = cmd;
+ if (c == 0)
+ c = getc(10000);
+ for (;;) {
+ switch (c) {
+ case 0:
+ break;
+ case '\177':
+ case '\b':
+ if (s > cmd) {
+ s--;
+ printf("\b \b");
+ }
+ break;
+ case '\n':
+ case '\r':
+ *s = 0;
+ return;
+ default:
+ if (s - cmd < sizeof(cmd) - 1)
+ *s++ = c;
+ xputchar(c);
+ }
+ c = getc(10000);
}
- c = getc(10000);
- }
}
int
main(void)
{
- int autoboot, c = 0;
- ino_t ino;
-
- board_init();
-
- dmadat = (void *)(0x20000000 + (16 << 20));
- /* Process configuration file */
-
- autoboot = 1;
-
- if ((ino = lookup(PATH_CONFIG)))
- fsread(ino, cmd, sizeof(cmd));
-
- if (*cmd) {
- if (parse())
- autoboot = 0;
- printf("%s: %s", PATH_CONFIG, cmd);
- /* Do not process this command twice */
- *cmd = 0;
- }
-
- /* Present the user with the boot2 prompt. */
-
- if (*kname == '\0')
- strcpy(kname, PATH_KERNEL);
- for (;;) {
- printf("\nDefault: %s\nboot: ", kname);
- if (!autoboot || (c = getc(2)) != -1)
- getstr(c);
- xputchar('\n');
- autoboot = 0;
- c = 0;
- if (parse())
- xputchar('\a');
+ int autoboot, c = 0;
+ ino_t ino;
+
+ board_init();
+
+ dmadat = (void *)(0x20000000 + (16 << 20));
+ /* Process configuration file */
+
+ autoboot = 1;
+
+ if ((ino = lookup(PATH_CONFIG)))
+ fsread(ino, cmd, sizeof(cmd));
+
+ if (*cmd) {
+ if (parse())
+ autoboot = 0;
+ printf("%s: %s", PATH_CONFIG, cmd);
+ /* Do not process this command twice */
+ *cmd = 0;
+ }
+
+ /* Present the user with the boot2 prompt. */
+
+ if (*kname == '\0')
+ strcpy(kname, PATH_KERNEL);
+ for (;;) {
+ printf("\nDefault: %s\nboot: ", kname);
+ if (!autoboot || (c = getc(2)) != -1)
+ getstr(c);
+ xputchar('\n');
+ autoboot = 0;
+ c = 0;
+ if (parse())
+ xputchar('\a');
#ifdef XMODEM_DL
- else if (*cmd == '*')
- Update();
+ else if (*cmd == '*')
+ Update();
#endif
- else
- load();
- }
+ else
+ load();
+ }
}
static void
load(void)
{
- Elf32_Ehdr eh;
- static Elf32_Phdr ep[2];
- caddr_t p;
- ino_t ino;
- uint32_t addr;
- int i, j;
-
- if (!(ino = lookup(kname))) {
- if (!ls)
- printf("No %s\n", kname);
- return;
- }
- if (xfsread(ino, &eh, sizeof(eh)))
- return;
- if (!IS_ELF(eh)) {
- printf("Invalid %s\n", "format");
- return;
- }
- fs_off = eh.e_phoff;
- for (j = i = 0; i < eh.e_phnum && j < 2; i++) {
- if (xfsread(ino, ep + j, sizeof(ep[0])))
- return;
- if (ep[j].p_type == PT_LOAD)
- j++;
- }
- for (i = 0; i < 2; i++) {
- p = (caddr_t)ep[i].p_paddr;
- fs_off = ep[i].p_offset;
- if (xfsread(ino, p, ep[i].p_filesz))
- return;
- }
- addr = eh.e_entry;
- ((void(*)(int))addr)(opts & RBX_MASK);
+ Elf32_Ehdr eh;
+ static Elf32_Phdr ep[2];
+ caddr_t p;
+ ino_t ino;
+ uint32_t addr;
+ int i, j;
+
+ if (!(ino = lookup(kname))) {
+ if (!ls)
+ printf("No %s\n", kname);
+ return;
+ }
+ if (xfsread(ino, &eh, sizeof(eh)))
+ return;
+ if (!IS_ELF(eh)) {
+ printf("Invalid %s\n", "format");
+ return;
+ }
+ fs_off = eh.e_phoff;
+ for (j = i = 0; i < eh.e_phnum && j < 2; i++) {
+ if (xfsread(ino, ep + j, sizeof(ep[0])))
+ return;
+ if (ep[j].p_type == PT_LOAD)
+ j++;
+ }
+ for (i = 0; i < 2; i++) {
+ p = (caddr_t)ep[i].p_paddr;
+ fs_off = ep[i].p_offset;
+ if (xfsread(ino, p, ep[i].p_filesz))
+ return;
+ }
+ addr = eh.e_entry;
+ ((void(*)(int))addr)(opts & RBX_MASK);
}
static int
parse()
{
- char *arg = cmd;
- char *ep, *p;
- int c, i;
-
- while ((c = *arg++)) {
- if (c == ' ' || c == '\t' || c == '\n')
- continue;
- for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
- ep = p;
- if (*p)
- *p++ = 0;
- if (c == '-') {
- while ((c = *arg++)) {
- for (i = 0; c != optstr[i]; i++)
- if (i == NOPT - 1)
- return -1;
- opts ^= OPT_SET(flags[i]);
- }
- } else {
- arg--;
- if ((i = ep - arg)) {
- if ((size_t)i >= sizeof(kname))
- return -1;
- memcpy(kname, arg, i + 1);
- }
+ char *arg = cmd;
+ char *ep, *p;
+ int c, i;
+
+ while ((c = *arg++)) {
+ if (c == ' ' || c == '\t' || c == '\n')
+ continue;
+ for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
+ ep = p;
+ if (*p)
+ *p++ = 0;
+ if (c == '-') {
+ while ((c = *arg++)) {
+ for (i = 0; c != optstr[i]; i++)
+ if (i == NOPT - 1)
+ return -1;
+ opts ^= OPT_SET(flags[i]);
+ }
+ } else {
+ arg--;
+ if ((i = ep - arg)) {
+ if ((size_t)i >= sizeof(kname))
+ return -1;
+ memcpy(kname, arg, i + 1);
+ }
+ }
+ arg = p;
}
- arg = p;
- }
- return 0;
+ return 0;
}
static int
dskread(void *buf, unsigned lba, unsigned nblk)
{
- struct dos_partition *dp;
- struct disklabel *d;
- char *sec;
- int i;
-
- if (!dsk_meta) {
- sec = dmadat->secbuf;
- dsk_start = 0;
- if (drvread(sec, DOSBBSECTOR, 1))
- return -1;
- dp = (void *)(sec + DOSPARTOFF);
- for (i = 0; i < NDOSPART; i++) {
- if (dp[i].dp_typ == DOSPTYP_386BSD)
- break;
- }
- if (i == NDOSPART)
- return -1;
- // Although dp_start is aligned within the disk partition structure,
- // DOSPARTOFF is 446, which is only word (2) aligned, not longword (4)
- // aligned. Cope by using memcpy to fetch the start of this partition.
- memcpy(&dsk_start, &dp[1].dp_start, 4);
- if (drvread(sec, dsk_start + LABELSECTOR, 1))
- return -1;
- d = (void *)(sec + LABELOFFSET);
- if (d->d_magic != DISKMAGIC || d->d_magic2 != DISKMAGIC) {
- printf("Invalid %s\n", "label");
- return -1;
- }
- if (!d->d_partitions[0].p_size) {
- printf("Invalid %s\n", "partition");
- return -1;
+ struct dos_partition *dp;
+ struct disklabel *d;
+ char *sec;
+ int i;
+
+ if (!dsk_meta) {
+ sec = dmadat->secbuf;
+ dsk_start = 0;
+ if (drvread(sec, DOSBBSECTOR, 1))
+ return -1;
+ dp = (void *)(sec + DOSPARTOFF);
+ for (i = 0; i < NDOSPART; i++) {
+ if (dp[i].dp_typ == DOSPTYP_386BSD)
+ break;
+ }
+ if (i == NDOSPART)
+ return -1;
+ /*
+ * Although dp_start is aligned within the disk
+ * partition structure, DOSPARTOFF is 446, which is
+ * only word (2) aligned, not longword (4) aligned.
+ * Cope by using memcpy to fetch the start of this
+ * partition.
+ */
+ memcpy(&dsk_start, &dp[1].dp_start, 4);
+ if (drvread(sec, dsk_start + LABELSECTOR, 1))
+ return -1;
+ d = (void *)(sec + LABELOFFSET);
+ if (d->d_magic != DISKMAGIC || d->d_magic2 != DISKMAGIC) {
+ printf("Invalid %s\n", "label");
+ return -1;
+ }
+ if (!d->d_partitions[0].p_size) {
+ printf("Invalid %s\n", "partition");
+ return -1;
+ }
+ dsk_start += d->d_partitions[0].p_offset;
+ dsk_start -= d->d_partitions[RAW_PART].p_offset;
+ dsk_meta++;
}
- dsk_start += d->d_partitions[0].p_offset;
- dsk_start -= d->d_partitions[RAW_PART].p_offset;
- dsk_meta++;
- }
- return drvread(buf, dsk_start + lba, nblk);
+ return drvread(buf, dsk_start + lba, nblk);
}
OpenPOWER on IntegriCloud