From 511d71e6895f3902612879ea5a09926a9f926569 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Fri, 22 Jan 2021 10:46:10 +0100 Subject: [PATCH 1/7] owipcalc: remove package This is a helpful utility, but it does not have any dependencies in this repository. Move it to packages feed. Cc: Jo-Philipp Wich Cc: Nick Hainke Signed-off-by: Adrian Schmutzler --- package/network/utils/owipcalc/Makefile | 44 - package/network/utils/owipcalc/src/owipcalc.c | 950 ------------------ 2 files changed, 994 deletions(-) delete mode 100644 package/network/utils/owipcalc/Makefile delete mode 100644 package/network/utils/owipcalc/src/owipcalc.c diff --git a/package/network/utils/owipcalc/Makefile b/package/network/utils/owipcalc/Makefile deleted file mode 100644 index dc68a0346b..0000000000 --- a/package/network/utils/owipcalc/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -# -# Copyright (C) 2012 Jo-Philipp Wich -# -# This is free software, licensed under the Apache 2 license. -# - -include $(TOPDIR)/rules.mk - -PKG_NAME:=owipcalc -PKG_RELEASE:=5 -PKG_LICENSE:=Apache-2.0 - -include $(INCLUDE_DIR)/package.mk - - -define Package/owipcalc - SECTION:=utils - CATEGORY:=Utilities - TITLE:=Simple IPv4/IPv6 address calculator - MAINTAINER:=Jo-Philipp Wich -endef - -define Package/owipcalc/description - The owipcalc utility supports a number of calculations and tests to work - with ip-address ranges, this is useful for scripts that e.g. need to - partition ipv6-prefixes into small subnets or to calculate address ranges - for dhcp pools. -endef - -define Build/Configure -endef - -define Build/Compile - $(TARGET_CC) $(TARGET_CFLAGS) \ - -o $(PKG_BUILD_DIR)/owipcalc $(PKG_BUILD_DIR)/owipcalc.c -endef - - -define Package/owipcalc/install - $(INSTALL_DIR) $(1)/usr/bin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/owipcalc $(1)/usr/bin/owipcalc -endef - -$(eval $(call BuildPackage,owipcalc)) diff --git a/package/network/utils/owipcalc/src/owipcalc.c b/package/network/utils/owipcalc/src/owipcalc.c deleted file mode 100644 index 5ed609f158..0000000000 --- a/package/network/utils/owipcalc/src/owipcalc.c +++ /dev/null @@ -1,950 +0,0 @@ -/* - * owipcalc - OpenWrt IP Calculator - * - * Copyright (C) 2012 Jo-Philipp Wich - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include -#include - -#include - - -struct cidr { - uint8_t family; - uint32_t prefix; - union { - struct in_addr v4; - struct in6_addr v6; - } addr; - union { - char v4[sizeof("255.255.255.255/255.255.255.255 ")]; - char v6[sizeof("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:255.255.255.255/128 ")]; - } buf; - struct cidr *next; -}; - -struct op { - const char *name; - const char *desc; - struct { - bool (*a1)(struct cidr *a); - bool (*a2)(struct cidr *a, struct cidr *b); - } f4; - struct { - bool (*a1)(struct cidr *a); - bool (*a2)(struct cidr *a, struct cidr *b); - } f6; -}; - - -static bool quiet = false; -static bool printed = false; - -static struct cidr *stack = NULL; - -#define qprintf(...) \ - do { \ - if (!quiet) printf(__VA_ARGS__); \ - printed = true; \ - } while(0) - -static void cidr_push(struct cidr *a) -{ - if (a) - { - a->next = stack; - stack = a; - } -} - -static bool cidr_pop(struct cidr *a) -{ - struct cidr *old = stack; - - if (old) - { - stack = stack->next; - free(old); - - return true; - } - - return false; -} - -static struct cidr * cidr_clone(struct cidr *a) -{ - struct cidr *b = malloc(sizeof(*b)); - - if (!b) - { - fprintf(stderr, "out of memory\n"); - exit(255); - } - - memcpy(b, a, sizeof(*b)); - cidr_push(b); - - return b; -} - - -static struct cidr * cidr_parse4(const char *s) -{ - char *p = NULL, *r; - struct in_addr mask; - struct cidr *addr = malloc(sizeof(struct cidr)); - - if (!addr || (strlen(s) >= sizeof(addr->buf.v4))) - goto err; - - snprintf(addr->buf.v4, sizeof(addr->buf.v4), "%s", s); - - addr->family = AF_INET; - - if ((p = strchr(addr->buf.v4, '/')) != NULL) - { - *p++ = 0; - - if (strchr(p, '.') != NULL) - { - if (inet_pton(AF_INET, p, &mask) != 1) - goto err; - - for (addr->prefix = 0; mask.s_addr; mask.s_addr >>= 1) - addr->prefix += (mask.s_addr & 1); - } - else - { - addr->prefix = strtoul(p, &r, 10); - - if ((p == r) || (*r != 0) || (addr->prefix > 32)) - goto err; - } - } - else - { - addr->prefix = 32; - } - - if (p == addr->buf.v4+1) - memset(&addr->addr.v4, 0, sizeof(addr->addr.v4)); - else if (inet_pton(AF_INET, addr->buf.v4, &addr->addr.v4) != 1) - goto err; - - return addr; - -err: - if (addr) - free(addr); - - return NULL; -} - -static bool cidr_add4(struct cidr *a, struct cidr *b) -{ - uint32_t x = ntohl(a->addr.v4.s_addr); - uint32_t y = ntohl(b->addr.v4.s_addr); - - struct cidr *n = cidr_clone(a); - - if ((n->family != AF_INET) || (b->family != AF_INET)) - return false; - - if ((uint32_t)(x + y) < x) - { - fprintf(stderr, "overflow during 'add'\n"); - return false; - } - - n->addr.v4.s_addr = htonl(x + y); - return true; -} - -static bool cidr_sub4(struct cidr *a, struct cidr *b) -{ - uint32_t x = ntohl(a->addr.v4.s_addr); - uint32_t y = ntohl(b->addr.v4.s_addr); - - struct cidr *n = cidr_clone(a); - - if ((n->family != AF_INET) || (b->family != AF_INET)) - return false; - - if ((uint32_t)(x - y) > x) - { - fprintf(stderr, "underflow during 'sub'\n"); - return false; - } - - n->addr.v4.s_addr = htonl(x - y); - return true; -} - -static bool cidr_network4(struct cidr *a) -{ - struct cidr *n = cidr_clone(a); - - n->addr.v4.s_addr &= htonl(~((1 << (32 - n->prefix)) - 1)); - n->prefix = 32; - - return true; -} - -static bool cidr_broadcast4(struct cidr *a) -{ - struct cidr *n = cidr_clone(a); - - n->addr.v4.s_addr |= htonl(((1 << (32 - n->prefix)) - 1)); - n->prefix = 32; - - return true; -} - -static bool cidr_contains4(struct cidr *a, struct cidr *b) -{ - uint32_t net1 = a->addr.v4.s_addr & htonl(~((1 << (32 - a->prefix)) - 1)); - uint32_t net2 = b->addr.v4.s_addr & htonl(~((1 << (32 - a->prefix)) - 1)); - - if (printed) - qprintf(" "); - - if ((b->prefix >= a->prefix) && (net1 == net2)) - { - qprintf("1"); - return true; - } - else - { - qprintf("0"); - return false; - } -} - -static bool cidr_netmask4(struct cidr *a) -{ - struct cidr *n = cidr_clone(a); - - n->addr.v4.s_addr = htonl(~((1 << (32 - n->prefix)) - 1)); - n->prefix = 32; - - return true; -} - -static bool cidr_private4(struct cidr *a) -{ - uint32_t x = ntohl(a->addr.v4.s_addr); - - if (printed) - qprintf(" "); - - if (((x >= 0x0A000000) && (x <= 0x0AFFFFFF)) || - ((x >= 0xAC100000) && (x <= 0xAC1FFFFF)) || - ((x >= 0xC0A80000) && (x <= 0xC0A8FFFF))) - { - qprintf("1"); - return true; - } - else - { - qprintf("0"); - return false; - } -} - -static bool cidr_linklocal4(struct cidr *a) -{ - uint32_t x = ntohl(a->addr.v4.s_addr); - - if (printed) - qprintf(" "); - - if ((x >= 0xA9FE0000) && (x <= 0xA9FEFFFF)) - { - qprintf("1"); - return true; - } - else - { - qprintf("0"); - return false; - } -} - -static bool cidr_prev4(struct cidr *a, struct cidr *b) -{ - struct cidr *n = cidr_clone(a); - - n->prefix = b->prefix; - n->addr.v4.s_addr -= htonl(1 << (32 - b->prefix)); - - return true; -} - -static bool cidr_next4(struct cidr *a, struct cidr *b) -{ - struct cidr *n = cidr_clone(a); - - n->prefix = b->prefix; - n->addr.v4.s_addr += htonl(1 << (32 - b->prefix)); - - return true; -} - -static bool cidr_6to4(struct cidr *a) -{ - struct cidr *n = cidr_clone(a); - uint32_t x = a->addr.v4.s_addr; - - memset(&n->addr.v6.s6_addr, 0, sizeof(n->addr.v6.s6_addr)); - - n->family = AF_INET6; - n->prefix = 48; - - n->addr.v6.s6_addr[0] = 0x20; - n->addr.v6.s6_addr[1] = 0x02; - n->addr.v6.s6_addr[2] = (x >> 24); - n->addr.v6.s6_addr[3] = (x >> 16) & 0xFF; - n->addr.v6.s6_addr[4] = (x >> 8) & 0xFF; - n->addr.v6.s6_addr[5] = x & 0xFF; - - return true; -} - -static bool cidr_print4(struct cidr *a) -{ - char *p; - - if (!a || (a->family != AF_INET)) - return false; - - if (!(p = (char *)inet_ntop(AF_INET, &a->addr.v4, a->buf.v4, sizeof(a->buf.v4)))) - return false; - - if (printed) - qprintf(" "); - - qprintf("%s", p); - - if (a->prefix < 32) - qprintf("/%u", a->prefix); - - cidr_pop(a); - - return true; -} - - -static struct cidr * cidr_parse6(const char *s) -{ - char *p = NULL, *r; - struct cidr *addr = malloc(sizeof(struct cidr)); - - if (!addr || (strlen(s) >= sizeof(addr->buf.v6))) - goto err; - - snprintf(addr->buf.v6, sizeof(addr->buf.v6), "%s", s); - - addr->family = AF_INET6; - - if ((p = strchr(addr->buf.v6, '/')) != NULL) - { - *p++ = 0; - - addr->prefix = strtoul(p, &r, 10); - - if ((p == r) || (*r != 0) || (addr->prefix > 128)) - goto err; - } - else - { - addr->prefix = 128; - } - - if (p == addr->buf.v6+1) - memset(&addr->addr.v6, 0, sizeof(addr->addr.v6)); - else if (inet_pton(AF_INET6, addr->buf.v6, &addr->addr.v6) != 1) - goto err; - - return addr; - -err: - if (addr) - free(addr); - - return NULL; -} - -static bool cidr_add6(struct cidr *a, struct cidr *b) -{ - uint8_t idx = 15, carry = 0, overflow = 0; - - struct cidr *n = cidr_clone(a); - struct in6_addr *x = &n->addr.v6; - struct in6_addr *y = &b->addr.v6; - - if ((a->family != AF_INET6) || (b->family != AF_INET6)) - return false; - - do { - overflow = !!((x->s6_addr[idx] + y->s6_addr[idx] + carry) >= 256); - x->s6_addr[idx] += y->s6_addr[idx] + carry; - carry = overflow; - } - while (idx-- > 0); - - if (carry) - { - fprintf(stderr, "overflow during 'add'\n"); - return false; - } - - return true; -} - -static bool cidr_sub6(struct cidr *a, struct cidr *b) -{ - uint8_t idx = 15, carry = 0, underflow = 0; - - struct cidr *n = cidr_clone(a); - struct in6_addr *x = &n->addr.v6; - struct in6_addr *y = &b->addr.v6; - - if ((n->family != AF_INET6) || (b->family != AF_INET6)) - return false; - - do { - underflow = !!((x->s6_addr[idx] - y->s6_addr[idx] - carry) < 0); - x->s6_addr[idx] -= y->s6_addr[idx] + carry; - carry = underflow; - } - while (idx-- > 0); - - if (carry) - { - fprintf(stderr, "underflow during 'sub'\n"); - return false; - } - - return true; -} - -static bool cidr_prev6(struct cidr *a, struct cidr *b) -{ - uint8_t idx, carry = 1, underflow = 0; - struct cidr *n = cidr_clone(a); - struct in6_addr *x = &n->addr.v6; - - if (b->prefix == 0) - { - fprintf(stderr, "underflow during 'prev'\n"); - return false; - } - - idx = (b->prefix - 1) / 8; - - do { - underflow = !!((x->s6_addr[idx] - carry) < 0); - x->s6_addr[idx] -= carry; - carry = underflow; - } - while (idx-- > 0); - - if (carry) - { - fprintf(stderr, "underflow during 'prev'\n"); - return false; - } - - n->prefix = b->prefix; - - return true; -} - -static bool cidr_next6(struct cidr *a, struct cidr *b) -{ - uint8_t idx, carry = 1, overflow = 0; - struct cidr *n = cidr_clone(a); - struct in6_addr *x = &n->addr.v6; - - if (b->prefix == 0) - { - fprintf(stderr, "overflow during 'next'\n"); - return false; - } - - idx = (b->prefix - 1) / 8; - - do { - overflow = !!((x->s6_addr[idx] + carry) >= 256); - x->s6_addr[idx] += carry; - carry = overflow; - } - while (idx-- > 0); - - if (carry) - { - fprintf(stderr, "overflow during 'next'\n"); - return false; - } - - n->prefix = b->prefix; - - return true; -} - -static bool cidr_network6(struct cidr *a) -{ - uint8_t i; - struct cidr *n = cidr_clone(a); - - for (i = 0; i < (128 - n->prefix) / 8; i++) - n->addr.v6.s6_addr[15-i] = 0; - - if ((128 - n->prefix) % 8) - n->addr.v6.s6_addr[15-i] &= ~((1 << ((128 - n->prefix) % 8)) - 1); - - return true; -} - -static bool cidr_contains6(struct cidr *a, struct cidr *b) -{ - struct in6_addr *x = &a->addr.v6; - struct in6_addr *y = &b->addr.v6; - uint8_t i = (128 - a->prefix) / 8; - uint8_t m = ~((1 << ((128 - a->prefix) % 8)) - 1); - uint8_t net1 = x->s6_addr[15-i] & m; - uint8_t net2 = y->s6_addr[15-i] & m; - - if (printed) - qprintf(" "); - - if ((b->prefix >= a->prefix) && (net1 == net2) && - ((i == 15) || !memcmp(&x->s6_addr, &y->s6_addr, 15-i))) - { - qprintf("1"); - return true; - } - else - { - qprintf("0"); - return false; - } -} - -static bool cidr_linklocal6(struct cidr *a) -{ - if (printed) - qprintf(" "); - - if ((a->addr.v6.s6_addr[0] == 0xFE) && - (a->addr.v6.s6_addr[1] >= 0x80) && - (a->addr.v6.s6_addr[1] <= 0xBF)) - { - qprintf("1"); - return true; - } - else - { - qprintf("0"); - return false; - } -} - -static bool cidr_ula6(struct cidr *a) -{ - if (printed) - qprintf(" "); - - if ((a->addr.v6.s6_addr[0] >= 0xFC) && - (a->addr.v6.s6_addr[0] <= 0xFD)) - { - qprintf("1"); - return true; - } - else - { - qprintf("0"); - return false; - } -} - -static bool cidr_print6(struct cidr *a) -{ - char *p; - - if (!a || (a->family != AF_INET6)) - return NULL; - - if (!(p = (char *)inet_ntop(AF_INET6, &a->addr.v6, a->buf.v6, sizeof(a->buf.v6)))) - return false; - - if (printed) - qprintf(" "); - - qprintf("%s", p); - - if (a->prefix < 128) - qprintf("/%u", a->prefix); - - cidr_pop(a); - - return true; -} - - -static struct cidr * cidr_parse(const char *op, const char *s, int af_hint) -{ - char *r; - struct cidr *a; - - uint8_t i; - uint32_t sum = strtoul(s, &r, 0); - - if ((r > s) && (*r == 0)) - { - a = malloc(sizeof(struct cidr)); - - if (!a) - return NULL; - - if (af_hint == AF_INET) - { - a->family = AF_INET; - a->prefix = sum; - a->addr.v4.s_addr = htonl(sum); - } - else - { - a->family = AF_INET6; - a->prefix = sum; - - for (i = 0; i <= 15; i++) - { - a->addr.v6.s6_addr[15-i] = sum % 256; - sum >>= 8; - } - } - - return a; - } - - if (strchr(s, ':')) - a = cidr_parse6(s); - else - a = cidr_parse4(s); - - if (!a) - return NULL; - - if (a->family != af_hint) - { - fprintf(stderr, "attempt to '%s' %s with %s address\n", - op, - (af_hint == AF_INET) ? "ipv4" : "ipv6", - (af_hint != AF_INET) ? "ipv4" : "ipv6"); - exit(4); - } - - return a; -} - -static bool cidr_howmany(struct cidr *a, struct cidr *b) -{ - if (printed) - qprintf(" "); - - if (b->prefix < a->prefix) - qprintf("0"); - else - qprintf("%u", 1 << (b->prefix - a->prefix)); - - return true; -} - -static bool cidr_prefix(struct cidr *a, struct cidr *b) -{ - a->prefix = b->prefix; - return true; -} - -static bool cidr_quiet(struct cidr *a) -{ - quiet = true; - return true; -} - - -struct op ops[] = { - { .name = "add", - .desc = "Add argument to base address", - .f4.a2 = cidr_add4, - .f6.a2 = cidr_add6 }, - - { .name = "sub", - .desc = "Substract argument from base address", - .f4.a2 = cidr_sub4, - .f6.a2 = cidr_sub6 }, - - { .name = "next", - .desc = "Advance base address to next prefix of given size", - .f4.a2 = cidr_next4, - .f6.a2 = cidr_next6 }, - - { .name = "prev", - .desc = "Lower base address to previous prefix of give size", - .f4.a2 = cidr_prev4, - .f6.a2 = cidr_prev6 }, - - { .name = "network", - .desc = "Turn base address into network address", - .f4.a1 = cidr_network4, - .f6.a1 = cidr_network6 }, - - { .name = "broadcast", - .desc = "Turn base address into broadcast address", - .f4.a1 = cidr_broadcast4 }, - - { .name = "prefix", - .desc = "Set the prefix of base address to argument", - .f4.a2 = cidr_prefix, - .f6.a2 = cidr_prefix }, - - { .name = "netmask", - .desc = "Calculate netmask of base address", - .f4.a1 = cidr_netmask4 }, - - { .name = "6to4", - .desc = "Calculate 6to4 prefix of given ipv4-address", - .f4.a1 = cidr_6to4 }, - - { .name = "howmany", - .desc = "Print amount of righ-hand prefixes that fit into base address", - .f4.a2 = cidr_howmany, - .f6.a2 = cidr_howmany }, - - { .name = "contains", - .desc = "Print '1' if argument fits into base address or '0' if not", - .f4.a2 = cidr_contains4, - .f6.a2 = cidr_contains6 }, - - { .name = "private", - .desc = "Print '1' if base address is in RFC1918 private space or '0' " - "if not", - .f4.a1 = cidr_private4 }, - - { .name = "linklocal", - .desc = "Print '1' if base address is in 169.254.0.0/16 or FE80::/10 " - "link local space or '0' if not", - .f4.a1 = cidr_linklocal4, - .f6.a1 = cidr_linklocal6 }, - - { .name = "ula", - .desc = "Print '1' if base address is in FC00::/7 unique local address " - "(ULA) space or '0' if not", - .f6.a1 = cidr_ula6 }, - - { .name = "quiet", - .desc = "Suppress output, useful for test operation where the result can " - "be inferred from the exit code", - .f4.a1 = cidr_quiet, - .f6.a1 = cidr_quiet }, - - { .name = "pop", - .desc = "Pop intermediate result from stack", - .f4.a1 = cidr_pop, - .f6.a1 = cidr_pop }, - - { .name = "print", - .desc = "Print intermediate result and pop it from stack, invoked " - "implicitely at the end of calculation if no intermediate prints " - "happened", - .f4.a1 = cidr_print4, - .f6.a1 = cidr_print6 }, -}; - -static void usage(const char *prog) -{ - int i; - - fprintf(stderr, - "\n" - "Usage:\n\n" - " %s {base address} operation [argument] " - "[operation [argument] ...]\n\n" - "Operations:\n\n", - prog); - - for (i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) - { - if (ops[i].f4.a2 || ops[i].f6.a2) - { - fprintf(stderr, " %s %s\n", - ops[i].name, - (ops[i].f4.a2 && ops[i].f6.a2) ? "{ipv4/ipv6/amount}" : - (ops[i].f6.a2 ? "{ipv6/amount}" : "{ipv4/amount}")); - } - else - { - fprintf(stderr, " %s\n", ops[i].name); - } - - fprintf(stderr, " %s.\n", ops[i].desc); - - if ((ops[i].f4.a1 && ops[i].f6.a1) || (ops[i].f4.a2 && ops[i].f6.a2)) - fprintf(stderr, " Applicable to ipv4- and ipv6-addresses.\n\n"); - else if (ops[i].f6.a2 || ops[i].f6.a1) - fprintf(stderr, " Only applicable to ipv6-addresses.\n\n"); - else - fprintf(stderr, " Only applicable to ipv4-addresses.\n\n"); - } - - fprintf(stderr, - "Examples:\n\n" - " Calculate a DHCP range:\n\n" - " $ %s 192.168.1.1/255.255.255.0 network add 100 print add 150 print\n" - " 192.168.1.100\n" - " 192.168.1.250\n\n" - " Count number of prefixes:\n\n" - " $ %s 2001:0DB8:FDEF::/48 howmany ::/64\n" - " 65536\n\n", - prog, prog); - - exit(1); -} - -static bool runop(char ***arg, int *status) -{ - int i; - char *arg1 = **arg; - char *arg2 = *(*arg+1); - struct cidr *a = stack; - struct cidr *b = NULL; - - if (!arg1) - return false; - - for (i = 0; i < sizeof(ops) / sizeof(ops[0]); i++) - { - if (!strcmp(ops[i].name, arg1)) - { - if (ops[i].f4.a2 || ops[i].f6.a2) - { - if (!arg2) - { - fprintf(stderr, "'%s' requires an argument\n", - ops[i].name); - - *status = 2; - return false; - } - - b = cidr_parse(ops[i].name, arg2, a->family); - - if (!b) - { - fprintf(stderr, "invalid address argument for '%s'\n", - ops[i].name); - - *status = 3; - return false; - } - - *arg += 2; - - if (((a->family == AF_INET) && !ops[i].f4.a2) || - ((a->family == AF_INET6) && !ops[i].f6.a2)) - { - fprintf(stderr, "'%s' not supported for %s addresses\n", - ops[i].name, - (a->family == AF_INET) ? "ipv4" : "ipv6"); - - *status = 5; - return false; - } - - *status = !((a->family == AF_INET) ? ops[i].f4.a2(a, b) - : ops[i].f6.a2(a, b)); - - return true; - } - else - { - *arg += 1; - - if (((a->family == AF_INET) && !ops[i].f4.a1) || - ((a->family == AF_INET6) && !ops[i].f6.a1)) - { - fprintf(stderr, "'%s' not supported for %s addresses\n", - ops[i].name, - (a->family == AF_INET) ? "ipv4" : "ipv6"); - - *status = 5; - return false; - } - - *status = !((a->family == AF_INET) ? ops[i].f4.a1(a) - : ops[i].f6.a1(a)); - - return true; - } - } - } - - return false; -} - -int main(int argc, char **argv) -{ - int status = 0; - char **arg = argv+2; - struct cidr *a; - - if (argc < 3) - usage(argv[0]); - - a = strchr(argv[1], ':') ? cidr_parse6(argv[1]) : cidr_parse4(argv[1]); - - if (!a) - usage(argv[0]); - - cidr_push(a); - - while (runop(&arg, &status)); - - if (*arg) - { - fprintf(stderr, "unknown operation '%s'\n", *arg); - exit(6); - } - - if (!printed && (status < 2)) - { - if (stack->family == AF_INET) - cidr_print4(stack); - else - cidr_print6(stack); - } - - qprintf("\n"); - - exit(status); -} From b2bab951166ab30717b345b95b0dc8d6999ba16e Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Fri, 22 Jan 2021 10:48:51 +0100 Subject: [PATCH 2/7] maccalc: remove package This is a helpful utility, but it does not have any dependencies in this repository. Move it to packages feed. The package does not seem to have a maintainer. Cc: Jo-Philipp Wich Cc: Nick Hainke Signed-off-by: Adrian Schmutzler --- package/network/utils/maccalc/Makefile | 43 ---- package/network/utils/maccalc/src/Makefile | 14 -- package/network/utils/maccalc/src/main.c | 256 --------------------- 3 files changed, 313 deletions(-) delete mode 100644 package/network/utils/maccalc/Makefile delete mode 100644 package/network/utils/maccalc/src/Makefile delete mode 100644 package/network/utils/maccalc/src/main.c diff --git a/package/network/utils/maccalc/Makefile b/package/network/utils/maccalc/Makefile deleted file mode 100644 index dc11b6b7c1..0000000000 --- a/package/network/utils/maccalc/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -# -# Copyright (C) 2011 OpenWrt.org -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# - -include $(TOPDIR)/rules.mk - -PKG_NAME:=maccalc -PKG_RELEASE:=1 -PKG_LICENSE:=GPL-2.0 - -PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) - -include $(INCLUDE_DIR)/package.mk - -define Package/maccalc - SECTION:=utils - CATEGORY:=Utilities - TITLE:=MAC address calculation -endef - -define Package/maccalc/description - This package contains a MAC address manipulation utility. -endef - -define Build/Configure -endef - -define Build/Compile - $(MAKE) -C $(PKG_BUILD_DIR) \ - CC="$(TARGET_CC)" \ - CFLAGS="$(TARGET_CFLAGS) -Wall" \ - LDFLAGS="$(TARGET_LDFLAGS)" -endef - -define Package/maccalc/install - $(INSTALL_DIR) $(1)/usr/sbin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/maccalc $(1)/usr/sbin/ -endef - -$(eval $(call BuildPackage,maccalc)) diff --git a/package/network/utils/maccalc/src/Makefile b/package/network/utils/maccalc/src/Makefile deleted file mode 100644 index 486badb256..0000000000 --- a/package/network/utils/maccalc/src/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -CC = gcc -CFLAGS = -Wall -OBJS = main.o - -all: maccalc - -%.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< - -maccalc: $(OBJS) - $(CC) -o $@ $(OBJS) - -clean: - rm -f maccalc *.o diff --git a/package/network/utils/maccalc/src/main.c b/package/network/utils/maccalc/src/main.c deleted file mode 100644 index dcb5f55c55..0000000000 --- a/package/network/utils/maccalc/src/main.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * MAC address manupulation utility - * - * Copyright (C) 2011 Gabor Juhos - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. - * - */ - -#include -#include -#include -#include -#include -#include - -#define MAC_ADDRESS_LEN 6 - -#define ERR_INVALID 1 -#define ERR_IO 2 - -static void usage(void); - -char *maccalc_name; - -static int parse_mac(const char *mac_str, unsigned char *buf) -{ - int t; - - t = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", - &buf[0], &buf[1], &buf[2], &buf[3], &buf[4], &buf[5]); - - if (t != MAC_ADDRESS_LEN) - return ERR_INVALID; - - return 0; -} - -static void print_mac(unsigned char *buf) -{ - printf("%02x:%02x:%02x:%02x:%02x:%02x\n", - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]); -} - -static int maccalc_do_add(int argc, const char *argv[]) -{ - unsigned char mac[MAC_ADDRESS_LEN]; - uint32_t t; - int err; - int i; - - if (argc != 2) { - usage(); - return ERR_INVALID; - } - - err = parse_mac(argv[0], mac); - if (err) - return err; - - i = atoi(argv[1]); - - t = (mac[3] << 16) | (mac[4] << 8) | mac[5]; - t += i; - mac[3] = (t >> 16) & 0xff; - mac[4] = (t >> 8) & 0xff; - mac[5] = t & 0xff; - - print_mac(mac); - return 0; -} - -static int maccalc_do_logical(int argc, const char *argv[], - unsigned char (*op)(unsigned char n1, - unsigned char n2)) -{ - unsigned char mac1[MAC_ADDRESS_LEN]; - unsigned char mac2[MAC_ADDRESS_LEN]; - int err; - int i; - - if (argc != 2) { - usage(); - return ERR_INVALID; - } - - err = parse_mac(argv[0], mac1); - if (err) - return err; - - err = parse_mac(argv[1], mac2); - if (err) - return err; - - for (i = 0; i < MAC_ADDRESS_LEN; i++) - mac1[i] = op(mac1[i],mac2[i]); - - print_mac(mac1); - return 0; -} - -static int maccalc_do_mac2bin(int argc, const char *argv[]) -{ - unsigned char mac[MAC_ADDRESS_LEN]; - ssize_t c; - int err; - - if (argc != 1) { - usage(); - return ERR_INVALID; - } - - err = parse_mac(argv[0], mac); - if (err) - return err; - - c = write(STDOUT_FILENO, mac, sizeof(mac)); - if (c != sizeof(mac)) { - fprintf(stderr, "failed to write to stdout\n"); - return ERR_IO; - } - - return 0; -} - -static ssize_t read_safe(int fd, void *buf, size_t count) -{ - ssize_t total = 0; - ssize_t r; - - while(count > 0) { - r = read(fd, buf, count); - if (r == 0) - /* EOF */ - break; - if (r < 0) { - if (errno == EINTR) - /* interrupted by a signal, restart */ - continue; - /* error */ - total = -1; - break; - } - - /* ok */ - total += r; - count -= r; - buf += r; - } - - return total; -} - -static int maccalc_do_bin2mac(int argc, const char *argv[]) -{ - unsigned char mac[MAC_ADDRESS_LEN]; - ssize_t c; - - if (argc != 0) { - usage(); - return ERR_INVALID; - } - - c = read_safe(STDIN_FILENO, mac, sizeof(mac)); - if (c != sizeof(mac)) { - fprintf(stderr, "failed to read from stdin\n"); - return ERR_IO; - } - - print_mac(mac); - return 0; -} - -static unsigned char op_or(unsigned char n1, unsigned char n2) -{ - return n1 | n2; -} - -static int maccalc_do_or(int argc, const char *argv[]) -{ - return maccalc_do_logical(argc, argv, op_or); -} - -static unsigned char op_and(unsigned char n1, unsigned char n2) -{ - return n1 & n2; -} - -static int maccalc_do_and(int argc, const char *argv[]) -{ - return maccalc_do_logical(argc, argv, op_and); -} - -static unsigned char op_xor(unsigned char n1, unsigned char n2) -{ - return n1 ^ n2; -} - -static int maccalc_do_xor(int argc, const char *argv[]) -{ - return maccalc_do_logical(argc, argv, op_xor); -} - -static void usage(void) -{ - fprintf(stderr, - "Usage: %s \n" - "valid commands:\n" - " add \n" - " and|or|xor \n" - " mac2bin \n" - " bin2mac\n", - maccalc_name); -} - -int main(int argc, const char *argv[]) -{ - int (*op)(int argc, const char *argv[]); - int ret; - - maccalc_name = (char *) argv[0]; - - if (argc < 2) { - usage(); - return EXIT_FAILURE; - } - - if (strcmp(argv[1], "add") == 0) { - op = maccalc_do_add; - } else if (strcmp(argv[1], "and") == 0) { - op = maccalc_do_and; - } else if (strcmp(argv[1], "or") == 0) { - op = maccalc_do_or; - } else if (strcmp(argv[1], "xor") == 0) { - op = maccalc_do_xor; - } else if (strcmp(argv[1], "mac2bin") == 0) { - op = maccalc_do_mac2bin; - } else if (strcmp(argv[1], "bin2mac") == 0) { - op = maccalc_do_bin2mac; - } else { - fprintf(stderr, "unknown command '%s'\n", argv[1]); - usage(); - return EXIT_FAILURE; - } - - argc -= 2; - argv += 2; - - ret = op(argc, argv); - if (ret) - return EXIT_FAILURE; - - return EXIT_SUCCESS; -} From f52081bcf938efcd910832f3c3713ab9f3ca0738 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Tue, 19 Jan 2021 20:05:35 +0100 Subject: [PATCH 3/7] treewide: provide global default for SUPPORTED_DEVICES The majority of our targets provide a default value for the variable SUPPORTED_DEVICES, which is used in images to check against the compatible on a running device: SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) At the moment, this is implemented in the Device/Default block of the individual targets or even subtargets. However, since we standardized device names and compatible in the recent past, almost all targets are following the same scheme now: device/image name: vendor_model compatible: vendor,model The equal redundant definitions are a symptom of this process. Consequently, this patch moves the definition to image.mk making it a global default. For the few targets not using the scheme above, SUPPORTED_DEVICES will be defined to a different value in Device/Default anyway, overwriting the default. In other words: This change is supposed to be cosmetic. This can be used as a global measure to get the current compatible with: $(firstword $(SUPPORTED_DEVICES)) (Though this is not precisely an achievement of this commit.) Signed-off-by: Adrian Schmutzler --- include/image.mk | 2 +- target/linux/apm821xx/image/Makefile | 1 - target/linux/at91/image/Makefile | 1 - target/linux/ath79/image/Makefile | 1 - target/linux/bcm63xx/image/bcm63xx_nand.mk | 1 - target/linux/gemini/image/Makefile | 1 - target/linux/ipq40xx/image/Makefile | 1 - target/linux/ipq806x/image/Makefile | 1 - target/linux/kirkwood/image/Makefile | 1 - target/linux/lantiq/image/Makefile | 1 - target/linux/layerscape/image/armv7.mk | 1 - target/linux/layerscape/image/armv8_64b.mk | 1 - target/linux/mediatek/image/Makefile | 1 - target/linux/mpc85xx/image/Makefile | 1 - target/linux/mvebu/image/Makefile | 1 - target/linux/omap/image/Makefile | 1 - target/linux/oxnas/image/ox810se.mk | 1 - target/linux/oxnas/image/ox820.mk | 1 - target/linux/ramips/image/Makefile | 1 - target/linux/realtek/image/Makefile | 1 - target/linux/rockchip/image/Makefile | 1 - target/linux/sunxi/image/Makefile | 1 - target/linux/tegra/image/Makefile | 1 - 23 files changed, 1 insertion(+), 23 deletions(-) diff --git a/include/image.mk b/include/image.mk index 8f46c75ffe..6843b935f7 100644 --- a/include/image.mk +++ b/include/image.mk @@ -404,7 +404,7 @@ define Device/Init UIMAGE_NAME := DEVICE_COMPAT_VERSION := 1.0 DEVICE_COMPAT_MESSAGE := - SUPPORTED_DEVICES := + SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) IMAGE_METADATA := FILESYSTEMS := $(TARGET_FILESYSTEMS) diff --git a/target/linux/apm821xx/image/Makefile b/target/linux/apm821xx/image/Makefile index 2331947e33..c1cb2bcfdd 100644 --- a/target/linux/apm821xx/image/Makefile +++ b/target/linux/apm821xx/image/Makefile @@ -88,7 +88,6 @@ define Device/Default KERNEL_LOADADDR := 0x00000000 DEVICE_DTS_DIR := ../dts DEVICE_DTS = $(subst _,-,$(1)) - SUPPORTED_DEVICES = $(subst _,$(comma),$(1)) endef include $(SUBTARGET).mk diff --git a/target/linux/at91/image/Makefile b/target/linux/at91/image/Makefile index 05f0b58af7..25fc34eba0 100644 --- a/target/linux/at91/image/Makefile +++ b/target/linux/at91/image/Makefile @@ -25,7 +25,6 @@ define Device/Default PROFILES := Default FILESYSTEMS := squashfs ubifs ext4 DEVICE_DTS = $(lastword $(subst _, ,$(1))) - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) KERNEL_NAME := zImage KERNEL_SIZE := 4096k KERNEL := kernel-bin | append-dtb | lzma | uImage lzma diff --git a/target/linux/ath79/image/Makefile b/target/linux/ath79/image/Makefile index 9bec159cf0..4a51cf1fbf 100644 --- a/target/linux/ath79/image/Makefile +++ b/target/linux/ath79/image/Makefile @@ -65,7 +65,6 @@ define Device/Default KERNEL := kernel-bin | append-dtb | lzma | uImage lzma KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | uImage lzma COMPILE := - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) IMAGES := sysupgrade.bin IMAGE/sysupgrade.bin = append-kernel | pad-to $$$$(BLOCKSIZE) | \ append-rootfs | pad-rootfs | append-metadata | check-size diff --git a/target/linux/bcm63xx/image/bcm63xx_nand.mk b/target/linux/bcm63xx/image/bcm63xx_nand.mk index 81c328b712..5903d03632 100644 --- a/target/linux/bcm63xx/image/bcm63xx_nand.mk +++ b/target/linux/bcm63xx/image/bcm63xx_nand.mk @@ -34,7 +34,6 @@ define Device/bcm63xx-nand CFE_WFI_FLAGS := UBINIZE_OPTS := -E 5 DEVICE_PACKAGES += nand-utils - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) endef define Device/sercomm-nand diff --git a/target/linux/gemini/image/Makefile b/target/linux/gemini/image/Makefile index 83f3d222d9..0eae4c6bd8 100644 --- a/target/linux/gemini/image/Makefile +++ b/target/linux/gemini/image/Makefile @@ -130,7 +130,6 @@ define Device/Default KERNEL_NAME := zImage KERNEL := kernel-bin | append-dtb BLOCKSIZE := 128k - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) endef # A reasonable set of default packages handling the NAS type diff --git a/target/linux/ipq40xx/image/Makefile b/target/linux/ipq40xx/image/Makefile index a764cb60af..2be262936f 100644 --- a/target/linux/ipq40xx/image/Makefile +++ b/target/linux/ipq40xx/image/Makefile @@ -8,7 +8,6 @@ define Device/Default KERNEL_PREFIX := $$(IMAGE_PREFIX) KERNEL_LOADADDR := 0x80208000 DEVICE_DTS = $$(SOC)-$(lastword $(subst _, ,$(1))) - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) IMAGES := sysupgrade.bin IMAGE/sysupgrade.bin = sysupgrade-tar | append-metadata IMAGE/sysupgrade.bin/squashfs := diff --git a/target/linux/ipq806x/image/Makefile b/target/linux/ipq806x/image/Makefile index bc917d4fa4..bab1da0090 100644 --- a/target/linux/ipq806x/image/Makefile +++ b/target/linux/ipq806x/image/Makefile @@ -30,7 +30,6 @@ define Device/Default KERNEL_PREFIX := $$(IMAGE_PREFIX) KERNEL_LOADADDR = 0x42208000 DEVICE_DTS = $$(SOC)-$(lastword $(subst _, ,$(1))) - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) IMAGES := sysupgrade.bin IMAGE/sysupgrade.bin = sysupgrade-tar | append-metadata IMAGE/sysupgrade.bin/squashfs := diff --git a/target/linux/kirkwood/image/Makefile b/target/linux/kirkwood/image/Makefile index a9aad01f7f..9d2d60e55f 100644 --- a/target/linux/kirkwood/image/Makefile +++ b/target/linux/kirkwood/image/Makefile @@ -30,7 +30,6 @@ define Device/Default IMAGES := sysupgrade.bin factory.bin IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata IMAGE/factory.bin := append-ubi - SUPPORTED_DEVICES = $(subst _,$(comma),$(1)) endef define Device/checkpoint_l-50 diff --git a/target/linux/lantiq/image/Makefile b/target/linux/lantiq/image/Makefile index b169d93859..a4ba22dfc4 100644 --- a/target/linux/lantiq/image/Makefile +++ b/target/linux/lantiq/image/Makefile @@ -65,7 +65,6 @@ define Device/Default FILESYSTEMS := squashfs SOC := $(DEFAULT_SOC) DEVICE_DTS = $$(SOC)_$(1) - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) IMAGES := sysupgrade.bin IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size endef diff --git a/target/linux/layerscape/image/armv7.mk b/target/linux/layerscape/image/armv7.mk index 08ef6cb9a1..62921a5ef9 100644 --- a/target/linux/layerscape/image/armv7.mk +++ b/target/linux/layerscape/image/armv7.mk @@ -15,7 +15,6 @@ define Device/Default KERNEL_LOADADDR := 0x80008000 KERNEL_ENTRY_POINT := 0x80008000 DEVICE_DTS = $(lastword $(subst _, ,$(1))) - SUPPORTED_DEVICES = $(subst _,$(comma),$(1)) IMAGE_SIZE := 64m IMAGE/sysupgrade.bin = \ ls-append-dtb $$(DEVICE_DTS) | pad-to 1M | \ diff --git a/target/linux/layerscape/image/armv8_64b.mk b/target/linux/layerscape/image/armv8_64b.mk index 264f7dfd84..a3f4428299 100644 --- a/target/linux/layerscape/image/armv8_64b.mk +++ b/target/linux/layerscape/image/armv8_64b.mk @@ -14,7 +14,6 @@ define Device/Default KERNEL_LOADADDR := 0x80080000 KERNEL_ENTRY_POINT := 0x80080000 DEVICE_DTS = freescale/$(subst _,-,$(1)) - SUPPORTED_DEVICES = $(subst _,$(comma),$(1)) IMAGE_SIZE := 64m IMAGE/sysupgrade.bin = \ ls-append-dtb $$(DEVICE_DTS) | pad-to 1M | \ diff --git a/target/linux/mediatek/image/Makefile b/target/linux/mediatek/image/Makefile index 724bf430ef..36ecdd5a9b 100644 --- a/target/linux/mediatek/image/Makefile +++ b/target/linux/mediatek/image/Makefile @@ -31,7 +31,6 @@ define Device/Default IMAGES := sysupgrade.bin IMAGE/sysupgrade.bin := append-kernel | pad-to 128k | append-rootfs | \ pad-rootfs | append-metadata - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) endef include $(SUBTARGET).mk diff --git a/target/linux/mpc85xx/image/Makefile b/target/linux/mpc85xx/image/Makefile index eb70db04db..618b8c7135 100644 --- a/target/linux/mpc85xx/image/Makefile +++ b/target/linux/mpc85xx/image/Makefile @@ -16,7 +16,6 @@ define Device/Default KERNEL_ENTRY := 0x00000000 KERNEL_LOADADDR := 0x00000000 KERNEL := kernel-bin - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) endef include $(SUBTARGET).mk diff --git a/target/linux/mvebu/image/Makefile b/target/linux/mvebu/image/Makefile index 502e081ec3..77548d683e 100644 --- a/target/linux/mvebu/image/Makefile +++ b/target/linux/mvebu/image/Makefile @@ -105,7 +105,6 @@ define Device/Default KERNEL := kernel-bin | append-dtb | uImage none IMAGES := sysupgrade.bin IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata - SUPPORTED_DEVICES = $(subst _,$(comma),$(1)) UBINIZE_OPTS := -E 5 UBOOT := BOOT_SCRIPT := diff --git a/target/linux/omap/image/Makefile b/target/linux/omap/image/Makefile index ce6377f29b..24c22165c2 100644 --- a/target/linux/omap/image/Makefile +++ b/target/linux/omap/image/Makefile @@ -38,7 +38,6 @@ define Device/Default DEVICE_DTS = $(lastword $(subst _, ,$(1))) IMAGES := sdcard.img.gz IMAGE/sdcard.img.gz := omap-sdcard | append-metadata | gzip - SUPPORTED_DEVICES = $(subst _,$(comma),$(1)) endef #uboot-omap-am335x_evm uboot-omap-omap3_beagle uboot-omap-omap3_overo uboot-omap-omap4_panda diff --git a/target/linux/oxnas/image/ox810se.mk b/target/linux/oxnas/image/ox810se.mk index b9bb5e7117..77bdcc7716 100644 --- a/target/linux/oxnas/image/ox810se.mk +++ b/target/linux/oxnas/image/ox810se.mk @@ -6,7 +6,6 @@ define Device/Default KERNEL_INSTALL := 1 FILESYSTEMS := squashfs ext4 PROFILES := Default - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) DEVICE_DTS := ox810se-$(subst _,-,$(1)) IMAGES := sysupgrade.tar IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata diff --git a/target/linux/oxnas/image/ox820.mk b/target/linux/oxnas/image/ox820.mk index a52e09786b..8dea842503 100644 --- a/target/linux/oxnas/image/ox820.mk +++ b/target/linux/oxnas/image/ox820.mk @@ -10,7 +10,6 @@ define Device/Default SUBPAGESIZE := 512 FILESYSTEMS := squashfs ubifs PROFILES := Default - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) DEVICE_DTS := ox820-$(subst _,-,$(1)) KERNEL := kernel-bin | append-dtb | uImage none IMAGES := ubinized.bin sysupgrade.tar diff --git a/target/linux/ramips/image/Makefile b/target/linux/ramips/image/Makefile index 4274c24884..2fb13dcf08 100644 --- a/target/linux/ramips/image/Makefile +++ b/target/linux/ramips/image/Makefile @@ -187,7 +187,6 @@ define Device/Default DEVICE_DTS = $$(SOC)_$(1) IMAGES := sysupgrade.bin COMPILE := - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) sysupgrade_bin := append-kernel | append-rootfs | pad-rootfs IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size endef diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile index 1251b47c93..87c616c3f2 100644 --- a/target/linux/realtek/image/Makefile +++ b/target/linux/realtek/image/Makefile @@ -13,7 +13,6 @@ define Device/Default KERNEL_INITRAMFS := kernel-bin | append-dtb | gzip | uImage gzip DEVICE_DTS_DIR := ../dts DEVICE_DTS = $$(SOC)_$(1) - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) IMAGES := sysupgrade.bin IMAGE/sysupgrade.bin := append-kernel | pad-to 64k | append-rootfs | pad-rootfs | \ append-metadata | check-size diff --git a/target/linux/rockchip/image/Makefile b/target/linux/rockchip/image/Makefile index 3c17e963be..022661623a 100644 --- a/target/linux/rockchip/image/Makefile +++ b/target/linux/rockchip/image/Makefile @@ -52,7 +52,6 @@ define Device/Default PROFILES := Default KERNEL := kernel-bin IMAGES := sysupgrade.img.gz - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) DEVICE_DTS = rockchip/$$(SOC)-$(lastword $(subst _, ,$(1))) endef diff --git a/target/linux/sunxi/image/Makefile b/target/linux/sunxi/image/Makefile index 01e9742b46..572c0597e8 100644 --- a/target/linux/sunxi/image/Makefile +++ b/target/linux/sunxi/image/Makefile @@ -37,7 +37,6 @@ define Device/Default KERNEL := kernel-bin | uImage none IMAGES := sdcard.img.gz IMAGE/sdcard.img.gz := sunxi-sdcard | append-metadata | gzip - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) SUNXI_DTS_DIR := SUNXI_DTS = $$(SUNXI_DTS_DIR)$$(SOC)-$(lastword $(subst _, ,$(1))) endef diff --git a/target/linux/tegra/image/Makefile b/target/linux/tegra/image/Makefile index 71a5fc581d..97f97e3cc2 100644 --- a/target/linux/tegra/image/Makefile +++ b/target/linux/tegra/image/Makefile @@ -38,7 +38,6 @@ define Device/Default KERNEL_NAME := zImage KERNEL := kernel-bin PROFILES := Default - SUPPORTED_DEVICES := $(subst _,$(comma),$(1)) endef define Device/compulab_trimslice From 96017a60138bdf97d2f1f7e7b519b4ad6ff13b88 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Sun, 10 Jan 2021 02:40:00 -0500 Subject: [PATCH 4/7] ath79: add support for Senao Engenius EAP1200H FCC ID: A8J-EAP1200H Engenius EAP1200H is an indoor wireless access point with 1 Gb ethernet port, dual-band wireless, internal antenna plates, and 802.3at PoE+ **Specification:** - QCA9557 SOC - QCA9882 WLAN PCI card, 5 GHz, 2x2, 26dBm - AR8035-A PHY RGMII GbE with PoE+ IN - 40 MHz clock - 16 MB FLASH MX25L12845EMI-10G - 2x 64 MB RAM NT5TU32M16FG - UART at J10 populated - 4 internal antenna plates (5 dbi, omni-directional) - 5 LEDs, 1 button (power, eth0, 2G, 5G, WPS) (reset) **MAC addresses:** MAC addresses are labeled as ETH, 2.4G, and 5GHz Only one Vendor MAC address in flash eth0 ETH *:a2 art 0x0 phy1 2.4G *:a3 --- phy0 5GHz *:a4 --- **Serial Access:** the RX line on the board for UART is shorted to ground by resistor R176 therefore it must be removed to use the console but it is not necessary to remove to view boot log optionally, R175 can be replaced with a solder bridge short the resistors R175 and R176 are next to the UART RX pin at J10 **Installation:** 2 ways to flash factory.bin from OEM: Method 1: Firmware upgrade page: OEM webpage at 192.168.1.1 username and password "admin" Navigate to "Firmware Upgrade" page from left pane Click Browse and select the factory.bin image Upload and verify checksum Click Continue to confirm and wait 3 minutes Method 2: Serial to load Failsafe webpage: After connecting to serial console and rebooting... Interrupt uboot with any key pressed rapidly execute `run failsafe_boot` OR `bootm 0x9fd70000` wait a minute connect to ethernet and navigate to "192.168.1.1/index.htm" Select the factory.bin image and upload wait about 3 minutes **Return to OEM:** If you have a serial cable, see Serial Failsafe instructions otherwise, uboot-env can be used to make uboot load the failsafe image *DISCLAIMER* The Failsafe image is unique to Engenius boards. If the failsafe image is missing or damaged this will brick the device DO NOT downgrade to ar71xx this way, it can cause kernel loop or halt ssh into openwrt and run `fw_setenv rootfs_checksum 0` reboot, wait 3 minutes connect to ethernet and navigate to 192.168.1.1/index.htm select OEM firmware image from Engenius and click upgrade **TFTP recovery:** Requires serial console, reset button does nothing rename initramfs to 'vmlinux-art-ramdisk' make available on TFTP server at 192.168.1.101 power board, interrupt boot execute tftpboot and bootm 0x81000000 NOTE: TFTP is not reliable due to bugged bootloader set MTU to 600 and try many times **Format of OEM firmware image:** The OEM software of EAP1200H is a heavily modified version of Openwrt Kamikaze. One of the many modifications is to the sysupgrade program. Image verification is performed simply by the successful ungzip and untar of the supplied file and name check and header verification of the resulting contents. To form a factory.bin that is accepted by OEM Openwrt build, the kernel and rootfs must have specific names... openwrt-ar71xx-generic-eap1200h-uImage-lzma.bin openwrt-ar71xx-generic-eap1200h-root.squashfs and begin with the respective headers (uImage, squashfs). Then the files must be tarballed and gzipped. The resulting binary is actually a tar.gz file in disguise. This can be verified by using binwalk on the OEM firmware images, ungzipping then untaring. Newer EnGenius software requires more checks but their script includes a way to skip them, otherwise the tar must include a text file with the version and md5sums in a deprecated format. The OEM upgrade script is at /etc/fwupgrade.sh. OKLI kernel loader is required because the OEM software expects the kernel to be no greater than 1536k and the factory.bin upgrade procedure would otherwise overwrite part of the kernel when writing rootfs. Note on PLL-data cells: The default PLL register values will not work because of the external AR8035 switch between the SOC and the ethernet port. For QCA955x series, the PLL registers for eth0 and eth1 can be see in the DTSI as 0x28 and 0x48 respectively. Therefore the PLL registers can be read from uboot for each link speed after attempting tftpboot or another network action using that link speed with `md 0x18050028 1` and `md 0x18050048 1`. The clock delay required for RGMII can be applied at the PHY side, using the at803x driver `phy-mode`. Therefore the PLL registers for GMAC0 do not need the bits for delay on the MAC side. This is possible due to fixes in at803x driver since Linux 5.1 and 5.3 Signed-off-by: Michael Pratt --- package/boot/uboot-envtools/files/ath79 | 1 + .../ath79/dts/qca9557_engenius_eap1200h.dts | 187 ++++++++++++++++++ .../generic/base-files/etc/board.d/02_network | 1 + .../etc/hotplug.d/firmware/11-ath10k-caldata | 1 + target/linux/ath79/image/generic.mk | 11 ++ 5 files changed, 201 insertions(+) create mode 100644 target/linux/ath79/dts/qca9557_engenius_eap1200h.dts diff --git a/package/boot/uboot-envtools/files/ath79 b/package/boot/uboot-envtools/files/ath79 index 4b84766814..abcb99663d 100644 --- a/package/boot/uboot-envtools/files/ath79 +++ b/package/boot/uboot-envtools/files/ath79 @@ -23,6 +23,7 @@ allnet,all-wap02860ac|\ arduino,yun|\ buffalo,bhr-4grv2|\ devolo,magic-2-wifi|\ +engenius,eap1200h|\ engenius,eap300-v2|\ engenius,eap350-v1|\ engenius,eap600|\ diff --git a/target/linux/ath79/dts/qca9557_engenius_eap1200h.dts b/target/linux/ath79/dts/qca9557_engenius_eap1200h.dts new file mode 100644 index 0000000000..72a50c922e --- /dev/null +++ b/target/linux/ath79/dts/qca9557_engenius_eap1200h.dts @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT + +#include "qca955x.dtsi" + +#include +#include +#include + +/ { + compatible = "engenius,eap1200h", "qca,qca9557"; + model = "EnGenius EAP1200H"; + + aliases { + label-mac-device = ð0; + led-boot = &led_power; + led-failsafe = &led_power; + led-running = &led_power; + led-upgrade = &led_power; + }; + + keys { + compatible = "gpio-keys"; + + reset { + label = "reset"; + gpios = <&gpio 17 GPIO_ACTIVE_LOW>; + debounce-interval = <60>; + linux,code = ; + }; + }; + + leds { + compatible = "gpio-leds"; + + led_power: power { + label = "amber:power"; + gpios = <&gpio 22 GPIO_ACTIVE_LOW>; + default-state = "on"; + }; + + wifi2g { + label = "blue:wifi2g"; + gpios = <&gpio 13 GPIO_ACTIVE_LOW>; + linux,default-trigger = "phy1tpt"; + }; + + wifi5g { + label = "green:wifi5g"; + gpios = <&gpio 23 GPIO_ACTIVE_LOW>; + linux,default-trigger = "phy0tpt"; + }; + + wps { + label = "blue:wps"; + gpios = <&gpio 19 GPIO_ACTIVE_LOW>; + }; + }; + + virtual_flash { + compatible = "mtd-concat"; + + devices = <&fwconcat0 &fwconcat1>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = ; + label = "firmware"; + reg = <0x0 0x0>; + }; + }; + }; +}; + +&uart { + status = "okay"; +}; + +&spi { + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + spi-max-frequency = <40000000>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "u-boot"; + reg = <0x000000 0x040000>; + read-only; + }; + + partition@40000 { + label = "u-boot-env"; + reg = <0x040000 0x010000>; + }; + + partition@50000 { + label = "custom"; + reg = <0x050000 0x050000>; + read-only; + }; + + partition@a0000 { + label = "loader"; + reg = <0x0a0000 0x010000>; + read-only; + }; + + fwconcat1: partition@b0000 { + label = "fwconcat1"; + reg = <0x0b0000 0x170000>; + }; + + partition@220000 { + label = "fakeroot"; + reg = <0x220000 0x010000>; + read-only; + }; + + fwconcat0: partition@230000 { + label = "fwconcat0"; + reg = <0x230000 0xb40000>; + }; + + partition@d70000 { + label = "failsafe"; + reg = <0xd70000 0x280000>; + read-only; + }; + + art: partition@ff0000 { + label = "art"; + reg = <0xff0000 0x010000>; + read-only; + }; + }; + }; +}; + +&mdio0 { + status = "okay"; + + phy5: ethernet-phy@5 { + reg = <5>; + eee-broken-100tx; + eee-broken-1000t; + }; +}; + +ð0 { + status = "okay"; + + mtd-mac-address = <&art 0x0>; + + phy-handle = <&phy5>; + phy-mode = "rgmii-id"; + + pll-data = <0x82000000 0x80000101 0x80001313>; +}; + +&pcie0 { + status = "okay"; + + wifi@0,0,0 { + compatible = "qcom,ath10k"; + reg = <0x0 0 0 0 0>; + qca,no-eeprom; + }; +}; + +&wmac { + status = "okay"; + + mtd-cal-data = <&art 0x1000>; + mtd-mac-address = <&art 0x0>; + mtd-mac-address-increment = <1>; +}; diff --git a/target/linux/ath79/generic/base-files/etc/board.d/02_network b/target/linux/ath79/generic/base-files/etc/board.d/02_network index 0c08871f99..2d76d16f9f 100755 --- a/target/linux/ath79/generic/base-files/etc/board.d/02_network +++ b/target/linux/ath79/generic/base-files/etc/board.d/02_network @@ -32,6 +32,7 @@ ath79_setup_interfaces() dlink,dap-2680-a1|\ dlink,dap-3320-a1|\ dlink,dir-505|\ + engenius,eap1200h|\ engenius,eap300-v2|\ engenius,eap600|\ engenius,ecb1200|\ diff --git a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata index 84323046f6..9a199b4deb 100644 --- a/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata +++ b/target/linux/ath79/generic/base-files/etc/hotplug.d/firmware/11-ath10k-caldata @@ -11,6 +11,7 @@ case "$FIRMWARE" in "ath10k/cal-pci-0000:00:00.0.bin") case $board in allnet,all-wap02860ac|\ + engenius,eap1200h|\ engenius,enstationac-v1|\ glinet,gl-x750) caldata_extract "art" 0x5000 0x844 diff --git a/target/linux/ath79/image/generic.mk b/target/linux/ath79/image/generic.mk index 3b5cb6bdfa..7432607fcd 100644 --- a/target/linux/ath79/image/generic.mk +++ b/target/linux/ath79/image/generic.mk @@ -957,6 +957,17 @@ define Device/embeddedwireless_dorin endef TARGET_DEVICES += embeddedwireless_dorin +define Device/engenius_eap1200h + $(Device/engenius_loader_okli) + SOC := qca9557 + DEVICE_MODEL := EAP1200H + DEVICE_PACKAGES := ath10k-firmware-qca988x-ct kmod-ath10k-ct + IMAGE_SIZE := 11520k + LOADER_FLASH_OFFS := 0x230000 + ENGENIUS_IMGNAME := ar71xx-generic-eap1200h +endef +TARGET_DEVICES += engenius_eap1200h + define Device/engenius_eap300-v2 $(Device/engenius_loader_okli) SOC := ar9341 From 111de654afe0703e3909bc83bfd00a2de4260062 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Sat, 23 Jan 2021 20:54:23 +0100 Subject: [PATCH 5/7] glibc: update to latest 2.32 commit (BZ#2692 BZ#26988 BZ#26831 BZ#2706) d3cb8f6222 aarch64: fix static PIE start code for BTI [BZ #27068] 082798622d __vfscanf_internal: fix aliasing violation (bug 26690) 33dc30bc83 aarch64: Use mmap to add PROT_BTI instead of mprotect [BZ #26831] 46e1e64fe3 elf: Pass the fd to note processing b6eae83717 elf: Move note processing after l_phdr is updated c6090dcebd aarch64: align address for BTI protection [BZ #26988] 610e2c5150 aarch64: Fix missing BTI protection from dependencies [BZ #26926] Signed-off-by: Hans Dedecker --- toolchain/glibc/common.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/glibc/common.mk b/toolchain/glibc/common.mk index a32e375117..7941f6d4d9 100644 --- a/toolchain/glibc/common.mk +++ b/toolchain/glibc/common.mk @@ -12,8 +12,8 @@ PKG_RELEASE:=2 PKG_SOURCE_PROTO:=git PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) -PKG_SOURCE_VERSION:=4c619b3eed558172198790f842740abb9af1989d -PKG_MIRROR_HASH:=b662bceabc5a077c5be8a582aaf1567450fd774df5e31f91928272c1e4e572de +PKG_SOURCE_VERSION:=d3cb8f6222a3cb955712b720d7c0c0dba37898f9 +PKG_MIRROR_HASH:=c3e97ad622eafaf539b733a18c0d62e9fb4c0f18d190b7bcc0e93611e582fb1e PKG_SOURCE_URL:=https://sourceware.org/git/glibc.git PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.xz From 4571ef48d8226dda152f921bd12eb254bea001bd Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Sat, 23 Jan 2021 22:03:51 +0100 Subject: [PATCH 6/7] bcm53xx: use default SUPPORTED_DEVICES for Meraki MR32 Since the new global SUPPORTED_DEVICES are now available in bcm53xx as well, we do not need to specify an explicit value for the MR32 anymore. Signed-off-by: Adrian Schmutzler --- target/linux/bcm53xx/image/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/target/linux/bcm53xx/image/Makefile b/target/linux/bcm53xx/image/Makefile index 00141118a1..90343b1e88 100644 --- a/target/linux/bcm53xx/image/Makefile +++ b/target/linux/bcm53xx/image/Makefile @@ -335,10 +335,8 @@ define Device/meraki_mr32 pad-to 10362880 KERNEL := kernel-bin | fit none $$(DTS_DIR)/$$(DEVICE_DTS).dtb IMAGES := sysupgrade.bin - IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata - # Currently the only device that uses the new image check - SUPPORTED_DEVICES := meraki,mr32 + IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata # The loader is specifically looking for fdt@2: # [ 3.190000] find_itb_subimage: error finding fdt@2: FDT_ERR_NOTFOUND From 29167cbca3653de05a8b915bc21327dac7d05174 Mon Sep 17 00:00:00 2001 From: Adrian Schmutzler Date: Sat, 23 Jan 2021 22:09:27 +0100 Subject: [PATCH 7/7] x86: fix upgrade by emptying SUPPORTED_DEVICES x86 uses append-metadata, but only for signing and not for the metadata itself. Since recently SUPPORTED_DEVICES was assigned with a global value and is not empty anymore, append-metadata will now actually put metadata into x86 images. This breaks sysupgrade on x86. To fix it for the moment, let's just empty SUPPORTED_DEVICES for this target again. In the long term, one should either not add metadata to the images if it is not desired, and/or remove the unintended fwtool check. Fixes: f52081bcf938 ("treewide: provide global default for SUPPORTED_DEVICES") Signed-off-by: Adrian Schmutzler --- target/linux/x86/image/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/target/linux/x86/image/Makefile b/target/linux/x86/image/Makefile index 85c850c128..81aab20666 100644 --- a/target/linux/x86/image/Makefile +++ b/target/linux/x86/image/Makefile @@ -144,6 +144,7 @@ define Device/Default endif IMAGES := $$(IMAGES-y) ARTIFACTS := $$(ARTIFACTS-y) + SUPPORTED_DEVICES := endef include $(SUBTARGET).mk