diff --git a/avm_kernel_config/Makefile b/avm_kernel_config/Makefile index 0b828dda..4b050c59 100644 --- a/avm_kernel_config/Makefile +++ b/avm_kernel_config/Makefile @@ -15,7 +15,7 @@ BIN_SRCS = gen_$(BASENAME).c extract_$(BASENAME).c # header files # HELPER_HDRS = $(BASENAME)_helpers.h -BIN_HDRS = $(BASENAME).h $(BASENAME)_macros.h +BIN_HDRS = ./linux/include/uapi/linux/$(BASENAME).h $(BASENAME)_macros.h # # object files # @@ -32,7 +32,7 @@ RANLIB = ranlib # libfdt (from kernel sources, subdir 'scripts/dtc/libfdt') # LIBFDT = libfdt -LIBFDT_LOC = ./$(LIBFDT) +LIBFDT_LOC = ./linux/scripts/dtc/$(LIBFDT) LIBFDT_LIB = $(LIBFDT_LOC)/$(LIBFDT).a LIBS += $(LIBFDT_LIB) include $(LIBFDT_LOC)/Makefile.$(LIBFDT) diff --git a/avm_kernel_config/README.md b/avm_kernel_config/README.md index 077450a1..827557ae 100644 --- a/avm_kernel_config/README.md +++ b/avm_kernel_config/README.md @@ -10,3 +10,7 @@ approach to take this way. You can find further information in an IPPF thread (but it's in German only): http://www.ip-phone-forum.de/showthread.php?t=287995 + +If you want to compile the contained sources for a specific model, you have to provide a symlink named "linux" to the root of the +correct kernel sources. The files "include/uapi/linux/avm_kernel_config.h" and the whole directory "scripts/dtc/libfdt" (from the +OpenFirmware device-tree compiler) are the parts needed from current kernel sources. \ No newline at end of file diff --git a/avm_kernel_config/avm_kernel_config.h b/avm_kernel_config/avm_kernel_config.h deleted file mode 100644 index 038c36a9..00000000 --- a/avm_kernel_config/avm_kernel_config.h +++ /dev/null @@ -1,47 +0,0 @@ -/* vi: set tabstop=4 syntax=c : */ - -#ifndef _INCLUDE_AVM_KERNEL_CONFIG_H_ -#define _INCLUDE_AVM_KERNEL_CONFIG_H_ - -enum _avm_kernel_config_tags { - avm_kernel_config_tags_undef, - avm_kernel_config_tags_modulememory, - avm_kernel_config_tags_version_info, - avm_kernel_config_tags_hw_config, - avm_kernel_config_tags_cache_config, - avm_kernel_config_tags_device_tree_subrev_0, /* subrev müssen aufeinander folgen */ - avm_kernel_config_tags_device_tree_subrev_1, - avm_kernel_config_tags_device_tree_subrev_2, - avm_kernel_config_tags_device_tree_subrev_3, - avm_kernel_config_tags_device_tree_subrev_4, - avm_kernel_config_tags_device_tree_subrev_5, - avm_kernel_config_tags_device_tree_subrev_6, - avm_kernel_config_tags_device_tree_subrev_7, - avm_kernel_config_tags_device_tree_subrev_8, - avm_kernel_config_tags_device_tree_subrev_9, /* subrev müssen aufeinander folgen */ - avm_kernel_config_tags_device_tree_subrev_last = avm_kernel_config_tags_device_tree_subrev_9, - avm_kernel_config_tags_avmnet, - avm_kernel_config_tags_last -}; - -#define avm_subrev_max \ - (avm_kernel_config_tags_device_tree_subrev_last - \ - avm_kernel_config_tags_device_tree_subrev_0 + 1) - -struct _kernel_modulmemory_config { - char *name; - unsigned int size; -}; - -struct _avm_kernel_config { - enum _avm_kernel_config_tags tag; - void *config; -}; - -struct _avm_kernel_version_info { - char buildnumber[32]; - char svnversion[32]; - char firmwarestring[128]; -}; - -#endif diff --git a/avm_kernel_config/avm_kernel_config_helpers.h b/avm_kernel_config/avm_kernel_config_helpers.h index e1d77766..ea7d6455 100644 --- a/avm_kernel_config/avm_kernel_config_helpers.h +++ b/avm_kernel_config/avm_kernel_config_helpers.h @@ -16,7 +16,7 @@ #ifdef FREETZ #include #else // FREETZ -#include "avm_kernel_config.h" +#include "linux/include/uapi/linux/avm_kernel_config.h" #endif // FREETZ struct memoryMappedFile diff --git a/avm_kernel_config/extract_avm_kernel_config.c b/avm_kernel_config/extract_avm_kernel_config.c index 32929d0c..a742879d 100644 --- a/avm_kernel_config/extract_avm_kernel_config.c +++ b/avm_kernel_config/extract_avm_kernel_config.c @@ -2,7 +2,7 @@ /*********************************************************************** * * * * - * Copyright (C) 2016 P.Hämmerlein (http://www.yourfritz.de) * + * Copyright (C) 2016-2017 P.Hämmerlein (http://www.yourfritz.de) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * @@ -25,10 +25,10 @@ void usage() { fprintf(stderr, "extract_avm_kernel_config - extract (binary copy of) kernel config area from AVM's kernel\n\n"); - fprintf(stderr, "(C) 2016 P. Hämmerlein (http://www.yourfritz.de)\n\n"); + fprintf(stderr, "(C) 2016-2017 P. Hämmerlein (http://www.yourfritz.de)\n\n"); fprintf(stderr, "Licensed under GPLv2, see LICENSE file from source repository.\n\n"); fprintf(stderr, "Usage:\n\n"); - fprintf(stderr, "extract_avm_kernel_config []\n"); + fprintf(stderr, "extract_avm_kernel_config [ -s ] []\n"); fprintf(stderr, "\nThe specified DTB content (a compiled OF device tree BLOB) is"); fprintf(stderr, "\nsearched in the unpacked kernel and the place, where it's found"); fprintf(stderr, "\nis assumed to be within the original kernel config area.\n"); @@ -37,6 +37,9 @@ void usage() fprintf(stderr, "\nare performed to guess the correct location.\n"); fprintf(stderr, "\nThe output is written to STDOUT, so you've to redirect it to the"); fprintf(stderr, "\nproper location.\n"); + fprintf(stderr, "\nTo support different models with changing sizes of the embedded"); + fprintf(stderr, "\nconfiguration area, a default size of 64 KB for this area is used,"); + fprintf(stderr, "\nwhich may be overwritten with the -s option.\n"); } bool checkConfigArea(struct _avm_kernel_config ** configArea, size_t configSize) @@ -47,14 +50,14 @@ bool checkConfigArea(struct _avm_kernel_config ** configArea, size_t configSize) return true; } -struct _avm_kernel_config ** findConfigArea(void *dtbLocation) +struct _avm_kernel_config ** findConfigArea(void *dtbLocation, size_t size) { struct _avm_kernel_config ** configArea = NULL; // previous 4K boundary should be the start of the config area configArea = (struct _avm_kernel_config **) (((int) dtbLocation >> 12) << 12); - if (checkConfigArea(configArea, 64 * 1024)) return configArea; + if (checkConfigArea(configArea, size)) return configArea; return NULL; } @@ -177,18 +180,72 @@ int main(int argc, char * argv[]) struct memoryMappedFile kernel; struct memoryMappedFile dtb; void * dtbLocation = NULL; + ssize_t size = 64 * 1024; + int i = 1; + int paramCount = argc; - if (argc < 2) + /* no reason to use a getopt implementation for our simple calling convention */ + if (paramCount > i) + { + char * sizeString = NULL; + + if (strcmp(argv[i], "-s") == 0) + { + if (paramCount > i + 1) + { + sizeString = argv[i + 1]; + i += 2; + paramCount -= 2; + } + else + { + fprintf(stderr, "Missing numeric value after option '-s'.\n"); + exit(2); + } + } + else if (strncmp(argv[i], "--size=", 7) == 0) + { + sizeString = strchr(argv[i], '='); + sizeString++; /* skip equal sign */ + i += 1; + paramCount -= 1; + } + + if (sizeString != NULL) + { + int newSize; + + newSize = atoi(sizeString); + if (newSize == 0) + { + fprintf(stderr, "Missing or invalid numeric value for size option.\n"); + exit(2); + } + if (newSize < 16 || newSize > 1024) + { + fprintf(stderr, "Size value should be between 16 and 1024 - change source files, if your size is really valid.\n"); + exit(2); + } + if ((newSize & 0x0F) > 0) + { + fprintf(stderr, "Size value should be a multiple of 16 - change source files, if your size is really valid.\n"); + exit(2); + } + size = newSize * 1024; + } + } + + if (paramCount < 2) { usage(); exit(1); } - if (openMemoryMappedFile(&kernel, argv[1], "unpacked kernel", O_RDONLY | O_SYNC, PROT_READ, MAP_SHARED)) + if (openMemoryMappedFile(&kernel, argv[i], "unpacked kernel", O_RDONLY | O_SYNC, PROT_READ, MAP_SHARED)) { - if (argc > 2) + if (paramCount > 2) { - if (openMemoryMappedFile(&dtb, argv[2], "device tree BLOB", O_RDONLY | O_SYNC, PROT_READ, MAP_SHARED)) + if (openMemoryMappedFile(&dtb, argv[i + 1], "device tree BLOB", O_RDONLY | O_SYNC, PROT_READ, MAP_SHARED)) { if (fdt_check_header(dtb.fileBuffer) == 0) { @@ -214,13 +271,13 @@ int main(int argc, char * argv[]) if (dtbLocation != NULL) { - struct _avm_kernel_config * *configArea = findConfigArea(dtbLocation); + struct _avm_kernel_config * *configArea = findConfigArea(dtbLocation, size); if (configArea != NULL) { - ssize_t written = write(1, (void *) configArea, 64 * 1024); + ssize_t written = write(1, (void *) configArea, size); - if (written == 64 * 1024) + if (written == size) { returnCode = 0; } diff --git a/avm_kernel_config/gen_avm_kernel_config.c b/avm_kernel_config/gen_avm_kernel_config.c index a51f63c3..50ed3f92 100644 --- a/avm_kernel_config/gen_avm_kernel_config.c +++ b/avm_kernel_config/gen_avm_kernel_config.c @@ -252,10 +252,13 @@ int processConfigArea(struct _avm_kernel_config * *configArea) // device tree for subrevision 0 is the fallback entry and may be expected // as 'always present', if FDTs exist at all - if (hasDeviceTree(configArea, 0)) + for (int i = 0; i <= avm_kernel_config_tags_device_tree_subrev_last; i++) { - outputDeviceTrees = true; - fprintf(stdout, "\tAVM_KERNEL_CONFIG_ENTRY\t%u, \"device_tree_subrev_0\"\n", avm_kernel_config_tags_device_tree_subrev_0); + if (hasDeviceTree(configArea, i)) + { + outputDeviceTrees = true; + fprintf(stdout, "\tAVM_KERNEL_CONFIG_ENTRY\t%u, \"device_tree_subrev_%u\"\n", avm_kernel_config_tags_device_tree_subrev_0 + i, i); + } } fprintf(stdout, "\tAVM_KERNEL_CONFIG_ENTRY\t0\n");