2016-06-27 19:22:38 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* libs/libc/hex2bin/lib_fhex2mem.c
|
2016-06-27 19:22:38 +02:00
|
|
|
*
|
2020-03-09 21:28:20 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2016-06-27 19:22:38 +02:00
|
|
|
*
|
2020-03-09 21:28:20 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2016-06-27 19:22:38 +02:00
|
|
|
*
|
2020-03-09 21:28:20 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2016-06-27 19:22:38 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <hex2bin.h>
|
|
|
|
|
|
|
|
#include <nuttx/streams.h>
|
|
|
|
|
2021-08-01 09:27:08 +02:00
|
|
|
#ifdef CONFIG_LIBC_HEX2BIN
|
2016-06-27 19:22:38 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-02-01 19:17:03 +01:00
|
|
|
* Name: fhex2mem
|
2016-06-27 19:22:38 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read the Intel HEX ASCII data provided on the standard stream
|
|
|
|
* 'instream' and write the binary to memory.
|
|
|
|
*
|
|
|
|
* If, for example, instream is stdin, then the HEX ASCII data would be
|
|
|
|
* taken from the console and written to memory.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* instream - The incoming standard stream from which Intel HEX data
|
|
|
|
* will be received.
|
|
|
|
* baseaddr - The base address of the memory region stream.
|
|
|
|
* endpaddr - The end address (plus 1) of the memory region.
|
|
|
|
* swap - Controls byte ordering. See enum hex2bin_swap_e for
|
|
|
|
* description of the values.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2016-06-27 19:22:38 +02:00
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-08-11 10:22:36 +02:00
|
|
|
int fhex2mem(FAR FILE *instream, unsigned long baseaddr,
|
|
|
|
unsigned long endpaddr, enum hex2bin_swap_e swap)
|
2016-06-27 19:22:38 +02:00
|
|
|
{
|
|
|
|
struct lib_stdinstream_s stdinstream;
|
|
|
|
struct lib_memsostream_s memoutstream;
|
|
|
|
|
|
|
|
/* Check memory addresses */
|
|
|
|
|
|
|
|
DEBUGASSERT(instream != NULL && endpaddr > baseaddr);
|
|
|
|
|
|
|
|
/* Wrap the file descriptor as raw stream; wrap the memory as a memory
|
|
|
|
* stream.
|
|
|
|
*/
|
|
|
|
|
|
|
|
lib_stdinstream(&stdinstream, instream);
|
|
|
|
lib_memsostream(&memoutstream, (FAR char *)baseaddr,
|
|
|
|
(int)(endpaddr - baseaddr));
|
|
|
|
|
|
|
|
/* And do the deed */
|
|
|
|
|
2023-09-10 21:32:34 +02:00
|
|
|
return hex2bin(&stdinstream.common, &memoutstream.common,
|
2023-08-11 10:22:36 +02:00
|
|
|
(unsigned long)baseaddr, (unsigned long)endpaddr,
|
2016-06-27 19:22:38 +02:00
|
|
|
(enum hex2bin_swap_e)swap);
|
|
|
|
}
|
|
|
|
|
2021-08-01 09:27:08 +02:00
|
|
|
#endif /* CONFIG_LIBC_HEX2BIN */
|