Merge branch 'master' into radar
authorChristian Lamparter <chunkeey@googlemail.com>
Mon, 15 Feb 2016 17:28:51 +0000 (18:28 +0100)
committerChristian Lamparter <chunkeey@googlemail.com>
Mon, 15 Feb 2016 17:31:16 +0000 (18:31 +0100)
1  2 
include/shared/fwdesc.h
tools/src/fwprepare.c

diff --combined include/shared/fwdesc.h
index 10327a7a591c7146182310c34378150c30469477,da05a4ecb73f2593050b4d9cd72036d0b5a2cb70..d542b01eb0409d8677c212e2f13838c9394ab4c9
@@@ -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 f022874c1d1689c1d0635ee975ec06a11a094be7,0000000000000000000000000000000000000000..f5e780635245c0915b8d46d132c6aeceeb41323b
mode 100644,000000..100644
--- /dev/null
@@@ -1,158 -1,0 +1,157 @@@
- #include <ctype.h>
 +/*
 + * Copyright 2012 Christian Lamparter <chunkeey@googlemail.com>
 + *
 + * 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 <stdlib.h>
 +#include <stdio.h>
 +#include <error.h>
 +#include <string.h>
 +#include <errno.h>
 +#include <sys/types.h>
 +#include <sys/stat.h>
 +#include <unistd.h>
 +
 +#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;
 +}