├── .gitignore
├── LA_OPT_Base_License.htm
├── Microsoft_Public_License.pdf
├── Microsoft_Limited_Public_License.pdf
├── src
├── picocom
│ ├── README.md
│ ├── custbaud.c
│ ├── termios2.h
│ ├── custbaud_bsd.h
│ └── custbaud.h
├── blfwk
│ ├── HexValues.h
│ ├── BlfwkErrors.h
│ ├── src
│ │ ├── HexValues.cpp
│ │ ├── Random.cpp
│ │ ├── RijndaelCTR.cpp
│ │ ├── ExcludesListMatcher.cpp
│ │ ├── Value.cpp
│ │ ├── AESKey.cpp
│ │ ├── AESCounter.cpp
│ │ ├── Crc.cpp
│ │ ├── Blob.cpp
│ │ ├── DataTarget.cpp
│ │ ├── format_string.cpp
│ │ ├── GHSSecInfo.cpp
│ │ ├── SimPeripheral.cpp
│ │ ├── GlobMatcher.cpp
│ │ └── SBSourceFile.cpp
│ ├── DataSourceImager.h
│ ├── Random.h
│ ├── RijndaelCTR.h
│ ├── serial.h
│ ├── GlobMatcher.h
│ ├── format_string.h
│ ├── int_size.h
│ ├── ExcludesListMatcher.h
│ ├── bootloader_config.h
│ ├── Crc.h
│ ├── host_types.h
│ ├── utils.h
│ ├── SearchPath.h
│ ├── OptionContext.h
│ ├── StringMatcher.h
│ ├── Blob.h
│ ├── SimPeripheral.h
│ ├── Peripheral.h
│ ├── BusPalPeripheral.h
│ ├── stdafx.h
│ ├── GHSSecInfo.h
│ ├── Bootloader.h
│ ├── IntelHexSourceFile.h
│ ├── SRecordSourceFile.h
│ ├── AESKey.h
│ ├── SimPacketizer.h
│ ├── Simulator.h
│ └── UartPeripheral.h
├── bootloader
│ ├── flashloader_image.h
│ ├── bl_version.h
│ ├── bl_user_entry.h
│ ├── bl_shutdown_cleanup.h
│ ├── bl_reliable_update.h
│ ├── bl_irq_common.h
│ ├── bl_app_crc_check.h
│ └── bootloader.h
├── utilities
│ ├── fsl_assert.h
│ ├── kinetis_family.h
│ └── vector_table_info.h
├── bm_usb
│ └── bootloader_hid_report_ids.h
├── include
│ └── bootloader_core.h
├── crc
│ ├── crc16.h
│ └── crc32.h
└── drivers
│ └── common
│ └── fsl_common.c
├── .gitattributes
├── apps
└── common
│ ├── blfwkdll
│ ├── blfwk.vcxproj.user
│ ├── blfwkdll.vcxproj.user
│ └── blfwkdll.vcxproj.filters
│ └── blfwk
│ └── blfwk.xcodeproj
│ └── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ └── blfwk.xccheckout
├── validation
├── blhost.xcodeproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
└── blhost
│ ├── src
│ ├── blhost.vcxproj.filters
│ ├── blhost.vcxproj.user
│ └── targetver.h
│ └── blhost.sln
├── Dockerfile.i386
├── Dockerfile.armv7l
├── Dockerfile.aarch64
├── .appveyor.yml
├── README.md
├── LICENSE.txt
└── .travis.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | [Dd]ebug/
2 | [Rr]elease/
3 |
--------------------------------------------------------------------------------
/LA_OPT_Base_License.htm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lauszus/blhost/HEAD/LA_OPT_Base_License.htm
--------------------------------------------------------------------------------
/Microsoft_Public_License.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lauszus/blhost/HEAD/Microsoft_Public_License.pdf
--------------------------------------------------------------------------------
/Microsoft_Limited_Public_License.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Lauszus/blhost/HEAD/Microsoft_Limited_Public_License.pdf
--------------------------------------------------------------------------------
/src/picocom/README.md:
--------------------------------------------------------------------------------
1 | These files are taken from the [picocom](https://github.com/npat-efault/picocom) project and allows us to use a custom UART baudrate on Linux.
2 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 | * text eol=lf
4 |
5 | # Except for Windows Visual Studio project files
6 | *.sln text eol=crlf
7 |
--------------------------------------------------------------------------------
/apps/common/blfwkdll/blfwk.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/apps/common/blfwkdll/blfwkdll.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/validation/blhost.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/apps/common/blfwk/blfwk.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Dockerfile.i386:
--------------------------------------------------------------------------------
1 | FROM i386/centos:centos7
2 |
3 | COPY . /lauszus-blhost
4 |
5 | RUN yum -y update
6 | RUN yum -y install gcc gcc-c++ make libudev-devel
7 |
8 | RUN linux32 --32bit i386 make -j$(nproc) -C /lauszus-blhost/validation/blhost/gcc
9 | RUN strip /lauszus-blhost/validation/blhost/gcc/Release/blhost
10 |
--------------------------------------------------------------------------------
/validation/blhost/src/blhost.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Dockerfile.armv7l:
--------------------------------------------------------------------------------
1 | FROM balenalib/armv7hf-debian:stretch
2 |
3 | COPY . /lauszus-blhost
4 |
5 | RUN [ "cross-build-start" ]
6 |
7 | RUN apt-get update
8 | RUN apt-get install -y apt-utils
9 | RUN apt-get install -y build-essential libudev-dev
10 |
11 | RUN make -j$(nproc) -C /lauszus-blhost/validation/blhost/gcc
12 | RUN strip /lauszus-blhost/validation/blhost/gcc/Release/blhost
13 |
14 | RUN [ "cross-build-end" ]
15 |
--------------------------------------------------------------------------------
/Dockerfile.aarch64:
--------------------------------------------------------------------------------
1 | FROM balenalib/aarch64-debian:latest
2 |
3 | COPY . /lauszus-blhost
4 |
5 | RUN [ "cross-build-start" ]
6 |
7 | RUN apt-get update
8 | RUN apt-get install -y apt-utils
9 | RUN apt-get install -y build-essential libudev-dev
10 | RUN apt-get install -y libstdc++6
11 |
12 | RUN make -j$(nproc) -C /lauszus-blhost/validation/blhost/gcc
13 | RUN strip /lauszus-blhost/validation/blhost/gcc/Release/blhost
14 |
15 | RUN [ "cross-build-end" ]
16 |
--------------------------------------------------------------------------------
/.appveyor.yml:
--------------------------------------------------------------------------------
1 | configuration: Release
2 |
3 | before_build:
4 | - cd validation\blhost
5 |
6 | build:
7 | parallel: true
8 | verbosity: minimal
9 |
10 | after_build:
11 | - ps: Rename-Item -Path ".\${env:configuration}\blhost.exe" -NewName "blhost-win.exe"
12 |
13 | artifacts:
14 | - path: validation\blhost\$(configuration)\blhost-win.exe
15 | name: blhost-win.exe
16 |
17 | deploy:
18 | provider: GitHub
19 | auth_token:
20 | secure: arEvoKdPUgzPQ2WehvUQPS6RpiUB35op7NN1a2mhvfdwmB/AnRFK3R0fackxKX+w
21 | artifact: blhost-win.exe
22 | draft: true
23 | on:
24 | APPVEYOR_REPO_TAG: true
25 |
--------------------------------------------------------------------------------
/src/blfwk/HexValues.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: HexValues.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_HexValues_h_)
8 | #define _HexValues_h_
9 |
10 | #include
11 |
12 | //! \brief Determines whether \a c is a hex digit character.
13 | bool isHexDigit(char c);
14 |
15 | //! \brief Converts a hexidecimal character to the integer equivalent.
16 | uint8_t hexCharToInt(char c);
17 |
18 | //! \brief Converts a hex-encoded byte to the integer equivalent.
19 | uint8_t hexByteToInt(const char *encodedByte);
20 |
21 | #endif // _HexValues_h_
22 |
--------------------------------------------------------------------------------
/src/blfwk/BlfwkErrors.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: BlfwkErrors.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_BlfwkErrors_h_)
8 | #define _BlfwkErrors_h_
9 |
10 | #include
11 | #include
12 |
13 | //! @addtogroup host_error
14 | //! @{
15 |
16 | namespace blfwk
17 | {
18 | /*!
19 | * \brief A semantic error discovered while processing the command file AST.
20 | */
21 | class semantic_error : public std::runtime_error
22 | {
23 | public:
24 | explicit semantic_error(const std::string &msg)
25 | : std::runtime_error(msg)
26 | {
27 | }
28 | };
29 |
30 | }; // namespace blfwk
31 |
32 | //! @}
33 |
34 | #endif // _BlfwkErrors_h_
35 |
--------------------------------------------------------------------------------
/validation/blhost/src/blhost.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -u -b i2c,0x10,100 -- get-property 1
5 | WindowsLocalDebugger
6 | $(OutDir)
7 |
8 |
9 | -p COM1 -b can -- get-property 1
10 | WindowsLocalDebugger
11 |
12 |
--------------------------------------------------------------------------------
/src/blfwk/src/HexValues.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: HexValues.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/HexValues.h"
9 | #include
10 |
11 | bool isHexDigit(char c)
12 | {
13 | return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
14 | }
15 |
16 | //! \return The integer equivalent to \a c.
17 | //! \retval -1 The character \a c is not a hex character.
18 | uint8_t hexCharToInt(char c)
19 | {
20 | if (c >= '0' && c <= '9')
21 | return c - '0';
22 | else if (c >= 'a' && c <= 'f')
23 | return c - 'a' + 10;
24 | else if (c >= 'A' && c <= 'F')
25 | return c - 'A' + 10;
26 | else
27 | return static_cast(-1);
28 | }
29 |
30 | //! \param encodedByte Must point to at least two ASCII hex characters.
31 | //!
32 | uint8_t hexByteToInt(const char *encodedByte)
33 | {
34 | return (hexCharToInt(encodedByte[0]) << 4) | hexCharToInt(encodedByte[1]);
35 | }
36 |
--------------------------------------------------------------------------------
/apps/common/blfwkdll/blfwkdll.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
6 | h;hh;hpp;hxx;hm;inl;inc;xsd
7 |
8 |
9 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
10 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 |
23 |
24 | Source Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # blhost
2 |
3 | #### Modified by Kristian Lauszus, 2018-2020
4 | _________
5 | [](https://travis-ci.org/Lauszus/blhost)
6 | [](https://ci.appveyor.com/project/Lauszus/blhost/branch/master)
7 |
8 | This repository contains the changes I have made to blhost, which is part of [KBOOT](https://www.nxp.com/support/developer-resources/reference-designs/kinetis-bootloader:KBOOT) from NXP.
9 |
10 | I have also developed a Python version, which supports uploading via serial and CAN-Bus: .
11 |
12 | ### Changes
13 |
14 | * Can now compile the code using GCC on Mac
15 | * Fixed setting the UART baudrate on Linux
16 | * Ping 3 times with a delay of 1 s between the ping commands
17 | * Allow to set a custom UART baudrate
18 | * Fixed "get_string_property_utf8" on Mac thanks to Andrew Pines
19 |
20 | The executables are automatically build using [Travis](https://travis-ci.org/) and [AppVeyor](https://www.appveyor.com/) for all major platforms including armv7l (Raspberry PI or similar). The executables can be found under the releases tab: .
21 |
--------------------------------------------------------------------------------
/src/blfwk/DataSourceImager.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: DataSourceImager.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_DataSourceImager_h_)
8 | #define _DataSourceImager_h_
9 |
10 | #include "Blob.h"
11 | #include "DataSource.h"
12 |
13 | namespace blfwk
14 | {
15 | /*!
16 | * \brief Converts a DataSource into a single binary buffer.
17 | */
18 | class DataSourceImager : public Blob
19 | {
20 | public:
21 | //! \brief Constructor.
22 | DataSourceImager();
23 |
24 | //! \name Setup
25 | //@{
26 | void setBaseAddress(uint32_t address);
27 | void setFillPattern(uint8_t pattern);
28 | //@}
29 |
30 | void reset();
31 |
32 | //! \name Accessors
33 | //@{
34 | uint32_t getBaseAddress() { return m_baseAddress; }
35 | //@}
36 |
37 | //! \name Operations
38 | //@{
39 | //! \brief Adds all of the segments of which \a dataSource is composed.
40 | void addDataSource(DataSource *source);
41 |
42 | //! \brief Adds the data from one data segment.
43 | void addDataSegment(DataSource::Segment *segment);
44 | //@}
45 |
46 | protected:
47 | uint8_t m_fill;
48 | uint32_t m_baseAddress;
49 | bool m_isBaseAddressSet;
50 | };
51 | };
52 |
53 | #endif // _DataSourceImager_h_
54 |
--------------------------------------------------------------------------------
/src/blfwk/Random.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: Random.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_Random_h_)
8 | #define _Random_h_
9 |
10 | #include "stdafx.h"
11 |
12 | #ifdef WIN32
13 | /*!
14 | * This class is from the crypto++ library.
15 | */
16 | class MicrosoftCryptoProvider
17 | {
18 | public:
19 | MicrosoftCryptoProvider();
20 | ~MicrosoftCryptoProvider();
21 | #if defined(_WIN64)
22 | typedef unsigned __int64 ProviderHandle; // type HCRYPTPROV, avoid #include
23 | #else
24 | typedef unsigned long ProviderHandle;
25 | #endif
26 | ProviderHandle GetProviderHandle() const { return m_hProvider; }
27 | private:
28 | ProviderHandle m_hProvider;
29 | };
30 |
31 | #pragma comment(lib, "advapi32.lib")
32 | #endif // WIN32
33 |
34 | /*!
35 | * Encapsulates the Windows CryptoAPI's CryptGenRandom or /dev/urandom on Unix systems.
36 | */
37 | class RandomNumberGenerator
38 | {
39 | public:
40 | RandomNumberGenerator();
41 | ~RandomNumberGenerator();
42 |
43 | uint8_t generateByte();
44 | void generateBlock(uint8_t *output, unsigned count);
45 |
46 | protected:
47 | #ifdef WIN32
48 | #ifndef WORKAROUND_MS_BUG_Q258000
49 | MicrosoftCryptoProvider m_provider;
50 | #endif
51 | #else // WIN32
52 | int m_fd;
53 | #endif // WIN32
54 | };
55 |
56 | #endif // _Random_h_
57 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Redistribution and use in source and binary forms, with or without modification,
2 | are permitted provided that the following conditions are met:
3 |
4 | o Redistributions of source code must retain the above copyright notice, this list
5 | of conditions and the following disclaimer.
6 |
7 | o Redistributions in binary form must reproduce the above copyright notice, this
8 | list of conditions and the following disclaimer in the documentation and/or
9 | other materials provided with the distribution.
10 |
11 | o Neither the name of Freescale Semiconductor, Inc. nor the names of its
12 | contributors may be used to endorse or promote products derived from this
13 | software without specific prior written permission.
14 |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 |
--------------------------------------------------------------------------------
/validation/blhost/blhost.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 2013 for Windows Desktop
4 | VisualStudioVersion = 12.0.30723.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blhost", "src\blhost.vcxproj", "{A498A89A-E965-4B36-B926-850AABF31939}"
7 | ProjectSection(ProjectDependencies) = postProject
8 | {DE64A8C3-695A-491F-B3E3-24D6A3057A40} = {DE64A8C3-695A-491F-B3E3-24D6A3057A40}
9 | EndProjectSection
10 | EndProject
11 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blfwk", "..\..\apps\common\blfwk\blfwk.vcxproj", "{DE64A8C3-695A-491F-B3E3-24D6A3057A40}"
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Win32 = Debug|Win32
16 | Release|Win32 = Release|Win32
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {A498A89A-E965-4B36-B926-850AABF31939}.Debug|Win32.ActiveCfg = Debug|Win32
20 | {A498A89A-E965-4B36-B926-850AABF31939}.Debug|Win32.Build.0 = Debug|Win32
21 | {A498A89A-E965-4B36-B926-850AABF31939}.Release|Win32.ActiveCfg = Release|Win32
22 | {A498A89A-E965-4B36-B926-850AABF31939}.Release|Win32.Build.0 = Release|Win32
23 | {DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|Win32.ActiveCfg = Debug|Win32
24 | {DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Debug|Win32.Build.0 = Debug|Win32
25 | {DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|Win32.ActiveCfg = Release|Win32
26 | {DE64A8C3-695A-491F-B3E3-24D6A3057A40}.Release|Win32.Build.0 = Release|Win32
27 | EndGlobalSection
28 | GlobalSection(SolutionProperties) = preSolution
29 | HideSolutionNode = FALSE
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/apps/common/blfwk/blfwk.xcodeproj/project.xcworkspace/xcshareddata/blfwk.xccheckout:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDESourceControlProjectFavoriteDictionaryKey
6 |
7 | IDESourceControlProjectIdentifier
8 | 39613C90-D3FD-466B-B9D9-DC666880F859
9 | IDESourceControlProjectName
10 | blfwk
11 | IDESourceControlProjectOriginsDictionary
12 |
13 | B0D5F4B3-E512-4A54-9F8A-89FE66DEC76C
14 | ssh://sw-git.freescale.net/git/sw_git/repos/mcu-boot.git
15 |
16 | IDESourceControlProjectPath
17 | apps/common/blfwk/blfwk.xcodeproj/project.xcworkspace
18 | IDESourceControlProjectRelativeInstallPathDictionary
19 |
20 | B0D5F4B3-E512-4A54-9F8A-89FE66DEC76C
21 | ../../../../..
22 |
23 | IDESourceControlProjectURL
24 | ssh://sw-git.freescale.net/git/sw_git/repos/mcu-boot.git
25 | IDESourceControlProjectVersion
26 | 110
27 | IDESourceControlProjectWCCIdentifier
28 | B0D5F4B3-E512-4A54-9F8A-89FE66DEC76C
29 | IDESourceControlProjectWCConfigurations
30 |
31 |
32 | IDESourceControlRepositoryExtensionIdentifierKey
33 | public.vcs.git
34 | IDESourceControlWCCIdentifierKey
35 | B0D5F4B3-E512-4A54-9F8A-89FE66DEC76C
36 | IDESourceControlWCCName
37 | mcu-boot
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/src/blfwk/RijndaelCTR.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: RijndaelCTR.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_RijndaelCTR_h_)
8 | #define _RijndaelCTR_h_
9 |
10 | #include "AESKey.h"
11 | #include "AESCounter.h"
12 | #include
13 |
14 | /*!
15 | * \brief Class to compute AES 128 CTR encryption/decryption.
16 | *
17 | * Currently only supports 128-bit keys and block sizes.
18 | */
19 | class RijndaelCTR
20 | {
21 | public:
22 | enum
23 | {
24 | BLOCK_SIZE = 16 //!< Number of bytes in one cipher block.
25 | };
26 |
27 | //! The cipher block data type.
28 | typedef uint8_t block_t[BLOCK_SIZE];
29 |
30 | public:
31 | //! \brief Constructor.
32 | RijndaelCTR(const AESKey<128> &key, const AESCounter<128> &counter);
33 |
34 | //! \brief Encrypt data.
35 | void encrypt(const uint8_t *data, unsigned length, uint8_t *dest);
36 |
37 | //! \brief Encrypt data.
38 | void decrypt(const uint8_t *data, unsigned length, uint8_t *dest);
39 |
40 | //! \brief Assignment operator.
41 | RijndaelCTR &operator=(const RijndaelCTR &other)
42 | {
43 | m_key = other.m_key;
44 | m_counter = other.m_counter;
45 | return *this;
46 | }
47 |
48 | protected:
49 | AESKey<128> m_key; //!< 128-bit key to use for encrypt/decrypt
50 | AESCounter<128> m_counter; //!< Counter value for encrypt/decrypt
51 |
52 | void incrementCounter(AESCounter<128>::counter_t *counter);
53 | void baseProcess(const uint8_t *data, unsigned length, uint8_t *dest);
54 |
55 | private:
56 | //! \brief inaccessible default constructor.
57 | RijndaelCTR() {}
58 | };
59 |
60 | #endif // _RijndaelCTR_h_
61 |
--------------------------------------------------------------------------------
/src/blfwk/serial.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the Bus Pirate project (http://code.google.com/p/the-bus-pirate/).
3 | *
4 | * Written and maintained by the Bus Pirate project and http://dangerousprototypes.com
5 | *
6 | * To the extent possible under law, the project has
7 | * waived all copyright and related or neighboring rights to Bus Pirate. This
8 | * work is published from United States.
9 | *
10 | * For details see: http://creativecommons.org/publicdomain/zero/1.0/.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 | */
16 | /*
17 | * OS independent serial interface
18 | *
19 | * Heavily based on Pirate-Loader:
20 | * http://the-bus-pirate.googlecode.com/svn/trunk/bootloader-v4/pirate-loader/source/pirate-loader.c
21 | *
22 | */
23 | #ifndef MYSERIAL_H_
24 | #define MYSERIAL_H_
25 |
26 | #ifdef MACOSX
27 | #include
28 |
29 | #define B1500000 1500000
30 | #define B1000000 1000000
31 | #define B921600 921600
32 | #endif
33 |
34 | #include
35 |
36 | #ifdef WIN32
37 | #include
38 | #include
39 |
40 | #define B115200 115200
41 | #define B921600 921600
42 |
43 | typedef long speed_t;
44 | #else
45 |
46 | #include
47 | #include
48 |
49 | #include "picocom/custbaud.h"
50 | #ifdef USE_CUSTOM_BAUD
51 | #include CUSTOM_BAUD_HEAD
52 | #endif
53 |
54 | #endif
55 |
56 | #if __cplusplus
57 | extern "C" {
58 | #endif
59 |
60 | int serial_setup(int fd, speed_t speed);
61 | int serial_set_read_timeout(int fd, uint32_t timeoutMs);
62 | int serial_write(int fd, char *buf, int size);
63 | int serial_read(int fd, char *buf, int size);
64 | int serial_open(char *port);
65 | int serial_close(int fd);
66 |
67 | #if __cplusplus
68 | }
69 | #endif
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/src/blfwk/GlobMatcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: GlobMatcher.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_GlobMatcher_h_)
8 | #define _GlobMatcher_h_
9 |
10 | #include "StringMatcher.h"
11 |
12 | namespace blfwk
13 | {
14 | /*!
15 | * \brief This class uses glob pattern matching to match strings.
16 | *
17 | * Glob patterns:
18 | * - * matches zero or more characters
19 | * - ? matches any single character
20 | * - [set] matches any character in the set
21 | * - [^set] matches any character NOT in the set
22 | * where a set is a group of characters or ranges. a range
23 | * is written as two characters seperated with a hyphen: a-z denotes
24 | * all characters between a to z inclusive.
25 | * - [-set] set matches a literal hypen and any character in the set
26 | * - []set] matches a literal close bracket and any character in the set
27 | *
28 | * - char matches itself except where char is '*' or '?' or '['
29 | * - \\char matches char, including any pattern character
30 | *
31 | * Examples:
32 | * - a*c ac abc abbc ...
33 | * - a?c acc abc aXc ...
34 | * - a[a-z]c aac abc acc ...
35 | * - a[-a-z]c a-c aac abc ...
36 | */
37 | class GlobMatcher : public StringMatcher
38 | {
39 | public:
40 | //! \brief Constructor.
41 | GlobMatcher(const std::string &pattern)
42 | : StringMatcher()
43 | , m_pattern(pattern)
44 | {
45 | }
46 |
47 | //! \brief Returns whether \a testValue matches the glob pattern.
48 | virtual bool match(const std::string &testValue);
49 |
50 | protected:
51 | std::string m_pattern; //!< The glob pattern to match against.
52 |
53 | //! \brief Glob implementation.
54 | bool globMatch(const char *str, const char *p);
55 | };
56 |
57 | }; // namespace blfwk
58 |
59 | #endif // _GlobMatcher_h_
60 |
--------------------------------------------------------------------------------
/src/picocom/custbaud.c:
--------------------------------------------------------------------------------
1 | /* vi: set sw=4 ts=4:
2 | *
3 | * custbaud.c
4 | *
5 | * by Nick Patavalis (npat@efault.net)
6 | *
7 | * This program is free software; you can redistribute it and/or
8 | * modify it under the terms of the GNU General Public License as
9 | * published by the Free Software Foundation; either version 2 of the
10 | * License, or (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful, but
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | * General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program; if not, write to the Free Software
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 | * USA
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 | #include "custbaud.h"
27 |
28 | #ifndef USE_CUSTOM_BAUD
29 |
30 | int use_custom_baud() { return 0; }
31 |
32 | int cfsetispeed_custom(struct termios *tios, int speed) { errno = EINVAL; return -1; }
33 | int cfsetospeed_custom(struct termios *tios, int speed) { errno = EINVAL; return -1; }
34 | int cfgetispeed_custom(const struct termios *tios) { errno = EINVAL; return -1; }
35 | int cfgetospeed_custom(const struct termios *tios) { errno = EINVAL; return -1; }
36 |
37 | #else /* USE_CUSTOM_BAUD */
38 |
39 | int
40 | use_custom_baud()
41 | {
42 | #ifdef __linux__
43 | static int use = -1;
44 | if ( use < 0 )
45 | use = getenv("NO_CUSTOM_BAUD") ? 0 : 1;
46 | return use;
47 | #else
48 | return 1;
49 | #endif
50 | }
51 |
52 | #endif /* of ndef USE_CUSTOM_BAUD */
53 |
54 | /**************************************************************************/
55 |
56 | /*
57 | * Local Variables:
58 | * mode:c
59 | * tab-width: 4
60 | * c-basic-offset: 4
61 | * End:
62 | */
63 |
--------------------------------------------------------------------------------
/src/blfwk/src/Random.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: Random.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/Random.h"
9 | #include
10 |
11 | #ifdef WIN32
12 | #ifndef _WIN32_WINNT
13 | #define _WIN32_WINNT 0x0400
14 | #endif
15 | #include
16 | #include
17 | #else // WIN32
18 | #include
19 | #include
20 | #include
21 | #endif // WIN32
22 |
23 | #ifdef WIN32
24 |
25 | MicrosoftCryptoProvider::MicrosoftCryptoProvider()
26 | {
27 | if (!CryptAcquireContext(&m_hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
28 | {
29 | throw std::runtime_error("CryptAcquireContext");
30 | }
31 | }
32 |
33 | MicrosoftCryptoProvider::~MicrosoftCryptoProvider()
34 | {
35 | CryptReleaseContext(m_hProvider, 0);
36 | }
37 |
38 | #endif // WIN32
39 |
40 | RandomNumberGenerator::RandomNumberGenerator()
41 | {
42 | #ifndef WIN32
43 | m_fd = open("/dev/urandom", O_RDONLY);
44 | if (m_fd == -1)
45 | {
46 | throw std::runtime_error("open /dev/urandom");
47 | }
48 | #endif // WIN32
49 | }
50 |
51 | RandomNumberGenerator::~RandomNumberGenerator()
52 | {
53 | #ifndef WIN32
54 | close(m_fd);
55 | #endif // WIN32
56 | }
57 |
58 | uint8_t RandomNumberGenerator::generateByte()
59 | {
60 | uint8_t result;
61 | generateBlock(&result, 1);
62 | return result;
63 | }
64 |
65 | void RandomNumberGenerator::generateBlock(uint8_t *output, unsigned count)
66 | {
67 | #ifdef WIN32
68 | #ifdef WORKAROUND_MS_BUG_Q258000
69 | static MicrosoftCryptoProvider m_provider;
70 | #endif
71 | if (!CryptGenRandom(m_provider.GetProviderHandle(), count, output))
72 | {
73 | throw std::runtime_error("CryptGenRandom");
74 | }
75 | #else // WIN32
76 | if (read(m_fd, output, count) != count)
77 | {
78 | throw std::runtime_error("read /dev/urandom");
79 | }
80 | #endif // WIN32
81 | }
82 |
--------------------------------------------------------------------------------
/src/blfwk/format_string.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_format_string_h_)
31 | #define _format_string_h_
32 |
33 | #include
34 | #include
35 |
36 | /*!
37 | * \brief Returns a formatted STL string using printf format strings.
38 | */
39 | std::string format_string(const char *fmt, ...);
40 |
41 | #endif // _format_string_h_
42 |
--------------------------------------------------------------------------------
/validation/blhost/src/targetver.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #pragma once
31 |
32 | // Including SDKDDKVer.h defines the highest available Windows platform.
33 |
34 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
35 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
36 |
37 | #include
38 |
--------------------------------------------------------------------------------
/src/blfwk/int_size.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_int_size_h_)
31 | #define _int_size_h_
32 |
33 | namespace blfwk
34 | {
35 | //! Supported sizes of integers.
36 | typedef enum
37 | {
38 | kWordSize, //!< 32-bit word.
39 | kHalfWordSize, //!< 16-bit half word.
40 | kByteSize //!< 8-bit byte.
41 | } int_size_t;
42 |
43 | }; // namespace blfwk
44 |
45 | #endif // _int_size_h_
46 |
--------------------------------------------------------------------------------
/src/blfwk/ExcludesListMatcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: ExcludesListMatcher.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_ExcludesListMatcher_h_)
8 | #define _ExcludesListMatcher_h_
9 |
10 | #include "GlobMatcher.h"
11 | #include
12 | #include
13 |
14 | namespace blfwk
15 | {
16 | /*!
17 | * \brief Matches strings using a series of include and exclude glob patterns.
18 | *
19 | * This string matcher class uses a sequential, ordered list of glob patterns to
20 | * determine whether a string matches. Attached to each pattern is an include/exclude
21 | * action. The patterns in the list effectively form a Boolean expression. Includes
22 | * act as an OR operator while excludes act as an AND NOT operator.
23 | *
24 | * Examples (plus prefix is include, minus prefix is exclude):
25 | * - +foo: foo
26 | * - -foo: !foo
27 | * - +foo, +bar: foo || bar
28 | * - +foo, -bar: foo && !bar
29 | * - +foo, -bar, +baz: foo && !bar || baz
30 | *
31 | * The only reason for inheriting from GlobMatcher is so we can access the protected
32 | * globMatch() method.
33 | */
34 | class ExcludesListMatcher : public GlobMatcher
35 | {
36 | public:
37 | //! \brief Default constructor.
38 | ExcludesListMatcher();
39 |
40 | //! \brief Destructor.
41 | ~ExcludesListMatcher();
42 |
43 | //! \name Pattern list
44 | //@{
45 | //! \brief Add one include or exclude pattern to the end of the match list.
46 | void addPattern(bool isInclude, const std::string &pattern);
47 | //@}
48 |
49 | //! \brief Performs a single string match test against testValue.
50 | virtual bool match(const std::string &testValue);
51 |
52 | protected:
53 | //! \brief Information about one glob pattern entry in a match list.
54 | struct glob_list_item_t
55 | {
56 | bool m_isInclude; //!< True if include, false if exclude.
57 | std::string m_glob; //!< The glob pattern to match.
58 | };
59 |
60 | typedef std::vector glob_list_t;
61 | glob_list_t m_patterns; //!< Ordered list of include and exclude patterns.
62 | };
63 |
64 | }; // namespace blfwk
65 |
66 | #endif // _ExcludesListMatcher_h_
67 |
--------------------------------------------------------------------------------
/src/blfwk/src/RijndaelCTR.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: RijndaelCTR.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/RijndaelCTR.h"
9 | #include "blfwk/rijndael.h"
10 | #include
11 | #include "blfwk/Logging.h"
12 |
13 | void logHexArray(Logger::log_level_t level, const uint8_t *bytes, unsigned count);
14 |
15 | //! \param key The key to use
16 | //! \param counter The counter to use
17 | RijndaelCTR::RijndaelCTR(const AESKey<128> &key, const AESCounter<128> &counter)
18 | : m_key(key)
19 | , m_counter(counter)
20 | {
21 | }
22 |
23 | void RijndaelCTR::decrypt(const uint8_t *data, unsigned length, uint8_t *dest)
24 | {
25 | baseProcess(data, length, dest);
26 | }
27 |
28 | void RijndaelCTR::encrypt(const uint8_t *data, unsigned length, uint8_t *dest)
29 | {
30 | baseProcess(data, length, dest);
31 | }
32 |
33 | void RijndaelCTR::baseProcess(const uint8_t *data, unsigned length, uint8_t *dest)
34 | {
35 | Rijndael cipher;
36 | unsigned blocks = length / BLOCK_SIZE;
37 | block_t remainder;
38 | AESCounter<128>::counter_t currentCounter;
39 |
40 | cipher.init(Rijndael::ECB, Rijndael::Encrypt, m_key, Rijndael::Key16Bytes);
41 |
42 | while (blocks--)
43 | {
44 | m_counter.getCounter(¤tCounter);
45 |
46 | cipher.blockEncrypt(currentCounter, BLOCK_SIZE * 8, currentCounter);
47 |
48 | for (int i = 0; i < BLOCK_SIZE; i++)
49 | {
50 | dest[i] = data[i] ^ currentCounter[i];
51 | }
52 |
53 | data += BLOCK_SIZE;
54 | dest += BLOCK_SIZE;
55 |
56 | m_counter.incrementCounter(BLOCK_SIZE);
57 | }
58 |
59 | if (length % sizeof(block_t))
60 | {
61 | m_counter.getCounter(¤tCounter);
62 |
63 | memset(remainder, 0, sizeof(remainder));
64 | memcpy(remainder, data, length % sizeof(block_t));
65 |
66 | cipher.blockEncrypt(currentCounter, BLOCK_SIZE * 8, currentCounter);
67 |
68 | for (unsigned int i = 0; i < length % sizeof(block_t); i++)
69 | {
70 | remainder[i] = data[i] ^ currentCounter[i];
71 | }
72 |
73 | memcpy(dest, remainder, length % sizeof(block_t));
74 |
75 | m_counter.incrementCounter(BLOCK_SIZE);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/blfwk/bootloader_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #ifndef __BOOTLOADER_CONFIG_H__
31 | #define __BOOTLOADER_CONFIG_H__
32 |
33 | ////////////////////////////////////////////////////////////////////////////////
34 | // Definitions
35 | ////////////////////////////////////////////////////////////////////////////////
36 |
37 | //
38 | // Bootloader configuration options
39 | //
40 |
41 | #define BL_HAS_QSPI_MODULE (0)
42 |
43 | #define BL_FEATURE_ENCRYPTION (0)
44 |
45 | #endif // __BOOTLOADER_CONFIG_H__
46 | ////////////////////////////////////////////////////////////////////////////////
47 | // EOF
48 | ////////////////////////////////////////////////////////////////////////////////
49 |
--------------------------------------------------------------------------------
/src/blfwk/Crc.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-15, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #if !defined(_Crc_h_)
32 | #define _Crc_h_
33 |
34 | #include
35 |
36 | namespace blfwk
37 | {
38 | /*!
39 | * \brief Crc class contains the functionality about crc ccalculation.
40 | */
41 | class Crc
42 | {
43 | public:
44 | //! \brief Default constructor.
45 | Crc(){};
46 |
47 | //! \brief Destructor.
48 | virtual ~Crc(){};
49 |
50 | //! \brief calculate crc32 for a given memory region
51 | //!
52 | //! \param start The start address of a memory region that contains the data
53 | //! \
54 | //! \param length Length in bytes to calculate
55 | //! \
56 | //! \return calculated result
57 | static uint32_t calculate_application_crc32(const uint8_t *start, uint32_t length);
58 | //@}
59 | //
60 | };
61 |
62 | } // namespace blfwk
63 | #endif // _Crc_h_
64 |
--------------------------------------------------------------------------------
/src/blfwk/host_types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _host_types_h_
32 | #define _host_types_h_
33 |
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 |
41 | //! @brief An array of strings.
42 | typedef std::vector string_vector_t;
43 |
44 | //! @brief An array of bytes.
45 | typedef std::vector uchar_vector_t;
46 |
47 | //! @brief An array of uint32_t's.
48 | typedef std::vector uint32_vector_t;
49 |
50 | //! @brief A stream of bytes.
51 | typedef std::deque uchar_deque_t;
52 |
53 | #endif // _host_types_h_
54 |
55 | ////////////////////////////////////////////////////////////////////////////////
56 | // EOF
57 | ////////////////////////////////////////////////////////////////////////////////
58 |
--------------------------------------------------------------------------------
/src/blfwk/src/ExcludesListMatcher.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: ExcludesListMatcher.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/ExcludesListMatcher.h"
9 |
10 | using namespace blfwk;
11 |
12 | ExcludesListMatcher::ExcludesListMatcher()
13 | : GlobMatcher("")
14 | {
15 | }
16 |
17 | ExcludesListMatcher::~ExcludesListMatcher()
18 | {
19 | }
20 |
21 | //! \param isInclude True if this pattern is an include, false if it is an exclude.
22 | //! \param pattern String containing the glob pattern.
23 | void ExcludesListMatcher::addPattern(bool isInclude, const std::string &pattern)
24 | {
25 | glob_list_item_t item;
26 | item.m_isInclude = isInclude;
27 | item.m_glob = pattern;
28 |
29 | // add to end of list
30 | m_patterns.push_back(item);
31 | }
32 |
33 | //! If there are no entries in the match list, the match fails.
34 | //!
35 | //! \param testValue The string to match against the pattern list.
36 | //! \retval true The \a testValue argument matches.
37 | //! \retval false No match was made against the argument.
38 | bool ExcludesListMatcher::match(const std::string &testValue)
39 | {
40 | if (!m_patterns.size())
41 | {
42 | return false;
43 | }
44 |
45 | // Iterate over the match list. Includes act as an OR operator, while
46 | // excludes act as an AND operator.
47 | bool didMatch = false;
48 | bool isFirstItem = true;
49 | glob_list_t::iterator it = m_patterns.begin();
50 | for (; it != m_patterns.end(); ++it)
51 | {
52 | glob_list_item_t &item = *it;
53 |
54 | // if this pattern is an include and it doesn't match, or
55 | // if this pattern is an exclude and it does match, then the match fails
56 | bool didItemMatch = globMatch(testValue.c_str(), item.m_glob.c_str());
57 |
58 | if (item.m_isInclude)
59 | {
60 | // Include
61 | if (isFirstItem)
62 | {
63 | didMatch = didItemMatch;
64 | }
65 | else
66 | {
67 | didMatch = didMatch || didItemMatch;
68 | }
69 | }
70 | else
71 | {
72 | // Exclude
73 | if (isFirstItem)
74 | {
75 | didMatch = !didItemMatch;
76 | }
77 | else
78 | {
79 | didMatch = didMatch && !didItemMatch;
80 | }
81 | }
82 |
83 | isFirstItem = false;
84 | }
85 |
86 | return didMatch;
87 | }
88 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: cpp
2 |
3 | sudo: false
4 |
5 | compiler:
6 | - gcc
7 |
8 | matrix:
9 | include:
10 | - os: osx
11 | env: PLATFORM=mac DOCKERBUILD=0
12 | - os: linux
13 | env: PLATFORM=amd64 DOCKERBUILD=0
14 | - os: linux
15 | env: PLATFORM=i386 DOCKERBUILD=1
16 | - os: linux
17 | env: PLATFORM=armv7l DOCKERBUILD=1
18 |
19 | services:
20 | - docker
21 |
22 | addons:
23 | apt:
24 | packages:
25 | - libudev-dev
26 |
27 | before_install:
28 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
29 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install hidapi; fi
30 |
31 | script:
32 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then xcodebuild -project validation/blhost.xcodeproj; fi
33 | # Docker is used for cross compiling the binaries for 32-bit Linux and armv7l.
34 | # Build the image, create a container from the image and get the container ID,
35 | # then make the directory, as this is normally created automatically using Make.
36 | # Finally copy over the compiled binary to the host.
37 | - if [[ "$DOCKERBUILD" == "1" ]]; then
38 | docker build -f Dockerfile.$PLATFORM -t lauszus/blhost .;
39 | CONTAINER_ID=$(docker create lauszus/blhost);
40 | mkdir -p validation/blhost/gcc/Release;
41 | docker cp $CONTAINER_ID:/lauszus-blhost/validation/blhost/gcc/Release/blhost validation/blhost/gcc/Release/blhost;
42 | else
43 | make -j2 -C validation/blhost/gcc;
44 | strip validation/blhost/gcc/Release/blhost;
45 | fi
46 | # Rename the binary, so the platform is part of the name.
47 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
48 | mv validation/blhost/gcc/Release/blhost blhost-$PLATFORM;
49 | else
50 | mv validation/blhost/gcc/Release/blhost blhost-linux-$PLATFORM;
51 | fi
52 |
53 | deploy:
54 | provider: releases
55 | api_key:
56 | secure: QqRXxTWE3ZxY6Jr6cFbOSMKhoDVHpE7tOGl3EcbgOfQ8oWczgN3xgoXQKKictK4hjXeX+9GuBIhHMdCLHalZ3EOyelNEG/UJ8bE7h3XWPB2Qp7jzgRriM1NvDo7uhvqoAAQr05ZQVBWyKsS980rLxncDlmRLVJbH8RmvlwB0PRVd1AOUsdkTbK9FkiWb/DpAsK21GLn6B/A+31SHqprXneivrFaQ+aNpyRvB9u3xOWEZ8xu68xwGl+xQvr5H+uvYfrgYgkxOoIXOjDFi3bEZ2gIA9ntSBM8J9veFlWnoO5Yr3sQuZRhBZBCVWykfAggvq1dx8hMAMCfNWPBM6SH3UJfi9sChurId75S5MstJec7w4STMfKQmhJvKvs985JAyAkSzdNOLYXwBvR94U+UEpLFN1RNESadnQY/+1t36Egy6b5lN+5G1cSeRNQXpvoNXr61XdTaDWaX/Fag3KNzc43QJJJ1bDwO15g9epNGVCmUQGIZ1dGakz/H6jjiXMaLSHh4VIKevhf5lUIQ/Qz6+MdT+tPX9jEX7jWbGQ87/eys+zRal6K1LmaQVhks1Hm8x4eyXdjaY7VuYjbkPUWeqJGdQ2cIAFICSZw+xCxokQzGVWL28Y6a47dB3cUsPyvTO/lqsXB4JKwyIGighLkoBEj7GpSmlGMvximFnltXy7BY=
57 | file_glob: true
58 | file: "blhost-*"
59 | skip_cleanup: true
60 | on:
61 | tags: true
62 |
--------------------------------------------------------------------------------
/src/blfwk/src/Value.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "blfwk/Value.h"
32 |
33 | using namespace blfwk;
34 |
35 | //! Returns a varying size depending on the word size attribute.
36 | //!
37 | size_t SizedIntegerValue::getSize() const
38 | {
39 | switch (m_size)
40 | {
41 | case kWordSize:
42 | return sizeof(uint32_t);
43 | case kHalfWordSize:
44 | return sizeof(uint16_t);
45 | case kByteSize:
46 | return sizeof(uint8_t);
47 | }
48 | return kWordSize;
49 | }
50 |
51 | //! The resulting mask can be used to truncate the integer value to be
52 | //! certain it doesn't extend beyond the associated word size.
53 | uint32_t SizedIntegerValue::getWordSizeMask() const
54 | {
55 | switch (m_size)
56 | {
57 | case kWordSize:
58 | return 0xffffffff;
59 | case kHalfWordSize:
60 | return 0x0000ffff;
61 | case kByteSize:
62 | return 0x000000ff;
63 | }
64 | return 0;
65 | }
66 |
--------------------------------------------------------------------------------
/src/bootloader/flashloader_image.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(__FLASHLOADER_IMAGE_H__)
31 | #define __FLASHLOADER_IMAGE_H__
32 |
33 | //! @addtogroup flashloader
34 | //! @{
35 |
36 | //! @name Flashloader globals
37 | //@{
38 |
39 | //! @brief Image of flashloader to load to RAM, in raw binary format.
40 | extern const uint8_t g_flashloaderImage[];
41 |
42 | //! @brief Size of flashloader image.
43 | extern const uint32_t g_flashloaderSize;
44 |
45 | //! @brief Base address in RAM of flashloader image.
46 | extern const uint32_t g_flashloaderBase;
47 |
48 | //! @brief Entry point of flashloader image.
49 | extern const uint32_t g_flashloaderEntry;
50 |
51 | //! @brief Stack limit of flashloader image.
52 | extern const uint32_t g_flashloaderStack;
53 |
54 | //@}
55 |
56 | //! @}
57 |
58 | #endif // __FLASHLOADER_IMAGE_H__
59 | ////////////////////////////////////////////////////////////////////////////////
60 | // EOF
61 | ////////////////////////////////////////////////////////////////////////////////
62 |
--------------------------------------------------------------------------------
/src/blfwk/utils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _utils_h_
32 | #define _utils_h_
33 |
34 | #include
35 | #include
36 |
37 | namespace utils
38 | {
39 | //! @brief Split a string into tokens by delimiter.
40 | std::vector string_split(const std::string &s, char delim);
41 |
42 | //! @brief Remove all except hex digits from a string.
43 | std::string string_hex(const std::string &s);
44 |
45 | //! @brief Check if a string is signed a number. If so, return number.
46 | bool stringtoi(const std::string &s, int32_t &number);
47 |
48 | //! @brief Check if a string is an unsigned number. If so, return number.
49 | bool stringtoui(const std::string &s, uint32_t &number);
50 |
51 | //! @brief Format bytes into GB, MB, KB, or bytes.
52 | std::string scale_bytes(uint64_t sizeInBytes);
53 |
54 | } // namespace utils
55 |
56 | #endif // _utils_h_
57 |
58 | ////////////////////////////////////////////////////////////////////////////////
59 | // EOF
60 | ////////////////////////////////////////////////////////////////////////////////
61 |
--------------------------------------------------------------------------------
/src/utilities/fsl_assert.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(__FSL_ASSERT_H__)
31 | #define __FSL_ASSERT_H__
32 |
33 | //! @addtogroup fsl_assert
34 | //! @{
35 |
36 | #ifdef BOOTLOADER_HOST
37 | // Use standard assert for Host
38 | #include
39 |
40 | #else
41 | #if !defined(assert)
42 | #if defined(DEBUG)
43 | #define assert(test) ((test) ? (void)0 : fsl_assert())
44 | #else
45 | #define assert(x) ((void)0)
46 | #endif
47 | #endif
48 |
49 | //! @brief This is implemented to simplify debugging when hitting an assert. It disables
50 | //! all interrupts and spins forever. When debugging it will still show a relevant call
51 | //! stack unlike the provided assert which would take a few more manual steps to give you
52 | //! the same info.
53 | void fsl_assert(void);
54 | #endif // BOOTLOADER_HOST
55 |
56 | //! @}
57 |
58 | #endif // __FSL_ASSERT_H__
59 | ////////////////////////////////////////////////////////////////////////////////
60 | // EOF
61 | ////////////////////////////////////////////////////////////////////////////////
62 |
--------------------------------------------------------------------------------
/src/bootloader/bl_version.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef __BL_VERSION_H__
32 | #define __BL_VERSION_H__
33 |
34 | #include "bootloader_common.h"
35 | #include "bootloader/bl_peripheral.h"
36 | #include "memory/memory.h"
37 | #include "packet/command_packet.h"
38 | #include "bootloader/bl_command.h"
39 | #include "property/property.h"
40 |
41 | //! @addtogroup context
42 | //! @{
43 |
44 | ////////////////////////////////////////////////////////////////////////////////
45 | // Definitions
46 | ////////////////////////////////////////////////////////////////////////////////
47 |
48 | //! @brief Version constants for the bootloader.
49 | enum _bootloader_version_constants
50 | {
51 | kBootloader_Version_Name = 'K',
52 | kBootloader_Version_Major = 2,
53 | kBootloader_Version_Minor = 0,
54 | kBootloader_Version_Bugfix = 0
55 | };
56 |
57 | //! @}
58 |
59 | #endif // __BL_VERSION_H__
60 | ////////////////////////////////////////////////////////////////////////////////
61 | // EOF
62 | ////////////////////////////////////////////////////////////////////////////////
63 |
--------------------------------------------------------------------------------
/src/utilities/kinetis_family.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #ifndef __KINETIS_FAMILY_H__
31 | #define __KINETIS_FAMILY_H__
32 |
33 | ////////////////////////////////////////////////////////////////////////////////
34 | // Definitions
35 | ////////////////////////////////////////////////////////////////////////////////
36 |
37 | //! @brief Family ID used for determine which family a specific chip belongs to
38 | enum
39 | {
40 | kFAMID_KL0x = 0,
41 | kFAMID_KL1x = 1,
42 | kFAMID_KL2x = 2,
43 | kFAMID_KL3x = 3,
44 | kFAMID_KL4x = 4
45 | };
46 |
47 | enum
48 | {
49 | kFAMID_K0x = 0,
50 | kFAMID_K1x = 1,
51 | kFAMID_K2x = 2,
52 | kFAMID_K3x = 3,
53 | kFAMID_K4x = 4,
54 | kFAMID_K5x = 5,
55 | kFAMID_K6x = 6,
56 | kFAMID_K7x = 7
57 | };
58 |
59 | enum
60 | {
61 | kSUBFAMID_KEx4 = 4,
62 | kSUBFAMID_KEx5 = 5,
63 | kSUBFAMID_KEx6 = 6,
64 | kSUBFAMID_KEx7 = 7,
65 | kSUBFAMID_KEx8 = 8
66 | };
67 |
68 | #endif // __KINETIS_FAMILY_H__
69 | ////////////////////////////////////////////////////////////////////////////////
70 | // EOF
71 | ////////////////////////////////////////////////////////////////////////////////
72 |
--------------------------------------------------------------------------------
/src/blfwk/src/AESKey.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: AESKey.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/AESKey.h"
9 | #include
10 | #include "blfwk/smart_ptr.h"
11 | #include "blfwk/HexValues.h"
12 | #include
13 |
14 | //! The data from the stream is expected to be hex encoded. Each two characters
15 | //! from the stream encode a single result byte. All non-hexadecimal characters
16 | //! are ignored, including newlines. Every two hexadecimal characters form
17 | //! an encoded byte. This is true even if the two characters representing the
18 | //! upper and lower nibbles are separated by whitespace or other characters.
19 | //!
20 | //! \post The stream read head is left pointing just after the last encoded byte.
21 | //!
22 | //! \param stream Input stream to read from.
23 | //! \param bytes Number of encoded bytes to read. This is the number of \e
24 | //! result bytes, not the count of bytes to read from the stream.
25 | //! \param[out] buffer Pointer to the buffer where decoded data is written.
26 | //!
27 | //! \exception std::runtime_error This exception will be thrown if less
28 | //! data than required is available from \a stream, or if some other
29 | //! error occurs while reading from \a stream.
30 | void AESKeyBase::_readFromStream(std::istream &stream, unsigned bytes, uint8_t *buffer) const
31 | {
32 | char temp[2];
33 | char c;
34 | char n = 0;
35 |
36 | while (bytes)
37 | {
38 | if (stream.get(c).fail())
39 | {
40 | throw std::runtime_error("not enough data in stream");
41 | }
42 |
43 | if (isHexDigit(c))
44 | {
45 | temp[n++] = c;
46 | if (n == 2)
47 | {
48 | *buffer++ = hexByteToInt(temp);
49 | bytes--;
50 | n = 0;
51 | }
52 | }
53 | }
54 | }
55 |
56 | //! Key data is written to \a stream as a sequence of hex encoded octets, each two
57 | //! characters long. No spaces or newlines are inserted between the encoded octets
58 | //! or at the end of the sequence.
59 | //!
60 | //! \exception std::runtime_error Thrown if the \a stream reports an error while
61 | //! writing the key data.
62 | void AESKeyBase::_writeToStream(std::ostream &stream, unsigned bytes, const uint8_t *buffer) const
63 | {
64 | const char hexChars[] = "0123456789ABCDEF";
65 | while (bytes--)
66 | {
67 | uint8_t thisByte = *buffer++;
68 | char byteString[2];
69 | byteString[0] = hexChars[(thisByte & 0xf0) >> 4];
70 | byteString[1] = hexChars[thisByte & 0x0f];
71 | if (stream.write(byteString, 2).bad())
72 | {
73 | throw std::runtime_error("error while writing to stream");
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/blfwk/src/AESCounter.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: AESCounter.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/AESCounter.h"
9 | #include
10 | #include "blfwk/smart_ptr.h"
11 | #include "blfwk/HexValues.h"
12 | #include
13 |
14 | //! The data from the stream is expected to be hex encoded. Each two characters
15 | //! from the stream encode a single result byte. All non-hexadecimal characters
16 | //! are ignored, including newlines. Every two hexadecimal characters form
17 | //! an encoded byte. This is true even if the two characters representing the
18 | //! upper and lower nibbles are separated by whitespace or other characters.
19 | //!
20 | //! \post The stream read head is left pointing just after the last encoded byte.
21 | //!
22 | //! \param stream Input stream to read from.
23 | //! \param bytes Number of encoded bytes to read. This is the number of \e
24 | //! result bytes, not the count of bytes to read from the stream.
25 | //! \param[out] buffer Pointer to the buffer where decoded data is written.
26 | //!
27 | //! \exception std::runtime_error This exception will be thrown if less
28 | //! data than required is available from \a stream, or if some other
29 | //! error occurs while reading from \a stream.
30 | void AESCounterBase::_readFromStream(std::istream &stream, unsigned bytes, uint8_t *buffer)
31 | {
32 | char temp[2];
33 | char c;
34 | char n = 0;
35 |
36 | while (bytes)
37 | {
38 | if (stream.get(c).fail())
39 | {
40 | throw std::runtime_error("not enough data in stream");
41 | }
42 |
43 | if (isHexDigit(c))
44 | {
45 | temp[n++] = c;
46 | if (n == 2)
47 | {
48 | *buffer++ = hexByteToInt(temp);
49 | bytes--;
50 | n = 0;
51 | }
52 | }
53 | }
54 | }
55 |
56 | //! Counter data is written to \a stream as a sequence of hex encoded octets, each two
57 | //! characters long. No spaces or newlines are inserted between the encoded octets
58 | //! or at the end of the sequence.
59 | //!
60 | //! \exception std::runtime_error Thrown if the \a stream reports an error while
61 | //! writing the key data.
62 | void AESCounterBase::_writeToStream(std::ostream &stream, unsigned bytes, const uint8_t *buffer) const
63 | {
64 | const char hexChars[] = "0123456789ABCDEF";
65 | while (bytes--)
66 | {
67 | uint8_t thisByte = *buffer++;
68 | char byteString[2];
69 | byteString[0] = hexChars[(thisByte & 0xf0) >> 4];
70 | byteString[1] = hexChars[thisByte & 0x0f];
71 | if (stream.write(byteString, 2).bad())
72 | {
73 | throw std::runtime_error("error while writing to stream");
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/blfwk/src/Crc.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-15, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "blfwk/Crc.h"
32 | #include "bootloader/bootloader.h"
33 | #include "crc/crc32.h"
34 |
35 | using namespace blfwk;
36 |
37 | // See Crc.h for documentation of this method.
38 | uint32_t Crc::calculate_application_crc32(const uint8_t *start, uint32_t length)
39 | {
40 | uint32_t crc32;
41 |
42 | // Initialize the CRC32 information
43 | crc32_data_t crcInfo;
44 | crc32_init(&crcInfo);
45 |
46 | // Run CRC, Considering skip crcExpectedValue address
47 | const bootloader_configuration_data_t *config =
48 | NULL; // Just used for calculate the offset, must not change the region it points to.
49 | uint32_t bypassStartAddress = 0x3C0 + ((uint32_t)&config->crcExpectedValue - (uint32_t)&config->tag);
50 | uint32_t bypassEndAddress = bypassStartAddress + sizeof(config->crcExpectedValue);
51 |
52 | if (length <= bypassStartAddress)
53 | {
54 | crc32_update(&crcInfo, (uint8_t *)start, length);
55 | }
56 | else
57 | {
58 | // Assume that crcExpectedValue address (4 byte) resides in crc addresses completely
59 | crc32_update(&crcInfo, (uint8_t *)start, bypassStartAddress);
60 | crc32_update(&crcInfo, (uint8_t *)(start + bypassEndAddress), length - bypassEndAddress);
61 | }
62 |
63 | // Finalize the CRC calculations
64 | crc32_finalize(&crcInfo, &crc32);
65 |
66 | return crc32;
67 | }
68 |
--------------------------------------------------------------------------------
/src/utilities/vector_table_info.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(__VECTOR_TABLE_INFO_H__)
31 | #define __VECTOR_TABLE_INFO_H__
32 |
33 | #include "bootloader_config.h"
34 |
35 | //! @addtogroup vector_table_info
36 | //! @{
37 |
38 | ////////////////////////////////////////////////////////////////////////////////
39 | // Definitions
40 | ////////////////////////////////////////////////////////////////////////////////
41 |
42 | //! @brief Defines a constant for the default vector table.
43 | enum _vector_table_address
44 | {
45 | //! @brief Address of the default vector table, which is always 0.
46 | kDefaultVectorTableAddress = 0
47 | };
48 |
49 | #if (BL_TARGET_FLASH)
50 | //! @brief Pointer to the application vector table, which is always at the
51 | //! end of the bootloader region in flash.
52 | #define APP_VECTOR_TABLE ((uint32_t *)BL_APP_VECTOR_TABLE_ADDRESS)
53 | #else
54 | //! @brief Pointer to the bootloader vector table, which is always at address 0.
55 | #define APP_VECTOR_TABLE ((uint32_t *)kDefaultVectorTableAddress)
56 | #endif
57 |
58 | //! @brief Constants for the entries of the vector table.
59 | enum _vector_table_entries
60 | {
61 | kInitialSP = 0, //!< Initial stack pointer.
62 | kInitialPC //!< Reset vector.
63 | };
64 |
65 | //! @}
66 |
67 | #endif // __VECTOR_TABLE_INFO_H__
68 | ////////////////////////////////////////////////////////////////////////////////
69 | // EOF
70 | ////////////////////////////////////////////////////////////////////////////////
71 |
--------------------------------------------------------------------------------
/src/bootloader/bl_user_entry.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(__BL_USER_ENTRY_H__)
31 | #define __BL_USER_ENTRY_H__
32 |
33 | //! @addtogroup context
34 | //! @{
35 |
36 | ////////////////////////////////////////////////////////////////////////////////
37 | // Definitions
38 | ////////////////////////////////////////////////////////////////////////////////
39 |
40 | #if defined(__cplusplus)
41 | extern "C" {
42 | #endif
43 |
44 | //! @name Bootloader Entry Point
45 | //@{
46 |
47 | //! @brief Entry point called by a user application to run the bootloader.
48 | //!
49 | //! For ROM targets, this function configures the RCM_FM register so that the ROM
50 | //! will execute automatically out of reset. Then the system is reset.
51 | //!
52 | //! Flash-resident configurations just call the reset handler as the entry point,
53 | //! since there is no way to automatically get back into the bootloader out of
54 | //! reset (or at least no guaranteed way).
55 | //!
56 | //! @param arg For future expansion. Currently unused.
57 | //!
58 | //! @todo For flash-resident configs, put the system into a known state. For example,
59 | //! by disabling all IRQs in NVIC.
60 | void bootloader_user_entry(void *arg);
61 |
62 | //@}
63 |
64 | #if defined(__cplusplus)
65 | }
66 | #endif
67 |
68 | //! @}
69 |
70 | #endif // __BL_USER_ENTRY_H__
71 | ////////////////////////////////////////////////////////////////////////////////
72 | // EOF
73 | ////////////////////////////////////////////////////////////////////////////////
74 |
--------------------------------------------------------------------------------
/src/blfwk/SearchPath.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_searchpath_h_)
31 | #define _searchpath_h_
32 |
33 | #include
34 | #include
35 |
36 | /*!
37 | * \brief Handles searching a list of paths for a file.
38 | */
39 | class PathSearcher
40 | {
41 | public:
42 | //!
43 | enum _target_type
44 | {
45 | kFindFile,
46 | kFindDirectory
47 | };
48 |
49 | //!
50 | typedef enum _target_type target_type_t;
51 |
52 | protected:
53 | //! Global search object singleton.
54 | static PathSearcher *s_searcher;
55 |
56 | public:
57 | //! \brief Access global path searching object.
58 | static PathSearcher &getGlobalSearcher();
59 |
60 | public:
61 | //! \brief Constructor.
62 | PathSearcher() {}
63 | //! \brief Add a new search path to the end of the list.
64 | void addSearchPath(std::string &path);
65 |
66 | //! \brief Attempts to locate a file by using the search paths.
67 | bool search(const std::string &base, target_type_t targetType, bool searchCwd, std::string &result);
68 |
69 | protected:
70 | typedef std::list string_list_t; //!< Linked list of strings.
71 | string_list_t m_paths; //!< Ordered list of paths to search.
72 |
73 | //! \brief Returns whether \a path is absolute.
74 | bool isAbsolute(const std::string &path);
75 |
76 | //! \brief Combines two paths into a single one.
77 | std::string joinPaths(const std::string &first, const std::string &second);
78 | };
79 |
80 | #endif // _searchpath_h_
81 |
--------------------------------------------------------------------------------
/src/blfwk/src/Blob.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: Blob.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/Blob.h"
9 | #include
10 | #include
11 | #include
12 |
13 | Blob::Blob()
14 | : m_data(0)
15 | , m_length(0)
16 | {
17 | }
18 |
19 | //! Makes a local copy of the \a data argument.
20 | //!
21 | Blob::Blob(const uint8_t *data, unsigned length)
22 | : m_data(0)
23 | , m_length(length)
24 | {
25 | m_data = reinterpret_cast(malloc(length));
26 | memcpy(m_data, data, length);
27 | }
28 |
29 | //! Makes a local copy of the data owned by \a other.
30 | //!
31 | Blob::Blob(const Blob &other)
32 | : m_data(0)
33 | , m_length(other.m_length)
34 | {
35 | m_data = reinterpret_cast(malloc(m_length));
36 | memcpy(m_data, other.m_data, m_length);
37 | }
38 |
39 | //! Disposes of the binary data associated with this object.
40 | Blob::~Blob()
41 | {
42 | if (m_data)
43 | {
44 | free(m_data);
45 | }
46 | }
47 |
48 | //! Copies \a data onto the blob's data. The blob does not assume ownership
49 | //! of \a data.
50 | //!
51 | //! \param data Pointer to a buffer containing the data which will be copied
52 | //! into the blob.
53 | //! \param length Number of bytes pointed to by \a data.
54 | void Blob::setData(const uint8_t *data, unsigned length)
55 | {
56 | setLength(length);
57 | memcpy(m_data, data, length);
58 | }
59 |
60 | //! Sets the #m_length member variable to \a length and resizes #m_data to
61 | //! the new length. The contents of #m_data past any previous contents are undefined.
62 | //! If the new \a length is 0 then the data will be freed and a subsequent call
63 | //! to getData() will return NULL.
64 | //!
65 | //! \param length New length of the blob's data in bytes.
66 | void Blob::setLength(unsigned length)
67 | {
68 | if (length == 0)
69 | {
70 | clear();
71 | return;
72 | }
73 |
74 | // Allocate new block.
75 | if (!m_data)
76 | {
77 | m_data = reinterpret_cast(malloc(length));
78 | if (!m_data)
79 | {
80 | throw std::runtime_error("failed to allocate memory");
81 | }
82 | }
83 | // Reallocate previous block.
84 | else
85 | {
86 | void *newBlob = realloc(m_data, length);
87 | if (!newBlob)
88 | {
89 | throw std::runtime_error("failed to reallocate memory");
90 | }
91 | m_data = reinterpret_cast(newBlob);
92 | }
93 |
94 | // Set length.
95 | m_length = length;
96 | }
97 |
98 | void Blob::append(const uint8_t *newData, unsigned newDataLength)
99 | {
100 | unsigned oldLength = m_length;
101 |
102 | setLength(m_length + newDataLength);
103 |
104 | memcpy(m_data + oldLength, newData, newDataLength);
105 | }
106 |
107 | void Blob::clear()
108 | {
109 | if (m_data)
110 | {
111 | free(m_data);
112 | m_data = NULL;
113 | }
114 |
115 | m_length = 0;
116 | }
117 |
118 | void Blob::relinquish()
119 | {
120 | m_data = NULL;
121 | m_length = 0;
122 | }
123 |
--------------------------------------------------------------------------------
/src/bm_usb/bootloader_hid_report_ids.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(__BOOTLOADER_HID_REPORT_IDS_H__)
31 | #define __BOOTLOADER_HID_REPORT_IDS_H__
32 |
33 | #include "packet/command_packet.h"
34 |
35 | ////////////////////////////////////////////////////////////////////////////////
36 | // Definitions
37 | ////////////////////////////////////////////////////////////////////////////////
38 |
39 | //! @brief Report IDs to use for the bootloader.
40 | enum _hid_report_ids
41 | {
42 | kBootloaderReportID_CommandOut = 1,
43 | kBootloaderReportID_DataOut = 2,
44 | kBootloaderReportID_CommandIn = 3,
45 | kBootloaderReportID_DataIn = 4
46 | };
47 |
48 | //! @brief Structure of a bootloader HID header.
49 | typedef struct _bl_hid_header
50 | {
51 | uint8_t reportID; //!< The report ID.
52 | uint8_t _padding; //!< Pad byte necessary so that the length is 2-byte aligned and the data is 4-byte aligned. Set
53 | //! to zero.
54 | uint8_t packetLengthLsb; //!< Low byte of the packet length in bytes.
55 | uint8_t packetLengthMsb; //!< High byte of the packet length in bytes.
56 | } bl_hid_header_t;
57 |
58 | //! @brief Structure of a bootloader HID report.
59 | typedef struct _bl_hid_report
60 | {
61 | bl_hid_header_t header; //!< Header of the report.
62 | uint8_t packet[kMinPacketBufferSize]; //!< The packet data that is transferred in the report.
63 | } bl_hid_report_t;
64 |
65 | #endif // __BOOTLOADER_HID_REPORT_IDS_H__
66 | ////////////////////////////////////////////////////////////////////////////////
67 | // EOF
68 | ////////////////////////////////////////////////////////////////////////////////
69 |
--------------------------------------------------------------------------------
/src/picocom/termios2.h:
--------------------------------------------------------------------------------
1 | /*
2 | * termios2.h
3 | *
4 | * Use termios2 interface to set custom baud rates to serial ports.
5 | *
6 | * by Nick Patavalis (npat@efault.net)
7 | *
8 | * ATTENTION: Linux-specific kludge!
9 | *
10 | * This program is free software; you can redistribute it and/or
11 | * modify it under the terms of the GNU General Public License as
12 | * published by the Free Software Foundation; either version 2 of the
13 | * License, or (at your option) any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful, but
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 | * General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program; if not, write to the Free Software
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 | * USA
24 | */
25 |
26 | #ifndef TERMIOS2_H
27 | #define TERMIOS2_H
28 |
29 | #include
30 |
31 | /* Replace termios functions, with termios2 functions */
32 | #define tcsetattr tc2setattr
33 | #define tcgetattr tc2getattr
34 | #define cfsetispeed cf2setispeed
35 | #define cfgetispeed cf2getispeed
36 |
37 | /* And define these new ones */
38 | #define cfsetospeed_custom cf2setospeed_custom
39 | #define cfsetispeed_custom cf2setispeed_custom
40 | #define cfgetospeed_custom(tiop) ((tiop)->c_ospeed)
41 | #define cfgetispeed_custom(tiop) ((tiop)->c_ispeed)
42 |
43 | /* Replacements for the standard tcsetattr(3), tcgetattr(3)
44 | * functions. Same user interface, but these use the new termios2
45 | * kernel interface (new ioctl's) which allow custom baud-rate
46 | * setting. */
47 |
48 | int tc2setattr(int fd, int optional_actions, const struct termios *tios);
49 | int tc2getattr(int fd, struct termios *tios);
50 |
51 | /* Replacements for the standard cfgetispeed(3), cfsetispeed(3)
52 | * functions. Use these to set / get standard *input* baudrates. You
53 | * can still use cfgetospeed(3), cfsetospeed(3) to set / get the
54 | * standard output baudrates. The new termios2 interface, unlike the
55 | * old one, supports different input and output speeds for a
56 | * device. The "speed" argument must be (and the return value will be)
57 | * one of the standard "Bxxxx" macros. If cf2getispeed() or
58 | * cfgetospeed(3) return BOTHER, then the respective baudrate is a
59 | * custom one. Read the "termios.c_ispeed" / "termios.c_ospeed" fields
60 | * to get the custom value (as a numeric speed). */
61 |
62 | int cf2setispeed(struct termios *tios, speed_t speed);
63 | speed_t cf2getispeed(const struct termios *tios);
64 |
65 | /* Use these to set *custom* input and output baudrates for a
66 | * device. The "speed" argument must be a numeric baudrate value
67 | * (e.g. 1234 for 1234 bps). */
68 |
69 | int cf2setispeed_custom(struct termios *tios, int speed);
70 | int cf2setospeed_custom(struct termios *tios, int speed);
71 |
72 | /***************************************************************************/
73 |
74 | #endif /* of TERMIOS2_H */
75 |
76 | /***************************************************************************/
77 |
78 | /*
79 | * Local Variables:
80 | * mode:c
81 | * tab-width: 4
82 | * c-basic-offset: 4
83 | * End:
84 | */
85 |
--------------------------------------------------------------------------------
/src/blfwk/OptionContext.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_OptionContext_h_)
31 | #define _OptionContext_h_
32 |
33 | #include
34 | #include "Value.h"
35 |
36 | namespace blfwk
37 | {
38 | /*!
39 | * \brief Pure abstract interface class to a table of options.
40 | */
41 | class OptionContext
42 | {
43 | public:
44 | //! @brief Force a virtual destructor.
45 | virtual ~OptionContext() {}
46 | //! \brief Detemine whether the named option is present in the table.
47 | //! \param name The name of the option to query.
48 | //! \retval true The option is present and has a value.
49 | //! \retval false No option with that name is in the table.
50 | virtual bool hasOption(const std::string &name) const = 0;
51 |
52 | //! \brief Returns the option's value.
53 | //! \param name The name of the option.
54 | //! \return The value for the option named \a name.
55 | //! \retval NULL No option is in the table with that name.
56 | virtual const Value *getOption(const std::string &name) const = 0;
57 |
58 | //! \brief Adds or changes an option's value.
59 | //!
60 | //! If the option was not already present in the table, it is added.
61 | //! Otherwise the old value is replaced.
62 | //!
63 | //! \param name The option's name.
64 | //! \param value New value for the option.
65 | virtual void setOption(const std::string &name, Value *value) = 0;
66 |
67 | //! \brief Removes an option from the table.
68 | //! \param name The name of the option to remove.
69 | virtual void deleteOption(const std::string &name) = 0;
70 | };
71 |
72 | }; // namespace blfwk
73 |
74 | #endif // _OptionContext_h_
75 |
--------------------------------------------------------------------------------
/src/blfwk/StringMatcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_StringMatcher_h_)
31 | #define _StringMatcher_h_
32 |
33 | #include
34 |
35 | namespace blfwk
36 | {
37 | /*!
38 | * \brief Abstract interface class used to select strings by name.
39 | */
40 | class StringMatcher
41 | {
42 | public:
43 | //! \brief Performs a single string match test against testValue.
44 | //!
45 | //! \retval true The \a testValue argument matches.
46 | //! \retval false No match was made against the argument.
47 | virtual bool match(const std::string &testValue) = 0;
48 | };
49 |
50 | /*!
51 | * \brief String matcher subclass that matches all test strings.
52 | */
53 | class WildcardMatcher : public StringMatcher
54 | {
55 | public:
56 | //! \brief Always returns true, indicating a positive match.
57 | virtual bool match(const std::string &testValue) { return true; }
58 | };
59 |
60 | /*!
61 | * \brief Simple string matcher that compares against a fixed value.
62 | */
63 | class FixedMatcher : public StringMatcher
64 | {
65 | public:
66 | //! \brief Constructor. Sets the string to compare against to be \a fixedValue.
67 | FixedMatcher(const std::string &fixedValue)
68 | : m_value(fixedValue)
69 | {
70 | }
71 |
72 | //! \brief Returns whether \a testValue is the same as the value passed to the constructor.
73 | //!
74 | //! \retval true The \a testValue argument matches the fixed compare value.
75 | //! \retval false The argument is not the same as the compare value.
76 | virtual bool match(const std::string &testValue) { return testValue == m_value; }
77 | protected:
78 | const std::string &m_value; //!< The section name to look for.
79 | };
80 |
81 | }; // namespace blfwk
82 |
83 | #endif // _StringMatcher_h_
84 |
--------------------------------------------------------------------------------
/src/picocom/custbaud_bsd.h:
--------------------------------------------------------------------------------
1 | /*
2 | * custbaud_bsd.h
3 | *
4 | * Custom baud rate support for BSD and macOS.
5 | *
6 | * by Joe Merten (https://github.com/JoeMerten www.jme.de)
7 | *
8 | * ATTENTION: BSD and macOS specific stuff!
9 | *
10 | * This program is free software; you can redistribute it and/or
11 | * modify it under the terms of the GNU General Public License as
12 | * published by the Free Software Foundation; either version 2 of the
13 | * License, or (at your option) any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful, but
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 | * General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program; if not, write to the Free Software
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 | * USA
24 | */
25 |
26 | #ifndef CUSTBAUD_BSD_H
27 | #define CUSTBAUD_BSD_H
28 |
29 | #include
30 |
31 | /***************************************************************************/
32 |
33 | /* macOS termios.h unfortunately just provides constants for baudrates
34 | * up to 230k, so we add the missing constants here. Regardless, that
35 | * most of the high baudrates needs special handling (implementation in
36 | * tcsetattr_custom()), we want to provide the values here to have them
37 | * available for term_baud_up()/down().
38 | *
39 | * FreeBSD 11.0 termios.h has 460k and 921k but misses e.g. 500k and >=1M.
40 | * OpenBSD 6.2 termios.h is missing all >230k (like macOS).
41 | * NetBSD 7.1.1 do same as FreeBSD 11.0.
42 | * DragonFly 5.0.2 looks same as OpenBSD 6.2.
43 | */
44 |
45 | #if defined(HIGH_BAUD)
46 |
47 | #ifndef B460800
48 | #define B460800 460800
49 | #endif
50 | #ifndef B500000
51 | #define B500000 500000
52 | #endif
53 | #ifndef B576000
54 | #define B576000 576000
55 | #endif
56 | #ifndef B921600
57 | #define B921600 921600
58 | #endif
59 | #ifndef B1000000
60 | #define B1000000 1000000
61 | #endif
62 | #ifndef B1152000
63 | #define B1152000 1152000
64 | #endif
65 | #ifndef B1500000
66 | #define B1500000 1500000
67 | #endif
68 | #ifndef B2000000
69 | #define B2000000 2000000
70 | #endif
71 | #ifndef B2500000
72 | #define B2500000 2500000
73 | #endif
74 | #ifndef B3000000
75 | #define B3000000 3000000
76 | #endif
77 | #ifndef B3500000
78 | #define B3500000 3500000
79 | #endif
80 | #ifndef B4000000
81 | #define B4000000 4000000
82 | #endif
83 |
84 | #endif /* HIGH_BAUD */
85 |
86 | /***************************************************************************/
87 |
88 | int cfsetospeed_custom(struct termios *tiop, int speed);
89 | int cfsetispeed_custom(struct termios *tiop, int speed);
90 | int cfgetospeed_custom(const struct termios *tiop);
91 | int cfgetispeed_custom(const struct termios *tiop);
92 |
93 | /***************************************************************************/
94 |
95 | #ifdef __APPLE__
96 | /* Replace tcsetattr function with our macOS specific one */
97 | #define tcsetattr tcsetattr_custom
98 | int tcsetattr_custom(int fd, int optional_actions, const struct termios *tiop);
99 | #endif
100 |
101 | /***************************************************************************/
102 |
103 | #endif /* CUSTBAUD_BSD_H */
104 |
--------------------------------------------------------------------------------
/src/blfwk/Blob.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_Blob_h_)
31 | #define _Blob_h_
32 |
33 | #include "stdafx.h"
34 |
35 | //! \class Blob
36 | //!
37 | //! \brief Manages a binary object of arbitrary length.
38 | //!
39 | //! The data block is allocated with malloc() instead of the new
40 | //! operator so that we can use realloc() to resize it.
41 | //!
42 | class Blob
43 | {
44 | public:
45 | //! \brief Default constructor.
46 | Blob();
47 |
48 | //! \brief Constructor.
49 | Blob(const uint8_t *data, unsigned length);
50 |
51 | //! \brief Copy constructor.
52 | Blob(const Blob &other);
53 |
54 | //! \brief Destructor.
55 | virtual ~Blob();
56 |
57 | //! \name Operations
58 | //@{
59 | //! \brief Replaces the blob's data.
60 | void setData(const uint8_t *data, unsigned length);
61 |
62 | //! \brief Change the size of the blob's data.
63 | void setLength(unsigned length);
64 |
65 | //! \brief Adds data to the end of the blob.
66 | void append(const uint8_t *newData, unsigned newDataLength);
67 |
68 | //! \brief Disposes of the data.
69 | void clear();
70 |
71 | //! \brief Tell the blob that it no longer owns its data.
72 | void relinquish();
73 | //@}
74 |
75 | //! \name Accessors
76 | //@{
77 | uint8_t *getData() { return m_data; }
78 | const uint8_t *getData() const { return m_data; }
79 | unsigned getLength() const { return m_length; }
80 | //@}
81 |
82 | //! \name Operators
83 | //@{
84 | operator uint8_t *() { return m_data; }
85 | operator const uint8_t *() const { return m_data; }
86 | //@}
87 |
88 | protected:
89 | uint8_t *m_data; //!< The binary data held by this object.
90 | unsigned m_length; //!< Number of bytes pointed to by #m_data.
91 | };
92 |
93 | #endif // _Blob_h_
94 |
--------------------------------------------------------------------------------
/src/blfwk/SimPeripheral.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _sim_peripheral_h_
32 | #define _sim_peripheral_h_
33 |
34 | #include "blfwk/Peripheral.h"
35 |
36 | namespace blfwk
37 | {
38 | /*!
39 | * @brief Peripheral that operates in the simulation space.
40 | *
41 | * Simulation peripherals are connected together using the streams provided to the init() method.
42 | * For example, to connect a "host" peripheral to a "device" peripheral, specify the host's output
43 | * stream as the device's input stream.
44 | */
45 | class SimPeripheral : public Peripheral
46 | {
47 | public:
48 | //! @brief Default Constructor.
49 | SimPeripheral(uchar_deque_t *inStream, uchar_deque_t *outStream)
50 | : m_inStream(inStream)
51 | , m_outStream(outStream)
52 | {
53 | }
54 |
55 | //! @brief Read bytes.
56 | //!
57 | //! @param buffer Pointer to buffer.
58 | //! @param requestedBytes Number of bytes to read.
59 | //! @param actualBytes Number of bytes actually read.
60 | //! @param timeoutMs Time in milliseconds to wait for read to complete.
61 | virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeoutMs);
62 |
63 | //! @brief Write bytes.
64 | //!
65 | //! @param buffer Pointer to buffer to write
66 | //! @param byteCount Number of bytes to write
67 | virtual status_t write(const uint8_t *buffer, uint32_t byteCount);
68 |
69 | protected:
70 | uchar_deque_t *m_inStream; //!< Writes go to this stream.
71 | uchar_deque_t *m_outStream; //!< Reads come from this stream.
72 | };
73 |
74 | } // namespace blfwk
75 |
76 | #endif // _sim_peripheral_h_
77 |
78 | ////////////////////////////////////////////////////////////////////////////////
79 | // EOF
80 | ////////////////////////////////////////////////////////////////////////////////
81 |
--------------------------------------------------------------------------------
/src/bootloader/bl_shutdown_cleanup.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(__SHUTDOWN_CLEANUP_H__)
31 | #define __SHUTDOWN_CLEANUP_H__
32 |
33 | #include "bootloader_common.h"
34 |
35 | //! @addtogroup bl_core
36 | //! @{
37 |
38 | ////////////////////////////////////////////////////////////////////////////////
39 | // Declarations
40 | ////////////////////////////////////////////////////////////////////////////////
41 |
42 | //! @brief Shutdown types.
43 | typedef enum _shutdown_types
44 | {
45 | kShutdownType_Shutdown = 0,
46 | kShutdownType_Cleanup = 1,
47 | kShutdownType_Reset = 2,
48 | } shutdown_type_t;
49 |
50 | ////////////////////////////////////////////////////////////////////////////////
51 | // API
52 | ////////////////////////////////////////////////////////////////////////////////
53 |
54 | #if defined(__cplusplus)
55 | extern "C" {
56 | #endif
57 |
58 | /*!
59 | * @brief Prepare system for exiting the bootloader.
60 | *
61 | * Performs any cleanup necessary to restore the system to default state prior to
62 | * exiting the bootloader. This involves restoring the vector table to default,
63 | * managing the flash cache, and so on.
64 | *
65 | * This routine *must* be invoked prior to permanently exiting the bootloader.
66 | *
67 | * @param shutdown Specifies different uses for this function
68 | * 'kShutdownType_Shutdown' means clean up prior to permanently exiting the bootloader.
69 | * 'kShutdownType_Cleanup' means only clear (flush) the flash cache
70 | * 'kShutdownType_Reset' means only shutdown all peripherals.
71 | */
72 | void shutdown_cleanup(shutdown_type_t shutdown);
73 |
74 | #if defined(__cplusplus)
75 | }
76 | #endif
77 |
78 | //! @}
79 |
80 | #endif // __SHUTDOWN_CLEANUP_H__
81 | ////////////////////////////////////////////////////////////////////////////////
82 | // EOF
83 | ////////////////////////////////////////////////////////////////////////////////
84 |
--------------------------------------------------------------------------------
/src/blfwk/Peripheral.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _Peripheral_h_
32 | #define _Peripheral_h_
33 |
34 | #include "BusPal.h"
35 | #include "bootloader_common.h"
36 | #include
37 |
38 | //! @addtogroup host_peripherals
39 | //! @{
40 |
41 | namespace blfwk
42 | {
43 | /*!
44 | * @brief Represents a peripheral.
45 | *
46 | * Interface class for objects that provide the source for commands or sink for responses.
47 | */
48 | class Peripheral
49 | {
50 | public:
51 | enum _host_peripheral_types
52 | {
53 | kHostPeripheralType_None,
54 | kHostPeripheralType_UART,
55 | kHostPeripheralType_BUSPAL_UART,
56 | kHostPeripheralType_USB_HID,
57 | kHostPeripheralType_SIM
58 | };
59 |
60 | struct PeripheralConfigData
61 | {
62 | _host_peripheral_types peripheralType;
63 | std::string comPortName;
64 | long comPortSpeed;
65 | uint32_t packetTimeoutMs;
66 | unsigned short usbHidVid;
67 | unsigned short usbHidPid;
68 | std::string usbHidSerialNumber;
69 | bool ping;
70 | BusPal::BusPalConfigData busPalConfig;
71 | };
72 |
73 | virtual ~Peripheral(){};
74 |
75 | //! @brief Read bytes.
76 | //!
77 | //! @param buffer Pointer to buffer
78 | //! @param requestedBytes Number of bytes to read
79 | //! @param timeoutMs Time in milliseconds to wait for read to complete.
80 | //! @param actualBytes Number of bytes actually read.
81 | virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeout) = 0;
82 |
83 | //! @brief Write bytes.
84 | virtual status_t write(const uint8_t *buffer, uint32_t byteCount) = 0;
85 | };
86 |
87 | } // namespace blfwk
88 |
89 | //! @}
90 |
91 | #endif // _Peripheral_h_
92 |
93 | ////////////////////////////////////////////////////////////////////////////////
94 | // EOF
95 | ////////////////////////////////////////////////////////////////////////////////
96 |
--------------------------------------------------------------------------------
/src/blfwk/src/DataTarget.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "blfwk/DataTarget.h"
32 | #include "blfwk/DataSource.h"
33 | #include "blfwk/BlfwkErrors.h"
34 | #include
35 |
36 | using namespace blfwk;
37 |
38 | //! \exception blfwk::semantic_error Thrown if the source has multiple segments.
39 | DataTarget::AddressRange ConstantDataTarget::getRangeForSegment(DataSource &source, DataSource::Segment &segment)
40 | {
41 | // can't handle multi-segment data sources
42 | if (source.getSegmentCount() > 1)
43 | {
44 | throw semantic_error("constant targets only support single-segment sources");
45 | }
46 |
47 | // always relocate the segment to our begin address
48 | AddressRange range;
49 | range.m_begin = m_begin;
50 |
51 | if (isBounded())
52 | {
53 | // we have an end address. trim the result range to the segment size
54 | // or let the end address crop the segment.
55 | range.m_end = std::min(m_end, m_begin + segment.getLength());
56 | }
57 | else
58 | {
59 | // we have no end address, so the segment size determines it.
60 | range.m_end = m_begin + segment.getLength();
61 | }
62 |
63 | return range;
64 | }
65 |
66 | //! If the \a segment has a natural location, the returned address range extends
67 | //! from the segment's base address to its base address plus its length.
68 | //!
69 | //! \exception blfwk::semantic_error This exception is thrown if the \a segment
70 | //! does not have a natural location associated with it.
71 | DataTarget::AddressRange NaturalDataTarget::getRangeForSegment(DataSource &source, DataSource::Segment &segment)
72 | {
73 | if (!segment.hasNaturalLocation())
74 | {
75 | throw semantic_error("source has no natural location");
76 | }
77 |
78 | AddressRange range;
79 | range.m_begin = segment.getBaseAddress();
80 | range.m_end = segment.getBaseAddress() + segment.getLength();
81 | return range;
82 | }
83 |
--------------------------------------------------------------------------------
/src/include/bootloader_core.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #ifndef __BOOTLOADER_CORE_H__
31 | #define __BOOTLOADER_CORE_H__
32 |
33 | #include "fsl_device_registers.h"
34 |
35 | // These functions are missing from the latest CMSIS core header files.
36 | #if __CORTEX_M == 0x00
37 |
38 | /** \brief Clear Enabled IRQs
39 |
40 | The function clears all device IRQs
41 | */
42 | __STATIC_INLINE void NVIC_ClearEnabledIRQs(void)
43 | {
44 | NVIC->ICER[0] = 0xFFFFFFFF;
45 | }
46 |
47 | /** \brief Clear All Pending Interrupts
48 |
49 | The function clears the pending bits of all external interrupts.
50 |
51 | */
52 | __STATIC_INLINE void NVIC_ClearAllPendingIRQs(void)
53 | {
54 | NVIC->ICPR[0] = 0xFFFFFFFF;
55 | }
56 |
57 | #elif __CORTEX_M == 0x04 || __CORTEX_M == 0x07
58 |
59 | /** \brief Clear Enabled IRQs
60 |
61 | The function clears all device IRQs
62 | */
63 | __STATIC_INLINE void NVIC_ClearEnabledIRQs(void)
64 | {
65 | NVIC->ICER[0] = 0xFFFFFFFF;
66 | NVIC->ICER[1] = 0xFFFFFFFF;
67 | NVIC->ICER[2] = 0xFFFFFFFF;
68 | NVIC->ICER[3] = 0xFFFFFFFF;
69 | NVIC->ICER[4] = 0xFFFFFFFF;
70 | NVIC->ICER[5] = 0xFFFFFFFF;
71 | NVIC->ICER[6] = 0xFFFFFFFF;
72 | NVIC->ICER[7] = 0xFFFFFFFF;
73 | }
74 |
75 | /** \brief Clear All Pending Interrupts
76 |
77 | The function clears the pending bits of all external interrupts.
78 |
79 | */
80 | __STATIC_INLINE void NVIC_ClearAllPendingIRQs(void)
81 | {
82 | NVIC->ICPR[0] = 0xFFFFFFFF;
83 | NVIC->ICPR[1] = 0xFFFFFFFF;
84 | NVIC->ICPR[2] = 0xFFFFFFFF;
85 | NVIC->ICPR[3] = 0xFFFFFFFF;
86 | NVIC->ICPR[4] = 0xFFFFFFFF;
87 | NVIC->ICPR[5] = 0xFFFFFFFF;
88 | NVIC->ICPR[6] = 0xFFFFFFFF;
89 | NVIC->ICPR[7] = 0xFFFFFFFF;
90 | }
91 | #else
92 | #error CORTEX_M version not defined
93 | #endif
94 |
95 | #endif // __BOOTLOADER_CORE_H__
96 | ////////////////////////////////////////////////////////////////////////////////
97 | // EOF
98 | ////////////////////////////////////////////////////////////////////////////////
99 |
--------------------------------------------------------------------------------
/src/blfwk/BusPalPeripheral.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _BusPalPeripheral_h_
32 | #define _BusPalPeripheral_h_
33 |
34 | #include "UartPeripheral.h"
35 | #include "BusPal.h"
36 |
37 | //! @addtogroup bus_pal_peripheral
38 | //! @{
39 |
40 | namespace blfwk
41 | {
42 | /*!
43 | * @brief Peripheral that talks to the target device over BusPal UART hardware.
44 | */
45 | class BusPalUartPeripheral : public UartPeripheral
46 | {
47 | public:
48 | //! @brief Parameterized constructor that opens the serial port.
49 | //!
50 | //! Opens and configures the port. Throws exception if port configuration fails.
51 | //!
52 | //! Note: following COM port configuration is assumed: 8 bits, 1 stop bit, no parity.
53 | //!
54 | //! @param port OS file path for COM port. For example "COM1" on Windows.
55 | //! @param speed Port speed, e.g. 9600.
56 | BusPalUartPeripheral(const char *port, long speed, const BusPal::BusPalConfigData &config);
57 |
58 | //! @brief Destructor.
59 | virtual ~BusPalUartPeripheral();
60 |
61 | //! @brief configure the bus pal with the passed in options
62 | void configure(const BusPal::BusPalConfigData &config);
63 |
64 | //! @brief Read bytes.
65 | //!
66 | //! @param buffer Pointer to buffer
67 | //! @param requestedBytes Number of bytes to read
68 | virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeoutMs);
69 |
70 | //! @brief Write bytes.
71 | //!
72 | //! @param buffer Pointer to buffer to write
73 | //! @param byteCount Number of bytes to write
74 | virtual status_t write(const uint8_t *buffer, uint32_t byteCount);
75 |
76 | protected:
77 | BusPal *m_busPal; //!< Represents Bus Pal hardware.
78 | };
79 |
80 | } // namespace blfwk
81 |
82 | //! @}
83 |
84 | #endif // _BusPalPeripheral_h_
85 |
86 | ////////////////////////////////////////////////////////////////////////////////
87 | // EOF
88 | ////////////////////////////////////////////////////////////////////////////////
89 |
--------------------------------------------------------------------------------
/src/crc/crc16.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #ifndef _CRC16_H_
31 | #define _CRC16_H_
32 |
33 | #include
34 |
35 | //! @addtogroup crc16
36 | //! @{
37 |
38 | ////////////////////////////////////////////////////////////////////////////////
39 | // Definitions
40 | ////////////////////////////////////////////////////////////////////////////////
41 |
42 | //! @brief State information for the CRC16 algorithm.
43 | typedef struct Crc16Data
44 | {
45 | uint16_t currentCrc; //!< Current CRC value.
46 | } crc16_data_t;
47 |
48 | ////////////////////////////////////////////////////////////////////////////////
49 | // API
50 | ////////////////////////////////////////////////////////////////////////////////
51 |
52 | #if __cplusplus
53 | extern "C" {
54 | #endif
55 |
56 | //! @name CRC16
57 | //@{
58 |
59 | //! @brief Initializes the parameters of the crc function, must be called first.
60 | //!
61 | //! @param crc16Config Instantiation of the data structure of type crc16_data_t.
62 | void crc16_init(crc16_data_t *crc16Config);
63 |
64 | //! @brief A "running" crc calculator that updates the crc value after each call.
65 | //!
66 | //! @param crc16Config Instantiation of the data structure of type crc16_data_t.
67 | //! @param src Pointer to the source buffer of data.
68 | //! @param lengthInBytes The length, given in bytes (not words or long-words).
69 | void crc16_update(crc16_data_t *crc16Config, const uint8_t *src, uint32_t lengthInBytes);
70 |
71 | //! @brief Calculates the final crc value, padding with zeros if necessary, must be called last.
72 | //!
73 | //! @param crc16Config Instantiation of the data structure of type crc16_data_t.
74 | //! @param hash Pointer to the value returned for the final calculated crc value.
75 | void crc16_finalize(crc16_data_t *crc16Config, uint16_t *hash);
76 |
77 | //@}
78 |
79 | #if __cplusplus
80 | }
81 | #endif
82 |
83 | //! @}
84 |
85 | #endif
86 | ////////////////////////////////////////////////////////////////////////////////
87 | // EOF
88 | ////////////////////////////////////////////////////////////////////////////////
89 |
--------------------------------------------------------------------------------
/src/blfwk/src/format_string.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "blfwk/format_string.h"
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | //! Size of the temporary buffer to hold the formatted output string.
38 | #define WIN32_FMT_BUF_LEN (512)
39 |
40 | /*!
41 | * \brief Simple template class to free a pointer.
42 | */
43 | template
44 | class free_ptr
45 | {
46 | public:
47 | //! \brief Constructor.
48 | free_ptr(T ptr)
49 | : m_p(ptr)
50 | {
51 | }
52 |
53 | //! \brief Destructor.
54 | ~free_ptr()
55 | {
56 | if (m_p)
57 | {
58 | free(m_p);
59 | }
60 | }
61 |
62 | protected:
63 | T m_p; //!< The value to free.
64 | };
65 |
66 | //! The purpose of this function to provide a convenient way of generating formatted
67 | //! STL strings inline. This is especially useful when throwing exceptions that take
68 | //! a std::string for a message. The length of the formatted output string is limited
69 | //! only by memory. Memory temporarily allocated for the output string is disposed of
70 | //! before returning.
71 | //!
72 | //! Example usage:
73 | //! \code
74 | //! throw std::runtime_error(format_string("error on line %d", line));
75 | //! \endcode
76 | //!
77 | //! \param fmt Format string using printf-style format markers.
78 | //! \return An STL string object of the formatted output.
79 | std::string format_string(const char *fmt, ...)
80 | {
81 | char *buf = 0;
82 | va_list vargs;
83 | va_start(vargs, fmt);
84 | int result = -1;
85 | #if WIN32
86 | buf = (char *)malloc(WIN32_FMT_BUF_LEN);
87 | if (buf)
88 | {
89 | result = _vsnprintf(buf, WIN32_FMT_BUF_LEN, fmt, vargs);
90 | }
91 | #else // WIN32
92 | result = vasprintf(&buf, fmt, vargs);
93 | #endif // WIN32
94 | va_end(vargs);
95 | if (result != -1 && buf)
96 | {
97 | free_ptr freebuf(buf);
98 | return std::string(buf);
99 | }
100 | return "";
101 | }
102 |
--------------------------------------------------------------------------------
/src/picocom/custbaud.h:
--------------------------------------------------------------------------------
1 | /* vi: set sw=4 ts=4:
2 | *
3 | * custbaud.h
4 | *
5 | * Automatically enable custom baudrate support for systems (OS /
6 | * version / architecture combinations) we know it works.
7 | *
8 | * by Nick Patavalis (npat@efault.net)
9 | *
10 | * This program is free software; you can redistribute it and/or
11 | * modify it under the terms of the GNU General Public License as
12 | * published by the Free Software Foundation; either version 2 of the
13 | * License, or (at your option) any later version.
14 | *
15 | * This program is distributed in the hope that it will be useful, but
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 | * General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with this program; if not, write to the Free Software
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 | * USA
24 | */
25 |
26 | #ifndef CUSTBAUD_H
27 | #define CUSTBAUD_H
28 |
29 | #include
30 |
31 | #ifndef NO_CUSTOM_BAUD
32 |
33 | #if defined (__linux__)
34 |
35 | /* Enable by-default for kernels > 2.6.0 on x86 and x86_64 only */
36 | #include
37 | #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)
38 | /* Some libc implementations (e.g. musl) do not define the cispeed and
39 | cospeed struct termios fields. We do not support custom baudrates
40 | on them. */
41 | #if ( (defined (__i386__) || defined (__x86_64__)) \
42 | && defined (_HAVE_STRUCT_TERMIOS_C_ISPEED) \
43 | && defined (_HAVE_STRUCT_TERMIOS_C_OSPEED) ) \
44 | || defined (USE_CUSTOM_BAUD)
45 | #ifndef USE_CUSTOM_BAUD
46 | #define USE_CUSTOM_BAUD
47 | #endif
48 | #define CUSTOM_BAUD_HEAD "termios2.h"
49 | #endif /* of arch */
50 | #endif /* of version */
51 |
52 | #elif defined (__APPLE__) && defined(__MACH__)
53 |
54 | #include
55 | #include
56 | #if TARGET_IPHONE_SIMULATOR
57 | /* Do not enable by default for iOS in Xcode simulator */
58 | #elif TARGET_OS_IPHONE
59 | /* Do not enable by default for iOS until it has been tested */
60 | #elif TARGET_OS_MAC
61 | #if defined (__i386__) || defined (__x86_64__)
62 | /* Enable by-default for Intel Mac, macOS / OSX >= 10.4 (Tiger) */
63 | #ifndef USE_CUSTOM_BAUD
64 | #define USE_CUSTOM_BAUD
65 | #endif
66 | #endif /* of arch */
67 | #endif /* of TARGET_OS_... */
68 | #define CUSTOM_BAUD_HEAD "custbaud_bsd.h"
69 |
70 | #elif defined (__NetBSD__)
71 |
72 | /* Do not enable by default */
73 | #define CUSTOM_BAUD_HEAD "custbaud_bsd.h"
74 |
75 | #elif defined (__FreeBSD__) || defined (__OpenBSD__) || \
76 | defined (__DragonFly__)
77 |
78 | /* I believe it doesn't hurt to enable by-default for these */
79 | #ifndef USE_CUSTOM_BAUD
80 | #define USE_CUSTOM_BAUD
81 | #endif
82 | #define CUSTOM_BAUD_HEAD "custbaud_bsd.h"
83 |
84 | #elif defined (USE_CUSTOM_BAUD)
85 |
86 | #error "USE_CUSTOM_BAUD not supported on this system!"
87 |
88 | #endif /* of platforms */
89 |
90 | #else /* of ndef NO_CUSTOM_BAUD */
91 |
92 | #ifdef USE_CUSTOM_BAUD
93 | #undef USE_CUSTOM_BAUD
94 | #endif
95 |
96 | #endif /* of ndef NO_CUSTOM_BAUD else */
97 |
98 |
99 | int use_custom_baud();
100 | int cfsetispeed_custom(struct termios *tios, int speed);
101 | int cfsetospeed_custom(struct termios *tios, int speed);
102 | int cfgetispeed_custom(const struct termios *tios);
103 | int cfgetospeed_custom(const struct termios *tios);
104 |
105 | #endif /* CUSTBAUD_H */
106 |
107 | /**************************************************************************/
108 |
109 | /*
110 | * Local Variables:
111 | * mode:c
112 | * tab-width: 4
113 | * c-basic-offset: 4
114 | * End:
115 | */
116 |
--------------------------------------------------------------------------------
/src/blfwk/stdafx.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #ifndef stdafx_h_
31 | #define stdafx_h_
32 |
33 | // stdafx.h : include file for standard system include files,
34 | // or project specific include files that are used frequently, but
35 | // are changed infrequently
36 | //
37 |
38 | // Default to external release.
39 | #ifndef SGTL_INTERNAL
40 | #define SGTL_INTERNAL 0
41 | #endif
42 |
43 | #include
44 | #include
45 | #include
46 |
47 | #if defined(WIN32)
48 | //#include
49 |
50 | // define this macro for use in VC++
51 | #if !defined(__LITTLE_ENDIAN__)
52 | #define __LITTLE_ENDIAN__ 1
53 | #endif // !defined(__LITTLE_ENDIAN__)
54 | #endif // defined(WIN32)
55 |
56 | #if defined(LINUX)
57 | // For Linux systems only, types.h only defines the signed
58 | // integer types. This is not professional code.
59 | // Update: They are defined in the header files in the more recent version of redhat enterprise gcc.
60 | //#include "/usr/include/sys/types.h"
61 | //#include
62 | // typedef unsigned long uint32_t;
63 | // typedef unsigned short uint16_t;
64 | // typedef unsigned char uint8_t;
65 |
66 | //#define TCHAR char
67 | //#define _tmain main
68 |
69 | // give a default endian in case one is not defined on Linux (it should be, though)
70 | #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
71 | #define __LITTLE_ENDIAN__ 1
72 | #endif // !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
73 |
74 | #endif // defined(Linux)
75 |
76 | // gcc on Mac OS X
77 | #if defined(__GNUC__) && (defined(__APPLE_CPP__) || defined(__APPLE_CC__) || defined(__MACOS_CLASSIC__))
78 | #include
79 |
80 | #if defined(TARGET_RT_LITTLE_ENDIAN) && TARGET_RT_LITTLE_ENDIAN
81 | #if !defined(__LITTLE_ENDIAN__)
82 | #define __LITTLE_ENDIAN__
83 | #endif
84 | #elif defined(TARGET_RT_BIG_ENDIAN) && TARGET_RT_BIG_ENDIAN
85 | #if !defined(__BIG_ENDIAN__)
86 | #define __BIG_ENDIAN__
87 | #endif
88 | #endif
89 | #endif
90 |
91 | #if !defined(TRUE)
92 | #define TRUE 1
93 | #endif // !defined(TRUE)
94 |
95 | #if !defined(FALSE)
96 | #define FALSE 0
97 | #endif // !defined(FALSE)
98 |
99 | #endif // stdafx_h_
100 |
--------------------------------------------------------------------------------
/src/crc/crc32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #ifndef _CRC_H_
31 | #define _CRC_H_
32 |
33 | #include
34 | #include "bootloader_common.h"
35 |
36 | //! @addtogroup crc32
37 | //! @{
38 |
39 | ////////////////////////////////////////////////////////////////////////////////
40 | // Definitions
41 | ////////////////////////////////////////////////////////////////////////////////
42 |
43 | //! @brief State information for the CRC32 algorithm.
44 | typedef struct Crc32Data
45 | {
46 | uint32_t currentCrc; //!< Current CRC value.
47 | uint32_t byteCountCrc; //!< Number of bytes processed.
48 | } crc32_data_t;
49 |
50 | ////////////////////////////////////////////////////////////////////////////////
51 | // API
52 | ////////////////////////////////////////////////////////////////////////////////
53 |
54 | #if __cplusplus
55 | extern "C" {
56 | #endif
57 |
58 | //! @name CRC32
59 | //@{
60 |
61 | //! @brief Initializes the parameters of the crc function, must be called first
62 | //!
63 | //! @param crc32Config Instantiation of the data structure of type crc32_data_t
64 | //! @retval kStatus_Success
65 | void crc32_init(crc32_data_t *crc32Config);
66 |
67 | //! @brief A "running" crc calculator that updates the crc value after each call
68 | //!
69 | //! @param crc32Config Instantiation of the data structure of type crc32_data_t
70 | //! @param src Pointer to the source buffer of data
71 | //! @param lengthInBytes The length, given in bytes (not words or long-words)
72 | //! @retval kStatus_Success
73 | void crc32_update(crc32_data_t *crc32Config, const uint8_t *src, uint32_t lengthInBytes);
74 |
75 | //! @brief Calculates the final crc value, padding with zeros if necessary, must be called last
76 | //!
77 | //! @param crc32Config Instantiation of the data structure of type crc32_data_t
78 | //! @param hash Pointer to the value returned for the final calculated crc value
79 | //! @retval kStatus_Success
80 | void crc32_finalize(crc32_data_t *crc32Config, uint32_t *hash);
81 |
82 | //@}
83 |
84 | #if __cplusplus
85 | }
86 | #endif
87 |
88 | //! @}
89 |
90 | #endif
91 | ////////////////////////////////////////////////////////////////////////////////
92 | // EOF
93 | ////////////////////////////////////////////////////////////////////////////////
94 |
--------------------------------------------------------------------------------
/src/blfwk/GHSSecInfo.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_GHSSecInfo_h_)
31 | #define _GHSSecInfo_h_
32 |
33 | #include "StELFFile.h"
34 | #include "smart_ptr.h"
35 |
36 | namespace blfwk
37 | {
38 | /*!
39 | * \brief Wrapper around the GHS-specific .secinfo ELF section.
40 | *
41 | * ELF files produced by the Green Hills MULTI toolset will have a
42 | * special .secinfo section. For the most part, this section contains
43 | * a list of address
44 | * ranges that should be filled by the C runtime startup code. The
45 | * address ranges correspond to those of ELF sections whose type is
46 | * #SHT_NOBITS. The GHS runtime uses this table instead of just filling
47 | * all #SHT_NOBITS sections because the linker command file can
48 | * be used to optionally not fill individual sections.
49 | *
50 | * The isSectionFilled() methods let calling code determine if an ELF
51 | * section is found in the .secinfo table. If the section is found,
52 | * then it should be filled.
53 | */
54 | class GHSSecInfo
55 | {
56 | public:
57 | //! \brief Default constructor.
58 | GHSSecInfo(StELFFile *elf);
59 |
60 | //! \brief Returns true if there is a .secinfo section present in the ELF file.
61 | bool hasSecinfo() const { return m_hasInfo; }
62 | //! \brief Determines if a section should be filled.
63 | bool isSectionFilled(uint32_t addr, uint32_t length);
64 |
65 | //! \brief Determines if \a section should be filled.
66 | bool isSectionFilled(const Elf32_Shdr §ion);
67 |
68 | protected:
69 | #pragma pack(1)
70 |
71 | /*!
72 | * \brief The structure of one .secinfo entry.
73 | */
74 | struct ghs_secinfo_t
75 | {
76 | uint32_t m_clearAddr; //!< Address to start filling from.
77 | uint32_t m_clearValue; //!< Value to fill with.
78 | uint32_t m_numBytesToClear; //!< Number of bytes to fill.
79 | };
80 |
81 | #pragma pack()
82 |
83 | protected:
84 | StELFFile *m_elf; //!< The parser object for our ELF file.
85 | bool m_hasInfo; //!< Whether .secinfo is present in the ELF file.
86 | smart_array_ptr
87 | m_info; //!< Pointer to the .secinfo entries. Will be NULL if there is no .secinfo section in the file.
88 | unsigned m_entryCount; //!< Number of entries in #m_info.
89 | };
90 |
91 | }; // namespace blfwk
92 |
93 | #endif // _GHSSecInfo_h_
94 |
--------------------------------------------------------------------------------
/src/blfwk/src/GHSSecInfo.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: GHSSecInfo.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/GHSSecInfo.h"
9 | #include
10 | #include "blfwk/Logging.h"
11 | #include "blfwk/EndianUtilities.h"
12 |
13 | //! The name of the GHS-specific section info table ELF section.
14 | const char *const kSecInfoSectionName = ".secinfo";
15 |
16 | using namespace blfwk;
17 |
18 | //! The ELF file passed into this constructor as the \a elf argument must remain
19 | //! valid for the life of this object.
20 | //!
21 | //! \param elf The ELF file parser. An assertion is raised if this is NULL.
22 | GHSSecInfo::GHSSecInfo(StELFFile *elf)
23 | : m_elf(elf)
24 | , m_hasInfo(false)
25 | , m_info(0)
26 | , m_entryCount(0)
27 | {
28 | assert(elf);
29 |
30 | // look up the section. if it's not there just leave m_info and m_entryCount to 0
31 | unsigned sectionIndex = m_elf->getIndexOfSectionWithName(kSecInfoSectionName);
32 | if (sectionIndex == SHN_UNDEF)
33 | {
34 | return;
35 | }
36 |
37 | // get the section data
38 | const Elf32_Shdr &secInfo = m_elf->getSectionAtIndex(sectionIndex);
39 | if (secInfo.sh_type != SHT_PROGBITS)
40 | {
41 | // .secinfo section isn't the right type, so something is wrong
42 | return;
43 | }
44 |
45 | m_hasInfo = true;
46 | m_info = (ghs_secinfo_t *)m_elf->getSectionDataAtIndex(sectionIndex);
47 | m_entryCount = secInfo.sh_size / sizeof(ghs_secinfo_t);
48 | }
49 |
50 | //! Looks up \a addr for \a length in the .secinfo array. Only if that address is in the
51 | //! .secinfo array does this section need to be filled. If the section is found but the
52 | //! length does not match the \a length argument, a message is logged at the
53 | //! #Logger::kWarning level.
54 | //!
55 | //! If the .secinfo section is not present in the ELF file, this method always returns
56 | //! true.
57 | //!
58 | //! \param addr The start address of the section to query.
59 | //! \param length The length of the section. If a section with a start address matching
60 | //! \a addr is found, its length must match \a length to be considered.
61 | //!
62 | //! \retval true The section matching \a addr and \a length was found and should be filled.
63 | //! True is also returned when the ELF file does not have a .secinfo section.
64 | //! \retval false The section was not found and should not be filled.
65 | bool GHSSecInfo::isSectionFilled(uint32_t addr, uint32_t length)
66 | {
67 | if (!m_hasInfo)
68 | {
69 | return true;
70 | }
71 |
72 | unsigned i;
73 | for (i = 0; i < m_entryCount; ++i)
74 | {
75 | // byte swap these values into host endianness
76 | uint32_t clearAddr = ENDIAN_LITTLE_TO_HOST_U32(m_info[i].m_clearAddr);
77 | uint32_t numBytesToClear = ENDIAN_LITTLE_TO_HOST_U32(m_info[i].m_numBytesToClear);
78 |
79 | // we only consider non-zero length clear regions
80 | if ((addr == clearAddr) && (numBytesToClear != 0))
81 | {
82 | // it is an error if the address matches but the length does not
83 | if (length != numBytesToClear)
84 | {
85 | Log::log(Logger::kWarning, "ELF Error: Size mismatch @ sect=%u, .secinfo=%u at addr 0x%08X\n", length,
86 | numBytesToClear, addr);
87 | }
88 | return true;
89 | }
90 | }
91 |
92 | return false;
93 | }
94 |
95 | //! Simply calls through to isSectionFilled(uint32_t, uint32_t) to determine
96 | //! if \a section should be filled.
97 | //!
98 | //! If the .secinfo section is not present in the ELF file, this method always returns
99 | //! true.
100 | bool GHSSecInfo::isSectionFilled(const Elf32_Shdr §ion)
101 | {
102 | return isSectionFilled(section.sh_addr, section.sh_size);
103 | }
104 |
--------------------------------------------------------------------------------
/src/drivers/common/fsl_common.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "fsl_common.h"
32 | #include "fsl_debug_console.h"
33 |
34 | #if !(defined(NODEBUG) || defined(NDEBUG))
35 | #if (defined(__CC_ARM)) || (defined(__ICCARM__))
36 | void __aeabi_assert(const char *failedExpr, const char *file, int line)
37 | {
38 | PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line);
39 | for (;;)
40 | {
41 | __asm("bkpt #0");
42 | }
43 | }
44 | #elif(defined(__GNUC__))
45 | void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
46 | {
47 | PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line, func);
48 | for (;;)
49 | {
50 | __asm("bkpt #0");
51 | }
52 | }
53 | #endif /* (defined(__CC_ARM)) || (defined (__ICCARM__)) */
54 | #endif /* !(defined(NODEBUG) || defined(NDEBUG)) */
55 |
56 | void InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
57 | {
58 | /* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
59 | #if defined(__CC_ARM)
60 | extern uint32_t Image$$VECTOR_ROM$$Base[];
61 | extern uint32_t Image$$VECTOR_RAM$$Base[];
62 | extern uint32_t Image$$RW_m_data$$Base[];
63 |
64 | #define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
65 | #define __VECTOR_RAM Image$$VECTOR_RAM$$Base
66 | #define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$RW_m_data$$Base - (uint32_t)Image$$VECTOR_RAM$$Base))
67 | #elif defined(__ICCARM__)
68 | extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
69 | extern uint32_t __VECTOR_TABLE[];
70 | extern uint32_t __VECTOR_RAM[];
71 | #elif defined(__GNUC__)
72 | extern uint32_t __VECTOR_TABLE[];
73 | extern uint32_t __VECTOR_RAM[];
74 | extern uint32_t __RAM_VECTOR_TABLE_SIZE_BYTES[];
75 | uint32_t __RAM_VECTOR_TABLE_SIZE = (uint32_t)(__RAM_VECTOR_TABLE_SIZE_BYTES);
76 | #endif /* defined(__CC_ARM) */
77 | uint32_t n;
78 |
79 | __disable_irq();
80 | if (SCB->VTOR != (uint32_t)__VECTOR_RAM)
81 | {
82 | /* Copy the vector table from ROM to RAM */
83 | for (n = 0; n < ((uint32_t)__RAM_VECTOR_TABLE_SIZE) / sizeof(uint32_t); n++)
84 | {
85 | __VECTOR_RAM[n] = __VECTOR_TABLE[n];
86 | }
87 | /* Point the VTOR to the position of vector table */
88 | SCB->VTOR = (uint32_t)__VECTOR_RAM;
89 | }
90 |
91 | /* make sure the __VECTOR_RAM is noncachable */
92 | __VECTOR_RAM[irq + 16] = irqHandler;
93 |
94 | __enable_irq();
95 | }
96 |
--------------------------------------------------------------------------------
/src/blfwk/Bootloader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _Bootloader_h_
32 | #define _Bootloader_h_
33 |
34 | #include "Command.h"
35 | #include "Packetizer.h"
36 | #include "Peripheral.h"
37 | #include "Logging.h"
38 |
39 | #include
40 |
41 | //! @addtogroup blfwk
42 | //! @{
43 |
44 | namespace blfwk
45 | {
46 | /*!
47 | * @brief Represents the host bootloader.
48 | *
49 | * This class provides a convenient way to access other bootloader
50 | * framework objects.
51 | */
52 | class Bootloader
53 | {
54 | public:
55 | //! @brief Default Constructor for Simulator.
56 | Bootloader();
57 |
58 | //! @brief Constructor.
59 | Bootloader(const Peripheral::PeripheralConfigData &config);
60 |
61 | //! @brief Destructor.
62 | virtual ~Bootloader();
63 |
64 | //! @brief Inject a command into the bootloader.
65 | //!
66 | //! @param cmd The command to send
67 | void inject(Command &cmd)
68 | {
69 | clock_t start = clock();
70 | cmd.sendTo(*m_hostPacketizer);
71 | clock_t finish = clock();
72 | Log::debug(" - took %2.3f seconds\n", (double)(finish - start) / CLOCKS_PER_SEC);
73 | }
74 |
75 | //! @brief Flush state.
76 | void flush();
77 |
78 | //! \brief Execute the execute command.
79 | void execute(uint32_t entry_point, uint32_t param = 0, uint32_t stack_pointer = 0);
80 |
81 | //! \brief Execute the reset command.
82 | void reset();
83 |
84 | //! \brief Execute the get-property(current-version) command.
85 | standard_version_t getVersion();
86 |
87 | //! \brief Execute the get-property(flash-security-state) command.
88 | uint32_t getSecurityState();
89 |
90 | //! \brief Send a ping if applicable.
91 | void ping(int retries, unsigned int delay, int comSpeed);
92 |
93 | //! @name Accessors.
94 | //@{
95 |
96 | //! @brief Get the host packetizer.
97 | Packetizer *getPacketizer() const { return m_hostPacketizer; }
98 | //@}
99 |
100 | protected:
101 | Packetizer *m_hostPacketizer; //!< Packet interface to send commands on.
102 | FileLogger *m_logger; //!< Singleton logger instance.
103 | };
104 |
105 | } // namespace blfwk
106 |
107 | //! @}
108 |
109 | #endif // _Bootloader_h_
110 |
111 | ////////////////////////////////////////////////////////////////////////////////
112 | // EOF
113 | ////////////////////////////////////////////////////////////////////////////////
114 |
--------------------------------------------------------------------------------
/src/blfwk/src/SimPeripheral.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "blfwk/SimPeripheral.h"
32 | #include "blfwk/Logging.h"
33 |
34 | using namespace blfwk;
35 |
36 | ////////////////////////////////////////////////////////////////////////////////
37 | // Code
38 | ////////////////////////////////////////////////////////////////////////////////
39 |
40 | // See sim_peripheral.h for documentation of this method.
41 | status_t SimPeripheral::read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t timeoutMs)
42 | {
43 | if (m_inStream->empty())
44 | return kStatus_Fail;
45 |
46 | uint32_t bytesRead = 0;
47 | for (int i = 0; i < (int)requestedBytes; ++i)
48 | {
49 | if (m_inStream->empty())
50 | break;
51 | unsigned char val = m_inStream->front();
52 | m_inStream->pop_front();
53 | buffer[i] = val;
54 | ++bytesRead;
55 | }
56 |
57 | if (actualBytes)
58 | {
59 | *actualBytes = bytesRead;
60 | }
61 |
62 | if (Log::getLogger()->getFilterLevel() == Logger::kDebug2)
63 | {
64 | // Log bytes read in hex
65 | Log::debug2("<");
66 | for (int i = 0; i < (int)bytesRead; i++)
67 | {
68 | Log::debug2("%02x", buffer[i]);
69 | if (i != (bytesRead - 1))
70 | {
71 | Log::debug2(" ");
72 | }
73 | }
74 | Log::debug2(">\n");
75 | }
76 |
77 | return kStatus_Success;
78 | }
79 |
80 | // See sim_peripheral.h for documentation of this method.
81 | status_t SimPeripheral::write(const uint8_t *buffer, uint32_t byteCount)
82 | {
83 | if (Log::getLogger()->getFilterLevel() == Logger::kDebug2)
84 | {
85 | // Log bytes written in hex
86 | Log::debug2("[");
87 | for (int i = 0; i < (int)byteCount; i++)
88 | {
89 | Log::debug2("%02x", buffer[i]);
90 | if (i != (byteCount - 1))
91 | {
92 | Log::debug2(" ");
93 | }
94 | }
95 | Log::debug2("]\n");
96 | }
97 |
98 | for (int i = 0; i < (int)byteCount; ++i)
99 | {
100 | m_outStream->push_back(buffer[i]);
101 | }
102 |
103 | return kStatus_Success;
104 | }
105 |
106 | ////////////////////////////////////////////////////////////////////////////////
107 | // EOF
108 | ////////////////////////////////////////////////////////////////////////////////
109 |
--------------------------------------------------------------------------------
/src/blfwk/IntelHexSourceFile.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-15, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_IntelHexSourceFile_h_)
31 | #define _IntelHexSourceFile_h_
32 |
33 | #include "SourceFile.h"
34 | #include "StIntelHexFile.h"
35 | #include "StExecutableImage.h"
36 |
37 | namespace blfwk
38 | {
39 | /*!
40 | * \brief Executable file in the Intel Hex format.
41 | *
42 | * Instead of presenting each Intel Hex in the file separately, this class
43 | * builds up a memory image of all of the records. Records next to each other
44 | * in memory are coalesced into a single memory region. The data source that
45 | * is returned from createDataSource() exposes these regions as its segments.
46 | */
47 | class IntelHexSourceFile : public SourceFile
48 | {
49 | public:
50 | //! \brief Default constructor.
51 | IntelHexSourceFile(const std::string &path);
52 |
53 | //! \brief Destructor.
54 | virtual ~IntelHexSourceFile() {}
55 | //! \brief Test whether the \a stream contains a valid Intel Hex file.
56 | static bool isIntelHexFile(std::istream &stream);
57 |
58 | //! \name Opening and closing
59 | //@{
60 | //! \brief Opens the file.
61 | virtual void open();
62 |
63 | //! \brief Closes the file.
64 | virtual void close();
65 | //@}
66 |
67 | //! \name Format capabilities
68 | //@{
69 | virtual bool supportsNamedSections() const { return false; }
70 | virtual bool supportsNamedSymbols() const { return false; }
71 | //@}
72 |
73 | //! \name Data sources
74 | //@{
75 | //! \brief Returns data source for the entire file.
76 | virtual DataSource *createDataSource();
77 | //@}
78 |
79 | //! \name Entry point
80 | //@{
81 | //! \brief Returns true if an entry point was set in the file.
82 | virtual bool hasEntryPoint();
83 |
84 | //! \brief Returns the entry point address.
85 | virtual uint32_t getEntryPointAddress();
86 | //@}
87 |
88 | protected:
89 | StIntelHexFile *m_file; //!< Intel Hex parser instance.
90 | StExecutableImage *m_image; //!< Memory image of the Intel Hex file..
91 | bool m_hasEntryRecord; //!< Whether a type 03 or 05 record was found.
92 | StIntelHexFile::IntelHex m_entryRecord; //!< Record for the entry point.
93 |
94 | protected:
95 | //! \brief Build memory image of the Intel Hex file.
96 | void buildMemoryImage();
97 | };
98 |
99 | }; // namespace blfwk
100 |
101 | #endif // _IntelHexSourceFile_h_
102 |
--------------------------------------------------------------------------------
/src/blfwk/SRecordSourceFile.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(_SRecordSourceFile_h_)
31 | #define _SRecordSourceFile_h_
32 |
33 | #include "SourceFile.h"
34 | #include "StSRecordFile.h"
35 | #include "StExecutableImage.h"
36 |
37 | namespace blfwk
38 | {
39 | /*!
40 | * \brief Executable file in the Motorola S-record format.
41 | *
42 | * Instead of presenting each S-record in the file separately, this class
43 | * builds up a memory image of all of the records. Records next to each other
44 | * in memory are coalesced into a single memory region. The data source that
45 | * is returned from createDataSource() exposes these regions as its segments.
46 | *
47 | * Because the S-record format does not support the concepts, no support is
48 | * provided for named sections or symbols.
49 | */
50 | class SRecordSourceFile : public SourceFile
51 | {
52 | public:
53 | //! \brief Default constructor.
54 | SRecordSourceFile(const std::string &path);
55 |
56 | //! \brief Destructor.
57 | virtual ~SRecordSourceFile() {}
58 | //! \brief Test whether the \a stream contains a valid S-record file.
59 | static bool isSRecordFile(std::istream &stream);
60 |
61 | //! \name Opening and closing
62 | //@{
63 | //! \brief Opens the file.
64 | virtual void open();
65 |
66 | //! \brief Closes the file.
67 | virtual void close();
68 | //@}
69 |
70 | //! \name Format capabilities
71 | //@{
72 | virtual bool supportsNamedSections() const { return false; }
73 | virtual bool supportsNamedSymbols() const { return false; }
74 | //@}
75 |
76 | //! \name Data sources
77 | //@{
78 | //! \brief Returns data source for the entire file.
79 | virtual DataSource *createDataSource();
80 | //@}
81 |
82 | //! \name Entry point
83 | //@{
84 | //! \brief Returns true if an entry point was set in the file.
85 | virtual bool hasEntryPoint();
86 |
87 | //! \brief Returns the entry point address.
88 | virtual uint32_t getEntryPointAddress();
89 | //@}
90 |
91 | protected:
92 | StSRecordFile *m_file; //!< S-record parser instance.
93 | StExecutableImage *m_image; //!< Memory image of the S-record file.
94 | bool m_hasEntryRecord; //!< Whether an S7,8,9 record was found.
95 | StSRecordFile::SRecord m_entryRecord; //!< Record for the entry point.
96 |
97 | protected:
98 | //! \brief Build memory image of the S-record file.
99 | void buildMemoryImage();
100 | };
101 |
102 | }; // namespace blfwk
103 |
104 | #endif // _SRecordSourceFile_h_
105 |
--------------------------------------------------------------------------------
/src/bootloader/bl_reliable_update.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #ifndef __BL_RELIABLE_UPDATE_H__
31 | #define __BL_RELIABLE_UPDATE_H__
32 |
33 | #include
34 | #include
35 | #include "property/property.h"
36 |
37 | //! @addtogroup reliable_update
38 | //! @{
39 |
40 | ////////////////////////////////////////////////////////////////////////////////
41 | // Declarations
42 | ////////////////////////////////////////////////////////////////////////////////
43 |
44 | #define BL_IS_HARDWARE_SWAP_ENABLED (BL_FEATURE_HARDWARE_SWAP_UPDATE && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP)
45 |
46 | typedef enum _reliable_update_option
47 | {
48 | kReliableUpdateOption_Normal = 0x0U, //!< Normal option, Update main appliction only if it is invalid
49 | kReliableUpdateOption_Swap = 0x1U, //!< Swap option, Always update main appliction
50 | } reliable_update_option_t;
51 |
52 | typedef enum _specified_application_type
53 | {
54 | kSpecifiedApplicationType_Main = 0x0U,
55 | kSpecifiedApplicationType_Backup = 0x1U,
56 | } specified_application_type_t;
57 |
58 | //! @brief Application crc check status codes.
59 | enum _reliable_update_status
60 | {
61 | kStatus_ReliableUpdateSuccess = MAKE_STATUS(kStatusGroup_ReliableUpdate, 0), //!< Reliable Update succeeded.
62 | kStatus_ReliableUpdateFail = MAKE_STATUS(kStatusGroup_ReliableUpdate, 1), //!< Reliable Update failed.
63 | kStatus_ReliableUpdateInacive =
64 | MAKE_STATUS(kStatusGroup_ReliableUpdate, 2), //!< Reliable Update Feature is inactive.
65 | kStatus_ReliableUpdateBackupApplicationInvalid =
66 | MAKE_STATUS(kStatusGroup_ReliableUpdate, 3), //!< Backup Application is invalid
67 | kStatus_ReliableUpdateStillInMainApplication =
68 | MAKE_STATUS(kStatusGroup_ReliableUpdate, 4), //!< Next boot will be still in Main Application
69 | kStatus_ReliableUpdateSwapSystemNotReady =
70 | MAKE_STATUS(kStatusGroup_ReliableUpdate, 5), //!< Cannot swap flash by default because swap system is not ready
71 | kStatus_ReliableUpdateBackupBootloaderNotReady =
72 | MAKE_STATUS(kStatusGroup_ReliableUpdate, 6), //!< Cannot swap flash because there is no valid backup bootloader
73 | kStatus_ReliableUpdateSwapIndicatorAddressInvalid =
74 | MAKE_STATUS(kStatusGroup_ReliableUpdate, 7), //!< Cannot swap flash because provided swap indicator is invalid
75 | };
76 |
77 | ////////////////////////////////////////////////////////////////////////////////
78 | // Prototypes
79 | ////////////////////////////////////////////////////////////////////////////////
80 |
81 | #if __cplusplus
82 | extern "C" {
83 | #endif
84 |
85 | void bootloader_reliable_update_as_requested(reliable_update_option_t option, uint32_t address);
86 | //@}
87 |
88 | #if __cplusplus
89 | }
90 | #endif
91 |
92 | //! @}
93 |
94 | #endif // __BL_RELIABLE_UPDATE_H__
95 |
--------------------------------------------------------------------------------
/src/blfwk/src/GlobMatcher.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * File: GlobMatcher.cpp
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 |
8 | #include "blfwk/GlobMatcher.h"
9 |
10 | #ifndef NEGATE
11 | #define NEGATE '^' // std cset negation char
12 | #endif
13 |
14 | using namespace blfwk;
15 |
16 | //! The glob pattern must match the \e entire test value argument in order
17 | //! for the match to be considered successful. Thus, even if, for example,
18 | //! the pattern matches all but the last character the result will be false.
19 | //!
20 | //! \retval true The test value does match the glob pattern.
21 | //! \retval false The test value does not match the glob pattern.
22 | bool GlobMatcher::match(const std::string &testValue)
23 | {
24 | return globMatch(testValue.c_str(), m_pattern.c_str());
25 | }
26 |
27 | //! \note This glob implementation was originally written by ozan s. yigit in
28 | //! December 1994. This is public domain source code.
29 | bool GlobMatcher::globMatch(const char *str, const char *p)
30 | {
31 | int negate;
32 | int match;
33 | int c;
34 |
35 | while (*p)
36 | {
37 | if (!*str && *p != '*')
38 | return false;
39 |
40 | switch (c = *p++)
41 | {
42 | case '*':
43 | while (*p == '*')
44 | p++;
45 |
46 | if (!*p)
47 | return true;
48 |
49 | if (*p != '?' && *p != '[' && *p != '\\')
50 | while (*str && *p != *str)
51 | str++;
52 |
53 | while (*str)
54 | {
55 | if (globMatch(str, p))
56 | return true;
57 | str++;
58 | }
59 | return false;
60 |
61 | case '?':
62 | if (*str)
63 | break;
64 | return false;
65 |
66 | // set specification is inclusive, that is [a-z] is a, z and
67 | // everything in between. this means [z-a] may be interpreted
68 | // as a set that contains z, a and nothing in between.
69 | case '[':
70 | if (*p != NEGATE)
71 | negate = false;
72 | else
73 | {
74 | negate = true;
75 | p++;
76 | }
77 |
78 | match = false;
79 |
80 | while (!match && (c = *p++))
81 | {
82 | if (!*p)
83 | return false;
84 | if (*p == '-')
85 | { // c-c
86 | if (!*++p)
87 | return false;
88 | if (*p != ']')
89 | {
90 | if (*str == c || *str == *p || (*str > c && *str < *p))
91 | match = true;
92 | }
93 | else
94 | { // c-]
95 | if (*str >= c)
96 | match = true;
97 | break;
98 | }
99 | }
100 | else
101 | { // cc or c]
102 | if (c == *str)
103 | match = true;
104 | if (*p != ']')
105 | {
106 | if (*p == *str)
107 | match = true;
108 | }
109 | else
110 | break;
111 | }
112 | }
113 |
114 | if (negate == match)
115 | return false;
116 | // if there is a match, skip past the cset and continue on
117 | while (*p && *p != ']')
118 | p++;
119 | if (!*p++) // oops!
120 | return false;
121 | break;
122 |
123 | case '\\':
124 | if (*p)
125 | c = *p++;
126 | default:
127 | if (c != *str)
128 | return false;
129 | break;
130 | }
131 | str++;
132 | }
133 |
134 | return !*str;
135 | }
136 |
--------------------------------------------------------------------------------
/src/bootloader/bl_irq_common.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include "bootloader_common.h"
32 | #include "bootloader/bl_peripheral_interface.h"
33 |
34 | //! @addtogroup bl_hw
35 | //! @{
36 |
37 | ///////////////////////////////////////////////////////////////////////////////
38 | // Prototypes
39 | ////////////////////////////////////////////////////////////////////////////////
40 |
41 | #if defined(__cplusplus)
42 | extern "C" {
43 | #endif // __cplusplus
44 |
45 | /*!
46 | * @brief Configure IRQ gate for I2C peripherals
47 | *
48 | * This function enables or disables IRQ gate for specified I2C peripheral
49 | *
50 | * @param instance I2C instance
51 | * @param set Option for disabling or enabling IRQ gates.
52 | */
53 | void I2C_SetSystemIRQ(uint32_t instance, PeripheralSystemIRQSetting set);
54 |
55 | /*!
56 | * @brief Configure IRQ gate for DSPI peripherals
57 | *
58 | * This function enables or disables IRQ gate for specified DSPI peripheral
59 | *
60 | * @param instance DSPI instance
61 | * @param set Option for disabling or enabling IRQ gates.
62 | */
63 | void DSPI_SetSystemIRQ(uint32_t instance, PeripheralSystemIRQSetting set);
64 |
65 | /*!
66 | * @brief Configure IRQ gate for LPUART peripherals
67 | *
68 | * This function enables or disables IRQ gate for specified LPUART peripheral
69 | *
70 | * @param instance LPUART instance
71 | * @param set Option for disabling or enabling IRQ gates.
72 | */
73 | void LPUART_SetSystemIRQ(uint32_t instance, PeripheralSystemIRQSetting set);
74 |
75 | /*!
76 | * @brief Configure IRQ gate for UART peripherals
77 | *
78 | * This function enables or disables IRQ gate for specified UART peripheral
79 | *
80 | * @param instance UART instance
81 | * @param set Option for disabling or enabling IRQ gates.
82 | */
83 | void UART_SetSystemIRQ(uint32_t instance, PeripheralSystemIRQSetting set);
84 |
85 | /*!
86 | * @brief Configure IRQ gate for LPI2C peripherals
87 | *
88 | * This function enables or disables IRQ gate for specified LPI2C peripheral
89 | *
90 | * @param instance LPI2C instance
91 | * @param set Option for disabling or enabling IRQ gates.
92 | */
93 | void lpi2c_set_system_IRQ_gate(uint32_t instance, PeripheralSystemIRQSetting set);
94 |
95 | /*!
96 | * @brief Configure IRQ gate for LPSPI peripherals
97 | *
98 | * This function enables or disables IRQ gate for specified LPSPI peripheral
99 | *
100 | * @param instance LPSPI instance
101 | * @param set Option for disabling or enabling IRQ gates.
102 | */
103 | void lpspi_set_system_IRQ_gate(uint32_t instance, PeripheralSystemIRQSetting set);
104 |
105 | #if defined(__cplusplus)
106 | }
107 | #endif // __cplusplus
108 |
109 | //! @}
110 |
111 | ////////////////////////////////////////////////////////////////////////////////
112 | // EOF
113 | ////////////////////////////////////////////////////////////////////////////////
114 |
--------------------------------------------------------------------------------
/src/blfwk/AESKey.h:
--------------------------------------------------------------------------------
1 | /*
2 | * File: AESKey.h
3 | *
4 | * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 | * See included license file for license details.
6 | */
7 | #if !defined(_AESKey_h_)
8 | #define _AESKey_h_
9 |
10 | #include
11 | #include
12 | #include "Random.h"
13 |
14 | //! An AES-128 key is 128 bits, or 16 bytes.
15 | typedef uint8_t aes128_key_t[16];
16 |
17 | /*!
18 | * \brief Base class for AESKey.
19 | *
20 | * This class implements some bigger, non-template methods used in the
21 | * AESKey templated subclass.
22 | */
23 | class AESKeyBase
24 | {
25 | public:
26 | //! \brief Reads hex encoded data from \a stream.
27 | void _readFromStream(std::istream &stream, unsigned bytes, uint8_t *buffer) const;
28 |
29 | //! \brief Writes hex encoded data to \a stream.
30 | void _writeToStream(std::ostream &stream, unsigned bytes, const uint8_t *buffer) const;
31 | };
32 |
33 | /*!
34 | * \brief Generic AES key class.
35 | *
36 | * The template parameter \a S is the number of bits in the key.
37 | *
38 | * The underlying key type can be accessed like this: AESKey<128>::key_t
39 | *
40 | * When a key instance is destroyed, it erases the key data by setting it
41 | * to all zeroes.
42 | *
43 | * \todo Add a way to allow only key sizes of 128, 192, and 256 bits.
44 | * \todo Find a cross platform way to prevent the key data from being written
45 | * to the VM swapfile.
46 | *
47 | * AESKey<128> key = AESKey<128>::readFromStream(s);
48 | */
49 | template
50 | class AESKey : public AESKeyBase
51 | {
52 | public:
53 | //! Type for this size of AES key.
54 | typedef uint8_t key_t[S / 8];
55 |
56 | public:
57 | //! \brief Default constructor.
58 | //!
59 | //! Initializes the key to 0.
60 | AESKey() { memset(m_key, 0, sizeof(m_key)); }
61 | //! \brief Constructor taking a key value reference.
62 | AESKey(const key_t &key) { memcpy(m_key, &key, sizeof(m_key)); }
63 | // \brief Constructor taking a key value pointer.
64 | AESKey(const key_t *key) { memcpy(m_key, key, sizeof(m_key)); }
65 | //! \brief Constructor, reads key from stream in hex format.
66 | AESKey(std::istream &stream) { readFromStream(stream); }
67 | //! \brief Copy constructor.
68 | AESKey(const AESKey &other) { memcpy(m_key, other.m_key, sizeof(m_key)); }
69 | //! \brief Destructor.
70 | //!
71 | //! Sets the key value to zero.
72 | ~AESKey() { memset(m_key, 0, sizeof(m_key)); }
73 | //! \brief Set to the key to a randomly generated value.
74 | void randomize()
75 | {
76 | RandomNumberGenerator rng;
77 | rng.generateBlock(m_key, sizeof(m_key));
78 | }
79 |
80 | //! \brief Reads the key from a hex encoded data stream.
81 | void readFromStream(std::istream &stream) { _readFromStream(stream, S / 8, reinterpret_cast(&m_key)); }
82 | //! \brief Writes the key to a data stream in hex encoded format.
83 | void writeToStream(std::ostream &stream) const
84 | {
85 | _writeToStream(stream, S / 8, reinterpret_cast(&m_key));
86 | }
87 |
88 | //! \name Key accessors
89 | //@{
90 | inline const key_t &getKey() const { return m_key; }
91 | inline void getKey(key_t *key) const { memcpy(key, m_key, sizeof(m_key)); }
92 | inline void setKey(const key_t &key) { memcpy(m_key, &key, sizeof(m_key)); }
93 | inline void setKey(const key_t *key) { memcpy(m_key, key, sizeof(m_key)); }
94 | inline void setKey(const AESKey &key) { memcpy(m_key, key.m_key, sizeof(m_key)); }
95 | //@}
96 |
97 | //! \name Operators
98 | //@{
99 | const AESKey &operator=(const AESKey &key)
100 | {
101 | setKey(key);
102 | return *this;
103 | }
104 | const AESKey &operator=(const key_t &key)
105 | {
106 | setKey(key);
107 | return *this;
108 | }
109 | const AESKey &operator=(const key_t *key)
110 | {
111 | setKey(key);
112 | return *this;
113 | }
114 |
115 | operator const key_t &() const { return m_key; }
116 | operator const key_t *() const { return m_key; }
117 | friend std::ostream &operator<<(std::ostream &os, const AESKey &key)
118 | {
119 | key.writeToStream(os);
120 | return os;
121 | }
122 |
123 | //@}
124 |
125 | protected:
126 | key_t m_key; //!< The key value.
127 | };
128 |
129 | //! Standard type definition for an AES-128 key.
130 | typedef AESKey<128> AES128Key;
131 |
132 | #endif // _AESKey_h_
133 |
--------------------------------------------------------------------------------
/src/bootloader/bl_app_crc_check.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef __APP_CRC_CHECK_H__
32 | #define __APP_CRC_CHECK_H__
33 |
34 | #include
35 | #include "bootloader_common.h"
36 |
37 | //! @addtogroup app_crc_check
38 | //! @{
39 |
40 | ////////////////////////////////////////////////////////////////////////////////
41 | // Declarations
42 | ////////////////////////////////////////////////////////////////////////////////
43 |
44 | //! @brief Application crc check status codes.
45 | enum _crc_check_status
46 | {
47 | kStatus_AppCrcCheckPassed = MAKE_STATUS(kStatusGroup_AppCrcCheck, 0), //!< Crc check is valid and passed.
48 | kStatus_AppCrcCheckFailed = MAKE_STATUS(kStatusGroup_AppCrcCheck, 1), //!< Crc check is valid but failed.
49 | kStatus_AppCrcCheckInactive =
50 | MAKE_STATUS(kStatusGroup_AppCrcCheck, 2), //!< Crc check is inactive, Needs to be verified.
51 | kStatus_AppCrcCheckInvalid =
52 | MAKE_STATUS(kStatusGroup_AppCrcCheck,
53 | 3), //!< Crc check is invalid, As the BCA is invalid or crc parameters are unset (all 0xff bytes).
54 | kStatus_AppCrcCheckOutOfRange =
55 | MAKE_STATUS(kStatusGroup_AppCrcCheck, 4) //!< Crc check is valid but addresses are out of range.
56 | };
57 |
58 | //! @brief CRC Checksum Header
59 | typedef struct _crc_checksum_header
60 | {
61 | uint32_t tag; //!< [00:03] Tag value used to validate the bootloader configuration data. Must be set to 'kcfg'.
62 | uint32_t crcStartAddress; //!< [04:07]
63 | uint32_t crcByteCount; //!< [08:0b]
64 | uint32_t crcExpectedValue; //!< [0c:0f]
65 | } crc_checksum_header_t;
66 |
67 | ////////////////////////////////////////////////////////////////////////////////
68 | // Prototypes
69 | ////////////////////////////////////////////////////////////////////////////////
70 |
71 | #if __cplusplus
72 | extern "C" {
73 | #endif
74 |
75 | //! @name Crc check
76 | //@{
77 |
78 | #if BL_FEATURE_CRC_ASSERT
79 | //! @brief Restore crc check failure pin to default state.
80 | void restore_crc_check_failure_pin(void);
81 | #endif
82 |
83 | //! @brief Initialize crc check status property based on BCA related fields.
84 | void init_crc_check_status(property_store_t *propertyStore);
85 |
86 | //! @brief Compare the CRC on a range of flash(specified in BCA) against a precomputed CRC value(stored in the BCA).
87 | bool is_application_crc_check_pass(void);
88 |
89 | //! @brief Calculate CRC checksum according to specified checksum header
90 | uint32_t calculate_application_crc32(crc_checksum_header_t *header, uint32_t crcHeaderStart);
91 |
92 | //@}
93 |
94 | #if __cplusplus
95 | }
96 | #endif
97 |
98 | //! @}
99 |
100 | #endif // __APP_CRC_CHECK_H__
101 | ////////////////////////////////////////////////////////////////////////////////
102 | // EOF
103 | ////////////////////////////////////////////////////////////////////////////////
104 |
--------------------------------------------------------------------------------
/src/blfwk/SimPacketizer.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _sim_packetizer_h_
32 | #define _sim_packetizer_h_
33 |
34 | #include "Packetizer.h"
35 | #include "SimPeripheral.h"
36 | #include "packet/command_packet.h"
37 |
38 | namespace blfwk
39 | {
40 | // Forward declarations.
41 | class Peripheral;
42 |
43 | /*!
44 | * @brief Provides source and sink for packets in the simulator space.
45 | */
46 | class SimPacketizer : public Packetizer
47 | {
48 | public:
49 | //! @brief Constants
50 | enum _simPacketizer_contants
51 | {
52 | kSimReadTimeoutMs = 5000
53 | };
54 |
55 | public:
56 | //! @brief Default Constructor.
57 | SimPacketizer(SimPeripheral *peripheral);
58 |
59 | //! @brief Destructor.
60 | virtual ~SimPacketizer();
61 |
62 | //! @brief Peripheral accessor.
63 | virtual SimPeripheral *getPeripheral() { return dynamic_cast(m_peripheral); }
64 | //! @brief Read a packet.
65 | //!
66 | //! Provides the address of a buffer containing the packet.
67 | //!
68 | //! @param packet Pointer location to write packet pointer
69 | //! @param packetLength Number of bytes in returned packet.
70 | virtual status_t readPacket(uint8_t **packet, uint32_t *packetLength, packet_type_t packetType);
71 |
72 | //! @brief Write a packet.
73 | //!
74 | //! @param packet Pointer to packet to write.
75 | //! @param byteCount Number of bytes in packet.
76 | virtual status_t writePacket(const uint8_t *packet, uint32_t byteCount, packet_type_t packetType);
77 |
78 | //! @brief Abort data phase.
79 | virtual void abortPacket() { setAborted(true); }
80 | //! @brief Send framing packet ack.
81 | virtual void sync(){};
82 |
83 | //! @brief Finalize.
84 | virtual void finalize();
85 |
86 | //! @brief Enable simulator command processor pump.
87 | virtual void enableSimulatorPump() { m_isPumpEnabled = true; }
88 | //! @brief Pump simulator command processor.
89 | virtual void pumpSimulator();
90 |
91 | //! @brief Set aborted flag.
92 | //!
93 | //! Used for out-of-band flow control for simulator.
94 | virtual void setAborted(bool aborted) { m_isAborted = aborted; }
95 | //! @brief Return the max packet size.
96 | virtual uint32_t getMaxPacketSize() { return kDefaultMaxPacketSize; }
97 | protected:
98 | bool m_isPumpEnabled; //!< True if simulator pump enabled.
99 | bool m_isAborted; //!< Data phase abort requested by receiver.
100 | uint8_t m_buffer[kDefaultMaxPacketSize]; //!< Buffer for bytes used to build read packet.
101 | };
102 |
103 | } // namespace blfwk
104 |
105 | #endif // _sim_packetizer_h_
106 |
107 | ////////////////////////////////////////////////////////////////////////////////
108 | // EOF
109 | ////////////////////////////////////////////////////////////////////////////////
110 |
--------------------------------------------------------------------------------
/src/blfwk/src/SBSourceFile.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #include
32 | #include
33 | #include "string.h"
34 | #include "blfwk/stdafx.h"
35 | #include "blfwk/EndianUtilities.h"
36 | #include "blfwk/GHSSecInfo.h"
37 | #include "blfwk/Logging.h"
38 | #include "blfwk/SBSourceFile.h"
39 |
40 | using namespace blfwk;
41 |
42 | SBSourceFile::SBSourceFile(const std::string &path)
43 | : BinarySourceFile(path, kSBSourceFile)
44 | {
45 | }
46 |
47 | SBSourceFile::~SBSourceFile()
48 | {
49 | }
50 |
51 | bool SBSourceFile::isSBFile(std::istream &stream)
52 | {
53 | try
54 | {
55 | boot_image_header_t header; //!< Header from the SB boot image.
56 |
57 | // readImageHeader
58 | // seek to beginning of the stream/file and read the plaintext header
59 | stream.seekg(0, std::ios_base::beg);
60 | if (stream.read((char *)&header, sizeof(header)).bad())
61 | {
62 | throw SBFileException("failed to read SB image header");
63 | }
64 |
65 | header.m_flags = ENDIAN_LITTLE_TO_HOST_U16(header.m_flags);
66 | header.m_imageBlocks = ENDIAN_LITTLE_TO_HOST_U32(header.m_imageBlocks);
67 | header.m_firstBootTagBlock = ENDIAN_LITTLE_TO_HOST_U32(header.m_firstBootTagBlock);
68 | header.m_firstBootableSectionID = ENDIAN_LITTLE_TO_HOST_U32(header.m_firstBootableSectionID);
69 | header.m_keyCount = ENDIAN_LITTLE_TO_HOST_U16(header.m_keyCount);
70 | header.m_keyDictionaryBlock = ENDIAN_LITTLE_TO_HOST_U16(header.m_keyDictionaryBlock);
71 | header.m_headerBlocks = ENDIAN_LITTLE_TO_HOST_U16(header.m_headerBlocks);
72 | header.m_sectionCount = ENDIAN_LITTLE_TO_HOST_U16(header.m_sectionCount);
73 | header.m_sectionHeaderSize = ENDIAN_LITTLE_TO_HOST_U16(header.m_sectionHeaderSize);
74 | header.m_timestamp = ENDIAN_LITTLE_TO_HOST_U64(header.m_timestamp);
75 |
76 | // check header signature 1
77 | if (header.m_signature[0] != 'S' || header.m_signature[1] != 'T' || header.m_signature[2] != 'M' ||
78 | header.m_signature[3] != 'P')
79 | {
80 | throw SBFileException("invalid SB signature 1");
81 | }
82 |
83 | // check header signature 2 for version 1.1 and greater
84 | if ((header.m_majorVersion > 1 || (header.m_majorVersion == 1 && header.m_minorVersion >= 1)) &&
85 | (header.m_signature2[0] != 's' || header.m_signature2[1] != 'g' || header.m_signature2[2] != 't' ||
86 | header.m_signature2[3] != 'l'))
87 | {
88 | Log::log(Logger::kWarning, "warning: invalid SB signature 2\n");
89 | }
90 |
91 | return true;
92 | }
93 | catch (...)
94 | {
95 | return false;
96 | }
97 | }
98 |
99 | DataSource *SBSourceFile::createDataSource()
100 | {
101 | throw std::runtime_error("SBSourceFile::createDataSource() has not been implemented.");
102 | }
103 |
--------------------------------------------------------------------------------
/src/blfwk/Simulator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _Simulator_h_
32 | #define _Simulator_h_
33 |
34 | #include "Bootloader.h"
35 | #include "Command.h"
36 | #include "SimulatorMemory.h"
37 | #include "SimPacketizer.h"
38 | #include "Peripheral.h"
39 | #include "Logging.h"
40 |
41 | #include "bootloader/bl_command.h"
42 | #include "bootloader/bl_context.h"
43 |
44 | namespace blfwk
45 | {
46 | /*!
47 | * @brief Represents the host bootloader.
48 | *
49 | * This class provides a convenient way to access other bootloader
50 | * framework objects.
51 | */
52 | class Simulator : public Bootloader
53 | {
54 | public:
55 | //! @brief A vector of memory stores.
56 | typedef std::vector memory_vector_t;
57 |
58 | //! @brief Get the singleton simulator object.
59 | static Simulator &getSimulator()
60 | {
61 | //! @brief Singleton object.
62 | static Simulator theSimulator;
63 | return theSimulator;
64 | }
65 |
66 | //! @brief Destructor.
67 | virtual ~Simulator();
68 |
69 | //! @brief Initialize.
70 | void init();
71 |
72 | //! @brief Configure and open state files.
73 | //!
74 | //! Must be called to open or create state files.
75 | //!
76 | //! @param pathToDir Directory for state files.
77 | //! @param forceCreate True to re-create state files even if they exist.
78 | bool openStateFiles(const std::string &pathToDir, bool forceCreate);
79 |
80 | //! @name Accessors.
81 | //@{
82 |
83 | //! @brief Get the host packetizer.
84 | SimPacketizer *getHost() const { return dynamic_cast(m_hostPacketizer); }
85 | //! @brief Get the device packetizer.
86 | SimPacketizer *getDevice() const { return m_devicePacketizer; }
87 | //! @brief Get a device state memory store.
88 | //!
89 | //! index Index into memory map for the simulated device.
90 | MemoryStore *getMemoryStore(int index) const { return m_memoryStore[index]; }
91 | //@}
92 |
93 | protected:
94 | //! @brief Constructor.
95 | Simulator();
96 | SimPacketizer *m_devicePacketizer; //!< Packet interface to recieve commands on.
97 | uchar_deque_t m_commandStream;
98 | uchar_deque_t m_responseStream;
99 | command_processor_data_t m_commandProcessor;
100 | bool m_areStateFilesOpen; //!< True if state files are in use
101 | memory_vector_t m_memoryStore; //!< Vector of memory stores, one per map entry.
102 | OptionsStore m_optionsStore; //!< Persistent options store.
103 | property_store_t m_propertyStore;
104 | peripheral_descriptor_t m_activePeripheral; //!< Descriptor for the active peripheral.
105 | FileLogger *m_logger; //!< Singleton logger instance.
106 | };
107 |
108 | } // namespace blfwk
109 |
110 | #endif // _Simulator_h_
111 |
112 | ////////////////////////////////////////////////////////////////////////////////
113 | // EOF
114 | ////////////////////////////////////////////////////////////////////////////////
115 |
--------------------------------------------------------------------------------
/src/bootloader/bootloader.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 | #if !defined(__BOOTLOADER_H__)
31 | #define __BOOTLOADER_H__
32 |
33 | #include "bootloader_common.h"
34 | #include "bootloader/bl_peripheral.h"
35 | #include "bootloader/bl_command.h"
36 | #include "bootloader/bl_context.h"
37 | #include "bootloader/bl_version.h"
38 | #include "bootloader/bl_user_entry.h"
39 | #include "bootloader/bl_peripheral_interface.h"
40 | #include "bootloader/bl_shutdown_cleanup.h"
41 |
42 | ////////////////////////////////////////////////////////////////////////////////
43 | // Definitions
44 | ////////////////////////////////////////////////////////////////////////////////
45 |
46 | //! @brief Bootloader status codes.
47 | //! @ingroup bl_core
48 | enum _bootloader_status
49 | {
50 | kStatus_UnknownCommand = MAKE_STATUS(kStatusGroup_Bootloader, 0),
51 | kStatus_SecurityViolation = MAKE_STATUS(kStatusGroup_Bootloader, 1),
52 | kStatus_AbortDataPhase = MAKE_STATUS(kStatusGroup_Bootloader, 2),
53 | kStatus_Ping = MAKE_STATUS(kStatusGroup_Bootloader, 3),
54 | kStatus_NoResponse = MAKE_STATUS(kStatusGroup_Bootloader, 4),
55 | kStatus_NoResponseExpected = MAKE_STATUS(kStatusGroup_Bootloader, 5)
56 | };
57 |
58 | //! @brief Root of the bootloader API tree.
59 | //!
60 | //! An instance of this struct resides in read-only memory in the bootloader. It
61 | //! provides a user application access to APIs exported by the bootloader.
62 | //!
63 | //! @note The order of existing fields must not be changed.
64 | //!
65 | //! @ingroup context
66 | #if 1 // Moved into each SOC based header file in future !!!!!!!!!!!!!
67 | typedef struct BootloaderTree
68 | {
69 | void (*runBootloader)(void *arg); //!< Function to start the bootloader executing.
70 | standard_version_t version; //!< Bootloader version number.
71 | const char *copyright; //!< Copyright string.
72 | const bootloader_context_t *runtimeContext; //!< Pointer to the bootloader's runtime context.
73 | const flash_driver_interface_t *flashDriver; //!< Flash driver API.
74 | const aes_driver_interface_t *aesDriver; //!< AES driver API.
75 | } bootloader_tree_t;
76 | #endif
77 | ////////////////////////////////////////////////////////////////////////////////
78 | // Prototypes
79 | ////////////////////////////////////////////////////////////////////////////////
80 |
81 | #if defined(__cplusplus)
82 | extern "C" {
83 | #endif
84 |
85 | /*!
86 | * @brief Verify that a given address is ok to jump to.
87 | *
88 | * @param applicationAddress The entry point address to validate.
89 | * @return Boolean indicating whether the address is valid.
90 | *
91 | * @ingroup bl_core
92 | */
93 | bool is_valid_application_location(uint32_t applicationAddress);
94 |
95 | #if defined(__cplusplus)
96 | }
97 | #endif
98 |
99 | #endif // __BOOTLOADER_H__
100 | ////////////////////////////////////////////////////////////////////////////////
101 | // EOF
102 | ////////////////////////////////////////////////////////////////////////////////
103 |
--------------------------------------------------------------------------------
/src/blfwk/UartPeripheral.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without modification,
6 | * are permitted provided that the following conditions are met:
7 | *
8 | * o Redistributions of source code must retain the above copyright notice, this list
9 | * of conditions and the following disclaimer.
10 | *
11 | * o Redistributions in binary form must reproduce the above copyright notice, this
12 | * list of conditions and the following disclaimer in the documentation and/or
13 | * other materials provided with the distribution.
14 | *
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from this
17 | * software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 | */
30 |
31 | #ifndef _uart_peripheral_h_
32 | #define _uart_peripheral_h_
33 |
34 | #include "Peripheral.h"
35 | #include "packet/command_packet.h"
36 |
37 | //! @addtogroup uart_peripheral
38 | //! @{
39 |
40 | namespace blfwk
41 | {
42 | /*!
43 | * @brief Peripheral that talks to the target device over COM port hardware.
44 | */
45 | class UartPeripheral : public Peripheral
46 | {
47 | public:
48 | //! @breif Constants.
49 | enum _uart_peripheral_constants
50 | {
51 | // The read() implementation for the UartPeripheral does not use this the timeout parameter.
52 | kUartPeripheral_UnusedTimeout = 0,
53 | // Serial timeout is set to this default during init().
54 | kUartPeripheral_DefaultReadTimeoutMs = 1000,
55 | kUartPeripheral_DefaultBaudRate = 9600
56 | };
57 |
58 | public:
59 | //! @brief Parameterized constructor that opens the serial port.
60 | //!
61 | //! Opens and configures the port. Throws exception if port configuration fails.
62 | //!
63 | //! Note: following COM port configuration is assumed: 8 bits, 1 stop bit, no parity.
64 | //!
65 | //! @param port OS file path for COM port. For example "COM1" on Windows.
66 | //! @param speed Port speed, e.g. 9600.
67 | UartPeripheral(const char *port, long speed = kUartPeripheral_DefaultBaudRate);
68 |
69 | //! @brief Destructor.
70 | virtual ~UartPeripheral();
71 |
72 | //! @brief Flush.
73 | //!
74 | //! should be called on an open COM port in order to flush any remaining data in the UART RX buffer
75 | void flushRX();
76 |
77 | //! @brief Read bytes.
78 | //!
79 | //! @param buffer Pointer to buffer.
80 | //! @param requestedBytes Number of bytes to read.
81 | //! @param actualBytes Number of bytes actually read.
82 | //! @param timeoutMs Time in milliseconds to wait for read to complete.
83 | virtual status_t read(uint8_t *buffer, uint32_t requestedBytes, uint32_t *actualBytes, uint32_t unused_timeoutMs);
84 |
85 | //! @brief Write bytes.
86 | //!
87 | //! @param buffer Pointer to buffer to write
88 | //! @param byteCount Number of bytes to write
89 | virtual status_t write(const uint8_t *buffer, uint32_t byteCount);
90 |
91 | protected:
92 | //! @brief Initialize.
93 | //!
94 | //! Opens and configures the port.
95 | //!
96 | //! Note: following COM port configuration is assumed: 8 bits, 1 stop bit, no parity.
97 | //!
98 | //! @param port OS file path for COM port. For example "COM1" on Windows.
99 | //! @param speed Port speed, e.g. 9600.
100 | bool init(const char *port, long speed);
101 |
102 | int m_fileDescriptor; //!< Port file descriptor.
103 | uint8_t m_buffer[kDefaultMaxPacketSize]; //!< Buffer for bytes used to build read packet.
104 | };
105 |
106 | } // namespace blfwk
107 |
108 | //! @}
109 |
110 | #endif // _uart_peripheral_h_
111 |
112 | ////////////////////////////////////////////////////////////////////////////////
113 | // EOF
114 | ////////////////////////////////////////////////////////////////////////////////
115 |
--------------------------------------------------------------------------------