From c0a46c343a9a6c1c4e42b9c5552ba99495f61857 Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Feb 2025 21:36:43 +0100 Subject: [PATCH 1/8] Use `nullptr` instead of `NULL` Signed-off-by: markuspg --- libuuu/buffer.cpp | 10 +++++----- libuuu/buffer.h | 8 ++++---- libuuu/http.cpp | 8 ++++---- libuuu/usbhotplug.cpp | 2 +- uuu/autocomplete.cpp | 8 ++++---- uuu/uuu.cpp | 12 ++++++------ 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/libuuu/buffer.cpp b/libuuu/buffer.cpp index 1649bc88..0a0ea757 100644 --- a/libuuu/buffer.cpp +++ b/libuuu/buffer.cpp @@ -139,7 +139,7 @@ class FSBasic virtual int Decompress(const string& /*backfifle*/, shared_ptr /*outp*/) { return 0; }; virtual bool seekable(const string& /*backfile*/) { return false; } - virtual std::shared_ptr ScanCompressblock(const string& /*backfile*/, size_t& /*input_offset*/, size_t& /*output_offset*/) { return NULL; }; + virtual std::shared_ptr ScanCompressblock(const string& /*backfile*/, size_t& /*input_offset*/, size_t& /*output_offset*/) { return nullptr; }; virtual int PreloadWorkThread(shared_ptroutp); virtual int split(const string &filename, string *outbackfile, string *outfilename, bool dir=false) @@ -969,13 +969,13 @@ shared_ptr 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 pd = pbz->request_data(input_offset, request_size); if (!pd) - return NULL; + return nullptr; uint8_t* p1 = pd->data(); @@ -1011,7 +1011,7 @@ shared_ptr FSBz2::ScanCompressblock(const string& backfile, size_ } } - return NULL; + return nullptr; } bool FSBz2::seekable(const string& backfile) @@ -1658,7 +1658,7 @@ std::shared_ptr 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 lck(m_pool_load_cv_mutex); m_pool_load_cv.wait(lck); } diff --git a/libuuu/buffer.h b/libuuu/buffer.h index 8813e342..bd1d199a 100644 --- a/libuuu/buffer.h +++ b/libuuu/buffer.h @@ -95,7 +95,7 @@ class FragmentBlock std::vector 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) @@ -118,7 +118,7 @@ class DataBuffer : public std::enable_shared_from_this 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 m_ref; @@ -223,7 +223,7 @@ class FileBuffer: public std::enable_shared_from_this std::lock_guard 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)) @@ -235,7 +235,7 @@ class FileBuffer: public std::enable_shared_from_this } return blk; } - return NULL; + return nullptr; } } void truncate_old_data_in_pool(); diff --git a/libuuu/http.cpp b/libuuu/http.cpp index acc5d6df..37ec2cb1 100644 --- a/libuuu/http.cpp +++ b/libuuu/http.cpp @@ -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. @@ -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) { @@ -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--; diff --git a/libuuu/usbhotplug.cpp b/libuuu/usbhotplug.cpp index 48607c6f..0e865b7f 100644 --- a/libuuu/usbhotplug.cpp +++ b/libuuu/usbhotplug.cpp @@ -241,7 +241,7 @@ static string get_device_path(libusb_device *dev) static string get_device_serial_no(libusb_device *dev, struct libusb_device_descriptor *desc, ConfigItem *item) { string serial; - struct libusb_device_handle *dev_handle = NULL; + struct libusb_device_handle *dev_handle = nullptr; int sid = desc->iSerialNumber; int ret = 0; diff --git a/uuu/autocomplete.cpp b/uuu/autocomplete.cpp index 9ca49734..e1e0daf4 100644 --- a/uuu/autocomplete.cpp +++ b/uuu/autocomplete.cpp @@ -60,7 +60,7 @@ void linux_auto_arg(const char *space = " ", const char * filter = "") { string str = filter; - const char *param[] = { "-b", "-d", "-v", "-V", "-s", NULL }; + const char *param[] = { "-b", "-d", "-v", "-V", "-s", nullptr }; int i = 0; for (int i = 0; param[i]; i++) @@ -121,7 +121,7 @@ void linux_autocomplete(int argc, char **argv) linux_auto_arg(); } - uuu_for_each_ls_file(linux_autocomplete_ls, cur.c_str(), NULL); + uuu_for_each_ls_file(linux_autocomplete_ls, cur.c_str(), nullptr); } string get_next_word(string str, size_t &pos) @@ -172,7 +172,7 @@ void power_shell_autocomplete(const char *p) if (argv.size() == 1) last.clear(); - uuu_for_each_ls_file(linux_autocomplete_ls, last.c_str(), NULL); + uuu_for_each_ls_file(linux_autocomplete_ls, last.c_str(), nullptr); } int auto_complete(int argc, char**argv) @@ -218,7 +218,7 @@ void print_autocomplete_help() { printf("Powershell: Enjoy auto [tab] command complete by run below command or put into Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1\n"); - HMODULE hModule = GetModuleHandleA(NULL); + HMODULE hModule = GetModuleHandleA(nullptr); char path[MAX_PATH]; GetModuleFileNameA(hModule, path, MAX_PATH); diff --git a/uuu/uuu.cpp b/uuu/uuu.cpp index 0814f9dc..03fbd8cc 100644 --- a/uuu/uuu.cpp +++ b/uuu/uuu.cpp @@ -110,7 +110,7 @@ class string_ex : public std::string { va_list args; va_start(args, fmt); - size_t len = std::vsnprintf(NULL, 0, fmt, args); + size_t len = std::vsnprintf(nullptr, 0, fmt, args); va_end(args); this->resize(len); @@ -505,7 +505,7 @@ class ShowNotify cout << "Download file:" << nt->str << endl; } - void print(int verbose = 0, uuu_notify*nt=NULL) + void print(int verbose = 0, uuu_notify*nt=nullptr) { verbose ? print_verbose(nt) : print_simple(); } @@ -839,7 +839,7 @@ int runshell(int shell) void print_udev() { - uuu_for_each_cfg(print_udev_rule, NULL); + uuu_for_each_cfg(print_udev_rule, nullptr); fprintf(stderr, "\n1: put above udev run into /etc/udev/rules.d/70-uuu.rules\n"); fprintf(stderr, "\tsudo sh -c \"uuu -udev > /etc/udev/rules.d/70-uuu.rules\"\n"); fprintf(stderr, "2: update udev rule\n"); @@ -858,7 +858,7 @@ void print_lsusb() printf("\tPath\t Chip\t Pro\t Vid\t Pid\t BcdVersion\t Serial_no\n"); printf("\t====================================================================\n"); - uuu_for_each_devices(print_usb_device, NULL); + uuu_for_each_devices(print_usb_device, nullptr); } #ifdef WIN32 @@ -889,7 +889,7 @@ int set_ignore_serial_number() return -1; #else printf("Set window registry to ignore usb hardware serial number for known uuu device:\n"); - return uuu_for_each_cfg(ignore_serial_number, NULL); + return uuu_for_each_cfg(ignore_serial_number, nullptr); #endif } @@ -1157,7 +1157,7 @@ int main(int argc, char **argv) printf("%sBuild in config:%s\n", g_vt_boldwhite, g_vt_default); printf("\tPctl\t Chip\t\t Vid\t Pid\t BcdVersion\t Serial_No\n"); printf("\t==================================================\n"); - uuu_for_each_cfg(print_cfg, NULL); + uuu_for_each_cfg(print_cfg, nullptr); if (!cmd_script.empty()) printf("\n%sRun built-in script:%s\n %s\n\n", g_vt_boldwhite, g_vt_default, cmd_script.c_str()); From 09d98b928e2feded23028e2142afd145bd8183e9 Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Feb 2025 21:42:43 +0100 Subject: [PATCH 2/8] Raise the C++ standard to "17" This adds some nifty features and should be well supported by now (at least it should work with Ubuntu 20.04). Signed-off-by: markuspg --- CMakeLists.txt | 2 +- libuuu/CMakeLists.txt | 2 +- uuu/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90a01979..eb6cbee8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/libuuu/CMakeLists.txt b/libuuu/CMakeLists.txt index 20a1b0fb..db1339a8 100644 --- a/libuuu/CMakeLists.txt +++ b/libuuu/CMakeLists.txt @@ -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) diff --git a/uuu/CMakeLists.txt b/uuu/CMakeLists.txt index 4ed667b6..7a62e4df 100644 --- a/uuu/CMakeLists.txt +++ b/uuu/CMakeLists.txt @@ -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) From be5d0d960e0c480501a7bf61335c6c5e1baef77e Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Feb 2025 21:46:21 +0100 Subject: [PATCH 3/8] Drop workaround for `fallthrough` attribute Signed-off-by: markuspg --- libuuu/zip.cpp | 6 ++---- libuuu/zip.h | 7 ------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/libuuu/zip.cpp b/libuuu/zip.cpp index c3121eed..d5488fb9 100644 --- a/libuuu/zip.cpp +++ b/libuuu/zip.cpp @@ -286,11 +286,9 @@ int Zip_file_Info::decompress(Zip *pZip, shared_ptrp) switch (ret) { case Z_NEED_DICT: ret = Z_DATA_ERROR; /* and fall through */ - FALLTHROUGH - // FALLTHROUGH + [[fallthrough]]; case Z_DATA_ERROR: - FALLTHROUGH - // FALLTHROUGH + [[fallthrough]]; case Z_MEM_ERROR: (void)inflateEnd(&m_strm); return -1; diff --git a/libuuu/zip.h b/libuuu/zip.h index 3a5e7a9f..403f7875 100644 --- a/libuuu/zip.h +++ b/libuuu/zip.h @@ -38,13 +38,6 @@ #include #include -/* Allow opportunistic use of the C++17 fall-through attribute . */ -#if defined(__cplusplus) && __cplusplus >= 201703L -#define FALLTHROUGH [[fallthrough]] -#else -#define FALLTHROUGH -#endif - class FileBuffer; #pragma pack(1) From fc6b52b8789fde4d3a1832b6963252129d19eec0 Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Feb 2025 22:35:05 +0100 Subject: [PATCH 4/8] Replace defines with `constexpr` in source files Signed-off-by: markuspg --- libuuu/buffer.cpp | 2 +- libuuu/http.cpp | 2 +- libuuu/rominfo.cpp | 10 +++++----- libuuu/sdp.cpp | 2 +- libuuu/sdps.cpp | 14 +++++++------- libuuu/usbhotplug.cpp | 2 +- libuuu/zip.cpp | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libuuu/buffer.cpp b/libuuu/buffer.cpp index 0a0ea757..983f2453 100644 --- a/libuuu/buffer.cpp +++ b/libuuu/buffer.cpp @@ -62,7 +62,7 @@ static map> g_filebuffer_map; static mutex g_mutex_map; static bool g_small_memory = true; -#define MAGIC_PATH '>' +static constexpr char MAGIC_PATH = '>'; string g_current_dir = ">"; diff --git a/libuuu/http.cpp b/libuuu/http.cpp index 37ec2cb1..84c31dc2 100644 --- a/libuuu/http.cpp +++ b/libuuu/http.cpp @@ -40,7 +40,7 @@ #include #include #include -#define INVALID_SOCKET -1 +static constexpr int INVALID_SOCKET = -1; #include #endif diff --git a/libuuu/rominfo.cpp b/libuuu/rominfo.cpp index 89b51a28..e5b3f720 100644 --- a/libuuu/rominfo.cpp +++ b/libuuu/rominfo.cpp @@ -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 @@ -183,7 +183,7 @@ size_t GetContainerActualSize(shared_ptr 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(CONTAINER_HDR_ALIGNMENT)); + sz = round_up(sz, CONTAINER_HDR_ALIGNMENT); if (sz > (p->size() - offset)) { diff --git a/libuuu/sdp.cpp b/libuuu/sdp.cpp index da008368..4e747350 100644 --- a/libuuu/sdp.cpp +++ b/libuuu/sdp.cpp @@ -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) { diff --git a/libuuu/sdps.cpp b/libuuu/sdps.cpp index d7f778db..1ad41ee3 100644 --- a/libuuu/sdps.cpp +++ b/libuuu/sdps.cpp @@ -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 () diff --git a/libuuu/usbhotplug.cpp b/libuuu/usbhotplug.cpp index 0e865b7f..166d46b9 100644 --- a/libuuu/usbhotplug.cpp +++ b/libuuu/usbhotplug.cpp @@ -236,7 +236,7 @@ static string get_device_path(libusb_device *dev) return str; } -#define SERIAL_NO_MAX 512 +static constexpr int SERIAL_NO_MAX = 512; static string get_device_serial_no(libusb_device *dev, struct libusb_device_descriptor *desc, ConfigItem *item) { diff --git a/libuuu/zip.cpp b/libuuu/zip.cpp index d5488fb9..e507f144 100644 --- a/libuuu/zip.cpp +++ b/libuuu/zip.cpp @@ -37,7 +37,7 @@ #include "liberror.h" #include "zip.h" -#define CHUNK 0x10000 +static constexpr size_t CHUNK = 0x10000; int Zip::BuildDirInfo() { From 5a690708ba9c8af3c317c15a47a1072c51c7b42a Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Feb 2025 23:14:11 +0100 Subject: [PATCH 5/8] Replace defines with `constexpr` in header files Signed-off-by: markuspg --- libuuu/buffer.h | 18 +++++++++--------- libuuu/ffu_format.h | 4 ++-- libuuu/liberror.h | 4 ++-- libuuu/libuuu.h | 2 +- libuuu/sdp.h | 38 +++++++++++++++++++------------------- libuuu/sparse_format.h | 10 +++++----- libuuu/tar.h | 2 +- libuuu/zip.h | 12 ++++++------ 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/libuuu/buffer.h b/libuuu/buffer.h index bd1d199a..5392b42d 100644 --- a/libuuu/buffer.h +++ b/libuuu/buffer.h @@ -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 - -#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_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; + +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; diff --git a/libuuu/ffu_format.h b/libuuu/ffu_format.h index 523400ab..071797ff 100644 --- a/libuuu/ffu_format.h +++ b/libuuu/ffu_format.h @@ -36,7 +36,7 @@ #include -#define FFU_SECURITY_SIGNATURE "SignedImage " +inline constexpr const char * FFU_SECURITY_SIGNATURE = "SignedImage "; #pragma pack(1) @@ -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 { diff --git a/libuuu/liberror.h b/libuuu/liberror.h index ce3aa6ef..9115475c 100644 --- a/libuuu/liberror.h +++ b/libuuu/liberror.h @@ -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; diff --git a/libuuu/libuuu.h b/libuuu/libuuu.h index 1636fad1..44ef167b 100644 --- a/libuuu/libuuu.h +++ b/libuuu/libuuu.h @@ -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); diff --git a/libuuu/sdp.h b/libuuu/sdp.h index cb36c3bf..ea507a3f 100644 --- a/libuuu/sdp.h +++ b/libuuu/sdp.h @@ -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 { diff --git a/libuuu/sparse_format.h b/libuuu/sparse_format.h index 4aaaf8a2..2542252b 100644 --- a/libuuu/sparse_format.h +++ b/libuuu/sparse_format.h @@ -38,12 +38,12 @@ typedef struct sparse_header { /* table implementation */ } sparse_header_t; -#define SPARSE_HEADER_MAGIC 0xed26ff3a +inline constexpr uint32_t SPARSE_HEADER_MAGIC = 0xed26ff3a; -#define CHUNK_TYPE_RAW 0xCAC1 -#define CHUNK_TYPE_FILL 0xCAC2 -#define CHUNK_TYPE_DONT_CARE 0xCAC3 -#define CHUNK_TYPE_CRC32 0xCAC4 +inline constexpr uint16_t CHUNK_TYPE_RAW = 0xCAC1; +inline constexpr uint16_t CHUNK_TYPE_FILL = 0xCAC2; +inline constexpr uint16_t CHUNK_TYPE_DONT_CARE = 0xCAC3; +inline constexpr uint16_t CHUNK_TYPE_CRC32 = 0xCAC4; typedef struct chunk_header { __le16 chunk_type; /* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */ diff --git a/libuuu/tar.h b/libuuu/tar.h index 19ea05ad..a574070b 100644 --- a/libuuu/tar.h +++ b/libuuu/tar.h @@ -38,7 +38,7 @@ class FileBuffer; -#define TAR_BLOCK_SIZE 512 +inline constexpr unsigned int TAR_BLOCK_SIZE = 512; #pragma pack(1) struct Tar_header diff --git a/libuuu/zip.h b/libuuu/zip.h index 403f7875..e7c5dd56 100644 --- a/libuuu/zip.h +++ b/libuuu/zip.h @@ -148,12 +148,12 @@ struct Zip_ext uint16_t size; }; -#define EOCD_SIGNATURE 0x06054b50 -#define DIR_SIGNATURE 0x02014b50 -#define DATA_SIGNATURE 0x08074b50 -#define FILE_SIGNATURE 0x04034b50 -#define EOCD64_LOCATOR_SIGNATURE 0x07064b50 -#define EOCD64_SIGNATURE 0x06064b50 +inline constexpr uint32_t EOCD_SIGNATURE = 0x06054b50; +inline constexpr uint32_t DIR_SIGNATURE = 0x02014b50; +inline constexpr uint32_t DATA_SIGNATURE = 0x08074b50; +inline constexpr uint32_t FILE_SIGNATURE = 0x04034b50; +inline constexpr uint32_t EOCD64_LOCATOR_SIGNATURE = 0x07064b50; +inline constexpr uint32_t EOCD64_SIGNATURE = 0x06064b50; class Zip; From 09b27768b20fc9fa520dfec86cef0c44274c0895 Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Feb 2025 23:20:28 +0100 Subject: [PATCH 6/8] Replace define with `constexpr` for `GIT_VERSION` Signed-off-by: markuspg --- libuuu/gen_ver.sh | 4 ++-- msvc/createversion.bat | 2 +- wrapper/CMakeLists.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libuuu/gen_ver.sh b/libuuu/gen_ver.sh index 68e8436d..72915eaa 100755 --- a/libuuu/gen_ver.sh +++ b/libuuu/gen_ver.sh @@ -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 @@ -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 diff --git a/msvc/createversion.bat b/msvc/createversion.bat index b5cd5d91..0c2e77a0 100644 --- a/msvc/createversion.bat +++ b/msvc/createversion.bat @@ -11,6 +11,6 @@ IF ERRORLEVEL 1 ( ) FOR /F "tokens=*" %%a in ('call git describe --long') do ( - echo #define GIT_VERSION "lib%%a" > %1/gitversion.h + echo inline constexpr const char * GIT_VERSION = "lib%%a"; > %1/gitversion.h ) ) diff --git a/wrapper/CMakeLists.txt b/wrapper/CMakeLists.txt index fa9c61f2..ccf03f37 100644 --- a/wrapper/CMakeLists.txt +++ b/wrapper/CMakeLists.txt @@ -27,7 +27,7 @@ if (WIN32) add_custom_command( OUTPUT ${gitversion_h} COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_files_dir} - COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_VERSION \"${version}\"" >> ${gitversion_h}; + COMMAND ${CMAKE_COMMAND} -E echo "inline constexpr const char * GIT_VERSION = \"${version}\";" >> ${gitversion_h}; COMMAND ${CMAKE_COMMAND} -E echo "#define PLATFORM_WINDOWS 1" >> ${gitversion_h} COMMAND ${CMAKE_COMMAND} -E echo "#define ENABLE_LOGGING 1" >> ${gitversion_h} COMMAND ${CMAKE_COMMAND} -E echo "#define DEFAULT_VISIBILITY /**/" >> ${gitversion_h} @@ -38,7 +38,7 @@ else () add_custom_command( OUTPUT ${gitversion_h} COMMAND ${CMAKE_COMMAND} -E make_directory ${generated_files_dir} - COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_VERSION \"${version}\"" >> ${gitversion_h}; + COMMAND ${CMAKE_COMMAND} -E echo "inline constexpr const char * GIT_VERSION = \"${version}\";" >> ${gitversion_h}; COMMENT "Generating gitversion.h" VERBATIM ) From 22e9d03e64c61c988d17607e93e814240ef96577 Mon Sep 17 00:00:00 2001 From: markuspg Date: Sat, 8 Feb 2025 23:22:50 +0100 Subject: [PATCH 7/8] Drop `g_version` in favour of `GIT_VERSION` Signed-off-by: markuspg --- libuuu/version.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libuuu/version.cpp b/libuuu/version.cpp index 229c5efa..fd7943c9 100644 --- a/libuuu/version.cpp +++ b/libuuu/version.cpp @@ -36,16 +36,14 @@ using namespace std; -static constexpr auto g_version = GIT_VERSION; - const char *uuu_get_version_string() { - return g_version; + return GIT_VERSION; } int uuu_get_version() { - string version_str{g_version}; + string version_str{GIT_VERSION}; // Find first dot because major version number must be before it auto pos = version_str.find("."); From 8df5a40e9ed1790b24a5d9243ec25ba9be3ebd6d Mon Sep 17 00:00:00 2001 From: markuspg Date: Mon, 10 Feb 2025 14:43:44 +0100 Subject: [PATCH 8/8] Add missing license headers to "bmap.(cpp|h)" Signed-off-by: markuspg --- libuuu/bmap.cpp | 29 +++++++++++++++++++++++++++++ libuuu/bmap.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/libuuu/bmap.cpp b/libuuu/bmap.cpp index c2cbfdf4..7d94cbee 100644 --- a/libuuu/bmap.cpp +++ b/libuuu/bmap.cpp @@ -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. + * + */ + #include #include diff --git a/libuuu/bmap.h b/libuuu/bmap.h index 89e7c1f4..c60df2a6 100644 --- a/libuuu/bmap.h +++ b/libuuu/bmap.h @@ -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