Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++17 introduction and minor clean-ups #453

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4)

project(uuu)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_SKIP_RPATH ON)

Expand Down
2 changes: 1 addition & 1 deletion libuuu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.4)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_SKIP_RPATH ON)

Expand Down
29 changes: 29 additions & 0 deletions libuuu/bmap.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much to see here (and in bmap.h), just some missing license headers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is okay to add BSD license headers, just remove copy write line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped the Copyright ... lines.

* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of the NXP Semiconductor nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#include <map>
#include <tinyxml2.h>

Expand Down
29 changes: 29 additions & 0 deletions libuuu/bmap.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* Neither the name of the NXP Semiconductor nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#pragma once

#include <string>
Expand Down
12 changes: 6 additions & 6 deletions libuuu/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static map<string, shared_ptr<FileBuffer>> g_filebuffer_map;
static mutex g_mutex_map;
static bool g_small_memory = true;

#define MAGIC_PATH '>'
static constexpr char MAGIC_PATH = '>';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my knowledge #defines are generally being frowned upon today. I took the switch to C++17 as an opportunity to replace all of these which defined constants by constexpr "variables".


string g_current_dir = ">";

Expand Down Expand Up @@ -139,7 +139,7 @@ class FSBasic

virtual int Decompress(const string& /*backfifle*/, shared_ptr<FileBuffer> /*outp*/) { return 0; };
virtual bool seekable(const string& /*backfile*/) { return false; }
virtual std::shared_ptr<FragmentBlock> ScanCompressblock(const string& /*backfile*/, size_t& /*input_offset*/, size_t& /*output_offset*/) { return NULL; };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few NULL constants were around still. I replaced these by nullptr.

virtual std::shared_ptr<FragmentBlock> ScanCompressblock(const string& /*backfile*/, size_t& /*input_offset*/, size_t& /*output_offset*/) { return nullptr; };
virtual int PreloadWorkThread(shared_ptr<FileBuffer>outp);

virtual int split(const string &filename, string *outbackfile, string *outfilename, bool dir=false)
Expand Down Expand Up @@ -969,13 +969,13 @@ shared_ptr<FragmentBlock> FSBz2::ScanCompressblock(const string& backfile, size_

pbz = get_file_buffer(backfile, true);
if (pbz == nullptr) {
return NULL;
return nullptr;
}

size_t request_size = 1 * 1000 * 1000;
shared_ptr<DataBuffer> pd = pbz->request_data(input_offset, request_size);
if (!pd)
return NULL;
return nullptr;

uint8_t* p1 = pd->data();

Expand Down Expand Up @@ -1011,7 +1011,7 @@ shared_ptr<FragmentBlock> FSBz2::ScanCompressblock(const string& backfile, size_
}
}

return NULL;
return nullptr;
}

bool FSBz2::seekable(const string& backfile)
Expand Down Expand Up @@ -1658,7 +1658,7 @@ std::shared_ptr<FragmentBlock> FileBuffer::request_new_blk()
while (offset > m_last_request_offset + m_total_buffer_size)
{
if (m_reset_stream)
return NULL;
return nullptr;
std::unique_lock<std::mutex> lck(m_pool_load_cv_mutex);
m_pool_load_cv.wait(lck);
}
Expand Down
24 changes: 12 additions & 12 deletions libuuu/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ int file_overwrite_monitor(std::string filename, FileBuffer *p);

//bit 0, data loaded
//bit 1, data total size known
#define FILEBUFFER_FLAG_LOADED_BIT 0x1
#define FILEBUFFER_FLAG_KNOWN_SIZE_BIT 0x2
#define FILEBUFFER_FLAG_ERROR_BIT 0x4
#define FILEBUFFER_FLAG_NEVER_FREE 0x8
#define FILEBUFFER_FLAG_PARTIAL_RELOADABLE 0x10
#define FILEBUFFER_FLAG_SEG_DONE 0x20
inline constexpr int FILEBUFFER_FLAG_LOADED_BIT = 0x1;
inline constexpr int FILEBUFFER_FLAG_KNOWN_SIZE_BIT = 0x2;
inline constexpr int FILEBUFFER_FLAG_ERROR_BIT = 0x4;
inline constexpr int FILEBUFFER_FLAG_NEVER_FREE = 0x8;
inline constexpr int FILEBUFFER_FLAG_PARTIAL_RELOADABLE = 0x10;
inline constexpr int FILEBUFFER_FLAG_SEG_DONE = 0x20;

