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>
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");
73 radars_to_add = radar_desc->num_radars -
74 ((radar_desc->head.length - sizeof(*radar_desc)) /
75 sizeof(struct carl9170fw_radar_map_entry));
76 if (radars_to_add == 0) {
77 /* been there, done that */
81 if (radars_to_add == __CARL9170FW_NUM_RADARS) {
82 struct carl9170fw_radar_desc *tmp;
83 unsigned int len, map_len;
85 map_len = sizeof(struct carl9170fw_radar_map_entry) * radars_to_add;
86 len = sizeof(*tmp) + map_len;
91 radar_desc = carlfw_desc_mod_len(fw, &radar_desc->head, map_len);
92 if (IS_ERR_OR_NULL(radar_desc))
93 return (int) PTR_ERR(radar_desc);
95 memcpy(&radar_desc->radars, radar_names, map_len);
98 fprintf(stderr, "don't know what you did, but congrats you broke it!");
103 static int add_checksums(struct carlfw __unused *fw)
106 * No magic here, The checksum descriptor is added/update
107 * automatically in a subroutine of carlfw_store().
112 int main(int argc, char *args[])
114 struct carlfw *fw = NULL;
122 fw = carlfw_load(args[1]);
123 if (IS_ERR_OR_NULL(fw)) {
125 fprintf(stderr, "Failed to open file \"%s\" (%d).\n",
130 err = add_radars(fw);
134 err = add_checksums(fw);
138 err = carlfw_store(fw);
140 fprintf(stderr, "Failed to apply checksum (%d).\n", err);
147 fprintf(stdout, "firmware was prepared successfully.\n");
157 return err ? EXIT_FAILURE : EXIT_SUCCESS;