2 * Copyright 2012 Christian Lamparter <chunkeey@googlemail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation version 2 of the License.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <sys/types.h>
27 #include "../../carlfw/include/radar.h"
32 static void checksum_help(void)
34 fprintf(stderr, "Usage:\n");
35 fprintf(stderr, "\tfwprepare FW-FILE\n");
37 fprintf(stderr, "\nDescription:\n");
38 fprintf(stderr, "\tThis simple utility prepares the firmware "
41 fprintf(stderr, "\nParameteres:\n");
42 fprintf(stderr, "\t 'FW-FILE' = firmware name\n");
43 fprintf(stderr, "\n");
46 static int add_radars(struct carlfw *fw) {
47 const struct carl9170fw_otus_desc *otus_desc = NULL;
48 struct carl9170fw_radar_desc *radar_desc = NULL;
51 otus_desc = carlfw_find_desc(fw, (uint8_t *) OTUS_MAGIC,
53 CARL9170FW_OTUS_DESC_CUR_VER);
55 fprintf(stderr, "No OTUS descriptor found\n");
59 if (!carl9170fw_supports(otus_desc->feature_set, CARL9170FW_RADAR_PATTERN_GENERATOR)) {
63 radar_desc = carlfw_find_desc(fw, (uint8_t *) RADAR_MAGIC,
65 CARL9170FW_RADAR_DESC_CUR_VER);
68 fprintf(stderr, "Firmware has radar pattern feature set, but "
69 "can't find a valid radar descriptor\n");
72 radars_to_add = radar_desc->num_radars -
73 ((radar_desc->head.length - sizeof(*radar_desc)) /
74 sizeof(struct carl9170fw_radar_map_entry));
75 if (radars_to_add == 0) {
76 /* been there, done that */
80 if (radars_to_add == __CARL9170FW_NUM_RADARS) {
81 struct carl9170fw_radar_desc *tmp;
82 unsigned int len, map_len;
84 map_len = sizeof(struct carl9170fw_radar_map_entry) * radars_to_add;
85 len = sizeof(*tmp) + map_len;
90 radar_desc = carlfw_desc_mod_len(fw, &radar_desc->head, map_len);
91 if (IS_ERR_OR_NULL(radar_desc))
92 return (int) PTR_ERR(radar_desc);
94 memcpy(&radar_desc->radars, radar_names, map_len);
97 fprintf(stderr, "don't know what you did, but congrats you broke it!");
102 static int add_checksums(struct carlfw __unused *fw)
105 * No magic here, The checksum descriptor is added/update
106 * automatically in a subroutine of carlfw_store().
111 int main(int argc, char *args[])
113 struct carlfw *fw = NULL;
121 fw = carlfw_load(args[1]);
122 if (IS_ERR_OR_NULL(fw)) {
124 fprintf(stderr, "Failed to open file \"%s\" (%d).\n",
129 err = add_radars(fw);
133 err = add_checksums(fw);
137 err = carlfw_store(fw);
139 fprintf(stderr, "Failed to apply checksum (%d).\n", err);
146 fprintf(stdout, "firmware was prepared successfully.\n");
156 return err ? EXIT_FAILURE : EXIT_SUCCESS;