#define FILEBUFFER_FLAG_LOADED (FILEBUFFER_FLAG_LOADED_BIT|FILEBUFFER_FLAG_KNOWN_SIZE_BIT) // LOADED must be known size
#define FILEBUFFER_FLAG_KNOWN_SIZE FILEBUFFER_FLAG_KNOWN_SIZE_BIT
inline constexpr int FILEBUFFER_FLAG_LOADED = (FILEBUFFER_FLAG_LOADED_BIT|FILEBUFFER_FLAG_KNOWN_SIZE_BIT); // LOADED must be known size
inline constexpr int FILEBUFFER_FLAG_KNOWN_SIZE = FILEBUFFER_FLAG_KNOWN_SIZE_BIT;

class FileBuffer;
class FSBasic;
Expand All @@ -95,7 +95,7 @@ class FragmentBlock
std::vector<uint8_t> m_data;
std::mutex m_mutex;
std::atomic_int m_dataflags{0};
uint8_t* m_pData = NULL;
uint8_t* m_pData = nullptr;
uint8_t* data()
{
if (m_pData)
Expand All @@ -118,7 +118,7 @@ class DataBuffer : public std::enable_shared_from_this<DataBuffer>
protected:

ALLOCATION_WAYS get_m_allocate_way() const noexcept { return m_allocate_way; }
uint8_t* m_pDatabuffer = NULL;
uint8_t* m_pDatabuffer = nullptr;
size_t m_DataSize = 0;
size_t m_MemSize = 0;
std::shared_ptr<FileBuffer> m_ref;
Expand Down Expand Up @@ -223,7 +223,7 @@ class FileBuffer: public std::enable_shared_from_this<FileBuffer>
std::lock_guard<std::mutex> lock(m_seg_map_mutex);
auto it = m_seg_map.lower_bound(offset);
if ( it == m_seg_map.end())
return NULL;
return nullptr;

auto blk = it->second;
if (check_offset_in_seg(offset, blk))
Expand All @@ -235,7 +235,7 @@ class FileBuffer: public std::enable_shared_from_this<FileBuffer>
}
return blk;
}
return NULL;
return nullptr;
}
}
void truncate_old_data_in_pool();
Expand Down
4 changes: 2 additions & 2 deletions libuuu/ffu_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include <cstdint>

#define FFU_SECURITY_SIGNATURE "SignedImage "
inline constexpr const char * FFU_SECURITY_SIGNATURE = "SignedImage ";

#pragma pack(1)

Expand All @@ -50,7 +50,7 @@ typedef struct _FFU_SECURITY_HEADER
uint32_t dwHashTableSize; // size of hash table
} FFU_SECURITY_HEADER;

#define FFU_SIGNATURE "ImageFlash "
inline constexpr const char * FFU_SIGNATURE = "ImageFlash ";

