From: Christian Lamparter Date: Mon, 15 Feb 2016 17:28:51 +0000 (+0100) Subject: Merge branch 'master' into radar X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;ds=sidebyside;h=ac0568e13e3d71a57e4b306f04e4b5089b5423d3;hp=-c;p=carl9170fw.git Merge branch 'master' into radar --- ac0568e13e3d71a57e4b306f04e4b5089b5423d3 diff --combined include/shared/fwdesc.h index 10327a7,da05a4e..d542b01 --- a/include/shared/fwdesc.h +++ b/include/shared/fwdesc.h @@@ -78,15 -78,15 +78,15 @@@ enum carl9170fw_feature_list /* HW (ANI, CCA, MIB) tally counters */ CARL9170FW_HW_COUNTERS, - /* Pattern generator */ - CARL9170FW_PATTERN_GENERATOR, - /* Firmware will pass BA when BARs are queued */ CARL9170FW_RX_BA_FILTER, /* Firmware has support to write a byte at a time */ CARL9170FW_HAS_WREGB_CMD, + /* Pattern generator */ + CARL9170FW_PATTERN_GENERATOR, + /* KEEP LAST */ __CARL9170FW_FEATURE_NUM }; @@@ -98,7 -98,6 +98,7 @@@ #define CHK_MAGIC "CHK\0" #define TXSQ_MAGIC "TXSQ" #define WOL_MAGIC "WOL\0" +#define PATTERN_MAGIC "RDR\0" #define LAST_MAGIC "LAST" #define CARL9170FW_SET_DAY(d) (((d) - 1) % 31) @@@ -183,24 -182,6 +183,24 @@@ struct carl9170fw_dbg_desc #define CARL9170FW_DBG_DESC_SIZE \ (sizeof(struct carl9170fw_dbg_desc)) +#define CARL9170FW_PATTERN_MAP_NAME_LEN 15 +struct carl9170fw_pattern_map_entry { + u8 index; + char name[CARL9170FW_PATTERN_MAP_NAME_LEN]; +} __packed; + +#define CARL9170FW_PATTERN_DESC_MIN_VER 1 +#define CARL9170FW_PATTERN_DESC_CUR_VER 1 +struct carl9170fw_pattern_desc { + struct carl9170fw_desc_head head; + + __le32 soft_pattern; + __le32 num_patterns; + struct carl9170fw_pattern_map_entry patterns[0]; +} __packed; +#define CARL9170FW_PATTERN_DESC_SIZE \ + (sizeof(struct carl9170fw_pattern_desc)) + #define CARL9170FW_CHK_DESC_MIN_VER 1 #define CARL9170FW_CHK_DESC_CUR_VER 2 struct carl9170fw_chk_desc { diff --combined tools/src/fwprepare.c index f022874,0000000..f5e7806 mode 100644,000000..100644 --- a/tools/src/fwprepare.c +++ b/tools/src/fwprepare.c @@@ -1,158 -1,0 +1,157 @@@ +/* + * Copyright 2012 Christian Lamparter + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include - #include + +#include "carlfw.h" ++#include "compiler.h" +#include "pattern.h" + - +static void checksum_help(void) +{ + fprintf(stderr, "Usage:\n"); + fprintf(stderr, "\tfwprepare FW-FILE\n"); + + fprintf(stderr, "\nDescription:\n"); + fprintf(stderr, "\tThis simple utility prepares the firmware " + "for release.\n"); + + fprintf(stderr, "\nParameteres:\n"); + fprintf(stderr, "\t 'FW-FILE' = firmware name\n"); + fprintf(stderr, "\n"); +} + +static int add_patterns(struct carlfw *fw) { + const struct carl9170fw_otus_desc *otus_desc = NULL; + struct carl9170fw_pattern_desc *pattern_desc = NULL; + int to_add; + + otus_desc = carlfw_find_desc(fw, (uint8_t *) OTUS_MAGIC, + sizeof(*otus_desc), + CARL9170FW_OTUS_DESC_CUR_VER); + if (!otus_desc) { + fprintf(stderr, "No OTUS descriptor found\n"); + return -1; + } + + if (!carl9170fw_supports(otus_desc->feature_set, CARL9170FW_PATTERN_GENERATOR)) { + return 0; + } + + pattern_desc = carlfw_find_desc(fw, (uint8_t *) PATTERN_MAGIC, + sizeof(*pattern_desc), + CARL9170FW_PATTERN_DESC_CUR_VER); + + if (!pattern_desc) { + fprintf(stderr, "Firmware has the pattern generator feature set, but " + "can't find a valid pattern descriptor\n"); + return 0; + } + + to_add = pattern_desc->num_patterns - + ((pattern_desc->head.length - sizeof(*pattern_desc)) / + sizeof(struct carl9170fw_pattern_map_entry)); + if (to_add == 0) { + /* been there, done that */ + return 0; + } + + if (to_add == __CARL9170FW_NUM_PATTERNS) { + struct carl9170fw_pattern_desc *tmp; + unsigned int len, map_len; + + map_len = sizeof(struct carl9170fw_pattern_map_entry) * to_add; + len = sizeof(*tmp) + map_len; + tmp = malloc(len); + if (!tmp) + return -ENOMEM; + + pattern_desc = carlfw_desc_mod_len(fw, &pattern_desc->head, map_len); + if (IS_ERR_OR_NULL(pattern_desc)) + return (int) PTR_ERR(pattern_desc); + + memcpy(&pattern_desc->patterns, pattern_names, map_len); + return 0; + } else { + fprintf(stderr, "No idea, what you just did. But congrats: you broke it!"); + return -EINVAL; + } +} + +static int add_checksums(struct carlfw __unused *fw) +{ + /* + * No magic here, The checksum descriptor is added/update + * automatically in a subroutine of carlfw_store(). + */ + return 0; +} + +int main(int argc, char *args[]) +{ + struct carlfw *fw = NULL; + int err = 0; + + if (argc != 2) { + err = -EINVAL; + goto out; + } + + fw = carlfw_load(args[1]); + if (IS_ERR_OR_NULL(fw)) { + err = PTR_ERR(fw); + fprintf(stderr, "Failed to open file \"%s\" (%d).\n", + args[1], err); + goto out; + } + + err = add_patterns(fw); + if (err) + goto out; + + err = add_checksums(fw); + if (err) + goto out; + + err = carlfw_store(fw); + if (err) { + fprintf(stderr, "Failed to apply checksum (%d).\n", err); + goto out; + } + +out: + switch (err) { + case 0: + fprintf(stdout, "firmware was prepared successfully.\n"); + break; + case -EINVAL: + checksum_help(); + break; + default: + break; + } + + carlfw_release(fw); + return err ? EXIT_FAILURE : EXIT_SUCCESS; +}