2022-08-30 10:01:12 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-06-26 17:53:35 -05:00
|
|
|
|
2009-11-17 15:04:49 -06:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net> *
|
|
|
|
***************************************************************************/
|
2012-01-30 10:38:09 -06:00
|
|
|
|
2009-11-17 15:04:49 -06:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common.h"
|
2009-12-03 06:14:28 -06:00
|
|
|
#include <helper/log.h>
|
2009-11-17 15:04:49 -06:00
|
|
|
|
|
|
|
unsigned get_flash_name_index(const char *name)
|
|
|
|
{
|
2010-06-14 04:51:25 -05:00
|
|
|
const char *name_index = strrchr(name, '.');
|
2021-07-03 11:51:20 -05:00
|
|
|
if (!name_index)
|
2009-11-17 15:04:49 -06:00
|
|
|
return 0;
|
2010-06-14 04:51:25 -05:00
|
|
|
if (name_index[1] < '0' || name_index[1] > '9')
|
2009-11-19 20:11:30 -06:00
|
|
|
return ~0U;
|
2009-11-17 15:04:49 -06:00
|
|
|
unsigned requested;
|
2010-06-14 04:51:25 -05:00
|
|
|
int retval = parse_uint(name_index + 1, &requested);
|
2012-01-30 10:38:09 -06:00
|
|
|
/* detect parsing error by forcing past end of bank list */
|
2021-07-03 09:47:35 -05:00
|
|
|
return (retval == ERROR_OK) ? requested : ~0U;
|
2009-11-17 15:04:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
bool flash_driver_name_matches(const char *name, const char *expected)
|
|
|
|
{
|
|
|
|
unsigned blen = strlen(name);
|
2012-01-30 10:38:09 -06:00
|
|
|
/* only match up to the length of the driver name... */
|
2009-11-17 15:04:49 -06:00
|
|
|
if (strncmp(name, expected, blen) != 0)
|
|
|
|
return false;
|
|
|
|
|
2012-01-30 10:38:09 -06:00
|
|
|
/* ...then check that name terminates at this spot. */
|
2009-11-17 15:04:49 -06:00
|
|
|
return expected[blen] == '.' || expected[blen] == '\0';
|
|
|
|
}
|