typedef struct _IMAGE_HEADER
{
Expand Down
4 changes: 2 additions & 2 deletions libuuu/gen_ver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e

if [ -f ../.tarball-version ]
then
echo "#define GIT_VERSION \"lib$(cat ../.tarball-version)\"" > "$file_to_write"
echo "inline constexpr const char * GIT_VERSION = \"lib$(cat ../.tarball-version)\";" > "$file_to_write"
exit 0
fi

Expand All @@ -24,5 +24,5 @@ then
#echo "In a repo"
# Get the version of the last commit of the repo
version=`git describe --long`
echo "#define GIT_VERSION \"lib$version\"" > $file_to_write
echo "inline constexpr const char * GIT_VERSION = \"lib$version\";" > $file_to_write
fi
10 changes: 5 additions & 5 deletions libuuu/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#define INVALID_SOCKET -1
static constexpr int INVALID_SOCKET = -1;
#include <unistd.h>
#endif

Expand Down Expand Up @@ -220,7 +220,7 @@ int HttpStream::HttpGetHeader(std::string host, std::string path, int port, bool

// End the request.
if (bResults)
bResults = WinHttpReceiveResponse(m_hRequest, NULL);
bResults = WinHttpReceiveResponse(m_hRequest, nullptr);

// Resend the request in case of
// ERROR_WINHTTP_RESEND_REQUEST error.
Expand All @@ -232,10 +232,10 @@ int HttpStream::HttpGetHeader(std::string host, std::string path, int port, bool
bResults = WinHttpQueryHeaders(m_hRequest,
WINHTTP_QUERY_STATUS_CODE |
WINHTTP_QUERY_FLAG_NUMBER,
NULL,
nullptr,
&status,
&dwSize,
NULL);
nullptr);

if (bResults)
{
Expand Down Expand Up @@ -286,7 +286,7 @@ int HttpStream::HttpGetHeader(std::string host, std::string path, int port, bool
dwSelectedScheme,
convert.from_bytes(up.first).c_str(),
convert.from_bytes(up.second).c_str(),
NULL);
nullptr);
}

retry--;
Expand Down
4 changes: 2 additions & 2 deletions libuuu/liberror.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
void set_last_err_string(const std::string &str);
void set_last_err_id(int id);

#define ERR_OUT_MEMORY -2
#define ERR_ACCESS_DENIED -3
inline constexpr int ERR_OUT_MEMORY = -2;
inline constexpr int ERR_ACCESS_DENIED = -3;
2 changes: 1 addition & 1 deletion libuuu/libuuu.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ EXT void uuu_set_debug_level(uint32_t mask);
*/
EXT void uuu_set_small_mem(uint32_t val);

#define MAX_USER_LEN 128
inline constexpr size_t MAX_USER_LEN = 128;
typedef int (*uuu_askpasswd)(char* prompt, char user[MAX_USER_LEN], char passwd[MAX_USER_LEN]);
EXT int uuu_set_askpasswd(uuu_askpasswd ask);

Expand Down
10 changes: 5 additions & 5 deletions libuuu/rominfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ const ROM_INFO * search_rom_info(const ConfigItem *item)
}


#define IV_MAX_LEN 32
#define HASH_MAX_LEN 64
static constexpr size_t IV_MAX_LEN = 32;
static constexpr size_t HASH_MAX_LEN = 64;

#define CONTAINER_HDR_ALIGNMENT 0x400
#define CONTAINER_HDR_ALIGNMENT_V2 0x4000
static constexpr uint32_t CONTAINER_HDR_ALIGNMENT = 0x400;
static constexpr uint32_t CONTAINER_HDR_ALIGNMENT_V2 = 0x4000;
static constexpr uint8_t CONTAINER_TAG = 0x87;
static constexpr uint8_t V2X_TAG = 0x82; // After imx943

