aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src/bcm4908kernel.c
diff options
context:
space:
mode:
authorPetr Štetiar <ynezz@true.cz>2021-07-05 11:54:26 +0200
committerRafał Miłecki <rafal@milecki.pl>2021-10-05 16:20:10 +0200
commit8cc9a74a3f6bf363645efda6db417f8dadd3d844 (patch)
tree68f1648a077df8e49328f087eccaf94c2e47d1e8 /tools/firmware-utils/src/bcm4908kernel.c
parentf82c93b93c0a021921ac7a30ba6e7a090c7ddd1c (diff)
downloadupstream-8cc9a74a3f6bf363645efda6db417f8dadd3d844.tar.gz
upstream-8cc9a74a3f6bf363645efda6db417f8dadd3d844.tar.bz2
upstream-8cc9a74a3f6bf363645efda6db417f8dadd3d844.zip
firmware-utils: update to version 2021-10-05
Includes following changes: db65821f006c cmake: fix missing install target 3a0cfc856991 Add initial GitLab CI support 8f47adea6f87 Add missing includes for byte swap operations fbafae9f8037 Convert to CMake based project Additionaly moves source code into separate Git project repository and converts the package build to utilize CMake. Signed-off-by: Petr Štetiar <ynezz@true.cz> [rmilecki: rebase, update to the latest repo git & rm -r src] Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Diffstat (limited to 'tools/firmware-utils/src/bcm4908kernel.c')
-rw-r--r--tools/firmware-utils/src/bcm4908kernel.c127
1 files changed, 0 insertions, 127 deletions
diff --git a/tools/firmware-utils/src/bcm4908kernel.c b/tools/firmware-utils/src/bcm4908kernel.c
deleted file mode 100644
index eaf04a0a48..0000000000
--- a/tools/firmware-utils/src/bcm4908kernel.c
+++ /dev/null
@@ -1,127 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (C) 2021 Rafał Miłecki <rafal@milecki.pl>
- */
-
-#include <byteswap.h>
-#include <endian.h>
-#include <errno.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#if !defined(__BYTE_ORDER)
-#error "Unknown byte order"
-#endif
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define cpu_to_le32(x) bswap_32(x)
-#define le32_to_cpu(x) bswap_32(x)
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-#define cpu_to_le32(x) (x)
-#define le32_to_cpu(x) (x)
-#else
-#error "Unsupported endianness"
-#endif
-
-struct bcm4908kernel_header {
- uint32_t boot_load_addr; /* AKA la_address */
- uint32_t boot_addr; /* AKA la_entrypt */
- uint32_t data_len;
- uint8_t magic[4];
- uint32_t uncomplen; /* Empty for LZMA, used for LZ4 */
-};
-
-static void usage() {
- printf("Usage:\n");
- printf("\n");
- printf("\t-i pathname\t\t\tinput kernel filepath\n");
- printf("\t-o pathname\t\t\toutput kernel filepath\n");
-}
-
-int main(int argc, char **argv) {
- struct bcm4908kernel_header header;
- uint8_t buf[1024];
- FILE *out = NULL;
- FILE *in = NULL;
- size_t length;
- size_t bytes;
- int err = 0;
- char c;
-
- if (argc >= 2 && !strcmp(argv[1], "-h")) {
- usage();
- return 0;
- }
-
- while ((c = getopt(argc, argv, "i:o:")) != -1) {
- switch (c) {
- case 'i':
- in = fopen(optarg, "r");
- break;
- case 'o':
- out = fopen(optarg, "w+");
- break;
- }
- }
-
- if (!in || !out) {
- fprintf(stderr, "Failed to open input and/or output file\n");
- usage();
- return -EINVAL;
- }
-
- if (fread(&header, 1, sizeof(header), in) != sizeof(header)) {
- fprintf(stderr, "Failed to read %zu bytes from input file\n", sizeof(header));
- err = -EIO;
- goto err_close;
- }
-
- if (!memcmp(header.magic, "BRCM", 4)) {
- fprintf(stderr, "Input file already contains BCM4908 kernel header\n");
- err = -EIO;
- goto err_close;
- }
-
- err = fseek(out, sizeof(header), SEEK_SET);
- if (err) {
- err = -errno;
- fprintf(stderr, "Failed to fseek(): %d\n", err);
- goto err_close;
- }
-
- length = 0;
- rewind(in);
- while ((bytes = fread(buf, 1, sizeof(buf), in)) > 0) {
- if (fwrite(buf, 1, bytes, out) != bytes) {
- fprintf(stderr, "Failed to write %zu B to the output file\n", bytes);
- err = -EIO;
- goto err_close;
- }
- length += bytes;
- }
-
- header.boot_load_addr = cpu_to_le32(0x00080000);
- header.boot_addr = cpu_to_le32(0x00080000);
- header.data_len = cpu_to_le32(length);
- header.magic[0] = 'B';
- header.magic[1] = 'R';
- header.magic[2] = 'C';
- header.magic[3] = 'M';
- header.uncomplen = 0;
-
- fseek(out, 0, SEEK_SET);
-
- if (fwrite(&header, 1, sizeof(header), out) != sizeof(header)) {
- fprintf(stderr, "Failed to write header to the output file\n");
- err = -EIO;
- goto err_close;
- }
-
-err_close:
- fclose(out);
- fclose(in);
- return err;
-}