From 7eb845e815924984b301aaf674b090cde28c1c6a Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Sun, 2 Nov 2008 17:01:06 +0000 Subject: Import a slightly modified Bayou version into svn. This is based on the last snapshot posted by Jordan Crouse. This commit is long overdue. Changes by me include: - Rename 'utils' to 'util' for consistency with our other projects. - Move the main code out of src/* into the top-level directory. - Add missing license headers to the following files: Makefile, pbuilder/liblar/Makefile, util/pbuilder/Makefile. - Dropped the util/pbuilder/lzma completely. I'm working on reusing the lzma/ dir from v3 via svn:externals. Alas, this also means that Bayou won't yet compile out of the box. - Coding-style and white-space fixes (indent) for all files. Signed-off-by: Uwe Hermann Acked-by: Uwe Hermann git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3719 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- payloads/bayou/config.c | 165 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 payloads/bayou/config.c (limited to 'payloads/bayou/config.c') diff --git a/payloads/bayou/config.c b/payloads/bayou/config.c new file mode 100644 index 0000000000..3aba88f9a4 --- /dev/null +++ b/payloads/bayou/config.c @@ -0,0 +1,165 @@ +/* + * This file is part of the bayou project. + * + * Copyright (C) 2008 Advanced Micro Devices, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "bayou.h" + +struct bayoucfg bayoucfg; + +static int add_payload(struct LAR *lar, struct larent *larent) +{ + struct payload *payload; + int plen; + u8 *params = NULL; + u8 *fptr; + + if (bayoucfg.n_entries == BAYOU_MAX_ENTRIES) + return -1; + + payload = &bayoucfg.entries[bayoucfg.n_entries]; + + if (strncmp((char *)larent->name, "payload/", 8)) + return -1; + + if (larstat(lar, (const char *)larent->name, &payload->stat)) + return -1; + + /* Make sure the LAR entry is valid. */ + if (!lfverify(lar, (const char *)larent->name)) + return -1; + + /* Get a pointer to the start of the file. */ + fptr = larfptr(lar, (const char *)larent->name); + + if (fptr == NULL) + return -1; + + if (!verify_self(fptr)) + return -1; + + payload->pentry.index = bayoucfg.n_entries; + payload->pentry.parent = 0; + payload->pentry.type = BPT_TYPE_CHOOSER; + payload->pentry.flags = 0; + + plen = self_get_params(fptr, ¶ms); + payload_parse_params(payload, params, plen); + + payload->fptr = fptr; + + bayoucfg.n_entries++; + + return 0; +} + +static int lar_walk_files(struct LAR *lar, + int (*cb) (struct LAR *, struct larent *)) +{ + struct larent *larent; + int ret = 0; + + rewindlar(lar); + + while ((larent = readlar(lar)) != NULL) { + if ((ret = cb(lar, larent))) + break; + } + + return ret; +} + +/** + * If reading the bayou_payload_table fails for some reason, then construct + * a dummy table. All valid payloads in the lar are added as chooser items. + */ +static void build_dummy_table(struct LAR *lar) +{ + bayoucfg.timeout = 0xFF; + bayoucfg.n_entries = 0; + + lar_walk_files(lar, add_payload); +} + +int get_configuration(struct LAR *lar) +{ + struct larstat stat; + struct bpt_config *bptcfg; + u8 *fptr, *ptr; + int i; + + /* + * If bayou_payload_table doesn't exist, then dummy up + * a table from the LAR contents. + */ + if (larstat(lar, "bayou_payload_table", &stat) || + !lfverify(lar, "bayou_payload_table")) + build_dummy_table(lar); + + /* Open up the BPT and get the creamy goodness within. */ + + fptr = larfptr(lar, "bayou_payload_table"); + + if (fptr == NULL) + build_dummy_table(lar); + + bptcfg = (struct bpt_config *)fptr; + bayoucfg.timeout = bptcfg->timeout; + + bayoucfg.n_entries = bptcfg->entries; + + if (bayoucfg.n_entries > BAYOU_MAX_ENTRIES) { + printf("W: Limiting the number of entries to %d\n", + BAYOU_MAX_ENTRIES); + bayoucfg.n_entries = BAYOU_MAX_ENTRIES; + } + + ptr = fptr + sizeof(struct bpt_config); + + for (i = 0; i < bayoucfg.n_entries; i++) { + struct bpt_pentry *entry = (struct bpt_pentry *)ptr; + struct payload *p = &(bayoucfg.entries[i]); + int plen; + u8 *params = NULL; + + memcpy(&p->pentry, entry, sizeof(struct bpt_pentry)); + + if (entry->type != BPT_TYPE_CHAIN) { + char *lname = (char *)ptr + sizeof(struct bpt_pentry); + + if (larstat(lar, (const char *)lname, &p->stat)) + build_dummy_table(lar); + + if (!lfverify(lar, (const char *)lname)) + build_dummy_table(lar); + + fptr = larfptr(lar, (const char *)lname); + + if (verify_self(fptr)) + p->fptr = fptr; + else + build_dummy_table(lar); + + plen = self_get_params(fptr, ¶ms); + payload_parse_params(p, params, plen); + } + + ptr += sizeof(struct bpt_pentry) + entry->nlen; + } + + return 0; +} -- cgit v1.2.3