Expand Down Expand Up @@ -183,7 +183,7 @@ size_t GetContainerActualSize(shared_ptr<DataBuffer> p, size_t offset, bool bROM
uint32_t sz = image->size + image->offset + cindex * align;

/* keep v1 align for calculate spl size */
sz = round_up(sz, static_cast<uint32_t>(CONTAINER_HDR_ALIGNMENT));
sz = round_up(sz, CONTAINER_HDR_ALIGNMENT);

if (sz > (p->size() - offset))
{
Expand Down
2 changes: 1 addition & 1 deletion libuuu/sdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ SDPBootCmd::SDPBootCmd(char *p) : SDPCmdBase(p)
insert_param_info("-barebox", &m_barebox, Param::Type::e_bool);
}

# define BAREBOX_MAGIC_OFFSET 0x20
static constexpr size_t BAREBOX_MAGIC_OFFSET = 0x20;

bool SDPBootCmd::is_barebox_img(void)
{
Expand Down
38 changes: 19 additions & 19 deletions libuuu/sdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,25 @@ struct BootData

#pragma pack ()

#define ROM_KERNEL_CMD_RD_MEM 0x0101
#define ROM_KERNEL_CMD_WR_MEM 0x0202
#define ROM_KERNEL_CMD_WR_FILE 0x0404
#define ROM_KERNEL_CMD_ERROR_STATUS 0x0505
#define RAM_KERNEL_CMD_HEADER 0x0606
//#define ROM_KERNEL_CMD_RE_ENUM 0x0909
#define ROM_KERNEL_CMD_DCD_WRITE 0x0A0A
#define ROM_KERNEL_CMD_JUMP_ADDR 0x0B0B
#define ROM_KERNEL_CMD_SKIP_DCD_HEADER 0x0C0C

#define MAX_DCD_WRITE_REG_CNT 85
#define ROM_WRITE_ACK 0x128A8A12
#define ROM_STATUS_ACK 0x88888888
#define ROM_OK_ACK 0x900DD009

#define IVT_BARKER_HEADER 0x402000D1
#define IVT_BARKER2_HEADER 0x412000D1

#define HAB_TAG_DCD 0xd2 /**< Device Configuration Data */
inline constexpr uint16_t ROM_KERNEL_CMD_RD_MEM = 0x0101;
inline constexpr uint16_t ROM_KERNEL_CMD_WR_MEM = 0x0202;
inline constexpr uint16_t ROM_KERNEL_CMD_WR_FILE = 0x0404;
inline constexpr uint16_t ROM_KERNEL_CMD_ERROR_STATUS = 0x0505;
inline constexpr uint16_t RAM_KERNEL_CMD_HEADER = 0x0606;
// inline constexpr uint16_t ROM_KERNEL_CMD_RE_ENUM = 0x0909;
inline constexpr uint16_t ROM_KERNEL_CMD_DCD_WRITE = 0x0A0A;
inline constexpr uint16_t ROM_KERNEL_CMD_JUMP_ADDR = 0x0B0B;
inline constexpr uint16_t ROM_KERNEL_CMD_SKIP_DCD_HEADER = 0x0C0C;

inline constexpr unsigned int MAX_DCD_WRITE_REG_CNT = 85;
inline constexpr uint32_t ROM_WRITE_ACK = 0x128A8A12;
inline constexpr uint32_t ROM_STATUS_ACK = 0x88888888;
inline constexpr uint32_t ROM_OK_ACK = 0x900DD009;

inline constexpr uint32_t IVT_BARKER_HEADER = 0x402000D1;
inline constexpr uint32_t IVT_BARKER2_HEADER = 0x412000D1;

inline constexpr uint8_t HAB_TAG_DCD = 0xd2; /**< Device Configuration Data */

class SDPCmdBase:public CmdBase
{
Expand Down
14 changes: 7 additions & 7 deletions libuuu/sdps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ struct _ST_HID_CBW
CDBHIDDOWNLOAD Cdb; // cdb: the command descriptor block
};

#define BLTC_DOWNLOAD_FW 2
#define HID_BLTC_REPORT_TYPE_DATA_OUT 2
#define HID_BLTC_REPORT_TYPE_COMMAND_OUT 1
static constexpr uint8_t BLTC_DOWNLOAD_FW = 2;
[[maybe_unused]] static constexpr uint8_t HID_BLTC_REPORT_TYPE_DATA_OUT = 2;
static constexpr uint8_t HID_BLTC_REPORT_TYPE_COMMAND_OUT = 1;

#define CBW_BLTC_SIGNATURE 0x43544C42; // "BLTC" (little endian)
#define CBW_PITC_SIGNATURE 0x43544950; // "PITC" (little endian)
static constexpr uint32_t CBW_BLTC_SIGNATURE = 0x43544C42; // "BLTC" (little endian)
[[maybe_unused]] static constexpr uint32_t CBW_PITC_SIGNATURE = 0x43544950; // "PITC" (little endian)
// Flags values for _ST_HID_CBW
#define CBW_DEVICE_TO_HOST_DIR 0x80; // "Data Out"
#define CBW_HOST_TO_DEVICE_DIR 0x00; // "Data In"
[[maybe_unused]] static constexpr uint8_t CBW_DEVICE_TO_HOST_DIR = 0x80; // "Data Out"
static constexpr uint8_t CBW_HOST_TO_DEVICE_DIR = 0x00; // "Data In"

#pragma pack ()

Expand Down
Loading
Loading