From patchwork Mon Jun 17 15:32:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804877 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611084wrr; Mon, 17 Jun 2024 08:33:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU0Dgjt7TERbx/3VVQvwTd59bG+aX3in9VKNKnY/DmHTXCpNEBqQlk6yJ8GQOlo5J7JFhSxbbAOX17H8S5itMCk X-Google-Smtp-Source: AGHT+IGlY+oJIOq9tV0AGvVMaZiBudFwaFRgvqGimZpvhQyfIP4m81qfM9ue8Ozk2GCMyrNUAEK8 X-Received: by 2002:a17:906:6886:b0:a6f:4ae3:5324 with SMTP id a640c23a62f3a-a6f60d3fd58mr613767266b.40.1718638425023; Mon, 17 Jun 2024 08:33:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638425; cv=none; d=google.com; s=arc-20160816; b=f86Je6jxi7t3HFOrkdJ4rlalHkTtRI701LnuRFXUoDM2sEFNyq3rLKCoQchXLoRTtu w4V4E8Ald0X1rApSg9Gfn0YFVeVKQA4wOTUDxfBg/isCGD1EnR5pdkWVzuqotCKjZ2qH AJppV6asV5IyrRHskU58me6TYyiAHZNHMfUvx+z76rk3wfj1wyw5VCuntdEDWbvgiZRs EOS7QY7EysKJs7lv06xnWPeoOMcN0inwVzIaTm2Ocob/nEi4nSart9HA5qip2XLC5oyr CbS02Njv/WPS/5rufbETTyg9CvHH2E+NV4gdNpE0itfWrNS3C+ivey+SEC2n1S1GvKvD Wjrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C0CMhQpQPKnCML8ZQNHlBapAy1uzEaVtf0jEJ481s18=; fh=UXxlqMaK7mAd0zEp1c/kHO0k9az1vKN/288cQEd20OI=; b=g6qvklvqfOVbO8mNtAxfuRcjon4/YT9i22BGCHa+qYwPIWts7fT9SjCkwpYz0p3Os1 MwH9L+mDdHCo56dDHUTSxyVFCWqapyXPmwuMzxKmSiExyAlx4d7PsHfHMsGz7Pjal+yw ZyG2zcuHSeXW264afXXPuF5BjwV7Mpap/J76X1hIqmx3Kh8xIVWpVooPP97RZvSHDvoC Xp83U04kbo/+ROOltWA44DjohIhsiRRHN48eE+K3U8d9JfGclpROhbY/RzLKtmckkaQP j/Eza25QswImjYVpgUKpbzEOHJpJ+/j1SNhfXzFo9RigjHVW2DWkIAtpbsfVaqJ/WqTD 0JyQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h9flOIWq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f7b4ba42csi192661066b.499.2024.06.17.08.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:44 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=h9flOIWq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 666BC88366; Mon, 17 Jun 2024 17:33:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="h9flOIWq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C1A75882D0; Mon, 17 Jun 2024 17:33:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 51ACA8831F for ; Mon, 17 Jun 2024 17:33:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-421eab59723so32691685e9.3 for ; Mon, 17 Jun 2024 08:33:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638409; x=1719243209; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C0CMhQpQPKnCML8ZQNHlBapAy1uzEaVtf0jEJ481s18=; b=h9flOIWql1hluGaJ/kvUVlqIKocjKJjgC1MPbLbUroygo8lzQw0JirpHFs9bC/OYfN SoqrTFm7BgmkqrKkQw5zThoQgAXKWt3G6oOgX1kJLEWbtMzbrYV9tO9zVDUZvdEQNzGN sh3uAtY2EbbC407gjYFRA9Usk8pDIC6O8KxHZLAi0SIpCd8Y4LQZXjrJ4adWiN67Pl1F uhwYh7i8ViVxUChHeaiKXJs8xNK3KVuhrJx9XnED38N7z75KrbKE9rBPMKwXYW9ho6Es 3wJX7n6930lyi0fjeaHx6d5W0AUyzVJ2zMURZaaXfxkrrQFfjPbr3R9S5Km7Y47ow52V s0OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638409; x=1719243209; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C0CMhQpQPKnCML8ZQNHlBapAy1uzEaVtf0jEJ481s18=; b=s1X8/1m1p9fxYvYvZZ1jTI0nNkpUYf/qvofGKXtdkwmLCuU/WZSnyUdpNTt/uCQBnw ITMI9w8Yml5alUgZ7MIwIQgU3nFoxo0hogPkT5z7cHMaAKcUlM6Z5buEqME6y8NVT+/o VVoHhq7qw+PFEvJ7CHYe5W9UlFKNPIqLKhlH/jlOLbHdXSTZBA67QkZW38rDD6/rs2v6 HD4pghizdQzbvB9ETFe9Pb/e0tfQWYAjLnDdLOPrJNAvG1TSWXZBmvmfrxewiw1pu+6l UzPouMKcpO1/8VI9l0hLiSe2jdgH80YHWpCj81Byb/vvjfn/0A2ysmZuh+ShbkSpnVMK /ivg== X-Gm-Message-State: AOJu0Yw/Uv4VFVrVB99BkA9u7/kXimhFTx0SB1Go3j2xcxSJnYLSwtV+ 7Nksx2+t8YyfJj9m/QQYLM3+4Qc4wTpICDUZsxYPyyZfo2aw1SvZfWje9QoH9LyX8MzfZLDbNLO J X-Received: by 2002:a05:600c:444f:b0:422:5b78:1c8f with SMTP id 5b1f17b1804b1-42304811928mr76833735e9.8.1718638409487; Mon, 17 Jun 2024 08:33:29 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:29 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Angelo Dureghello , Tom Rini , TsiChung Liew , Stefan Roese , Peng Fan , Jason Liu , William Zhang Subject: [PATCH v4 01/14] flash: prefix error codes with FL_ Date: Mon, 17 Jun 2024 17:32:53 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Prefix the flash status codes (ERR_*) with FL_ in order to avoid clashes with third-party libraries. Case in point: including the lwIP library header file which defines err_enum_t as an enum with values being ERR_*. Signed-off-by: Jerome Forissier Reviewed-by: Tom Rini Reviewed-by: Ilias Apalodimas --- board/cobra5272/flash.c | 26 +++++++++--------- board/freescale/m5253demo/flash.c | 6 ++--- common/flash.c | 44 +++++++++++++++---------------- drivers/mtd/cfi_flash.c | 36 ++++++++++++------------- include/flash.h | 20 +++++++------- 5 files changed, 66 insertions(+), 66 deletions(-) diff --git a/board/cobra5272/flash.c b/board/cobra5272/flash.c index 8416af163ad..6464975f184 100644 --- a/board/cobra5272/flash.c +++ b/board/cobra5272/flash.c @@ -134,22 +134,22 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) { ulong result; int iflag, cflag, prot, sect; - int rc = ERR_OK; + int rc = FL_ERR_OK; int chip1; ulong start; /* first look for protection bits */ if (info->flash_id == FLASH_UNKNOWN) - return ERR_UNKNOWN_FLASH_TYPE; + return FL_ERR_UNKNOWN_FLASH_TYPE; if ((s_first < 0) || (s_first > s_last)) { - return ERR_INVAL; + return FL_ERR_INVAL; } if ((info->flash_id & FLASH_VENDMASK) != (AMD_MANUFACT & FLASH_VENDMASK)) { - return ERR_UNKNOWN_FLASH_VENDOR; + return FL_ERR_UNKNOWN_FLASH_VENDOR; } prot = 0; @@ -159,7 +159,7 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) } } if (prot) - return ERR_PROTECTED; + return FL_ERR_PROTECTED; /* * Disable interrupts which might cause a timeout @@ -216,11 +216,11 @@ int flash_erase(flash_info_t *info, int s_first, int s_last) MEM_FLASH_ADDR1 = CMD_READ_ARRAY; if (chip1 == ERR) { - rc = ERR_PROG_ERROR; + rc = FL_ERR_PROG_ERROR; goto outahere; } if (chip1 == TMO) { - rc = ERR_TIMEOUT; + rc = FL_ERR_TIMEOUT; goto outahere; } @@ -251,7 +251,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data) { volatile u16 *addr = (volatile u16 *) dest; ulong result; - int rc = ERR_OK; + int rc = FL_ERR_OK; int cflag, iflag; int chip1; ulong start; @@ -261,7 +261,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data) */ result = *addr; if ((result & data) != data) - return ERR_NOT_ERASED; + return FL_ERR_NOT_ERASED; /* @@ -302,7 +302,7 @@ static int write_word(flash_info_t *info, ulong dest, ulong data) *addr = CMD_READ_ARRAY; if (chip1 == ERR || *addr != data) - rc = ERR_PROG_ERROR; + rc = FL_ERR_PROG_ERROR; if (iflag) enable_interrupts(); @@ -321,13 +321,13 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) if (addr & 1) { printf ("unaligned destination not supported\n"); - return ERR_ALIGN; + return FL_ERR_ALIGN; } #if 0 if (cnt & 1) { printf ("odd transfer sizes not supported\n"); - return ERR_ALIGN; + return FL_ERR_ALIGN; } #endif @@ -365,5 +365,5 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) cnt -= 1; } - return ERR_OK; + return FL_ERR_OK; } diff --git a/board/freescale/m5253demo/flash.c b/board/freescale/m5253demo/flash.c index eeb9cfd3125..b6b7df88761 100644 --- a/board/freescale/m5253demo/flash.c +++ b/board/freescale/m5253demo/flash.c @@ -71,7 +71,7 @@ int flash_get_offsets(ulong base, flash_info_t * info) } } - return ERR_OK; + return FL_ERR_OK; } void flash_print_info(flash_info_t * info) @@ -368,9 +368,9 @@ int write_buff(flash_info_t * info, uchar * src, ulong addr, ulong cnt) } if (cnt == 0) - return ERR_OK; + return FL_ERR_OK; - return ERR_OK; + return FL_ERR_OK; } /*----------------------------------------------------------------------- diff --git a/common/flash.c b/common/flash.c index 848f44e59df..99fd84e2aef 100644 --- a/common/flash.c +++ b/common/flash.c @@ -110,13 +110,13 @@ addr2info(ulong addr) * Make sure all target addresses are within Flash bounds, * and no protected sectors are hit. * Returns: - * ERR_OK 0 - OK - * ERR_TIMEOUT 1 - write timeout - * ERR_NOT_ERASED 2 - Flash not erased - * ERR_PROTECTED 4 - target range includes protected sectors - * ERR_INVAL 8 - target address not in Flash memory - * ERR_ALIGN 16 - target address not aligned on boundary - * (only some targets require alignment) + * FL_ERR_OK 0 - OK + * FL_ERR_TIMEOUT 1 - write timeout + * FL_ERR_NOT_ERASED 2 - Flash not erased + * FL_ERR_PROTECTED 4 - target range includes protected sectors + * FL_ERR_INVAL 8 - target address not in Flash memory + * FL_ERR_ALIGN 16 - target address not aligned on boundary + * (only some targets require alignment) */ int flash_write(char *src, ulong addr, ulong cnt) @@ -131,11 +131,11 @@ flash_write(char *src, ulong addr, ulong cnt) __maybe_unused ulong cnt_orig = cnt; if (cnt == 0) { - return (ERR_OK); + return (FL_ERR_OK); } if (!info_first || !info_last) { - return (ERR_INVAL); + return (FL_ERR_INVAL); } for (info = info_first; info <= info_last; ++info) { @@ -146,7 +146,7 @@ flash_write(char *src, ulong addr, ulong cnt) if ((end >= info->start[i]) && (addr < e_addr) && (info->protect[i] != 0) ) { - return (ERR_PROTECTED); + return (FL_ERR_PROTECTED); } } } @@ -169,11 +169,11 @@ flash_write(char *src, ulong addr, ulong cnt) #if defined(CONFIG_FLASH_VERIFY) if (memcmp(src_orig, addr_orig, cnt_orig)) { printf("\nVerify failed!\n"); - return ERR_PROG_ERROR; + return FL_ERR_PROG_ERROR; } #endif /* CONFIG_SYS_FLASH_VERIFY_AFTER_WRITE */ - return (ERR_OK); + return (FL_ERR_OK); } /*----------------------------------------------------------------------- @@ -182,33 +182,33 @@ flash_write(char *src, ulong addr, ulong cnt) void flash_perror(int err) { switch (err) { - case ERR_OK: + case FL_ERR_OK: break; - case ERR_TIMEOUT: + case FL_ERR_TIMEOUT: puts ("Timeout writing to Flash\n"); break; - case ERR_NOT_ERASED: + case FL_ERR_NOT_ERASED: puts ("Flash not Erased\n"); break; - case ERR_PROTECTED: + case FL_ERR_PROTECTED: puts ("Can't write to protected Flash sectors\n"); break; - case ERR_INVAL: + case FL_ERR_INVAL: puts ("Outside available Flash\n"); break; - case ERR_ALIGN: + case FL_ERR_ALIGN: puts ("Start and/or end address not on sector boundary\n"); break; - case ERR_UNKNOWN_FLASH_VENDOR: + case FL_ERR_UNKNOWN_FLASH_VENDOR: puts ("Unknown Vendor of Flash\n"); break; - case ERR_UNKNOWN_FLASH_TYPE: + case FL_ERR_UNKNOWN_FLASH_TYPE: puts ("Unknown Type of Flash\n"); break; - case ERR_PROG_ERROR: + case FL_ERR_PROG_ERROR: puts ("General Flash Programming Error\n"); break; - case ERR_ABORTED: + case FL_ERR_ABORTED: puts("Flash Programming Aborted\n"); break; default: diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c index 8ade7949a68..6369c7127c6 100644 --- a/drivers/mtd/cfi_flash.c +++ b/drivers/mtd/cfi_flash.c @@ -592,11 +592,11 @@ static int flash_status_check(flash_info_t *info, flash_sect_t sector, flash_read_long(info, sector, 0)); flash_write_cmd(info, sector, 0, info->cmd_reset); udelay(1); - return ERR_TIMEOUT; + return FL_ERR_TIMEOUT; } udelay(1); /* also triggers watchdog */ } - return ERR_OK; + return FL_ERR_OK; } /*----------------------------------------------------------------------- @@ -615,9 +615,9 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, case CFI_CMDSET_INTEL_PROG_REGIONS: case CFI_CMDSET_INTEL_EXTENDED: case CFI_CMDSET_INTEL_STANDARD: - if (retcode == ERR_OK && + if (retcode == FL_ERR_OK && !flash_isset(info, sector, 0, FLASH_STATUS_DONE)) { - retcode = ERR_INVAL; + retcode = FL_ERR_INVAL; printf("Flash %s error at address %lx\n", prompt, info->start[sector]); if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS | @@ -626,14 +626,14 @@ static int flash_full_status_check(flash_info_t *info, flash_sect_t sector, } else if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS)) { puts("Block Erase Error.\n"); - retcode = ERR_NOT_ERASED; + retcode = FL_ERR_NOT_ERASED; } else if (flash_isset(info, sector, 0, FLASH_STATUS_PSLBS)) { puts("Locking Error\n"); } if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) { puts("Block locked.\n"); - retcode = ERR_PROTECTED; + retcode = FL_ERR_PROTECTED; } if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS)) puts("Vpp Low Error.\n"); @@ -701,12 +701,12 @@ static int flash_status_poll(flash_info_t *info, void *src, void *dst, if (get_timer(start) > tout) { printf("Flash %s timeout at address %lx data %lx\n", prompt, (ulong)dst, (ulong)flash_read8(dst)); - return ERR_TIMEOUT; + return FL_ERR_TIMEOUT; } udelay(1); /* also triggers watchdog */ } #endif /* CONFIG_SYS_CFI_FLASH_STATUS_POLL */ - return ERR_OK; + return FL_ERR_OK; } /*----------------------------------------------------------------------- @@ -809,7 +809,7 @@ static int flash_write_cfiword(flash_info_t *info, ulong dest, cfiword_t cword) break; } if (!flag) - return ERR_NOT_ERASED; + return FL_ERR_NOT_ERASED; /* Disable interrupts which might cause a timeout here */ flag = disable_interrupts(); @@ -898,7 +898,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, shift = 3; break; default: - retcode = ERR_INVAL; + retcode = FL_ERR_INVAL; goto out_unmap; } @@ -929,7 +929,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, } } if (!flag) { - retcode = ERR_NOT_ERASED; + retcode = FL_ERR_NOT_ERASED; goto out_unmap; } @@ -949,7 +949,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, retcode = flash_status_check(info, sector, info->buffer_write_tout, "write to buffer"); - if (retcode == ERR_OK) { + if (retcode == FL_ERR_OK) { /* reduce the number of loops by the width of * the port */ @@ -974,7 +974,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, src += 8, dst += 8; break; default: - retcode = ERR_INVAL; + retcode = FL_ERR_INVAL; goto out_unmap; } } @@ -1024,7 +1024,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, } break; default: - retcode = ERR_INVAL; + retcode = FL_ERR_INVAL; goto out_unmap; } @@ -1042,7 +1042,7 @@ static int flash_write_cfibuffer(flash_info_t *info, ulong dest, uchar *cp, default: debug("Unknown Command Set\n"); - retcode = ERR_INVAL; + retcode = FL_ERR_INVAL; break; } @@ -1388,7 +1388,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) if (i > cnt) i = cnt; rc = flash_write_cfibuffer(info, wp, src, i); - if (rc != ERR_OK) + if (rc != FL_ERR_OK) return rc; i -= i & (info->portwidth - 1); wp += i; @@ -1397,7 +1397,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) FLASH_SHOW_PROGRESS(scale, dots, digit, i); /* Only check every once in a while */ if ((cnt & 0xFFFF) < buffered_size && ctrlc()) - return ERR_ABORTED; + return FL_ERR_ABORTED; } #else while (cnt >= info->portwidth) { @@ -1412,7 +1412,7 @@ int write_buff(flash_info_t *info, uchar *src, ulong addr, ulong cnt) FLASH_SHOW_PROGRESS(scale, dots, digit, info->portwidth); /* Only check every once in a while */ if ((cnt & 0xFFFF) < info->portwidth && ctrlc()) - return ERR_ABORTED; + return FL_ERR_ABORTED; } #endif /* CONFIG_SYS_FLASH_USE_BUFFER_WRITE */ diff --git a/include/flash.h b/include/flash.h index 3710a2731b7..77bee42f76b 100644 --- a/include/flash.h +++ b/include/flash.h @@ -125,16 +125,16 @@ void flash_perror(int err); /*----------------------------------------------------------------------- * return codes from flash_write(): */ -#define ERR_OK 0 -#define ERR_TIMEOUT 1 -#define ERR_NOT_ERASED 2 -#define ERR_PROTECTED 4 -#define ERR_INVAL 8 -#define ERR_ALIGN 16 -#define ERR_UNKNOWN_FLASH_VENDOR 32 -#define ERR_UNKNOWN_FLASH_TYPE 64 -#define ERR_PROG_ERROR 128 -#define ERR_ABORTED 256 +#define FL_ERR_OK 0 +#define FL_ERR_TIMEOUT 1 +#define FL_ERR_NOT_ERASED 2 +#define FL_ERR_PROTECTED 4 +#define FL_ERR_INVAL 8 +#define FL_ERR_ALIGN 16 +#define FL_ERR_UNKNOWN_FLASH_VENDOR 32 +#define FL_ERR_UNKNOWN_FLASH_TYPE 64 +#define FL_ERR_PROG_ERROR 128 +#define FL_ERR_ABORTED 256 /*----------------------------------------------------------------------- * Protection Flags for flash_protect(): From patchwork Mon Jun 17 15:32:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804890 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp615146wrr; Mon, 17 Jun 2024 08:43:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUJPQRdyzaRtEqdkcZLe0+6rMvYNPtJ9M289o9AzYs+TuWPJw/5LqmHKZdq4HzvCjxEP1MZAWDQhIOC0labPybl X-Google-Smtp-Source: AGHT+IETyRnfVsCm2hbaQ2FWvPtSRamC80C6+co+xa5Ko1KNgmr6lVUw3QNqKv7RcEgFv5ZcbSJd X-Received: by 2002:a17:907:970b:b0:a59:b590:5d71 with SMTP id a640c23a62f3a-a6f60bc9ac8mr849544966b.0.1718639017697; Mon, 17 Jun 2024 08:43:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718639017; cv=none; d=google.com; s=arc-20160816; b=qogy9ZQIuW/DTSiFkT++8SF0uCI/liNukI9IgKp7+EcCU+kK1muRuFDj5thh/2cEpm xHDnyU+ae3U/By49al52YagqxWp6Kyrb/Qhm3l+62B8d6bSxjHxUuwna5ocabFntjQUb u369ztZGgBvS/MoiwOr5vI8dwV/S7i7rlq4ox25iJOpRU9C4edfppy2FtS7pjt0p90lK 2hUI8eXy7IWow0rYgY5eS2MP5f1MJ0cZSjAz9dwMNtOrI8YaKTIJcjngn1eUFyQ4uwGi lOlTb2CvIbfZfMcjfqetkjgmpMYwHpWkC9BtOAcx7ExaJgFlGIEcsppwbdvgdP8vneJF JriQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gFXRBA9oZwR5Jb5AsDUu83LMTxFQCLzDf/g4Nok7iQ0=; fh=jA5+4xpZqOFRrKv2rsqME7+/gvcgoHEInob+8djA8mg=; b=OXGyHSkkv/mCTQKFaH7xZvUy83Awup/ruJjLdXjKQswPVZRza2UC2jrgVcqHrGitTW tDjD5BFT782T30TIRR49eN1OWh3+11ThjLPkaqqrPXwLXf5juOayvVQ/+EexE0fATf+T N5ZboqyUjXyCebiJTaEPRZRRrSsNBG+GHk8rdgUyQXVb3d4x9cRRYZ2QVXcpCUW595Vi zu37qLwIp+KWWuuIlJRxl00mHTRd4wu/kdbOOungmeQ4Db1ttMR8InV/U0lje6D7uXZA bcSu7hynUElvliUHR6l1hwbHXGdXnKtL2hNgN0cGGLUgkhmyUGkV83tLrw9faS62atQ0 lsOA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aw2TTEX5; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56e7d29dsi440514866b.928.2024.06.17.08.43.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:43:37 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aw2TTEX5; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 203FD882E8; Mon, 17 Jun 2024 17:43:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="aw2TTEX5"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A17D787CDA; Mon, 17 Jun 2024 17:33:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 504E5882D0 for ; Mon, 17 Jun 2024 17:33:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-421eab59723so32692145e9.3 for ; Mon, 17 Jun 2024 08:33:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638412; x=1719243212; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gFXRBA9oZwR5Jb5AsDUu83LMTxFQCLzDf/g4Nok7iQ0=; b=aw2TTEX58TzAxpwQUo7XJuurKeVgra6rERXkavPJrZ1xyF8opqgtar2yDgVLwbXGpq 4q3G4uxUdjrrEMsrWiULv/uxNdDzQ42Ta6Qne+oD9f2S7KF8drezVv46Wq32hSfw+RE2 GkfxPTcR5w+W80+05xBcacrubqHYRvX2jr79sOjEM0evNkPxOh6Be1ODWjvoOJwF8UzO X89AEO5AwFDypDyDg8jDw4bq6e9rhG5KsKwIPzlpuaxbr8GOvfo/gCzPZmgQvVoLx9rz iJimq+l5HFV7im71cwQEl8k8ThAW1xrt+W58TsvJZkiAA+QDP2HpaEmrWT+UziJGr0lH K0PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638412; x=1719243212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gFXRBA9oZwR5Jb5AsDUu83LMTxFQCLzDf/g4Nok7iQ0=; b=B+MvIn1PkXzARqC4TFZnORBx6M5xnQGZueVXDlUa+OGwqxM0bPt0y5dqCmgYEECyEc 4JDsTcEGObJmMW9V9Ghp/zA0031SbcAA6CsJpl2f+arnDEEPkG4J4JLvZORPvww3FnwC Lsfvg/M465hUScLmfJOmvz2gN8jzS3dHglPnK1uajOtWgH8mSmxBVz/I7pamRXZQq/k7 ykxzVM/vxmVGYcYB7Cs9ttFxj7HMoN/3O1aFMulBt2AYQ28Hjmo/syLWvhQqA51H/N0F 5knDQ71oqBbiUoXHimAq69m72bRUmXwY5TmR6ejg+U6VUIUN6oYkGXnDRZX5VwczXNvu vMgg== X-Gm-Message-State: AOJu0YwYEQUvYMfGVFCsoQcsRjw/j06Wc21hz95Oe2ROwOmmLNc9hSmC Rk9F/O+/EBVeRe8fhiud8tetGgu1eqzdvDS6Z96fi9VgjBnb59Iie9PEd4KKfU5PVoaFZtKnQ6N QQbU= X-Received: by 2002:a05:600c:5113:b0:421:2202:1cd1 with SMTP id 5b1f17b1804b1-4230484404dmr76149445e9.25.1718638411833; Mon, 17 Jun 2024 08:33:31 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:31 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Lukasz Majewski , Mattijs Korpershoek , Joe Hershberger , Ramon Fried , Marek Vasut , Simon Glass , Jonas Karlman , Paul Barker , Sean Anderson , Jesse Taube , Greg Malysa , Shengyu Qu , Andrew Davis , Sumit Garg , Bryan Brattlof , "Leon M. Busch-George" , Ying Sun , Heinrich Schuchardt , Joshua Watt , Rasmus Villemoes , Bin Meng , Andre Przywara , Leo Yu-Chi Liang , Mayuresh Chitale , Oleksandr Suvorov , Samuel Holland , Jaehoon Chung , Ashok Reddy Soma , Ion Agorria , Quentin Schulz , Alexey Romanov , Yang Xiwen , Neil Armstrong , Boon Khai Ng , Yanhong Wang , Nicolas Frattaroli , Miquel Raynal , Baruch Siach Subject: [PATCH v4 02/14] net: introduce alternative implementation as net-lwip/ Date: Mon, 17 Jun 2024 17:32:54 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 17 Jun 2024 17:43:34 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Prepare the introduction of the lwIP (lightweight IP) TCP/IP stack by adding a new net-lwip/ directory and the NET_LWIP symbol. Network support is either NO_NET, NET (legacy stack) or NET_LWIP. Subsequent commits will introduce the lwIP code, re-work the NETDEVICE integration and port some of the NET commands and features to lwIP. SPL_NET cannot be enabled when NET_LWIP=y. SPL_NET pulls some symbols that are part of NET (such as arp_init(), arp_timeout_check(), arp_receive(), net_arp_wait_packet_ip()). lwIP support in SPL may be added later. Similarly, DFU_TFTP and FASTBOOT are not compatible with NET_LWIP because of dependencies on net_loop(), tftp_timeout_ms, tftp_timeout_count_max and other NET things. Let's add a dependency on !NET_LWIP for now. As for SANDBOX, NET_LWIP cannot be used either because of strong assumptions on the network stack. Make NET_LWIP depend on !SANDBOX so that the NET_LWIP alternative is not visible in make menuconfig when sandbox_defconfig is used. Signed-off-by: Jerome Forissier --- Kconfig | 41 ++++++++++++++++++++++++++++++++++++++ Makefile | 2 +- common/Kconfig | 2 +- common/spl/Kconfig | 1 + drivers/dfu/Kconfig | 1 + drivers/fastboot/Kconfig | 1 + drivers/net/Kconfig | 1 + drivers/net/phy/Kconfig | 2 +- drivers/usb/gadget/Kconfig | 2 +- net-lwip/Kconfig | 37 ++++++++++++++++++++++++++++++++++ net/Kconfig | 14 ------------- 11 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 net-lwip/Kconfig diff --git a/Kconfig b/Kconfig index 82df59f176e..cfe2a6d3eac 100644 --- a/Kconfig +++ b/Kconfig @@ -745,7 +745,48 @@ source "dts/Kconfig" source "env/Kconfig" +choice + prompt "Networking stack" + default NET + +config NO_NET + bool "No networking support" + +config NET + bool "Legacy U-Boot networking stack" + imply NETDEVICES + +config NET_LWIP + bool "Use lwIP for networking stack" + imply NETDEVICES + depends on !SANDBOX + help + Include networking support based on the lwIP (lightweight IP) + TCP/IP stack (https://nongnu.org/lwip). This is a replacement for + the default U-Boot network stack and applications located in net/ + and enabled via CONFIG_NET as well as other pieces of code that + depend on CONFIG_NET (such as cmd/net.c enabled via CONFIG_CMD_NET). + Therefore the two symbols CONFIG_NET and CONFIG_NET_LWIP are mutually + exclusive. + +endchoice + +if NET source "net/Kconfig" +endif + +if NET_LWIP +source "net-lwip/Kconfig" +endif + +config SYS_RX_ETH_BUFFER + int "Number of receive packet buffers" + default 4 + help + Defines the number of Ethernet receive buffers. On some Ethernet + controllers it is recommended to set this value to 8 or even higher, + since all buffers can be full shortly after enabling the interface on + high Ethernet traffic. source "drivers/Kconfig" diff --git a/Makefile b/Makefile index f8206b2e30a..ceb99a2698e 100644 --- a/Makefile +++ b/Makefile @@ -859,7 +859,7 @@ libs-$(CONFIG_OF_EMBED) += dts/ libs-y += env/ libs-y += lib/ libs-y += fs/ -libs-y += net/ +libs-$(CONFIG_NET) += net/ libs-y += disk/ libs-y += drivers/ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/ diff --git a/common/Kconfig b/common/Kconfig index 5e3070e9253..807b726384d 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -424,7 +424,7 @@ config LOGF_FUNC_PAD config LOG_SYSLOG bool "Log output to syslog server" - depends on NET + depends on NET || NET_LWIP help Enables a log driver which broadcasts log records via UDP port 514 to syslog servers. diff --git a/common/spl/Kconfig b/common/spl/Kconfig index 6405374bcc1..f67f0a859db 100644 --- a/common/spl/Kconfig +++ b/common/spl/Kconfig @@ -1055,6 +1055,7 @@ config SPL_DM_SPI_FLASH config SPL_NET bool "Support networking" + depends on !NET_LWIP help Enable support for network devices (such as Ethernet) in SPL. This permits SPL to load U-Boot over a network link rather than diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig index 0360d9da142..6405a23574e 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -20,6 +20,7 @@ config DFU_WRITE_ALT config DFU_TFTP bool "DFU via TFTP" depends on NETDEVICES + depends on !NET_LWIP select UPDATE_COMMON select DFU_OVER_TFTP help diff --git a/drivers/fastboot/Kconfig b/drivers/fastboot/Kconfig index 70207573de2..1eb460f5a02 100644 --- a/drivers/fastboot/Kconfig +++ b/drivers/fastboot/Kconfig @@ -1,5 +1,6 @@ menu "Fastboot support" depends on CMDLINE + depends on !NET_LWIP config FASTBOOT bool diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index b2d7b499766..efc55e45ca8 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -48,6 +48,7 @@ config DM_DSA bool "Enable Driver Model for DSA switches" depends on DM_MDIO depends on PHY_FIXED + depends on !NET_LWIP help Enable driver model for DSA switches diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 3d96938eaba..738752d29c2 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -11,7 +11,7 @@ config MV88E6352_SWITCH menuconfig PHYLIB bool "Ethernet PHY (physical media interface) support" - depends on NET + depends on NET || NET_LWIP help Enable Ethernet PHY (physical media interface) support. diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 4621a6fd5e6..03fe3bca197 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -224,7 +224,7 @@ endif # USB_GADGET_DOWNLOAD config USB_ETHER bool "USB Ethernet Gadget" - depends on NET + depends on NET || NET_LWIP default y if ARCH_SUNXI && USB_MUSB_GADGET help Creates an Ethernet network device through a USB peripheral diff --git a/net-lwip/Kconfig b/net-lwip/Kconfig new file mode 100644 index 00000000000..a0938964b51 --- /dev/null +++ b/net-lwip/Kconfig @@ -0,0 +1,37 @@ +# +# Network configuration (with lwIP stack) +# + +config LWIP_DEBUG + bool "Enable debug traces in the lwIP library" + +config LWIP_ASSERT + bool "Enable assertions in the lwIP library" + +config PROT_DHCP_LWIP + bool "DHCP support in lwIP" + depends on PROT_UDP_LWIP + help + Enable support for the DHCP protocol in lwIP. + +config PROT_DNS_LWIP + bool + depends on PROT_UDP_LWIP + +config PROT_RAW_LWIP + bool + +config PROT_TCP_LWIP + bool + +config PROT_UDP_LWIP + bool + +config BOOTDEV_ETH + bool "Enable bootdev for ethernet" + depends on BOOTSTD + default y + help + Provide a bootdev for ethernet so that is it possible to boot + an operating system over the network, using the PXE (Preboot + Execution Environment) protocol. diff --git a/net/Kconfig b/net/Kconfig index 5dff6336293..4929428d2a5 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -2,11 +2,6 @@ # Network configuration # -menuconfig NET - bool "Networking support" - default y - imply NETDEVICES - if NET config ARP_TIMEOUT @@ -254,12 +249,3 @@ config IPV6 address and find it, it will force using IPv6 in the network stack. endif # if NET - -config SYS_RX_ETH_BUFFER - int "Number of receive packet buffers" - default 4 - help - Defines the number of Ethernet receive buffers. On some Ethernet - controllers it is recommended to set this value to 8 or even higher, - since all buffers can be full shortly after enabling the interface on - high Ethernet traffic. From patchwork Mon Jun 17 15:32:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804878 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611160wrr; Mon, 17 Jun 2024 08:33:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW5euKa0gpTBPgiEB1lPlKBsr3nBBjVceeZftIyivJuDOeMJwYNT/3MtHajW77sYTLRFHr73Wgf4991P04V2Vjp X-Google-Smtp-Source: AGHT+IEOO7kFLPyF/34WlUUS9nirVqVS8Ei8Lyy5vJnDrVHvStV9SdmjcB+C/CP0M81FK3YymD82 X-Received: by 2002:a17:907:874e:b0:a6f:6659:a53 with SMTP id a640c23a62f3a-a6f66590d74mr636894866b.6.1718638438289; Mon, 17 Jun 2024 08:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638438; cv=none; d=google.com; s=arc-20160816; b=mxkFP36/mAHOy7i9I4V59GhO/QTxZfnJqolFRx5Q8o9wzaaTlkQh7VU01pTBml8bDV YICSF3wO0fJv/NF2Ef153qgE8gMLAUeNyDgWK0HsTWSLk0jhyPLaO+Aa0YA1hQ1UpSri lHWtUy0Jja8/8DFb4cZO4q5/TfdDjtMWiRzin32LcAnIYgs58fr4Ea0ff2D/VEwGun/Y n6nR6dl0nfVyxCtNBFgEWtyT86wMRIsmvooxksQCsmYyOEQdyLvappDBacFls3xeVRl9 IKiK8Bvd7xiQMk5gg6hfhtgBBYONQHRLtSc8TCmwxRsUrrt8D3AD8ht6dIuqwcrfNg+G 6UmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gMMRcBGL12T0AH8Kpdsbn8ZMkctkt8UorPUFiE0AQGw=; fh=ckm8Wo1T/zcD3NtaWFnydWgRCyWa3jUVPabaFdUDSJ4=; b=WKwtQY+7bCPlRPyQnuFbl430BCV/JldjO1bhB+052uCjJCUJhRTJvU65w4R8n9IS50 shIwP8jFrUsh239zHcOTcIg1rHPTNwK1uBIvAP4XjHIWZ/MhxTBN+48ZBdRnjwxiN1fg 0SSN3Dep0vtlMcuUbuZaAPdUViddLiV8qALSoCEOD3xuoqfp8BYb1sps/bO8gQmhA1my didi3LA5efzjTySjtlUvlPt/l8jKOf6jiZyGFW5RobmQLWHGT5SSkpAdU6KcqP3tWc6U MGY6oKoHFBbrB4p8FcZVXpAuyolM+dYvrxJpMYfSBAzJs6AjxG39g/60FVA/uVYRrA2s 1wGw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QLocvMWR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56dd69aesi458686766b.458.2024.06.17.08.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:58 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QLocvMWR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E6DBE882E6; Mon, 17 Jun 2024 17:33:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="QLocvMWR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CDAA9882FA; Mon, 17 Jun 2024 17:33:39 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1ACB5882D0 for ; Mon, 17 Jun 2024 17:33:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4218314a6c7so37596075e9.0 for ; Mon, 17 Jun 2024 08:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638415; x=1719243215; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gMMRcBGL12T0AH8Kpdsbn8ZMkctkt8UorPUFiE0AQGw=; b=QLocvMWRDosptw1UzOlNZG74UtU6odl/FYxkZFiXkZkzbW9Ymss+o3qXOiGEbF9klA gN9XHjKVKbQwsBTD2DQgIZbIXzqKwL6GVW1CrgWk3/1z1Ck7QlI0zGhHYkBYWD8rsl9i Smjd4kn8hzwhnpUIeE0bzpl5Rj2JQLbagoS9ZmAmu2VAc6jGZgLmuBqYeFlqxUJ0Dkfj oj224n1vb/Q8zDe3eUiKAKWLOfp0fO23GFEEJJL/437ulbwS7g+jgMGJGDJxAN3y5g6w Na9YSu/eHxQA7t2FiYtVg0KtChXTXVDrY12ZuSJdxEEBXoi+I4WQnjveqO3cMPeJsiMo vr1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638415; x=1719243215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gMMRcBGL12T0AH8Kpdsbn8ZMkctkt8UorPUFiE0AQGw=; b=jfcgbP5Jqvyb4MxNA/5G+HXPEqLhvHdJWKHsOXnBA/aTmlow1V2wm36/1HetS6snFN vR2o+ON+zTy4EFCdoZ2rBEVKBmLJMXyeE6ex7feZnNw7vq05xleM9CUjoep3yn9MQM1/ /ZZY20q6ZVdoUmwAavsAArrJN9El9ffMSal+iPbS7v59dL+MxjrVpl/rh1kkgCxWW6Zx j/OW2BSrxU0TeOg3Eau+2XxBZ0OLPQxAA4EqGG5iXcbnUAvsEuQLTZQgM3JSkck+VZrz z7OgmFFLmw1fBWHxUcnoFWi5aZIKqTNyeocTolHOiP3R9ncYKQFbYw1sPRmm7xWD6NFF pLDg== X-Gm-Message-State: AOJu0YxwOVEdhe/fMXcpRCegF9kjw/moq4H+LC0rWFJqFjc16706Tqv0 3U+UUa5yjSMmP4k2Cp+Ynm0A87vPD2lUTLOdy8VieAT3VMZiwpcmuwfu5rSvyXF8KTnTuSupnkf jtI0= X-Received: by 2002:a05:600c:1d07:b0:422:1def:e17f with SMTP id 5b1f17b1804b1-4230484faf0mr88061405e9.31.1718638414300; Mon, 17 Jun 2024 08:33:34 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:33 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Joe Hershberger , Ramon Fried , Simon Glass , Sumit Garg , Heinrich Schuchardt , Andrew Davis , Marek Vasut , Bryan Brattlof , Jesse Taube , "Leon M. Busch-George" , Masahisa Kojima , Sean Anderson Subject: [PATCH v4 03/14] net: split include/net.h into net{, -common, -legacy, -lwip}.h Date: Mon, 17 Jun 2024 17:32:55 +0200 Message-Id: <6f71559d95e185f6867ed4967125a32d9e5cd07f.1718638104.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Make net.h a wrapper which includes net-common.h and either net-legacy.h or net-lwip.h based on NET_LWIP. Signed-off-by: Jerome Forissier --- Makefile | 4 +- include/net-common.h | 408 +++++++++++++++++++ include/net-legacy.h | 649 +++++++++++++++++++++++++++++ include/net-lwip.h | 14 + include/net.h | 944 +------------------------------------------ 5 files changed, 1078 insertions(+), 941 deletions(-) create mode 100644 include/net-common.h create mode 100644 include/net-legacy.h create mode 100644 include/net-lwip.h diff --git a/Makefile b/Makefile index ceb99a2698e..0fe1623c550 100644 --- a/Makefile +++ b/Makefile @@ -836,7 +836,9 @@ UBOOTINCLUDE := \ -I$(srctree)/arch/arm/thumb1/include)) \ -I$(srctree)/arch/$(ARCH)/include \ -include $(srctree)/include/linux/kconfig.h \ - -I$(srctree)/dts/upstream/include + -I$(srctree)/dts/upstream/include \ + $(if $(CONFIG_NET_LWIP), -I$(srctree)/lib/lwip/lwip/src/include \ + -I$(srctree)/lib/lwip/u-boot) NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) diff --git a/include/net-common.h b/include/net-common.h new file mode 100644 index 00000000000..77bdf17c6cd --- /dev/null +++ b/include/net-common.h @@ -0,0 +1,408 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __NET_COMMON_H__ +#define __NET_COMMON_H__ + +#include +#include +#include +#include +#include +#include +#include + +#define DEBUG_NET_PKT_TRACE 0 /* Trace all packet data */ + +/* + * The number of receive packet buffers, and the required packet buffer + * alignment in memory. + * + */ +#define PKTBUFSRX CONFIG_SYS_RX_ETH_BUFFER +#define PKTALIGN ARCH_DMA_MINALIGN + +/* IPv4 addresses are always 32 bits in size */ +struct in_addr { + __be32 s_addr; +}; + +#define PROT_IP 0x0800 /* IP protocol */ +#define PROT_ARP 0x0806 /* IP ARP protocol */ +#define PROT_WOL 0x0842 /* ether-wake WoL protocol */ +#define PROT_RARP 0x8035 /* IP ARP protocol */ +#define PROT_VLAN 0x8100 /* IEEE 802.1q protocol */ +#define PROT_IPV6 0x86dd /* IPv6 over bluebook */ +#define PROT_PPP_SES 0x8864 /* PPPoE session messages */ +#define PROT_NCSI 0x88f8 /* NC-SI control packets */ + +#define IPPROTO_ICMP 1 /* Internet Control Message Protocol */ +#define IPPROTO_TCP 6 /* Transmission Control Protocol */ +#define IPPROTO_UDP 17 /* User Datagram Protocol */ + +#define IP_OFFS 0x1fff /* ip offset *= 8 */ +#define IP_FLAGS 0xe000 /* first 3 bits */ +#define IP_FLAGS_RES 0x8000 /* reserved */ +#define IP_FLAGS_DFRAG 0x4000 /* don't fragments */ +#define IP_FLAGS_MFRAG 0x2000 /* more fragments */ + +#define IP_HDR_SIZE (sizeof(struct ip_hdr)) + +#define IP_MIN_FRAG_DATAGRAM_SIZE (IP_HDR_SIZE + 8) + + +/* + * Internet Protocol (IP) + UDP header. + */ +struct ip_udp_hdr { + u8 ip_hl_v; /* header length and version */ + u8 ip_tos; /* type of service */ + u16 ip_len; /* total length */ + u16 ip_id; /* identification */ + u16 ip_off; /* fragment offset field */ + u8 ip_ttl; /* time to live */ + u8 ip_p; /* protocol */ + u16 ip_sum; /* checksum */ + struct in_addr ip_src; /* Source IP address */ + struct in_addr ip_dst; /* Destination IP address */ + u16 udp_src; /* UDP source port */ + u16 udp_dst; /* UDP destination port */ + u16 udp_len; /* Length of UDP packet */ + u16 udp_xsum; /* Checksum */ +} __attribute__((packed)); + +#define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr)) +#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE) + +/* Number of packets processed together */ +#define ETH_PACKETS_BATCH_RECV 32 + +/* ARP hardware address length */ +#define ARP_HLEN 6 +/* + * The size of a MAC address in string form, each digit requires two chars + * and five separator characters to form '00:00:00:00:00:00'. + */ +#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1) + +# define ARP_ETHER 1 /* Ethernet hardware address */ + +/* + * Maximum packet size; used to allocate packet storage. Use + * the maxium Ethernet frame size as specified by the Ethernet + * standard including the 802.1Q tag (VLAN tagging). + * maximum packet size = 1522 + * maximum packet size and multiple of 32 bytes = 1536 + */ +#define PKTSIZE 1522 +#ifndef CONFIG_DM_DSA +#define PKTSIZE_ALIGN 1536 +#else +/* Maximum DSA tagging overhead (headroom and/or tailroom) */ +#define DSA_MAX_OVR 256 +#define PKTSIZE_ALIGN (1536 + DSA_MAX_OVR) +#endif + +extern int net_restart_wrap; /* Tried all network devices */ +extern uchar *net_rx_packets[PKTBUFSRX]; /* Receive packets */ + +struct udevice *eth_get_dev(void); /* get the current device */ + +/* + * The devname can be either an exact name given by the driver or device tree + * or it can be an alias of the form "eth%d" + */ +struct udevice *eth_get_dev_by_name(const char *devname); + +/* + * Get the hardware address for an ethernet interface . + * Args: + * base_name - base name for device (normally "eth") + * index - device index number (0 for first) + * enetaddr - returns 6 byte hardware address + * Returns: + * Return true if the address is valid. + */ +int eth_env_get_enetaddr_by_index(const char *base_name, int index, + uchar *enetaddr); + +/** + * eth_env_set_enetaddr_by_index() - set the MAC address environment variable + * + * This sets up an environment variable with the given MAC address (@enetaddr). + * The environment variable to be set is defined by <@base_name><@index>addr. + * If @index is 0 it is omitted. For common Ethernet this means ethaddr, + * eth1addr, etc. + * + * @base_name: Base name for variable, typically "eth" + * @index: Index of interface being updated (>=0) + * @enetaddr: Pointer to MAC address to put into the variable + * Return: 0 if OK, other value on error + */ +int eth_env_set_enetaddr_by_index(const char *base_name, int index, + uchar *enetaddr); + +int eth_init(void); /* Initialize the device */ +int eth_send(void *packet, int length); /* Send a packet */ +#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) +int eth_receive(void *packet, int length); /* Receive a packet*/ +extern void (*push_packet)(void *packet, int length); +#endif +int eth_rx(void); /* Check for received packets */ + +static inline void net_send_packet(uchar *pkt, int len) +{ + if (DEBUG_NET_PKT_TRACE) + print_hex_dump_bytes("tx: ", DUMP_PREFIX_OFFSET, pkt, len); + /* Currently no way to return errors from eth_send() */ + (void) eth_send(pkt, len); +} + +enum eth_recv_flags { + /* + * Check hardware device for new packets (otherwise only return those + * which are already in the memory buffer ready to process) + */ + ETH_RECV_CHECK_DEVICE = 1 << 0, +}; + +/** + * struct eth_ops - functions of Ethernet MAC controllers + * + * start: Prepare the hardware to send and receive packets + * send: Send the bytes passed in "packet" as a packet on the wire + * recv: Check if the hardware received a packet. If so, set the pointer to the + * packet buffer in the packetp parameter. If not, return an error or 0 to + * indicate that the hardware receive FIFO is empty. If 0 is returned, the + * network stack will not process the empty packet, but free_pkt() will be + * called if supplied + * free_pkt: Give the driver an opportunity to manage its packet buffer memory + * when the network stack is finished processing it. This will only be + * called when no error was returned from recv - optional + * stop: Stop the hardware from looking for packets - may be called even if + * state == PASSIVE + * mcast: Join or leave a multicast group (for TFTP) - optional + * write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux + * on some platforms like ARM). This function expects the + * eth_pdata::enetaddr field to be populated. The method can + * return -ENOSYS to indicate that this is not implemented for + this hardware - optional. + * read_rom_hwaddr: Some devices have a backup of the MAC address stored in a + * ROM on the board. This is how the driver should expose it + * to the network stack. This function should fill in the + * eth_pdata::enetaddr field - optional + * set_promisc: Enable or Disable promiscuous mode + * get_sset_count: Number of statistics counters + * get_string: Names of the statistic counters + * get_stats: The values of the statistic counters + */ +struct eth_ops { + int (*start)(struct udevice *dev); + int (*send)(struct udevice *dev, void *packet, int length); + int (*recv)(struct udevice *dev, int flags, uchar **packetp); + int (*free_pkt)(struct udevice *dev, uchar *packet, int length); + void (*stop)(struct udevice *dev); + int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join); + int (*write_hwaddr)(struct udevice *dev); + int (*read_rom_hwaddr)(struct udevice *dev); + int (*set_promisc)(struct udevice *dev, bool enable); + int (*get_sset_count)(struct udevice *dev); + void (*get_strings)(struct udevice *dev, u8 *data); + void (*get_stats)(struct udevice *dev, u64 *data); +}; + +#define eth_get_ops(dev) ((struct eth_ops *)(dev)->driver->ops) + +struct udevice *eth_get_dev(void); /* get the current device */ +unsigned char *eth_get_ethaddr(void); /* get the current device MAC */ +int eth_get_dev_index(void); +int eth_rx(void); /* Check for received packets */ +void eth_halt(void); /* stop SCC */ +const char *eth_get_name(void); +int eth_get_dev_index(void); +int eth_init_state_only(void); /* Set active state */ + +int eth_initialize(void); /* Initialize network subsystem */ +void eth_try_another(int first_restart); /* Change the device */ +void eth_set_current(void); /* set nterface to ethcur var */ + +enum eth_state_t { + ETH_STATE_INIT, + ETH_STATE_PASSIVE, + ETH_STATE_ACTIVE +}; + +/** + * struct eth_pdata - Platform data for Ethernet MAC controllers + * + * @iobase: The base address of the hardware registers + * @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env + * @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_... + * @max_speed: Maximum speed of Ethernet connection supported by MAC + * @priv_pdata: device specific plat + */ +struct eth_pdata { + phys_addr_t iobase; + unsigned char enetaddr[ARP_HLEN]; + int phy_interface; + int max_speed; + void *priv_pdata; +}; + +struct ethernet_hdr { + u8 et_dest[ARP_HLEN]; /* Destination node */ + u8 et_src[ARP_HLEN]; /* Source node */ + u16 et_protlen; /* Protocol or length */ +} __attribute__((packed)); + +/* Ethernet header size */ +#define ETHER_HDR_SIZE (sizeof(struct ethernet_hdr)) + +/** + * is_zero_ethaddr - Determine if give Ethernet address is all zeros. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is all zeroes. + */ +static inline int is_zero_ethaddr(const u8 *addr) +{ + return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); +} + +/** + * is_multicast_ethaddr - Determine if the Ethernet address is a multicast. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is a multicast address. + * By definition the broadcast address is also a multicast address. + */ +static inline int is_multicast_ethaddr(const u8 *addr) +{ + return 0x01 & addr[0]; +} + +/* + * is_broadcast_ethaddr - Determine if the Ethernet address is broadcast + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is the broadcast address. + */ +static inline int is_broadcast_ethaddr(const u8 *addr) +{ + return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == + 0xff; +} + +/* + * is_valid_ethaddr - Determine if the given Ethernet address is valid + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not + * a multicast address, and is not FF:FF:FF:FF:FF:FF. + * + * Return true if the address is valid. + */ +static inline int is_valid_ethaddr(const u8 *addr) +{ + /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to + * explicitly check for it here. */ + return !is_multicast_ethaddr(addr) && !is_zero_ethaddr(addr); +} + +/** + * string_to_enetaddr() - Parse a MAC address + * + * Convert a string MAC address + * + * Implemented in lib/net_utils.c (built unconditionally) + * + * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit + * hex value + * @enetaddr: Place to put MAC address (6 bytes) + */ +void string_to_enetaddr(const char *addr, uint8_t *enetaddr); + +/** + * string_to_ip() - Convert a string to ip address + * + * Implemented in lib/net_utils.c (built unconditionally) + * + * @s: Input string to parse + * @return: in_addr struct containing the parsed IP address + */ +struct in_addr string_to_ip(const char *s); + +/* Processes a received packet */ +void net_process_received_packet(uchar *in_packet, int len); + +/** + * update_tftp - Update firmware over TFTP (via DFU) + * + * This function updates board's firmware via TFTP + * + * @param addr - memory address where data is stored + * @param interface - the DFU medium name - e.g. "mmc" + * @param devstring - the DFU medium number - e.g. "1" + * + * Return: - 0 on success, other value on failure + */ +int update_tftp(ulong addr, char *interface, char *devstring); + +/** + * env_get_ip() - Convert an environment value to to an ip address + * + * @var: Environment variable to convert. The value of this variable must be + * in the format format a.b.c.d, where each value is a decimal number from + * 0 to 255 + * Return: IP address, or 0 if invalid + */ +static inline struct in_addr env_get_ip(char *var) +{ + return string_to_ip(env_get(var)); +} + +int net_init(void); + +/** + * dhcp_run() - Run DHCP on the current ethernet device + * + * This sets the autoload variable, then puts it back to similar to its original + * state (y, n or unset). + * + * @addr: Address to load the file into (0 if @autoload is false) + * @fname: Filename of file to load (NULL if @autoload is false or to use the + * default filename) + * @autoload: true to load the file, false to just get the network IP + * @return 0 if OK, -EINVAL if the environment failed, -ENOENT if ant file was + * not found + */ +int dhcp_run(ulong addr, const char *fname, bool autoload); + +/** + * do_tftpb - Run the tftpboot command + * + * @cmdtp: Command information for tftpboot + * @flag: Command flags (CMD_FLAG_...) + * @argc: Number of arguments + * @argv: List of arguments + * Return: result (see enum command_ret_t) + */ +int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); + +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ +int wget_with_dns(ulong dst_addr, char *uri); +/** + * wget_validate_uri() - varidate the uri + * + * @uri: uri string of target file of wget + * Return: true if uri is valid, false if uri is invalid + */ +bool wget_validate_uri(char *uri); +//int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); + +#endif /* __NET_COMMON_H__ */ diff --git a/include/net-legacy.h b/include/net-legacy.h new file mode 100644 index 00000000000..0c0c873005a --- /dev/null +++ b/include/net-legacy.h @@ -0,0 +1,649 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * LiMon Monitor (LiMon) - Network. + * + * Copyright 1994 - 2000 Neil Russell. + * (See License) + * + * History + * 9/16/00 bor adapted to TQM823L/STK8xxL board, RARP/TFTP boot added + */ + +#ifndef __NET_LEGACY_H__ +#define __NET_LEGACY_H__ + +#include +#include /* for nton* / ntoh* stuff */ +#include +#include +#include +#include + +struct bd_info; +struct cmd_tbl; +struct udevice; + +#define DEBUG_LL_STATE 0 /* Link local state machine changes */ +#define DEBUG_DEV_PKT 0 /* Packets or info directed to the device */ +#define DEBUG_NET_PKT 0 /* Packets on info on the network at large */ +#define DEBUG_INT_STATE 0 /* Internal network state changes */ + +/* Number of packets processed together */ +#define ETH_PACKETS_BATCH_RECV 32 + +/* ARP hardware address length */ +#define ARP_HLEN 6 +/* + * The size of a MAC address in string form, each digit requires two chars + * and five separator characters to form '00:00:00:00:00:00'. + */ +#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1) + +/** + * An incoming packet handler. + * @param pkt pointer to the application packet + * @param dport destination UDP port + * @param sip source IP address + * @param sport source UDP port + * @param len packet length + */ +typedef void rxhand_f(uchar *pkt, unsigned dport, + struct in_addr sip, unsigned sport, + unsigned len); + +/** + * An incoming ICMP packet handler. + * @param type ICMP type + * @param code ICMP code + * @param dport destination UDP port + * @param sip source IP address + * @param sport source UDP port + * @param pkt pointer to the ICMP packet data + * @param len packet length + */ +typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport, + struct in_addr sip, unsigned sport, uchar *pkt, unsigned len); + +/* + * A timeout handler. Called after time interval has expired. + */ +typedef void thand_f(void); + +/* + * The devname can be either an exact name given by the driver or device tree + * or it can be an alias of the form "eth%d" + */ +struct udevice *eth_get_dev_by_name(const char *devname); +/* Used only when NetConsole is enabled */ +int eth_is_active(struct udevice *dev); /* Test device for active state */ +void eth_halt_state_only(void); /* Set passive state */ + + +/** + * eth_env_set_enetaddr_by_index() - set the MAC address environment variable + * + * This sets up an environment variable with the given MAC address (@enetaddr). + * The environment variable to be set is defined by <@base_name><@index>addr. + * If @index is 0 it is omitted. For common Ethernet this means ethaddr, + * eth1addr, etc. + * + * @base_name: Base name for variable, typically "eth" + * @index: Index of interface being updated (>=0) + * @enetaddr: Pointer to MAC address to put into the variable + * Return: 0 if OK, other value on error + */ +int eth_env_set_enetaddr_by_index(const char *base_name, int index, + uchar *enetaddr); + + +/* + * Initialize USB ethernet device with CONFIG_DM_ETH + * Returns: + * 0 is success, non-zero is error status. + */ +int usb_ether_init(void); + +/* + * Get the hardware address for an ethernet interface . + * Args: + * base_name - base name for device (normally "eth") + * index - device index number (0 for first) + * enetaddr - returns 6 byte hardware address + * Returns: + * Return true if the address is valid. + */ +int eth_env_get_enetaddr_by_index(const char *base_name, int index, + uchar *enetaddr); + +int eth_init(void); /* Initialize the device */ +int eth_send(void *packet, int length); /* Send a packet */ + +#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) +int eth_receive(void *packet, int length); /* Receive a packet*/ +extern void (*push_packet)(void *packet, int length); +#endif +void eth_halt(void); /* stop SCC */ +const char *eth_get_name(void); /* get name of current device */ +int eth_mcast_join(struct in_addr mcast_addr, int join); + +/**********************************************************************/ +/* + * Protocol headers. + */ + +#define ETH_FCS_LEN 4 /* Octets in the FCS */ + +struct e802_hdr { + u8 et_dest[ARP_HLEN]; /* Destination node */ + u8 et_src[ARP_HLEN]; /* Source node */ + u16 et_protlen; /* Protocol or length */ + u8 et_dsap; /* 802 DSAP */ + u8 et_ssap; /* 802 SSAP */ + u8 et_ctl; /* 802 control */ + u8 et_snap1; /* SNAP */ + u8 et_snap2; + u8 et_snap3; + u16 et_prot; /* 802 protocol */ +} __attribute__((packed)); + +/* 802 + SNAP + ethernet header size */ +#define E802_HDR_SIZE (sizeof(struct e802_hdr)) + +/* + * Virtual LAN Ethernet header + */ +struct vlan_ethernet_hdr { + u8 vet_dest[ARP_HLEN]; /* Destination node */ + u8 vet_src[ARP_HLEN]; /* Source node */ + u16 vet_vlan_type; /* PROT_VLAN */ + u16 vet_tag; /* TAG of VLAN */ + u16 vet_type; /* protocol type */ +} __attribute__((packed)); + +/* VLAN Ethernet header size */ +#define VLAN_ETHER_HDR_SIZE (sizeof(struct vlan_ethernet_hdr)) + +/* + * Internet Protocol (IP) header. + */ +struct ip_hdr { + u8 ip_hl_v; /* header length and version */ + u8 ip_tos; /* type of service */ + u16 ip_len; /* total length */ + u16 ip_id; /* identification */ + u16 ip_off; /* fragment offset field */ + u8 ip_ttl; /* time to live */ + u8 ip_p; /* protocol */ + u16 ip_sum; /* checksum */ + struct in_addr ip_src; /* Source IP address */ + struct in_addr ip_dst; /* Destination IP address */ +} __attribute__((packed)); + +#define IP_OFFS 0x1fff /* ip offset *= 8 */ +#define IP_FLAGS 0xe000 /* first 3 bits */ +#define IP_FLAGS_RES 0x8000 /* reserved */ +#define IP_FLAGS_DFRAG 0x4000 /* don't fragments */ +#define IP_FLAGS_MFRAG 0x2000 /* more fragments */ + +#define IP_HDR_SIZE (sizeof(struct ip_hdr)) + +#define IP_MIN_FRAG_DATAGRAM_SIZE (IP_HDR_SIZE + 8) + +/* + * Address Resolution Protocol (ARP) header. + */ +struct arp_hdr { + u16 ar_hrd; /* Format of hardware address */ +# define ARP_ETHER 1 /* Ethernet hardware address */ + u16 ar_pro; /* Format of protocol address */ + u8 ar_hln; /* Length of hardware address */ + u8 ar_pln; /* Length of protocol address */ +# define ARP_PLEN 4 + u16 ar_op; /* Operation */ +# define ARPOP_REQUEST 1 /* Request to resolve address */ +# define ARPOP_REPLY 2 /* Response to previous request */ + +# define RARPOP_REQUEST 3 /* Request to resolve address */ +# define RARPOP_REPLY 4 /* Response to previous request */ + + /* + * The remaining fields are variable in size, according to + * the sizes above, and are defined as appropriate for + * specific hardware/protocol combinations. + */ + u8 ar_data[0]; +#define ar_sha ar_data[0] +#define ar_spa ar_data[ARP_HLEN] +#define ar_tha ar_data[ARP_HLEN + ARP_PLEN] +#define ar_tpa ar_data[ARP_HLEN + ARP_PLEN + ARP_HLEN] +#if 0 + u8 ar_sha[]; /* Sender hardware address */ + u8 ar_spa[]; /* Sender protocol address */ + u8 ar_tha[]; /* Target hardware address */ + u8 ar_tpa[]; /* Target protocol address */ +#endif /* 0 */ +} __attribute__((packed)); + +#define ARP_HDR_SIZE (8+20) /* Size assuming ethernet */ + +/* + * ICMP stuff (just enough to handle (host) redirect messages) + */ +#define ICMP_ECHO_REPLY 0 /* Echo reply */ +#define ICMP_NOT_REACH 3 /* Detination unreachable */ +#define ICMP_REDIRECT 5 /* Redirect (change route) */ +#define ICMP_ECHO_REQUEST 8 /* Echo request */ + +/* Codes for REDIRECT. */ +#define ICMP_REDIR_NET 0 /* Redirect Net */ +#define ICMP_REDIR_HOST 1 /* Redirect Host */ + +/* Codes for NOT_REACH */ +#define ICMP_NOT_REACH_PORT 3 /* Port unreachable */ + +struct icmp_hdr { + u8 type; + u8 code; + u16 checksum; + union { + struct { + u16 id; + u16 sequence; + } echo; + u32 gateway; + struct { + u16 unused; + u16 mtu; + } frag; + u8 data[0]; + } un; +} __attribute__((packed)); + +#define ICMP_HDR_SIZE (sizeof(struct icmp_hdr)) +#define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE) + +/* + * Maximum packet size; used to allocate packet storage. Use + * the maxium Ethernet frame size as specified by the Ethernet + * standard including the 802.1Q tag (VLAN tagging). + * maximum packet size = 1522 + * maximum packet size and multiple of 32 bytes = 1536 + */ +#define PKTSIZE 1522 +#ifndef CONFIG_DM_DSA +#define PKTSIZE_ALIGN 1536 +#else +/* Maximum DSA tagging overhead (headroom and/or tailroom) */ +#define DSA_MAX_OVR 256 +#define PKTSIZE_ALIGN (1536 + DSA_MAX_OVR) +#endif + +/* + * Maximum receive ring size; that is, the number of packets + * we can buffer before overflow happens. Basically, this just + * needs to be enough to prevent a packet being discarded while + * we are processing the previous one. + */ +#define RINGSZ 4 +#define RINGSZ_LOG2 2 + +/**********************************************************************/ +/* + * Globals. + * + * Note: + * + * All variables of type struct in_addr are stored in NETWORK byte order + * (big endian). + */ + +/* net.c */ +/** BOOTP EXTENTIONS **/ +extern struct in_addr net_gateway; /* Our gateway IP address */ +extern struct in_addr net_netmask; /* Our subnet mask (0 = unknown) */ +/* Our Domain Name Server (0 = unknown) */ +extern struct in_addr net_dns_server; +#if defined(CONFIG_BOOTP_DNS2) +/* Our 2nd Domain Name Server (0 = unknown) */ +extern struct in_addr net_dns_server2; +#endif +extern char net_nis_domain[32]; /* Our IS domain */ +extern char net_hostname[32]; /* Our hostname */ +#ifdef CONFIG_NET +extern char net_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN]; /* Our root path */ +#endif +/* Indicates whether the pxe path prefix / config file was specified in dhcp option */ +extern char *pxelinux_configfile; +/** END OF BOOTP EXTENTIONS **/ +extern u8 net_ethaddr[ARP_HLEN]; /* Our ethernet address */ +extern u8 net_server_ethaddr[ARP_HLEN]; /* Boot server enet address */ +extern struct in_addr net_ip; /* Our IP addr (0 = unknown) */ +extern struct in_addr net_server_ip; /* Server IP addr (0 = unknown) */ +extern uchar *net_tx_packet; /* THE transmit packet */ +extern uchar *net_rx_packets[PKTBUFSRX]; /* Receive packets */ +extern uchar *net_rx_packet; /* Current receive packet */ +extern int net_rx_packet_len; /* Current rx packet length */ +extern const u8 net_bcast_ethaddr[ARP_HLEN]; /* Ethernet broadcast address */ +extern const u8 net_null_ethaddr[ARP_HLEN]; + +#define VLAN_NONE 4095 /* untagged */ +#define VLAN_IDMASK 0x0fff /* mask of valid vlan id */ +extern ushort net_our_vlan; /* Our VLAN */ +extern ushort net_native_vlan; /* Our Native VLAN */ + +extern int net_restart_wrap; /* Tried all network devices */ + +enum proto_t { + BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS, NFS, CDP, + NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT_UDP, FASTBOOT_TCP, + WOL, UDP, NCSI, WGET, RS +}; + +extern char net_boot_file_name[1024];/* Boot File name */ +/* Indicates whether the file name was specified on the command line */ +extern bool net_boot_file_name_explicit; +/* The actual transferred size of the bootfile (in bytes) */ +extern u32 net_boot_file_size; +/* Boot file size in blocks as reported by the DHCP server */ +extern u32 net_boot_file_expected_size_in_blocks; + +#if defined(CONFIG_CMD_DNS) +extern char *net_dns_resolve; /* The host to resolve */ +extern char *net_dns_env_var; /* the env var to put the ip into */ +#endif + +#if defined(CONFIG_CMD_PING) +extern struct in_addr net_ping_ip; /* the ip address to ping */ +#endif + +#if defined(CONFIG_CMD_CDP) +/* when CDP completes these hold the return values */ +extern ushort cdp_native_vlan; /* CDP returned native VLAN */ +extern ushort cdp_appliance_vlan; /* CDP returned appliance VLAN */ + +/* + * Check for a CDP packet by examining the received MAC address field + */ +static inline int is_cdp_packet(const uchar *ethaddr) +{ + extern const u8 net_cdp_ethaddr[ARP_HLEN]; + + return memcmp(ethaddr, net_cdp_ethaddr, ARP_HLEN) == 0; +} +#endif + +#if defined(CONFIG_CMD_SNTP) +extern struct in_addr net_ntp_server; /* the ip address to NTP */ +extern int net_ntp_time_offset; /* offset time from UTC */ +#endif + +int net_loop(enum proto_t); + +/* Load failed. Start again. */ +int net_start_again(void); + +/* Get size of the ethernet header when we send */ +int net_eth_hdr_size(void); + +/* Set ethernet header; returns the size of the header */ +int net_set_ether(uchar *xet, const uchar *dest_ethaddr, uint prot); +int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot); + +/* Set IP header */ +void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source, + u16 pkt_len, u8 proto); +void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, + int sport, int len); + +/** + * compute_ip_checksum() - Compute IP checksum + * + * @addr: Address to check (must be 16-bit aligned) + * @nbytes: Number of bytes to check (normally a multiple of 2) + * Return: 16-bit IP checksum + */ +unsigned compute_ip_checksum(const void *addr, unsigned nbytes); + +/** + * add_ip_checksums() - add two IP checksums + * + * @offset: Offset of first sum (if odd we do a byte-swap) + * @sum: First checksum + * @new_sum: New checksum to add + * Return: updated 16-bit IP checksum + */ +unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned new_sum); + +/** + * ip_checksum_ok() - check if a checksum is correct + * + * This works by making sure the checksum sums to 0 + * + * @addr: Address to check (must be 16-bit aligned) + * @nbytes: Number of bytes to check (normally a multiple of 2) + * Return: true if the checksum matches, false if not + */ +int ip_checksum_ok(const void *addr, unsigned nbytes); + +/* Callbacks */ +rxhand_f *net_get_udp_handler(void); /* Get UDP RX packet handler */ +void net_set_udp_handler(rxhand_f *); /* Set UDP RX packet handler */ +rxhand_f *net_get_arp_handler(void); /* Get ARP RX packet handler */ +void net_set_arp_handler(rxhand_f *); /* Set ARP RX packet handler */ +bool arp_is_waiting(void); /* Waiting for ARP reply? */ +void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */ +void net_set_timeout_handler(ulong, thand_f *);/* Set timeout handler */ + +/* Network loop state */ +enum net_loop_state { + NETLOOP_CONTINUE, + NETLOOP_RESTART, + NETLOOP_SUCCESS, + NETLOOP_FAIL +}; +extern enum net_loop_state net_state; + +static inline void net_set_state(enum net_loop_state state) +{ + debug_cond(DEBUG_INT_STATE, "--- NetState set to %d\n", state); + net_state = state; +} + +/* + * net_get_async_tx_pkt_buf - Get a packet buffer that is not in use for + * sending an asynchronous reply + * + * returns - ptr to packet buffer + */ +uchar * net_get_async_tx_pkt_buf(void); + +/** + * net_send_ip_packet() - Transmit "net_tx_packet" as UDP or TCP packet, + * send ARP request if needed (ether will be populated) + * @ether: Raw packet buffer + * @dest: IP address to send the datagram to + * @dport: Destination UDP port + * @sport: Source UDP port + * @payload_len: Length of data after the UDP header + * @action: TCP action to be performed + * @tcp_seq_num: TCP sequence number of this transmission + * @tcp_ack_num: TCP stream acknolegement number + * + * Return: 0 on success, other value on failure + */ +int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport, + int payload_len, int proto, u8 action, u32 tcp_seq_num, + u32 tcp_ack_num); +/** + * net_send_tcp_packet() - Transmit TCP packet. + * @payload_len: length of payload + * @dport: Destination TCP port + * @sport: Source TCP port + * @action: TCP action to be performed + * @tcp_seq_num: TCP sequence number of this transmission + * @tcp_ack_num: TCP stream acknolegement number + * + * Return: 0 on success, other value on failure + */ +int net_send_tcp_packet(int payload_len, int dport, int sport, u8 action, + u32 tcp_seq_num, u32 tcp_ack_num); +int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, + int sport, int payload_len); + +#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD) +void nc_start(void); +int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port, + unsigned src_port, unsigned len); +#endif + +static __always_inline int eth_is_on_demand_init(void) +{ +#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD) + extern enum proto_t net_loop_last_protocol; + + return net_loop_last_protocol != NETCONS; +#else + return 1; +#endif +} + +static inline void eth_set_last_protocol(int protocol) +{ +#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD) + extern enum proto_t net_loop_last_protocol; + + net_loop_last_protocol = protocol; +#endif +} + +/* + * Check if autoload is enabled. If so, use either NFS or TFTP to download + * the boot file. + */ +void net_auto_load(void); + +/* + * The following functions are a bit ugly, but necessary to deal with + * alignment restrictions on ARM. + * + * We're using inline functions, which had the smallest memory + * footprint in our tests. + */ +/* return IP *in network byteorder* */ +static inline struct in_addr net_read_ip(void *from) +{ + struct in_addr ip; + + memcpy((void *)&ip, (void *)from, sizeof(ip)); + return ip; +} + +/* return ulong *in network byteorder* */ +static inline u32 net_read_u32(void *from) +{ + u32 l; + + memcpy((void *)&l, (void *)from, sizeof(l)); + return l; +} + +/* write IP *in network byteorder* */ +static inline void net_write_ip(void *to, struct in_addr ip) +{ + memcpy(to, (void *)&ip, sizeof(ip)); +} + +/* copy IP */ +static inline void net_copy_ip(void *to, void *from) +{ + memcpy((void *)to, from, sizeof(struct in_addr)); +} + +/* copy ulong */ +static inline void net_copy_u32(void *to, void *from) +{ + memcpy((void *)to, (void *)from, sizeof(u32)); +} + +/** + * net_random_ethaddr - Generate software assigned random Ethernet address + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Generate a random Ethernet address (MAC) that is not multicast + * and has the local assigned bit set. + */ +static inline void net_random_ethaddr(uchar *addr) +{ + int i; + unsigned int seed = get_ticks(); + + for (i = 0; i < 6; i++) + addr[i] = rand_r(&seed); + + addr[0] &= 0xfe; /* clear multicast bit */ + addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ +} + +/* Convert an IP address to a string */ +void ip_to_string(struct in_addr x, char *s); + +/** + * string_to_ip() - Convert a string to ip address + * + * Implemented in lib/net_utils.c (built unconditionally) + * + * @s: Input string to parse + * @return: in_addr struct containing the parsed IP address + */ +struct in_addr string_to_ip(const char *s); + +/* Convert a VLAN id to a string */ +void vlan_to_string(ushort x, char *s); + +/* Convert a string to a vlan id */ +ushort string_to_vlan(const char *s); + +/* read a VLAN id from an environment variable */ +ushort env_get_vlan(char *); + +/* copy a filename (allow for "..." notation, limit length) */ +void copy_filename(char *dst, const char *src, int size); + +/* check if serverip is specified in filename from the command line */ +int is_serverip_in_cmd(void); + +/** + * net_parse_bootfile - Parse the bootfile env var / cmd line param + * + * @param ipaddr - a pointer to the ipaddr to populate if included in bootfile + * @param filename - a pointer to the string to save the filename part + * @param max_len - The longest - 1 that the filename part can be + * + * return 1 if parsed, 0 if bootfile is empty + */ +int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len); + +/** + * reset_phy() - Reset the Ethernet PHY + * + * This should be implemented by boards if CONFIG_RESET_PHY_R is enabled + */ +void reset_phy(void); + +#if CONFIG_IS_ENABLED(NET) || CONFIG_IS_ENABLED(NET_LWIP) +/** + * eth_set_enable_bootdevs() - Enable or disable binding of Ethernet bootdevs + * + * These get in the way of bootstd testing, so are normally disabled by tests. + * This provide control of this setting. It only affects binding of Ethernet + * devices, so if that has already happened, this flag does nothing. + * + * @enable: true to enable binding of bootdevs when binding new Ethernet + * devices, false to disable it + */ +void eth_set_enable_bootdevs(bool enable); +#else +static inline void eth_set_enable_bootdevs(bool enable) {} +#endif + +#endif /* __NET_LEGACY_H__ */ diff --git a/include/net-lwip.h b/include/net-lwip.h new file mode 100644 index 00000000000..f5c743b8d11 --- /dev/null +++ b/include/net-lwip.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef __NET_LWIP_H__ +#define __NET_LWIP_H__ + +#include +#include + +struct netif *net_lwip_new_netif(void); +struct netif *net_lwip_new_netif_noip(void); +void net_lwip_remove_netif(struct netif *netif); +struct netif *net_lwip_get_netif(void); + +#endif /* __NET_LWIP_H__ */ diff --git a/include/net.h b/include/net.h index ac511eab103..afa46f239ee 100644 --- a/include/net.h +++ b/include/net.h @@ -1,950 +1,14 @@ /* SPDX-License-Identifier: GPL-2.0 */ -/* - * LiMon Monitor (LiMon) - Network. - * - * Copyright 1994 - 2000 Neil Russell. - * (See License) - * - * History - * 9/16/00 bor adapted to TQM823L/STK8xxL board, RARP/TFTP boot added - */ #ifndef __NET_H__ #define __NET_H__ -#include -#include -#include /* for nton* / ntoh* stuff */ -#include -#include -#include -#include -#include -#include +#include -struct bd_info; -struct cmd_tbl; -struct udevice; - -#define DEBUG_LL_STATE 0 /* Link local state machine changes */ -#define DEBUG_DEV_PKT 0 /* Packets or info directed to the device */ -#define DEBUG_NET_PKT 0 /* Packets on info on the network at large */ -#define DEBUG_INT_STATE 0 /* Internal network state changes */ -#define DEBUG_NET_PKT_TRACE 0 /* Trace all packet data */ - -/* - * The number of receive packet buffers, and the required packet buffer - * alignment in memory. - * - */ -#define PKTBUFSRX CONFIG_SYS_RX_ETH_BUFFER -#define PKTALIGN ARCH_DMA_MINALIGN - -/* Number of packets processed together */ -#define ETH_PACKETS_BATCH_RECV 32 - -/* ARP hardware address length */ -#define ARP_HLEN 6 -/* - * The size of a MAC address in string form, each digit requires two chars - * and five separator characters to form '00:00:00:00:00:00'. - */ -#define ARP_HLEN_ASCII (ARP_HLEN * 2) + (ARP_HLEN - 1) - -/* IPv4 addresses are always 32 bits in size */ -struct in_addr { - __be32 s_addr; -}; - -/** - * do_tftpb - Run the tftpboot command - * - * @cmdtp: Command information for tftpboot - * @flag: Command flags (CMD_FLAG_...) - * @argc: Number of arguments - * @argv: List of arguments - * Return: result (see enum command_ret_t) - */ -int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); - -/** - * dhcp_run() - Run DHCP on the current ethernet device - * - * This sets the autoload variable, then puts it back to similar to its original - * state (y, n or unset). - * - * @addr: Address to load the file into (0 if @autoload is false) - * @fname: Filename of file to load (NULL if @autoload is false or to use the - * default filename) - * @autoload: true to load the file, false to just get the network IP - * @return 0 if OK, -EINVAL if the environment failed, -ENOENT if ant file was - * not found - */ -int dhcp_run(ulong addr, const char *fname, bool autoload); - -/** - * An incoming packet handler. - * @param pkt pointer to the application packet - * @param dport destination UDP port - * @param sip source IP address - * @param sport source UDP port - * @param len packet length - */ -typedef void rxhand_f(uchar *pkt, unsigned dport, - struct in_addr sip, unsigned sport, - unsigned len); - -/** - * An incoming ICMP packet handler. - * @param type ICMP type - * @param code ICMP code - * @param dport destination UDP port - * @param sip source IP address - * @param sport source UDP port - * @param pkt pointer to the ICMP packet data - * @param len packet length - */ -typedef void rxhand_icmp_f(unsigned type, unsigned code, unsigned dport, - struct in_addr sip, unsigned sport, uchar *pkt, unsigned len); - -/* - * A timeout handler. Called after time interval has expired. - */ -typedef void thand_f(void); - -enum eth_state_t { - ETH_STATE_INIT, - ETH_STATE_PASSIVE, - ETH_STATE_ACTIVE -}; - -/** - * struct eth_pdata - Platform data for Ethernet MAC controllers - * - * @iobase: The base address of the hardware registers - * @enetaddr: The Ethernet MAC address that is loaded from EEPROM or env - * @phy_interface: PHY interface to use - see PHY_INTERFACE_MODE_... - * @max_speed: Maximum speed of Ethernet connection supported by MAC - * @priv_pdata: device specific plat - */ -struct eth_pdata { - phys_addr_t iobase; - unsigned char enetaddr[ARP_HLEN]; - int phy_interface; - int max_speed; - void *priv_pdata; -}; - -enum eth_recv_flags { - /* - * Check hardware device for new packets (otherwise only return those - * which are already in the memory buffer ready to process) - */ - ETH_RECV_CHECK_DEVICE = 1 << 0, -}; - -/** - * struct eth_ops - functions of Ethernet MAC controllers - * - * start: Prepare the hardware to send and receive packets - * send: Send the bytes passed in "packet" as a packet on the wire - * recv: Check if the hardware received a packet. If so, set the pointer to the - * packet buffer in the packetp parameter. If not, return an error or 0 to - * indicate that the hardware receive FIFO is empty. If 0 is returned, the - * network stack will not process the empty packet, but free_pkt() will be - * called if supplied - * free_pkt: Give the driver an opportunity to manage its packet buffer memory - * when the network stack is finished processing it. This will only be - * called when no error was returned from recv - optional - * stop: Stop the hardware from looking for packets - may be called even if - * state == PASSIVE - * mcast: Join or leave a multicast group (for TFTP) - optional - * write_hwaddr: Write a MAC address to the hardware (used to pass it to Linux - * on some platforms like ARM). This function expects the - * eth_pdata::enetaddr field to be populated. The method can - * return -ENOSYS to indicate that this is not implemented for - this hardware - optional. - * read_rom_hwaddr: Some devices have a backup of the MAC address stored in a - * ROM on the board. This is how the driver should expose it - * to the network stack. This function should fill in the - * eth_pdata::enetaddr field - optional - * set_promisc: Enable or Disable promiscuous mode - * get_sset_count: Number of statistics counters - * get_string: Names of the statistic counters - * get_stats: The values of the statistic counters - */ -struct eth_ops { - int (*start)(struct udevice *dev); - int (*send)(struct udevice *dev, void *packet, int length); - int (*recv)(struct udevice *dev, int flags, uchar **packetp); - int (*free_pkt)(struct udevice *dev, uchar *packet, int length); - void (*stop)(struct udevice *dev); - int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join); - int (*write_hwaddr)(struct udevice *dev); - int (*read_rom_hwaddr)(struct udevice *dev); - int (*set_promisc)(struct udevice *dev, bool enable); - int (*get_sset_count)(struct udevice *dev); - void (*get_strings)(struct udevice *dev, u8 *data); - void (*get_stats)(struct udevice *dev, u64 *data); -}; - -#define eth_get_ops(dev) ((struct eth_ops *)(dev)->driver->ops) - -struct udevice *eth_get_dev(void); /* get the current device */ -/* - * The devname can be either an exact name given by the driver or device tree - * or it can be an alias of the form "eth%d" - */ -struct udevice *eth_get_dev_by_name(const char *devname); -unsigned char *eth_get_ethaddr(void); /* get the current device MAC */ - -/* Used only when NetConsole is enabled */ -int eth_is_active(struct udevice *dev); /* Test device for active state */ -int eth_init_state_only(void); /* Set active state */ -void eth_halt_state_only(void); /* Set passive state */ - -int eth_initialize(void); /* Initialize network subsystem */ -void eth_try_another(int first_restart); /* Change the device */ -void eth_set_current(void); /* set nterface to ethcur var */ - -int eth_get_dev_index(void); /* get the device index */ - -/** - * eth_env_set_enetaddr_by_index() - set the MAC address environment variable - * - * This sets up an environment variable with the given MAC address (@enetaddr). - * The environment variable to be set is defined by <@base_name><@index>addr. - * If @index is 0 it is omitted. For common Ethernet this means ethaddr, - * eth1addr, etc. - * - * @base_name: Base name for variable, typically "eth" - * @index: Index of interface being updated (>=0) - * @enetaddr: Pointer to MAC address to put into the variable - * Return: 0 if OK, other value on error - */ -int eth_env_set_enetaddr_by_index(const char *base_name, int index, - uchar *enetaddr); - - -/* - * Initialize USB ethernet device with CONFIG_DM_ETH - * Returns: - * 0 is success, non-zero is error status. - */ -int usb_ether_init(void); - -/* - * Get the hardware address for an ethernet interface . - * Args: - * base_name - base name for device (normally "eth") - * index - device index number (0 for first) - * enetaddr - returns 6 byte hardware address - * Returns: - * Return true if the address is valid. - */ -int eth_env_get_enetaddr_by_index(const char *base_name, int index, - uchar *enetaddr); - -int eth_init(void); /* Initialize the device */ -int eth_send(void *packet, int length); /* Send a packet */ - -#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) -int eth_receive(void *packet, int length); /* Receive a packet*/ -extern void (*push_packet)(void *packet, int length); -#endif -int eth_rx(void); /* Check for received packets */ -void eth_halt(void); /* stop SCC */ -const char *eth_get_name(void); /* get name of current device */ -int eth_mcast_join(struct in_addr mcast_addr, int join); - -/**********************************************************************/ -/* - * Protocol headers. - */ - -/* - * Ethernet header - */ - -struct ethernet_hdr { - u8 et_dest[ARP_HLEN]; /* Destination node */ - u8 et_src[ARP_HLEN]; /* Source node */ - u16 et_protlen; /* Protocol or length */ -} __attribute__((packed)); - -/* Ethernet header size */ -#define ETHER_HDR_SIZE (sizeof(struct ethernet_hdr)) - -#define ETH_FCS_LEN 4 /* Octets in the FCS */ - -struct e802_hdr { - u8 et_dest[ARP_HLEN]; /* Destination node */ - u8 et_src[ARP_HLEN]; /* Source node */ - u16 et_protlen; /* Protocol or length */ - u8 et_dsap; /* 802 DSAP */ - u8 et_ssap; /* 802 SSAP */ - u8 et_ctl; /* 802 control */ - u8 et_snap1; /* SNAP */ - u8 et_snap2; - u8 et_snap3; - u16 et_prot; /* 802 protocol */ -} __attribute__((packed)); - -/* 802 + SNAP + ethernet header size */ -#define E802_HDR_SIZE (sizeof(struct e802_hdr)) - -/* - * Virtual LAN Ethernet header - */ -struct vlan_ethernet_hdr { - u8 vet_dest[ARP_HLEN]; /* Destination node */ - u8 vet_src[ARP_HLEN]; /* Source node */ - u16 vet_vlan_type; /* PROT_VLAN */ - u16 vet_tag; /* TAG of VLAN */ - u16 vet_type; /* protocol type */ -} __attribute__((packed)); - -/* VLAN Ethernet header size */ -#define VLAN_ETHER_HDR_SIZE (sizeof(struct vlan_ethernet_hdr)) - -#define PROT_IP 0x0800 /* IP protocol */ -#define PROT_ARP 0x0806 /* IP ARP protocol */ -#define PROT_WOL 0x0842 /* ether-wake WoL protocol */ -#define PROT_RARP 0x8035 /* IP ARP protocol */ -#define PROT_VLAN 0x8100 /* IEEE 802.1q protocol */ -#define PROT_IPV6 0x86dd /* IPv6 over bluebook */ -#define PROT_PPP_SES 0x8864 /* PPPoE session messages */ -#define PROT_NCSI 0x88f8 /* NC-SI control packets */ - -#define IPPROTO_ICMP 1 /* Internet Control Message Protocol */ -#define IPPROTO_TCP 6 /* Transmission Control Protocol */ -#define IPPROTO_UDP 17 /* User Datagram Protocol */ - -/* - * Internet Protocol (IP) header. - */ -struct ip_hdr { - u8 ip_hl_v; /* header length and version */ - u8 ip_tos; /* type of service */ - u16 ip_len; /* total length */ - u16 ip_id; /* identification */ - u16 ip_off; /* fragment offset field */ - u8 ip_ttl; /* time to live */ - u8 ip_p; /* protocol */ - u16 ip_sum; /* checksum */ - struct in_addr ip_src; /* Source IP address */ - struct in_addr ip_dst; /* Destination IP address */ -} __attribute__((packed)); - -#define IP_OFFS 0x1fff /* ip offset *= 8 */ -#define IP_FLAGS 0xe000 /* first 3 bits */ -#define IP_FLAGS_RES 0x8000 /* reserved */ -#define IP_FLAGS_DFRAG 0x4000 /* don't fragments */ -#define IP_FLAGS_MFRAG 0x2000 /* more fragments */ - -#define IP_HDR_SIZE (sizeof(struct ip_hdr)) - -#define IP_MIN_FRAG_DATAGRAM_SIZE (IP_HDR_SIZE + 8) - -/* - * Internet Protocol (IP) + UDP header. - */ -struct ip_udp_hdr { - u8 ip_hl_v; /* header length and version */ - u8 ip_tos; /* type of service */ - u16 ip_len; /* total length */ - u16 ip_id; /* identification */ - u16 ip_off; /* fragment offset field */ - u8 ip_ttl; /* time to live */ - u8 ip_p; /* protocol */ - u16 ip_sum; /* checksum */ - struct in_addr ip_src; /* Source IP address */ - struct in_addr ip_dst; /* Destination IP address */ - u16 udp_src; /* UDP source port */ - u16 udp_dst; /* UDP destination port */ - u16 udp_len; /* Length of UDP packet */ - u16 udp_xsum; /* Checksum */ -} __attribute__((packed)); - -#define IP_UDP_HDR_SIZE (sizeof(struct ip_udp_hdr)) -#define UDP_HDR_SIZE (IP_UDP_HDR_SIZE - IP_HDR_SIZE) - -/* - * Address Resolution Protocol (ARP) header. - */ -struct arp_hdr { - u16 ar_hrd; /* Format of hardware address */ -# define ARP_ETHER 1 /* Ethernet hardware address */ - u16 ar_pro; /* Format of protocol address */ - u8 ar_hln; /* Length of hardware address */ - u8 ar_pln; /* Length of protocol address */ -# define ARP_PLEN 4 - u16 ar_op; /* Operation */ -# define ARPOP_REQUEST 1 /* Request to resolve address */ -# define ARPOP_REPLY 2 /* Response to previous request */ - -# define RARPOP_REQUEST 3 /* Request to resolve address */ -# define RARPOP_REPLY 4 /* Response to previous request */ - - /* - * The remaining fields are variable in size, according to - * the sizes above, and are defined as appropriate for - * specific hardware/protocol combinations. - */ - u8 ar_data[0]; -#define ar_sha ar_data[0] -#define ar_spa ar_data[ARP_HLEN] -#define ar_tha ar_data[ARP_HLEN + ARP_PLEN] -#define ar_tpa ar_data[ARP_HLEN + ARP_PLEN + ARP_HLEN] -#if 0 - u8 ar_sha[]; /* Sender hardware address */ - u8 ar_spa[]; /* Sender protocol address */ - u8 ar_tha[]; /* Target hardware address */ - u8 ar_tpa[]; /* Target protocol address */ -#endif /* 0 */ -} __attribute__((packed)); - -#define ARP_HDR_SIZE (8+20) /* Size assuming ethernet */ - -/* - * ICMP stuff (just enough to handle (host) redirect messages) - */ -#define ICMP_ECHO_REPLY 0 /* Echo reply */ -#define ICMP_NOT_REACH 3 /* Detination unreachable */ -#define ICMP_REDIRECT 5 /* Redirect (change route) */ -#define ICMP_ECHO_REQUEST 8 /* Echo request */ - -/* Codes for REDIRECT. */ -#define ICMP_REDIR_NET 0 /* Redirect Net */ -#define ICMP_REDIR_HOST 1 /* Redirect Host */ - -/* Codes for NOT_REACH */ -#define ICMP_NOT_REACH_PORT 3 /* Port unreachable */ - -struct icmp_hdr { - u8 type; - u8 code; - u16 checksum; - union { - struct { - u16 id; - u16 sequence; - } echo; - u32 gateway; - struct { - u16 unused; - u16 mtu; - } frag; - u8 data[0]; - } un; -} __attribute__((packed)); - -#define ICMP_HDR_SIZE (sizeof(struct icmp_hdr)) -#define IP_ICMP_HDR_SIZE (IP_HDR_SIZE + ICMP_HDR_SIZE) - -/* - * Maximum packet size; used to allocate packet storage. Use - * the maxium Ethernet frame size as specified by the Ethernet - * standard including the 802.1Q tag (VLAN tagging). - * maximum packet size = 1522 - * maximum packet size and multiple of 32 bytes = 1536 - */ -#define PKTSIZE 1522 -#ifndef CONFIG_DM_DSA -#define PKTSIZE_ALIGN 1536 -#else -/* Maximum DSA tagging overhead (headroom and/or tailroom) */ -#define DSA_MAX_OVR 256 -#define PKTSIZE_ALIGN (1536 + DSA_MAX_OVR) -#endif - -/* - * Maximum receive ring size; that is, the number of packets - * we can buffer before overflow happens. Basically, this just - * needs to be enough to prevent a packet being discarded while - * we are processing the previous one. - */ -#define RINGSZ 4 -#define RINGSZ_LOG2 2 - -/**********************************************************************/ -/* - * Globals. - * - * Note: - * - * All variables of type struct in_addr are stored in NETWORK byte order - * (big endian). - */ - -/* net.c */ -/** BOOTP EXTENTIONS **/ -extern struct in_addr net_gateway; /* Our gateway IP address */ -extern struct in_addr net_netmask; /* Our subnet mask (0 = unknown) */ -/* Our Domain Name Server (0 = unknown) */ -extern struct in_addr net_dns_server; -#if defined(CONFIG_BOOTP_DNS2) -/* Our 2nd Domain Name Server (0 = unknown) */ -extern struct in_addr net_dns_server2; -#endif -extern char net_nis_domain[32]; /* Our IS domain */ -extern char net_hostname[32]; /* Our hostname */ -#ifdef CONFIG_NET -extern char net_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN]; /* Our root path */ -#endif -/* Indicates whether the pxe path prefix / config file was specified in dhcp option */ -extern char *pxelinux_configfile; -/** END OF BOOTP EXTENTIONS **/ -extern u8 net_ethaddr[ARP_HLEN]; /* Our ethernet address */ -extern u8 net_server_ethaddr[ARP_HLEN]; /* Boot server enet address */ -extern struct in_addr net_ip; /* Our IP addr (0 = unknown) */ -extern struct in_addr net_server_ip; /* Server IP addr (0 = unknown) */ -extern uchar *net_tx_packet; /* THE transmit packet */ -extern uchar *net_rx_packets[PKTBUFSRX]; /* Receive packets */ -extern uchar *net_rx_packet; /* Current receive packet */ -extern int net_rx_packet_len; /* Current rx packet length */ -extern const u8 net_bcast_ethaddr[ARP_HLEN]; /* Ethernet broadcast address */ -extern const u8 net_null_ethaddr[ARP_HLEN]; - -#define VLAN_NONE 4095 /* untagged */ -#define VLAN_IDMASK 0x0fff /* mask of valid vlan id */ -extern ushort net_our_vlan; /* Our VLAN */ -extern ushort net_native_vlan; /* Our Native VLAN */ - -extern int net_restart_wrap; /* Tried all network devices */ - -enum proto_t { - BOOTP, RARP, ARP, TFTPGET, DHCP, DHCP6, PING, PING6, DNS, NFS, CDP, - NETCONS, SNTP, TFTPSRV, TFTPPUT, LINKLOCAL, FASTBOOT_UDP, FASTBOOT_TCP, - WOL, UDP, NCSI, WGET, RS -}; - -extern char net_boot_file_name[1024];/* Boot File name */ -/* Indicates whether the file name was specified on the command line */ -extern bool net_boot_file_name_explicit; -/* The actual transferred size of the bootfile (in bytes) */ -extern u32 net_boot_file_size; -/* Boot file size in blocks as reported by the DHCP server */ -extern u32 net_boot_file_expected_size_in_blocks; - -#if defined(CONFIG_CMD_DNS) -extern char *net_dns_resolve; /* The host to resolve */ -extern char *net_dns_env_var; /* the env var to put the ip into */ -#endif - -#if defined(CONFIG_CMD_PING) -extern struct in_addr net_ping_ip; /* the ip address to ping */ -#endif - -#if defined(CONFIG_CMD_CDP) -/* when CDP completes these hold the return values */ -extern ushort cdp_native_vlan; /* CDP returned native VLAN */ -extern ushort cdp_appliance_vlan; /* CDP returned appliance VLAN */ - -/* - * Check for a CDP packet by examining the received MAC address field - */ -static inline int is_cdp_packet(const uchar *ethaddr) -{ - extern const u8 net_cdp_ethaddr[ARP_HLEN]; - - return memcmp(ethaddr, net_cdp_ethaddr, ARP_HLEN) == 0; -} -#endif - -#if defined(CONFIG_CMD_SNTP) -extern struct in_addr net_ntp_server; /* the ip address to NTP */ -extern int net_ntp_time_offset; /* offset time from UTC */ -#endif - -/* Initialize the network adapter */ -int net_init(void); -int net_loop(enum proto_t); - -/* Load failed. Start again. */ -int net_start_again(void); - -/* Get size of the ethernet header when we send */ -int net_eth_hdr_size(void); - -/* Set ethernet header; returns the size of the header */ -int net_set_ether(uchar *xet, const uchar *dest_ethaddr, uint prot); -int net_update_ether(struct ethernet_hdr *et, uchar *addr, uint prot); - -/* Set IP header */ -void net_set_ip_header(uchar *pkt, struct in_addr dest, struct in_addr source, - u16 pkt_len, u8 proto); -void net_set_udp_header(uchar *pkt, struct in_addr dest, int dport, - int sport, int len); - -/** - * compute_ip_checksum() - Compute IP checksum - * - * @addr: Address to check (must be 16-bit aligned) - * @nbytes: Number of bytes to check (normally a multiple of 2) - * Return: 16-bit IP checksum - */ -unsigned compute_ip_checksum(const void *addr, unsigned nbytes); - -/** - * add_ip_checksums() - add two IP checksums - * - * @offset: Offset of first sum (if odd we do a byte-swap) - * @sum: First checksum - * @new_sum: New checksum to add - * Return: updated 16-bit IP checksum - */ -unsigned add_ip_checksums(unsigned offset, unsigned sum, unsigned new_sum); - -/** - * ip_checksum_ok() - check if a checksum is correct - * - * This works by making sure the checksum sums to 0 - * - * @addr: Address to check (must be 16-bit aligned) - * @nbytes: Number of bytes to check (normally a multiple of 2) - * Return: true if the checksum matches, false if not - */ -int ip_checksum_ok(const void *addr, unsigned nbytes); - -/* Callbacks */ -rxhand_f *net_get_udp_handler(void); /* Get UDP RX packet handler */ -void net_set_udp_handler(rxhand_f *); /* Set UDP RX packet handler */ -rxhand_f *net_get_arp_handler(void); /* Get ARP RX packet handler */ -void net_set_arp_handler(rxhand_f *); /* Set ARP RX packet handler */ -bool arp_is_waiting(void); /* Waiting for ARP reply? */ -void net_set_icmp_handler(rxhand_icmp_f *f); /* Set ICMP RX handler */ -void net_set_timeout_handler(ulong, thand_f *);/* Set timeout handler */ - -/* Network loop state */ -enum net_loop_state { - NETLOOP_CONTINUE, - NETLOOP_RESTART, - NETLOOP_SUCCESS, - NETLOOP_FAIL -}; -extern enum net_loop_state net_state; - -static inline void net_set_state(enum net_loop_state state) -{ - debug_cond(DEBUG_INT_STATE, "--- NetState set to %d\n", state); - net_state = state; -} - -/* - * net_get_async_tx_pkt_buf - Get a packet buffer that is not in use for - * sending an asynchronous reply - * - * returns - ptr to packet buffer - */ -uchar * net_get_async_tx_pkt_buf(void); - -/* Transmit a packet */ -static inline void net_send_packet(uchar *pkt, int len) -{ - if (DEBUG_NET_PKT_TRACE) - print_hex_dump_bytes("tx: ", DUMP_PREFIX_OFFSET, pkt, len); - /* Currently no way to return errors from eth_send() */ - (void) eth_send(pkt, len); -} - -/** - * net_send_ip_packet() - Transmit "net_tx_packet" as UDP or TCP packet, - * send ARP request if needed (ether will be populated) - * @ether: Raw packet buffer - * @dest: IP address to send the datagram to - * @dport: Destination UDP port - * @sport: Source UDP port - * @payload_len: Length of data after the UDP header - * @action: TCP action to be performed - * @tcp_seq_num: TCP sequence number of this transmission - * @tcp_ack_num: TCP stream acknolegement number - * - * Return: 0 on success, other value on failure - */ -int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport, - int payload_len, int proto, u8 action, u32 tcp_seq_num, - u32 tcp_ack_num); -/** - * net_send_tcp_packet() - Transmit TCP packet. - * @payload_len: length of payload - * @dport: Destination TCP port - * @sport: Source TCP port - * @action: TCP action to be performed - * @tcp_seq_num: TCP sequence number of this transmission - * @tcp_ack_num: TCP stream acknolegement number - * - * Return: 0 on success, other value on failure - */ -int net_send_tcp_packet(int payload_len, int dport, int sport, u8 action, - u32 tcp_seq_num, u32 tcp_ack_num); -int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, - int sport, int payload_len); - -/* Processes a received packet */ -void net_process_received_packet(uchar *in_packet, int len); - -#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD) -void nc_start(void); -int nc_input_packet(uchar *pkt, struct in_addr src_ip, unsigned dest_port, - unsigned src_port, unsigned len); -#endif - -static __always_inline int eth_is_on_demand_init(void) -{ -#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD) - extern enum proto_t net_loop_last_protocol; - - return net_loop_last_protocol != NETCONS; -#else - return 1; -#endif -} - -static inline void eth_set_last_protocol(int protocol) -{ -#if defined(CONFIG_NETCONSOLE) && !defined(CONFIG_SPL_BUILD) - extern enum proto_t net_loop_last_protocol; - - net_loop_last_protocol = protocol; -#endif -} - -/* - * Check if autoload is enabled. If so, use either NFS or TFTP to download - * the boot file. - */ -void net_auto_load(void); - -/* - * The following functions are a bit ugly, but necessary to deal with - * alignment restrictions on ARM. - * - * We're using inline functions, which had the smallest memory - * footprint in our tests. - */ -/* return IP *in network byteorder* */ -static inline struct in_addr net_read_ip(void *from) -{ - struct in_addr ip; - - memcpy((void *)&ip, (void *)from, sizeof(ip)); - return ip; -} - -/* return ulong *in network byteorder* */ -static inline u32 net_read_u32(void *from) -{ - u32 l; - - memcpy((void *)&l, (void *)from, sizeof(l)); - return l; -} - -/* write IP *in network byteorder* */ -static inline void net_write_ip(void *to, struct in_addr ip) -{ - memcpy(to, (void *)&ip, sizeof(ip)); -} - -/* copy IP */ -static inline void net_copy_ip(void *to, void *from) -{ - memcpy((void *)to, from, sizeof(struct in_addr)); -} - -/* copy ulong */ -static inline void net_copy_u32(void *to, void *from) -{ - memcpy((void *)to, (void *)from, sizeof(u32)); -} - -/** - * is_zero_ethaddr - Determine if give Ethernet address is all zeros. - * @addr: Pointer to a six-byte array containing the Ethernet address - * - * Return true if the address is all zeroes. - */ -static inline int is_zero_ethaddr(const u8 *addr) -{ - return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); -} - -/** - * is_multicast_ethaddr - Determine if the Ethernet address is a multicast. - * @addr: Pointer to a six-byte array containing the Ethernet address - * - * Return true if the address is a multicast address. - * By definition the broadcast address is also a multicast address. - */ -static inline int is_multicast_ethaddr(const u8 *addr) -{ - return 0x01 & addr[0]; -} - -/* - * is_broadcast_ethaddr - Determine if the Ethernet address is broadcast - * @addr: Pointer to a six-byte array containing the Ethernet address - * - * Return true if the address is the broadcast address. - */ -static inline int is_broadcast_ethaddr(const u8 *addr) -{ - return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == - 0xff; -} - -/* - * is_valid_ethaddr - Determine if the given Ethernet address is valid - * @addr: Pointer to a six-byte array containing the Ethernet address - * - * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not - * a multicast address, and is not FF:FF:FF:FF:FF:FF. - * - * Return true if the address is valid. - */ -static inline int is_valid_ethaddr(const u8 *addr) -{ - /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to - * explicitly check for it here. */ - return !is_multicast_ethaddr(addr) && !is_zero_ethaddr(addr); -} - -/** - * net_random_ethaddr - Generate software assigned random Ethernet address - * @addr: Pointer to a six-byte array containing the Ethernet address - * - * Generate a random Ethernet address (MAC) that is not multicast - * and has the local assigned bit set. - */ -static inline void net_random_ethaddr(uchar *addr) -{ - int i; - unsigned int seed = get_ticks(); - - for (i = 0; i < 6; i++) - addr[i] = rand_r(&seed); - - addr[0] &= 0xfe; /* clear multicast bit */ - addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ -} - -/** - * string_to_enetaddr() - Parse a MAC address - * - * Convert a string MAC address - * - * Implemented in lib/net_utils.c (built unconditionally) - * - * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit - * hex value - * @enetaddr: Place to put MAC address (6 bytes) - */ -void string_to_enetaddr(const char *addr, uint8_t *enetaddr); - -/* Convert an IP address to a string */ -void ip_to_string(struct in_addr x, char *s); - -/** - * string_to_ip() - Convert a string to ip address - * - * Implemented in lib/net_utils.c (built unconditionally) - * - * @s: Input string to parse - * @return: in_addr struct containing the parsed IP address - */ -struct in_addr string_to_ip(const char *s); - -/* Convert a VLAN id to a string */ -void vlan_to_string(ushort x, char *s); - -/* Convert a string to a vlan id */ -ushort string_to_vlan(const char *s); - -/* read a VLAN id from an environment variable */ -ushort env_get_vlan(char *); - -/* copy a filename (allow for "..." notation, limit length) */ -void copy_filename(char *dst, const char *src, int size); - -/* check if serverip is specified in filename from the command line */ -int is_serverip_in_cmd(void); - -/** - * net_parse_bootfile - Parse the bootfile env var / cmd line param - * - * @param ipaddr - a pointer to the ipaddr to populate if included in bootfile - * @param filename - a pointer to the string to save the filename part - * @param max_len - The longest - 1 that the filename part can be - * - * return 1 if parsed, 0 if bootfile is empty - */ -int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len); - -/** - * update_tftp - Update firmware over TFTP (via DFU) - * - * This function updates board's firmware via TFTP - * - * @param addr - memory address where data is stored - * @param interface - the DFU medium name - e.g. "mmc" - * @param devstring - the DFU medium number - e.g. "1" - * - * Return: - 0 on success, other value on failure - */ -int update_tftp(ulong addr, char *interface, char *devstring); - -/** - * env_get_ip() - Convert an environment value to to an ip address - * - * @var: Environment variable to convert. The value of this variable must be - * in the format format a.b.c.d, where each value is a decimal number from - * 0 to 255 - * Return: IP address, or 0 if invalid - */ -static inline struct in_addr env_get_ip(char *var) -{ - return string_to_ip(env_get(var)); -} - -/** - * reset_phy() - Reset the Ethernet PHY - * - * This should be implemented by boards if CONFIG_RESET_PHY_R is enabled - */ -void reset_phy(void); - -#if CONFIG_IS_ENABLED(NET) -/** - * eth_set_enable_bootdevs() - Enable or disable binding of Ethernet bootdevs - * - * These get in the way of bootstd testing, so are normally disabled by tests. - * This provide control of this setting. It only affects binding of Ethernet - * devices, so if that has already happened, this flag does nothing. - * - * @enable: true to enable binding of bootdevs when binding new Ethernet - * devices, false to disable it - */ -void eth_set_enable_bootdevs(bool enable); +#if defined(CONFIG_NET_LWIP) +#include #else -static inline void eth_set_enable_bootdevs(bool enable) {} +#include #endif -/** - * wget_with_dns() - runs dns host IP address resulution before wget - * - * @dst_addr: destination address to download the file - * @uri: uri string of target file of wget - * Return: downloaded file size, negative if failed - */ -int wget_with_dns(ulong dst_addr, char *uri); - -/** - * wget_validate_uri() - varidate the uri - * - * @uri: uri string of target file of wget - * Return: true if uri is valid, false if uri is invalid - */ -bool wget_validate_uri(char *uri); - #endif /* __NET_H__ */ From patchwork Mon Jun 17 15:32:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804879 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611247wrr; Mon, 17 Jun 2024 08:34:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWSBazZy2zzaUDc3JsA6Kd3c73Wj6SZUwkOkTUoz25gzZDLo7SRf+94boxxWPlOGlxiAwl4NyFdB9MFaiOxh68s X-Google-Smtp-Source: AGHT+IFORMpjm39d+RAldExId/YEmIsYw/dRiK15eWTvj8O2ozm6YHEhOk8NHXiz78H1zcg8n6Sf X-Received: by 2002:a17:906:dfd1:b0:a6f:40d5:e287 with SMTP id a640c23a62f3a-a6f60de5f13mr703422666b.74.1718638449400; Mon, 17 Jun 2024 08:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638449; cv=none; d=google.com; s=arc-20160816; b=XEXMG7mKr1AquIUy7cPYXfePoZzpSX9KDRF7PElrIVMAdX6acQ44oqMEztmq79cL36 KmObNZYaGkln34JbhU73g48x1X0uGcQxcRv3C4ZCvtaVaaaPQa4L9XOyp2XdApNrI4jZ OcVOh2mioEo7rIlpL1ri/08XFmoyja4fDj4DhSfYMTppgw+gMzR0wVV49N66DkBswpr3 KlJujq4E5RkKN8meKn+ln/lOcDBAORDXvIPfMvArVew9P6/2HCSiKSKMEFAsRwPKuoMz EiDcM3PngSwGq1MYC/lpelW3/+pRSnrPJYWfIIbWoOxVLDuiO8yozCi02o44vwEg1BoS adMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/5/mioqcCmEnA4nfuYL4SIkuxTq5Mnmg2VJwgmTrsJA=; fh=ekXsUQPhZdr3j4yJ9xR4wW90wSJ6ZxPoTiiDogoheA0=; b=ND88faykEUu01j3rDxG3p1gkie5lk73i7bTNkSt6y+1relGbEf5iRAb2/whIuLOWrf uAqwrnRPn7/X4cSExG3WOzXpM6seP7E9iu6fd8GpKp5YKQzcyffGxKGo+3WqIhBxELHv dlcTBREtFKTcF4dzjhXNEgvC5rQs5OlTeMbrAG6VFnCu5jz+Lw0Bjx6mGN+x5gHmDMW8 wFGRiO19/QurPdBSvUY8gs/jsgdZ7VuxKBEyyYofGTUqGTkMnjXF/lBl+20zxYkMnCBA bZlGt5bcCSpJ+hpLuK9OvC/aNSo+2iZqa3TpOn8aOaNETsXr9ulBtFzBuFVhwJtfuh0q I9mw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ISE0AP7w; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56e26d88si455017066b.779.2024.06.17.08.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:34:09 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ISE0AP7w; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 57E538837A; Mon, 17 Jun 2024 17:33:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ISE0AP7w"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B30D987CDA; Mon, 17 Jun 2024 17:33:40 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D53DE88365 for ; Mon, 17 Jun 2024 17:33:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-421f4d1c057so34958655e9.3 for ; Mon, 17 Jun 2024 08:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638416; x=1719243216; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/5/mioqcCmEnA4nfuYL4SIkuxTq5Mnmg2VJwgmTrsJA=; b=ISE0AP7wBzISjIIzjrVlm8yD+lXzhMTFGgYETFy2Tu257gMHVG/FOohxXff7guDpqW nzwGD2oBNUxQUoUdkPNFeuG7IS4AWS7nrgczfQisUwfwu1blZqZRdBPqZ0Bd8NxOpvBF By/5+dIR1IPeBOctMMFH8zH+zLsKAz12z66LIXgNo2koMe3L047h9bvjTsYLPk6pIGuR 74Q9NFdJrYq1ZFP3xpx2lN1yr6QAcPf33LFWE/vzn3SHU4drZlbTSabl7F6OPAv3vf4m lzDK/Pp1R63iPlymLvaFtFDy81Lo5n3SCM5Cq1QD/dVPxS2yY55AGhId+aWJTF74P7RY YgCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638416; x=1719243216; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/5/mioqcCmEnA4nfuYL4SIkuxTq5Mnmg2VJwgmTrsJA=; b=dASVIi/k1G3UQuT+Fg2MUp3ukK/bgyhAodp8JNbwLHOGQMXC7TPZRnWM99L22bXpge sXkKuYzZsRA2kNjotHiJS2WBgdOcqPWh9sBq9MG2lAQeEbkkTGzMUE8bczbXa2fJJuLb 8TQ6W1dXfQgoioin5mS4viDnRbHkSpWdraHwVrDkDYBgZ9n4NW+v4B3Ak8mnCWQJ/BkZ cDMLw/9RrbZuVexbKEVMwxVzE8ogkmjMolKcoqXRDxoTNSTGhvIt1XHWURkJXqiETd4Q SZcO/ou6ZXrTT8QCd1PSMY7lz+JpnTJ+5WYxCD4dJyIqOSepQzpK9s4ymaV/O+VfejmJ ofWw== X-Gm-Message-State: AOJu0YwcBhwXF/rTtvH3HEk601HHPHH+zeRa+lS/x+4WkgY6AMO2f4ia aXmcjGvEXMMKs8vLsELR8tVFJzKiiPaYZ1vchRf2Pju7uH530EkW3I0z2IDqVUZGh8wAcEFp5vk mAeM= X-Received: by 2002:a05:600c:314f:b0:422:370a:ca54 with SMTP id 5b1f17b1804b1-423048262b8mr70924875e9.24.1718638416282; Mon, 17 Jun 2024 08:33:36 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:36 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Oleksandr Suvorov , Sean Anderson Subject: [PATCH v4 04/14] net-lwip: build lwIP Date: Mon, 17 Jun 2024 17:32:56 +0200 Message-Id: <9a1341a10d47a2877a649ea625aefab4e0bd377d.1718638104.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Build the lwIP library when NET_LWIP is enabled. The following files are adaptation layers written specially for U-Boot: lib/lwip/u-boot/arch/cc.h lib/lwip/u-boot/arch/sys_arch.h (empty) lib/lwip/u-boot/limits.h (empty) lib/lwip/u-boot/lwipopts.h They were initially contributed by Maxim in a previous RFC patch series. Signed-off-by: Jerome Forissier Co-developed-by: Maxim Uvarov Cc: Maxim Uvarov Acked-by: Ilias Apalodimas --- lib/Makefile | 2 + lib/lwip/Makefile | 55 +++++++++ lib/lwip/u-boot/arch/cc.h | 43 +++++++ lib/lwip/u-boot/arch/sys_arch.h | 0 lib/lwip/u-boot/limits.h | 0 lib/lwip/u-boot/lwipopts.h | 197 ++++++++++++++++++++++++++++++++ 6 files changed, 297 insertions(+) create mode 100644 lib/lwip/Makefile create mode 100644 lib/lwip/u-boot/arch/cc.h create mode 100644 lib/lwip/u-boot/arch/sys_arch.h create mode 100644 lib/lwip/u-boot/limits.h create mode 100644 lib/lwip/u-boot/lwipopts.h diff --git a/lib/Makefile b/lib/Makefile index 2a76acf100d..c35786a0576 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -94,6 +94,8 @@ obj-$(CONFIG_LIBAVB) += libavb/ obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/ obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o +obj-$(CONFIG_NET_LWIP) += lwip/ + ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16-ccitt.o obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16-ccitt.o diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile new file mode 100644 index 00000000000..dfcd700ca47 --- /dev/null +++ b/lib/lwip/Makefile @@ -0,0 +1,55 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (C) 2024 Linaro Ltd. + +obj-y += \ + lwip/src/api/api_lib.o \ + lwip/src/api/api_msg.o \ + lwip/src/api/err.o \ + lwip/src/api/if_api.o \ + lwip/src/api/netbuf.o \ + lwip/src/api/netdb.o \ + lwip/src/api/netifapi.o \ + lwip/src/api/sockets.o \ + lwip/src/api/tcpip.o \ + lwip/src/apps/http/http_client.o \ + lwip/src/apps/tftp/tftp.o \ + lwip/src/core/altcp_alloc.o \ + lwip/src/core/altcp.o \ + lwip/src/core/altcp_tcp.o \ + lwip/src/core/def.o \ + lwip/src/core/dns.o \ + lwip/src/core/inet_chksum.o \ + lwip/src/core/init.o \ + lwip/src/core/ip.o \ + lwip/src/core/ipv4/acd.o \ + lwip/src/core/ipv4/autoip.o \ + lwip/src/core/ipv4/dhcp.o \ + lwip/src/core/ipv4/etharp.o \ + lwip/src/core/ipv4/icmp.o \ + lwip/src/core/ipv4/igmp.o \ + lwip/src/core/ipv4/ip4_addr.o \ + lwip/src/core/ipv4/ip4.o \ + lwip/src/core/ipv4/ip4_frag.o \ + lwip/src/core/ipv6/dhcp6.o \ + lwip/src/core/ipv6/ethip6.o \ + lwip/src/core/ipv6/icmp6.o \ + lwip/src/core/ipv6/inet6.o \ + lwip/src/core/ipv6/ip6_addr.o \ + lwip/src/core/ipv6/ip6.o \ + lwip/src/core/ipv6/ip6_frag.o \ + lwip/src/core/ipv6/mld6.o \ + lwip/src/core/ipv6/nd6.o \ + lwip/src/core/mem.o \ + lwip/src/core/memp.o \ + lwip/src/core/netif.o \ + lwip/src/core/pbuf.o \ + lwip/src/core/raw.o \ + lwip/src/core/stats.o \ + lwip/src/core/sys.o \ + lwip/src/core/tcp.o \ + lwip/src/core/tcp_in.o \ + lwip/src/core/tcp_out.o \ + lwip/src/core/timeouts.o \ + lwip/src/core/udp.o \ + lwip/src/netif/ethernet.o diff --git a/lib/lwip/u-boot/arch/cc.h b/lib/lwip/u-boot/arch/cc.h new file mode 100644 index 00000000000..31c036dc0c5 --- /dev/null +++ b/lib/lwip/u-boot/arch/cc.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2023 Linaro Ltd. */ + +#ifndef LWIP_ARCH_CC_H +#define LWIP_ARCH_CC_H + +#include +#include +#include +#include + +#define LWIP_ERRNO_INCLUDE + +#define LWIP_ERRNO_STDINCLUDE 1 +#define LWIP_NO_UNISTD_H 1 +#define LWIP_TIMEVAL_PRIVATE 1 + +#ifdef CONFIG_LIB_RAND +#define LWIP_RAND() ((u32_t)rand()) +#endif + +/* different handling for unit test, normally not needed */ +#ifdef LWIP_NOASSERT_ON_ERROR +#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \ + handler; }} while (0) +#endif + +#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS + +#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \ + x, __LINE__, __FILE__); } while (0) + +#define atoi(str) (int)dectoul(str, NULL) +#define lwip_strnstr(a, b) strnstr(a, b) + +#define LWIP_ERR_T int +#define LWIP_CONST_CAST(target_type, val) ((target_type)((uintptr_t)val)) + +#if defined(CONFIG_SYS_BIG_ENDIAN) +#define BYTE_ORDER BIG_ENDIAN +#endif + +#endif /* LWIP_ARCH_CC_H */ diff --git a/lib/lwip/u-boot/arch/sys_arch.h b/lib/lwip/u-boot/arch/sys_arch.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/lib/lwip/u-boot/limits.h b/lib/lwip/u-boot/limits.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/lib/lwip/u-boot/lwipopts.h b/lib/lwip/u-boot/lwipopts.h new file mode 100644 index 00000000000..fd9fd2c2bd9 --- /dev/null +++ b/lib/lwip/u-boot/lwipopts.h @@ -0,0 +1,197 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* Copyright (C) 2023 Linaro Ltd. */ + +#ifndef LWIP_UBOOT_LWIPOPTS_H +#define LWIP_UBOOT_LWIPOPTS_H + +#if defined(CONFIG_LWIP_DEBUG) +#define LWIP_DEBUG 1 +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_TYPES_ON LWIP_DBG_ON +#define ETHARP_DEBUG LWIP_DBG_ON +#define NETIF_DEBUG LWIP_DBG_ON +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_ON +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_ON +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_ON +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_ON +#define AUTOIP_DEBUG LWIP_DBG_ON +#define DNS_DEBUG LWIP_DBG_ON +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#else +#define LWIP_DBG_MIN_LEVEL LWIP_DBG_LEVEL_ALL +#define LWIP_DBG_TYPES_ON LWIP_DBG_OFF +#define ETHARP_DEBUG LWIP_DBG_OFF +#define NETIF_DEBUG LWIP_DBG_OFF +#define PBUF_DEBUG LWIP_DBG_OFF +#define API_LIB_DEBUG LWIP_DBG_OFF +#define API_MSG_DEBUG LWIP_DBG_OFF +#define SOCKETS_DEBUG LWIP_DBG_OFF +#define ICMP_DEBUG LWIP_DBG_OFF +#define IGMP_DEBUG LWIP_DBG_OFF +#define INET_DEBUG LWIP_DBG_OFF +#define IP_DEBUG LWIP_DBG_OFF +#define IP_REASS_DEBUG LWIP_DBG_OFF +#define RAW_DEBUG LWIP_DBG_OFF +#define MEM_DEBUG LWIP_DBG_OFF +#define MEMP_DEBUG LWIP_DBG_OFF +#define SYS_DEBUG LWIP_DBG_OFF +#define TIMERS_DEBUG LWIP_DBG_OFF +#define TCP_DEBUG LWIP_DBG_OFF +#define TCP_INPUT_DEBUG LWIP_DBG_OFF +#define TCP_FR_DEBUG LWIP_DBG_OFF +#define TCP_RTO_DEBUG LWIP_DBG_OFF +#define TCP_CWND_DEBUG LWIP_DBG_OFF +#define TCP_WND_DEBUG LWIP_DBG_OFF +#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF +#define TCP_RST_DEBUG LWIP_DBG_OFF +#define TCP_QLEN_DEBUG LWIP_DBG_OFF +#define UDP_DEBUG LWIP_DBG_OFF +#define TCPIP_DEBUG LWIP_DBG_OFF +#define SLIP_DEBUG LWIP_DBG_OFF +#define DHCP_DEBUG LWIP_DBG_OFF +#define AUTOIP_DEBUG LWIP_DBG_OFF +#define DNS_DEBUG LWIP_DBG_OFF +#define IP6_DEBUG LWIP_DBG_OFF +#define DHCP6_DEBUG LWIP_DBG_OFF +#endif +#define LWIP_TESTMODE 0 + +#if !defined(CONFIG_LWIP_ASSERT) +#define LWIP_NOASSERT 1 +#define LWIP_ASSERT(message, assertion) +#endif + +#include "lwip/debug.h" + +#define SYS_LIGHTWEIGHT_PROT 0 +#define NO_SYS 1 + +#define LWIP_IPV4 1 +#define LWIP_IPV6 0 + +#define MEM_ALIGNMENT 1 +#define MEM_SIZE 1600 + +#define MEMP_NUM_PBUF 4 +#define MEMP_NUM_RAW_PCB 2 +#define MEMP_NUM_UDP_PCB 4 +#define MEMP_NUM_TCP_PCB 2 +#define MEMP_NUM_TCP_PCB_LISTEN 2 +#define MEMP_NUM_TCP_SEG 16 +#define MEMP_NUM_REASSDATA 1 +#define MEMP_NUM_ARP_QUEUE 2 +#define MEMP_NUM_SYS_TIMEOUT 4 +#define MEMP_NUM_NETBUF 2 +#define MEMP_NUM_NETCONN 32 +#define MEMP_NUM_TCPIP_MSG_API 8 +#define MEMP_NUM_TCPIP_MSG_INPKT 8 +#define PBUF_POOL_SIZE 8 + +#define LWIP_ARP 1 +#define ARP_TABLE_SIZE 10 +#define ARP_QUEUEING 1 + +#define IP_FORWARD 0 +#define IP_OPTIONS_ALLOWED 1 +#define IP_REASSEMBLY 0 +#define IP_FRAG 0 +#define IP_REASS_MAXAGE 3 +#define IP_REASS_MAX_PBUFS 4 +#define IP_FRAG_USES_STATIC_BUF 0 + +#define IP_DEFAULT_TTL 255 + +#define LWIP_ICMP 0 + +#if defined(CONFIG_PROT_RAW_LWIP) +#define LWIP_RAW 1 +#else +#define LWIP_RAW 0 +#endif + +#if defined(CONFIG_PROT_DHCP_LWIP) +#define LWIP_DHCP 1 +#define LWIP_DHCP_BOOTP_FILE 1 +#else +#define LWIP_DHCP 0 +#endif + +#define LWIP_DHCP_DOES_ACD_CHECK 0 + +#define LWIP_AUTOIP 0 + +#define LWIP_SNMP 0 + +#define LWIP_IGMP 0 + +#if defined(CONFIG_PROT_DNS_LWIP) +#define LWIP_DNS 1 +#define DNS_TABLE_SIZE 1 +#else +#define LWIP_DNS 0 +#endif + +#if defined(CONFIG_PROT_UDP_LWIP) +#define LWIP_UDP 1 +#else +#define LWIP_UDP 0 +#endif + +#if defined(CONFIG_PROT_TCP_LWIP) +#define LWIP_TCP 1 +#else +#define LWIP_TCP 0 +#endif + +#define LWIP_LISTEN_BACKLOG 0 + +#define PBUF_LINK_HLEN 14 +#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_HLEN) + +#define LWIP_HAVE_LOOPIF 0 + +#define LWIP_NETCONN 0 +#define LWIP_DISABLE_MEMP_SANITY_CHECKS 1 + +#define LWIP_SOCKET 0 +#define SO_REUSE 0 + +#define LWIP_STATS 0 + +#define PPP_SUPPORT 0 + +#define LWIP_TCPIP_CORE_LOCKING 0 + +#define LWIP_NETIF_LOOPBACK 0 + +/* use malloc instead of pool */ +#define MEMP_MEM_MALLOC 1 +#define MEMP_MEM_INIT 1 +#define MEM_LIBC_MALLOC 1 + +#endif /* LWIP_UBOOT_LWIPOPTS_H */ From patchwork Mon Jun 17 15:32:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804880 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611318wrr; Mon, 17 Jun 2024 08:34:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUa9mu91GqIJr8sIO3bfiABDNKa2pl9//fMs9Jb5np6sb6WPUfCFim8uvMr2H2+af4Ep6ukuRkUzMxYVqNIRvLW X-Google-Smtp-Source: AGHT+IFsrs0QL+FuU19QnJAXlFjvhjmp5gNZDkOw6Tk4SjqPUF/slyZTvSxl/8CHq8bF3O66Ygt4 X-Received: by 2002:a17:907:c209:b0:a6f:8696:98e6 with SMTP id a640c23a62f3a-a6f86969a58mr278114066b.25.1718638460666; Mon, 17 Jun 2024 08:34:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638460; cv=none; d=google.com; s=arc-20160816; b=B29QFTWNIJlBEpWnmi2nRpte59ItTcSkfhxlVNUHnerbKrSC4Nf29fGKvvmqoxxa2Y 3gD8qQgjyAQ9WklKRgxBm+Zbq1yypfb9XltKvFmMiFNpjagO6uicjvXpuql+HlMgqyzP VFxHDCCg1nBpIxAdtR2uAVXb7oiHDXElx+3W8Dta1b5/yg+7P6eH/XxEnQTUzDRaiVT7 ZSu6pgkanlZm8DpSJH7g62T40HGTd8n4OlVQXtXu9r0hVnBwUD4LqV6CjIgbqxxJX2Se om8akiD2nCo1K5lYY8zWBxcsUdRIWQPW2nZlCwUobHfnrZRh8aMj2YGhOyvKKvL3g0sN 8Krg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DgffOfhzfN11aJiGi57auQeHNFE++aK5yr2tVO39euQ=; fh=/g6j02FSWy0vVSWFJE90HlhdZ9dwkrOYfwYRl0wUWQA=; b=UbglSfdedVB/I0mVDOLsH9U9lUozut3Kdf+71H0My/UWc7cyu/B4AR8EYQkqaeOyg+ M0UV8y8s3ccC8OilAy9quTk6971+G5Dr68vMQZasPIz3fB7OQoPsRrvOembXN0hKF7x1 Ura3RMnAYivN5I8OesFAlcikgOjkyWe9FvPXhJCvfJSHs14NWur38FKKLWQxnn6eMOyU q9/DgJgb5bEFQV8CVNs/RozBEpWJkyfCwhDoLDBj2kGjB2XHHhy4EfD+B1nyeoSq2Wek VVw7HqRkRArByqLr1VdV6LWD0wX/ml52OmL/Jj2kdoUrn9Rf8sVS+/NZpGNd89ZEni1/ KnWg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EW91vjlZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56e3c8c1si464353466b.831.2024.06.17.08.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:34:20 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EW91vjlZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1FE0D883A4; Mon, 17 Jun 2024 17:33:44 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="EW91vjlZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EF83288398; Mon, 17 Jun 2024 17:33:42 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5BE688839F for ; Mon, 17 Jun 2024 17:33:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-422df2a81f2so32832585e9.0 for ; Mon, 17 Jun 2024 08:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638420; x=1719243220; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DgffOfhzfN11aJiGi57auQeHNFE++aK5yr2tVO39euQ=; b=EW91vjlZTyerQBezmrDqbbWsfXFdeHl0oCPfPgDbVseAfb/8x/Y52741EIbLA1NSKb 8a8R34AjnyDgRVpzYEA9slyomJe/0WDu24cTRPexE3uRiJIqL0FVPWWAOuToeM3QUUQD XSEo3Ap0cjbv+4lRxVggFT8cciQR4bQr9TKc0RyLlJcKIjp0eNTpa9LsFJFsA2FViw8z 0JE/0gDjlVPrHrRPdRg9Uuz7jl3B1KAL4Pzk9/UOuCraodtf3EAZG4TvtvvIGGqEN5Yn a5oLl2zv7R++iblCZc8EnfFWhHzcFDhkYZ99mplW0LTSr97pFsx9yh8iltWFttNpcNAF cYOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638420; x=1719243220; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DgffOfhzfN11aJiGi57auQeHNFE++aK5yr2tVO39euQ=; b=bod51pwnEpYnGKjge/7qa5aMnocTEdoKyM6tLEb+TwaKxIiBVQWp4CxM5rxvJ8AwMH ehm0zGZI4m0vEdGkPzhuWh6d4spTXaU9aA+eH3PuaHcWmTruDW8ZCYYESeQ99cqTvvJk PnOA602IH1pKNbweMFOkNg26N/5w8WHtHSynhqE4ZK5EYgFA+3AaAaRdEo0ghoG6AR1i 5w2OR2b0VvqfUFP59+vjLDYE1unU8Zj+a4FiRLPrJtAg/hTANGBX8oxBw4i2g/T4lWmt fm3uYEp54GDY498/3YeOUdCeNB5OshVJIoxXcXGUtmd4ic1rDOH8kVDSTw1Sba/3bXy+ q8gA== X-Gm-Message-State: AOJu0YzWZkaPpZ1l8wi9+R/8Dbkau6xu3ImWf/PsZN/tKd4iROrdCk1w yyZ2d6X6bV7EBjvxvK0NooJJuzaxVALQ5sHxS6a/5WAQgnj797OA288U4oCbdjgNL32KSdrBI3Z cRhA= X-Received: by 2002:a05:600c:c10:b0:421:d68a:e3f2 with SMTP id 5b1f17b1804b1-4230482fbfbmr75791835e9.23.1718638419541; Mon, 17 Jun 2024 08:33:39 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:39 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Joe Hershberger , Ramon Fried , Simon Glass , Andrew Davis , Sumit Garg , Marek Vasut , Heinrich Schuchardt , Bryan Brattlof , Jesse Taube , "Leon M. Busch-George" , Eddie James , Mattijs Korpershoek , AKASHI Takahiro , Francis Laniel , Peter Robinson , Abdellatif El Khlifi , Shiji Yang , Nikhil M Jain , Artur Rojek , Yang Xiwen , Yanhong Wang , Kever Yang , Boon Khai Ng , Neil Armstrong , Jonas Karlman Subject: [PATCH v4 05/14] net-lwip: add DHCP support and dhcp commmand Date: Mon, 17 Jun 2024 17:32:57 +0200 Message-Id: <1455663bf6d4f8537d3919b755ef5148b65975c5.1718638104.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add what it takes to enable NETDEVICES with NET_LWIP and enable DHCP as well as the dhcp command. CMD_TFTPBOOT is selected by BOOTMETH_EFI due to this code having an implicit dependency on do_tftpb(). Signed-off-by: Jerome Forissier --- Makefile | 6 + boot/Kconfig | 3 +- cmd/Kconfig | 26 ++++ cmd/Makefile | 4 + cmd/net-lwip.c | 13 ++ common/board_r.c | 4 +- drivers/net/Kconfig | 2 +- include/net-lwip.h | 2 + net-lwip/Makefile | 15 +++ net-lwip/dhcp.c | 99 +++++++++++++++ net-lwip/eth_internal.h | 35 ++++++ net-lwip/net-lwip.c | 270 ++++++++++++++++++++++++++++++++++++++++ net-lwip/tftp.c | 11 ++ 13 files changed, 486 insertions(+), 4 deletions(-) create mode 100644 cmd/net-lwip.c create mode 100644 net-lwip/Makefile create mode 100644 net-lwip/dhcp.c create mode 100644 net-lwip/eth_internal.h create mode 100644 net-lwip/net-lwip.c create mode 100644 net-lwip/tftp.c diff --git a/Makefile b/Makefile index 0fe1623c550..92a0ab770bb 100644 --- a/Makefile +++ b/Makefile @@ -862,6 +862,7 @@ libs-y += env/ libs-y += lib/ libs-y += fs/ libs-$(CONFIG_NET) += net/ +libs-$(CONFIG_NET_LWIP) += net-lwip/ libs-y += disk/ libs-y += drivers/ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/ @@ -2132,6 +2133,11 @@ etags: cscope: $(FIND) $(FINDFLAGS) $(TAG_SUBDIRS) -name '*.[chS]' -print > \ cscope.files +ifdef CONFIG_NET_LWIP + echo net/eth-uclass.c net/eth_common.c net/eth_bootdev.c \ + net/mdio-uclass.c net/mdio-mux-uclass.c >> \ + cscope.files +endif @find $(TAG_SUBDIRS) -name '*.[chS]' -type l -print | \ grep -xvf - cscope.files > cscope.files.no-symlinks; \ mv cscope.files.no-symlinks cscope.files diff --git a/boot/Kconfig b/boot/Kconfig index 6f3096c15a6..004e69dd92a 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -378,7 +378,7 @@ config BOOT_DEFAULTS_CMDS select CMD_FAT select CMD_FS_GENERIC select CMD_PART if PARTITIONS - select CMD_DHCP if CMD_NET + select CMD_DHCP if CMD_NET || CMD_NET_LWIP select CMD_PING if CMD_NET select CMD_PXE if CMD_NET select CMD_BOOTI if ARM64 @@ -540,6 +540,7 @@ config BOOTMETH_EXTLINUX_PXE config BOOTMETH_EFILOADER bool "Bootdev support for EFI boot" depends on EFI_BINARY_EXEC + select CMD_TFTPBOOT if CMD_NET_LWIP default y help Enables support for EFI boot using bootdevs. This makes the diff --git a/cmd/Kconfig b/cmd/Kconfig index b026439c773..1bfa528e945 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2084,6 +2084,32 @@ config CMD_WOL endif +if NET_LWIP + +menuconfig CMD_NET_LWIP + bool "Network commands (lwIP)" + default y + +if CMD_NET_LWIP + +config CMD_DHCP + bool "dhcp" + select PROT_DHCP_LWIP + help + Boot image via network using DHCP/TFTP protocol + +config CMD_TFTPBOOT + bool "tftp" + select PROT_UDP_LWIP + default n + help + tftpboot - load file via network using TFTP protocol + Currently a placeholder (not implemented) + +endif + +endif + menu "Misc commands" config CMD_2048 diff --git a/cmd/Makefile b/cmd/Makefile index 87133cc27a8..535b6838ca5 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -128,6 +128,10 @@ endif obj-$(CONFIG_CMD_MUX) += mux.o obj-$(CONFIG_CMD_NAND) += nand.o obj-$(CONFIG_CMD_NET) += net.o +obj-$(CONFIG_CMD_NET_LWIP) += net-lwip.o +ifdef CONFIG_CMD_NET_LWIP +CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot +endif obj-$(CONFIG_ENV_SUPPORT) += nvedit.o obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o obj-$(CONFIG_CMD_ONENAND) += onenand.o diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c new file mode 100644 index 00000000000..82edb5fd2e6 --- /dev/null +++ b/cmd/net-lwip.c @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include +#include + +#if defined(CONFIG_CMD_DHCP) +U_BOOT_CMD( + dhcp, 3, 1, do_dhcp, + "boot image via network using DHCP/TFTP protocol", + "[loadAddress] [[hostIPaddr:]bootfilename]" +); +#endif diff --git a/common/board_r.c b/common/board_r.c index da0b80f24ff..6548eb8fdd5 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -472,7 +472,7 @@ static int initr_status_led(void) } #endif -#ifdef CONFIG_CMD_NET +#if defined(CONFIG_CMD_NET) || defined(CONFIG_CMD_NET_LWIP) static int initr_net(void) { puts("Net: "); @@ -727,7 +727,7 @@ static init_fnc_t init_sequence_r[] = { #ifdef CONFIG_PCI_ENDPOINT pci_ep_init, #endif -#ifdef CONFIG_CMD_NET +#if defined(CONFIG_CMD_NET) || defined(CONFIG_CMD_NET_LWIP) INIT_FUNC_WATCHDOG_RESET initr_net, #endif diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index efc55e45ca8..640c4218518 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -97,7 +97,7 @@ config DSA_SANDBOX menuconfig NETDEVICES bool "Network device support" - depends on NET + depends on NET || NET_LWIP select DM_ETH help You must select Y to enable any network device support diff --git a/include/net-lwip.h b/include/net-lwip.h index f5c743b8d11..46cf6875f7e 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -11,4 +11,6 @@ struct netif *net_lwip_new_netif_noip(void); void net_lwip_remove_netif(struct netif *netif); struct netif *net_lwip_get_netif(void); +int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); + #endif /* __NET_LWIP_H__ */ diff --git a/net-lwip/Makefile b/net-lwip/Makefile new file mode 100644 index 00000000000..a56c32bfa74 --- /dev/null +++ b/net-lwip/Makefile @@ -0,0 +1,15 @@ +ccflags-y += -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot + +obj-$(CONFIG_$(SPL_TPL_)BOOTDEV_ETH) += ../net/eth_bootdev.o +obj-$(CONFIG_DM_MDIO) += ../net/mdio-uclass.o +obj-$(CONFIG_DM_MDIO_MUX) += ../net/mdio-mux-uclass.o +obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o +obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o +obj-$(CONFIG_$(SPL_)DM_ETH) += net-lwip.o +obj-$(CONFIG_CMD_DHCP) += dhcp.o +obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o + +# Disable this warning as it is triggered by: +# sprintf(buf, index ? "foo%d" : "foo", index) +# and this is intentional usage. +CFLAGS_eth_common.o += -Wno-format-extra-args diff --git a/net-lwip/dhcp.c b/net-lwip/dhcp.c new file mode 100644 index 00000000000..38ea565508f --- /dev/null +++ b/net-lwip/dhcp.c @@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DHCP_TIMEOUT_MS 10000 + +#ifdef CONFIG_CMD_TFTPBOOT +/* Boot file obtained from DHCP (if present) */ +static char boot_file_name[DHCP_BOOT_FILE_LEN]; +#endif + +static void call_lwip_dhcp_fine_tmr(void *ctx) +{ + dhcp_fine_tmr(); + sys_timeout(10, call_lwip_dhcp_fine_tmr, NULL); +} + +int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + unsigned long start; + struct netif *netif; + struct dhcp *dhcp; + bool bound; + + netif = net_lwip_new_netif_noip(); + if (!netif) + return CMD_RET_FAILURE; + + start = get_timer(0); + dhcp_start(netif); + call_lwip_dhcp_fine_tmr(NULL); + + /* Wait for DHCP to complete */ + do { + eth_rx(); + sys_check_timeouts(); + bound = dhcp_supplied_address(netif); + if (bound) + break; + if (ctrlc()) { + printf("Abort\n"); + break; + } + mdelay(1); + } while (get_timer(start) < DHCP_TIMEOUT_MS); + + sys_untimeout(call_lwip_dhcp_fine_tmr, NULL); + + if (!bound) { + net_lwip_remove_netif(netif); + return CMD_RET_FAILURE; + } + + dhcp = netif_dhcp_data(netif); + + env_set("bootfile", dhcp->boot_file_name); + if (dhcp->offered_gw_addr.addr != 0) + env_set("gatewayip", ip4addr_ntoa(&dhcp->offered_gw_addr)); + env_set("ipaddr", ip4addr_ntoa(&dhcp->offered_ip_addr)); + env_set("netmask", ip4addr_ntoa(&dhcp->offered_sn_mask)); + env_set("serverip", ip4addr_ntoa(&dhcp->server_ip_addr)); +#ifdef CONFIG_PROT_DNS_LWIP + env_set("dnsip", ip4addr_ntoa(dns_getserver(0))); + env_set("dnsip2", ip4addr_ntoa(dns_getserver(1))); +#endif +#ifdef CONFIG_CMD_TFTPBOOT + if (dhcp->boot_file_name[0] != '\0') + strncpy(boot_file_name, dhcp->boot_file_name, + sizeof(boot_file_name)); +#endif + + printf("DHCP client bound to address %pI4 (%lu ms)\n", + &dhcp->offered_ip_addr, get_timer(start)); + + net_lwip_remove_netif(netif); + return CMD_RET_SUCCESS; +} + +int dhcp_run(ulong addr, const char *fname, bool autoload) +{ + char *dhcp_argv[] = {"dhcp", NULL, }; + struct cmd_tbl cmdtp = {}; /* dummy */ + + if (autoload) { + /* Will be supported when TFTP is added */ + return -EOPNOTSUPP; + } + + return do_dhcp(&cmdtp, 0, 1, dhcp_argv); +} diff --git a/net-lwip/eth_internal.h b/net-lwip/eth_internal.h new file mode 100644 index 00000000000..0b829a8d388 --- /dev/null +++ b/net-lwip/eth_internal.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * (C) Copyright 2001-2015 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + * Joe Hershberger, National Instruments + */ + +#ifndef __ETH_INTERNAL_H +#define __ETH_INTERNAL_H + +/* Do init that is common to driver model and legacy networking */ +void eth_common_init(void); + +/** + * eth_env_set_enetaddr_by_index() - set the MAC address environment variable + * + * This sets up an environment variable with the given MAC address (@enetaddr). + * The environment variable to be set is defined by <@base_name><@index>addr. + * If @index is 0 it is omitted. For common Ethernet this means ethaddr, + * eth1addr, etc. + * + * @base_name: Base name for variable, typically "eth" + * @index: Index of interface being updated (>=0) + * @enetaddr: Pointer to MAC address to put into the variable + * Return: 0 if OK, other value on error + */ +int eth_env_set_enetaddr_by_index(const char *base_name, int index, + uchar *enetaddr); + +int eth_mac_skip(int index); +void eth_current_changed(void); +void eth_set_dev(struct udevice *dev); +void eth_set_current_to_next(void); + +#endif diff --git a/net-lwip/net-lwip.c b/net-lwip/net-lwip.c new file mode 100644 index 00000000000..39e7e51e542 --- /dev/null +++ b/net-lwip/net-lwip.c @@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* Copyright (C) 2024 Linaro Ltd. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* xx:xx:xx:xx:xx:xx\0 */ +#define MAC_ADDR_STRLEN 18 + +#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) +void (*push_packet)(void *, int len) = 0; +#endif +int net_restart_wrap; +static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN]; +uchar *net_rx_packets[PKTBUFSRX]; +uchar *net_rx_packet; +uchar *net_tx_packet; + +static err_t low_level_output(struct netif *netif, struct pbuf *p) +{ + int err; + + /* + * lwIP is alwys configured to use one device, the active one, so + * there is no need to use the netif parameter. + */ + + /* switch dev to active state */ + eth_init_state_only(); + + err = eth_send(p->payload, p->len); + if (err) { + log_err("eth_send error %d\n", err); + return ERR_ABRT; + } + return ERR_OK; +} + +static err_t net_lwip_if_init(struct netif *netif) +{ +#if LWIP_IPV4 + netif->output = etharp_output; +#endif + netif->linkoutput = low_level_output; + netif->mtu = 1500; + netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; + + return ERR_OK; +} + +static void eth_init_rings(void) +{ + static bool called; + int i; + + if (called) + return; + called = true; + + net_tx_packet = &net_pkt_buf[0] + (PKTALIGN - 1); + net_tx_packet -= (ulong)net_tx_packet % PKTALIGN; + for (i = 0; i < PKTBUFSRX; i++) + net_rx_packets[i] = net_tx_packet + (i + 1) * PKTSIZE_ALIGN; +} + +struct netif *net_lwip_get_netif(void) +{ + struct netif *netif, *found = NULL; + + NETIF_FOREACH(netif) { + if (!found) + found = netif; + else + printf("Error: more than one netif in lwIP\n"); + } + return found; +} + +static int get_udev_ipv4_info(struct udevice *dev, ip4_addr_t *ip, + ip4_addr_t *mask, ip4_addr_t *gw) +{ + char ipstr[9] = { 'i', 'p', 'a' , 'd', 'd', 'r', }; + char maskstr[10] = { 'n', 'e', 't', 'm', 'a', 's', 'k', }; + char gwstr[12] = { 'g', 'a', 't', 'e', 'w', 'a', 'y', 'i', 'p', }; + char *env; + int ret; + + if (dev_seq(dev) > 0) { + ret = snprintf(ipstr, sizeof(ipstr), "ipaddr%d", dev_seq(dev)); + if (ret < 0 || ret >= sizeof(ipstr)) + return -1; + snprintf(maskstr, sizeof(maskstr), "netmask%d", dev_seq(dev)); + if (ret < 0 || ret >= sizeof(maskstr)) + return -1; + snprintf(gwstr, sizeof(gwstr), "gw%d", dev_seq(dev)); + if (ret < 0 || ret >= sizeof(gwstr)) + return -1; + } + + ip4_addr_set_zero(ip); + ip4_addr_set_zero(mask); + ip4_addr_set_zero(gw); + + env = env_get(ipstr); + if (env) + ipaddr_aton(env, ip); + + env = env_get(maskstr); + if (env) + ipaddr_aton(env, mask); + + env = env_get(gwstr); + if (env) + ipaddr_aton(env, gw); + + return 0; +} + +static struct netif *new_netif(bool with_ip) +{ + unsigned char enetaddr[ARP_HLEN]; + char hwstr[MAC_ADDR_STRLEN]; + ip4_addr_t ip, mask, gw; + struct udevice *dev; + struct netif *netif; + int ret; + static bool first_call = true; + + eth_init_rings(); + + if (first_call) { + if (eth_init()) { + printf("eth_init() error\n"); + return NULL; + } + first_call = false; + } + + netif_remove(net_lwip_get_netif()); + + eth_set_current(); + + dev = eth_get_dev(); + if (!dev) + return NULL; + + ip4_addr_set_zero(&ip); + ip4_addr_set_zero(&mask); + ip4_addr_set_zero(&gw); + + if (with_ip) + if (get_udev_ipv4_info(dev, &ip, &mask, &gw) < 0) + return NULL; + + eth_env_get_enetaddr_by_index("eth", dev_seq(dev), enetaddr); + ret = snprintf(hwstr, MAC_ADDR_STRLEN, "%pM", enetaddr); + if (ret < 0 || ret >= MAC_ADDR_STRLEN) + return NULL; + + netif = calloc(1, sizeof(struct netif)); + if (!netif) + return NULL; + + netif->name[0] = 'e'; + netif->name[1] = 't'; + + string_to_enetaddr(hwstr, netif->hwaddr); + netif->hwaddr_len = ETHARP_HWADDR_LEN; + + if (!netif_add(netif, &ip, &mask, &gw, netif, net_lwip_if_init, + netif_input)) { + printf("error: netif_add() failed\n"); + free(netif); + return NULL; + } + + netif_set_up(netif); + netif_set_link_up(netif); + /* Routing: use this interface to reach the default gateway */ + netif_set_default(netif); + + return netif; +} + +/* Configure lwIP to use the currently active network device */ +struct netif *net_lwip_new_netif() +{ + return new_netif(true); +} + +struct netif *net_lwip_new_netif_noip() +{ + + return new_netif(false); +} + +void net_lwip_remove_netif(struct netif *netif) +{ + netif_remove(netif); + free(netif); +} + +int net_init(void) +{ + net_lwip_new_netif(); + + return 0; +} + +static struct pbuf *alloc_pbuf_and_copy(uchar *data, int len) +{ + struct pbuf *p, *q; + + /* We allocate a pbuf chain of pbufs from the pool. */ + p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); + if (!p) { + LINK_STATS_INC(link.memerr); + LINK_STATS_INC(link.drop); + return NULL; + } + + for (q = p; q != NULL; q = q->next) { + memcpy(q->payload, data, q->len); + data += q->len; + } + + LINK_STATS_INC(link.recv); + + return p; +} + +void net_process_received_packet(uchar *in_packet, int len) +{ + struct netif *netif; + struct pbuf *pbuf; + + if (len < ETHER_HDR_SIZE) + return; + +#if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER) + if (push_packet) { + (*push_packet)(in_packet, len); + return; + } +#endif + + netif = net_lwip_get_netif(); + if (!netif) + return; + + pbuf = alloc_pbuf_and_copy(in_packet, len); + if (!pbuf) + return; + + netif->input(pbuf, netif); +} + +u32_t sys_now(void) +{ + return get_timer(0); +} diff --git a/net-lwip/tftp.c b/net-lwip/tftp.c new file mode 100644 index 00000000000..1fa246f55d9 --- /dev/null +++ b/net-lwip/tftp.c @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include +#include + +int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + /* Not implemented */ + return CMD_RET_FAILURE; +} From patchwork Mon Jun 17 15:32:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804881 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611400wrr; Mon, 17 Jun 2024 08:34:31 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU0tM5cjQ1c08TH3PEy6rpvCI6StL0d2vSZuJ25nn0/gpYplpHN494F9nNUgLqfEx3uB65rv8HuTYC4zHi+kco4 X-Google-Smtp-Source: AGHT+IGGre9GrG10FKKl2bEceMcSd+uR8rtxxR5ynXf2vZAKUUQpS6TOBDmykOKEmeD61rUUvbFz X-Received: by 2002:a17:906:2988:b0:a6f:6078:6e6e with SMTP id a640c23a62f3a-a6f60d42787mr588730666b.46.1718638471658; Mon, 17 Jun 2024 08:34:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638471; cv=none; d=google.com; s=arc-20160816; b=zTAxxO7tGvo63VfqEOb7LH7j9yIxrPd7Zxm7ptX4k85U+tkc7iJJQHfWNdh/rTP37p reGl21rSlWpLwuVzBNcq/6kuYirwLvrQYFCpSq4plPbchTv4eRFMcRDjcO3D4opbfHc9 MYsYIyDy50sE0rmK203Na1LzbhiJQIlNY/mgqY3r/5wg2Q1oeL//IQNgldXhOPEdnp+K KKsDO4SKXynhZJMIUDJjFrb9+6i4AF316OkOYWIC1NX8hDeOV79CRURZUDN/uXhJ1hKR 1VpURMux8qdMrTPXQ1loJsuwMgeat5ZKS97DX//iBTXqVzKv61iVVivs+0iGEFHz6UHR j6KQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=87Jpm45kzVS5H2Yenyow8XXD5OE3qOF3CkCP62vN/2s=; fh=y2nlSdy1rqA5NrxJUQRURuS/z+wpts0xge8v0NIVeLA=; b=gZciNn4H383WLKAFLmEpVaq9SCC40X3QNkQ+z4NeGEZGxXFPhPM8V4kgRuCg0RsM5Z iAcg3yYIYG++hmgEmdkkw3Ix82xYmHUKCBV6YvdSs7pmI+2pRLM+IbfFDBEO2Rp/OLJv fOdxC6Vbiw2n7i1JgrFE/R5rnIJWMOzOeUI32wAP4t+cIFao1L9s67/+1PNjRFeuy1YN DbbD4raJEghYHrVGWZP5sgkfPrmjUAZD9EQkB+eqDJkP9BqXAGHH1rKWKA/xK1JjdYWh TOuc12AS017n8cgOnQZoXALeMgA61lBykESLJIuJSRMiaeqchnAm0hRHzA8ROFIOfcvN A8YQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=csic0GLB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56df768fsi453138566b.560.2024.06.17.08.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:34:31 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=csic0GLB; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 801DF88378; Mon, 17 Jun 2024 17:33:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="csic0GLB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 399A887CDA; Mon, 17 Jun 2024 17:33:44 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id DAE2D880F5 for ; Mon, 17 Jun 2024 17:33:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-42138eadf64so36131285e9.3 for ; Mon, 17 Jun 2024 08:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638421; x=1719243221; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=87Jpm45kzVS5H2Yenyow8XXD5OE3qOF3CkCP62vN/2s=; b=csic0GLBf7zHiAWfVmA1T/OpXVuJqtjrOPUWsv0NVdu+DT1tEbk0IiJ/79pNUJ92gT aUdwyD4cb2LxWkqHsVpV7K7GApiLGNmcHn33b8Z1Urk1HSovEurNQqbYpzkGG8FtDP4R hFQdj0Y/rG6z1g7YOev4JiPBhbO0ZPX5SXGNO6FXOO7BRSetO2ki+X5v4y/FnwAzzUQ1 UWbInQ4o6qiO5aftifTvFg78+r4Z4OCkJTVtJdf5btdTaTiJ06D9wsTcxAIOCSRsaO5R VJnBtKiHAp7qzwBvMWTohdeK5P8MmN4JII2IP7yLAf+anyTpmTYkjSdV6o8hxczguu6a +34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638421; x=1719243221; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=87Jpm45kzVS5H2Yenyow8XXD5OE3qOF3CkCP62vN/2s=; b=mu/1M8Rbps+Psa21bawtqekMhH3fjPAQKrZtZoBFvBM9xXQQDBkjzt8EA1a8w40aaO +iJnMe8QZzECWk3QVgxhJ/BWu8VPRqZF7TQI7aWVECIV+i9/y3Po1M/iKUWSQLPnbN2N iQdUDpeGJdGMZS4LSOlhpIHTn5IBTM84z0HetAHG8AvKIE6LRfi62jZ2aPcS1pjB8Jrj R4+Ux8i665/Zy+lqg2DZoKS2eqkmwXCdVkK1povBV38bfGCLXSiaLc7fSwmnfkhueaC2 gDS7DoMejfrOokoZ5kQtSFAPCSRu3MC7KJhDViWNwg5WqTVOnLKjBaYlJegwenaOBA8f oRyg== X-Gm-Message-State: AOJu0YyStAp+xhfDC+d7d1ahExy/BNl76Bv/BU18xHGBwWsjDpvo+vtA oQjUTaJ657H5sW1FoRfVpHy7sulZNRMlsy4j0GuBpR/+lyP7ABBtQ1SczKujwoyzBgEhvKd0a7T 8GsE= X-Received: by 2002:a05:600c:a03:b0:422:9c91:a26f with SMTP id 5b1f17b1804b1-4230482c20fmr79025625e9.19.1718638421156; Mon, 17 Jun 2024 08:33:41 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:40 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Mattijs Korpershoek , AKASHI Takahiro , Francis Laniel , Peter Robinson Subject: [PATCH v4 06/14] net-lwip: add TFTP support and tftpboot command Date: Mon, 17 Jun 2024 17:32:58 +0200 Message-Id: <951df32b91d392899208d7fc841b161fa78ed33b.1718638104.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Implement do_tftpb(). Signed-off-by: Jerome Forissier --- cmd/Kconfig | 3 +- cmd/net-lwip.c | 8 ++ net-lwip/dhcp.c | 11 ++- net-lwip/tftp.c | 221 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 237 insertions(+), 6 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 1bfa528e945..94a8de266f6 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2101,10 +2101,9 @@ config CMD_DHCP config CMD_TFTPBOOT bool "tftp" select PROT_UDP_LWIP - default n + default y help tftpboot - load file via network using TFTP protocol - Currently a placeholder (not implemented) endif diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c index 82edb5fd2e6..80f0872bb8f 100644 --- a/cmd/net-lwip.c +++ b/cmd/net-lwip.c @@ -11,3 +11,11 @@ U_BOOT_CMD( "[loadAddress] [[hostIPaddr:]bootfilename]" ); #endif + +#if defined(CONFIG_CMD_TFTPBOOT) +U_BOOT_CMD( + tftpboot, 3, 0, do_tftpb, + "boot image via network using TFTP protocol\n", + "[loadAddress] [[hostIPaddr:]bootfilename]" +); +#endif diff --git a/net-lwip/dhcp.c b/net-lwip/dhcp.c index 38ea565508f..af8ac214e81 100644 --- a/net-lwip/dhcp.c +++ b/net-lwip/dhcp.c @@ -88,11 +88,20 @@ int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) int dhcp_run(ulong addr, const char *fname, bool autoload) { char *dhcp_argv[] = {"dhcp", NULL, }; +#ifdef CONFIG_CMD_TFTPBOOT + char *tftp_argv[] = {"tftpboot", boot_file_name, NULL, }; +#endif struct cmd_tbl cmdtp = {}; /* dummy */ if (autoload) { - /* Will be supported when TFTP is added */ +#ifdef CONFIG_CMD_TFTPBOOT + /* Assume DHCP was already performed */ + if (boot_file_name[0]) + return do_tftpb(&cmdtp, 0, 2, tftp_argv); + return 0; +#else return -EOPNOTSUPP; +#endif } return do_dhcp(&cmdtp, 0, 1, dhcp_argv); diff --git a/net-lwip/tftp.c b/net-lwip/tftp.c index 1fa246f55d9..295c8a7ebf2 100644 --- a/net-lwip/tftp.c +++ b/net-lwip/tftp.c @@ -2,10 +2,225 @@ /* Copyright (C) 2024 Linaro Ltd. */ #include -#include +#include +#include +#include +#include +#include +#include +#include + +#define PROGRESS_PRINT_STEP_BYTES (100 * 1024) + +enum done_state { + NOT_DONE = 0, + SUCCESS = 1, + FAILURE = 2 +}; + +struct tftp_ctx { + ulong daddr; + ulong size; + ulong prevsize; + ulong start_time; + enum done_state done; +}; + +static void *tftp_open(const char *fname, const char *mode, u8_t is_write) +{ + return NULL; +} + +static void tftp_close(void *handle) +{ + struct tftp_ctx *ctx = handle; + ulong elapsed; + + if (ctx->done == FAILURE) { + /* Closing after an error */ + return; + } + + elapsed = get_timer(ctx->start_time); + ctx->done = SUCCESS; + printf("\nBytes transferred = %lu (%lx hex)\n", ctx->size, ctx->size); + + if (env_set_hex("filesize", ctx->size)) { + log_err("filesize not updated\n"); + return; + } +} + +static int tftp_read(void *handle, void *buf, int bytes) +{ + return 0; +} + +static int tftp_write(void *handle, struct pbuf *p) +{ + struct tftp_ctx *ctx = handle; + struct pbuf *q; + + for (q = p; q != NULL; q = q->next) { + memcpy((void *)ctx->daddr, q->payload, q->len); + ctx->daddr += q->len; + ctx->size += q->len; + if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + printf("#"); + ctx->prevsize = ctx->size; + } + } + + return 0; +} + +static void tftp_error(void *handle, int err, const char *msg, int size) +{ + struct tftp_ctx *ctx = handle; + char message[100]; + + ctx->done = FAILURE; + memset(message, 0, sizeof(message)); + memcpy(message, msg, LWIP_MIN(sizeof(message) - 1, (size_t)size)); + + printf("\nTFTP error: %d (%s)\n", err, message); +} + +static const struct tftp_context tftp_context = { + tftp_open, + tftp_close, + tftp_read, + tftp_write, + tftp_error +}; + +static int tftp_run(ulong addr, char *fname, ip_addr_t srvip) +{ + struct netif *netif; + struct tftp_ctx ctx; + err_t err; + + if (!fname || addr == 0) + return -1; + + netif = net_lwip_new_netif(); + if (!netif) + return -1; + + ctx.done = NOT_DONE; + ctx.size = 0; + ctx.prevsize = 0; + ctx.daddr = addr; + + printf("Using %s device\n", eth_get_name()); + printf("TFTP from server %s; our IP address is %s\n", + ip4addr_ntoa(&srvip), env_get("ipaddr")); + printf("Filename '%s'.\n", fname); + printf("Load address: 0x%lx\n", ctx.daddr); + printf("Loading: "); + + err = tftp_init_client(&tftp_context); + if (!(err == ERR_OK || err == ERR_USE)) + log_err("tftp_init_client err: %d\n", err); + + ctx.start_time = get_timer(0); + err = tftp_get(&ctx, &srvip, TFTP_PORT, fname, TFTP_MODE_OCTET); + /* might return different errors, like routing problems */ + if (err != ERR_OK) { + printf("tftp_get() error %d\n", err); + net_lwip_remove_netif(netif); + return -1; + } + + while (!ctx.done) { + eth_rx(); + sys_check_timeouts(); + if (ctrlc()) + break; + } + + tftp_cleanup(); + + net_lwip_remove_netif(netif); + + if (ctx.done == SUCCESS) { + if (env_set_hex("fileaddr", addr)) { + log_err("fileaddr not updated\n"); + return -1; + } + return 0; + } + + return -1; +} int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - /* Not implemented */ - return CMD_RET_FAILURE; + char *fname; + char *server_ip; + ip_addr_t srvip; + ulong addr; + char *end; + char *col; + + image_load_addr = env_get_ulong("loadaddr", 16, image_load_addr); + + switch (argc) { + case 1: + fname = env_get("bootfile"); + break; + case 2: + /* + * Only one arg - accept two forms: + * Just load address, or just boot file name. The latter + * form must be written in a format which can not be + * mis-interpreted as a valid number. + */ + addr = hextoul(argv[1], &end); + if (end == (argv[1] + strlen(argv[1]))) { + image_load_addr = addr; + fname = env_get("bootfile"); + } else { + fname = argv[1]; + } + break; + case 3: + image_load_addr = hextoul(argv[1], NULL); + fname = argv[2]; + break; + default: + return CMD_RET_USAGE; + } + + col = strchr(fname, ':'); + if (col) { + server_ip = fname; + *col = '\0'; + fname = col + 1; + } else { + server_ip = env_get("serverip"); + if (!server_ip) { + log_err("error: serverip variable has to be set\n"); + return CMD_RET_FAILURE; + } + } + if (!ipaddr_aton(server_ip, &srvip)) { + log_err("error: ipaddr_aton\n"); + return CMD_RET_FAILURE; + } + + if (!fname) { + log_err("error: no file name\n"); + return CMD_RET_FAILURE; + } + + if (!image_load_addr) { + log_err("error: no load address\n"); + return CMD_RET_FAILURE; + } + + if (tftp_run(image_load_addr, fname, srvip) < 0) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; } From patchwork Mon Jun 17 15:32:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804882 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611474wrr; Mon, 17 Jun 2024 08:34:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUQ3QFsAcGCiIOUlvUMIHSqxTCH6bGfsYG+jos12RZCrW8IC1fPthdNY21Oah+g6tosrX9EGiBMW14ObZ2XPEuN X-Google-Smtp-Source: AGHT+IEjondPnmA+ubeGL3QaS11x1MTFLHU7z1uwL2eLAJebrpF2IIEO3yC0buyDObBK72vgDsO8 X-Received: by 2002:a19:e014:0:b0:52c:98b1:36d9 with SMTP id 2adb3069b0e04-52ca6e9da28mr7252112e87.62.1718638482034; Mon, 17 Jun 2024 08:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638482; cv=none; d=google.com; s=arc-20160816; b=oeuRfgVt62irf9mvkAeRfiJIj3SbthS6bbHoJqbsl0qogfRdwJvfI/p1WAsWlFTXkL qPNLC6R3Zlrnif01ybI/RBgVargQDCs04dCQRy3F3qMcY2Cxd++W6U9/dA45QMT/gIVR zSn9fxZdLaOZQmLf1iKsQpKlYYBnR9rlNFkXUbirbALL7izgdfUyLbxRsePunoVFxBZV hxDa0BJCwZc4C4+UNP08tCcHsYolqoC2DHQ9C6spaIeN+HbRaX9HIpP/fwoeMLW7zQTf Q3WZ9zyjVXCwUDnaOMRntvS1cMM+GNg78cDOy4cTfz0FmaaLgogEGuyTpyhi4RGzcCVm Zf4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ba6V2jwrSohqfhLWHSsiGktUyB3OyaTdQBVDttl3Kfg=; fh=7uPs/cguLYnM12fXj44p32RH3Z+fhJ+3gQe5lH8zA1w=; b=QWd6EsdVfUrMfhLtThwE1Hn0wK/xkRl+VE0R1RmXKM70qdqUq9WS7PXSSS5uMrwjn9 k/43p/6xYXD2LLCB+pCmQ1u9igTClngcB0Bi9umLLdUl9Vl6e/woew7i0BCDutkPtPK/ S0zyyKgxJw0gZzrSBJFF9XFq727d/QqJao+goRUEuPqF9YVSulB3Wax1BiH5D4B6Y4Yv ijOqqpAJ1EccTmXNjm8U4SQNkGI5V4g28SwkSEmX/4ihfy045G6iCUTLe9oVkCwYgz4M dBVrhiwVA7vZUBQflS9Qhmfa112+m+QeY6rD9LEZiK0CwD1DOXmleTsmkXYZynt9h1Mr Sl4Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GA+DKmOz; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56d4bbc8si439108566b.225.2024.06.17.08.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:34:42 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GA+DKmOz; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DDA108839A; Mon, 17 Jun 2024 17:33:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="GA+DKmOz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 053D8883B3; Mon, 17 Jun 2024 17:33:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D398988398 for ; Mon, 17 Jun 2024 17:33:43 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4230366ad7bso39004225e9.1 for ; Mon, 17 Jun 2024 08:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638423; x=1719243223; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ba6V2jwrSohqfhLWHSsiGktUyB3OyaTdQBVDttl3Kfg=; b=GA+DKmOzhq5DBvvQ1oZ8HmlYfFTf9Wt1zrxjhsKiKNNCSPFbXrxCSXvC431LOMv29b LFW45XvN3S8mzQEvl7GQK7pCdVfuFG4oqDU5UzFO3AwUDkz7ajghTT15Xi3ei6uXmuGU dDX9mI5g9+/LxQYciahzE2q1znZzd7BpE6ja7ZUFc8eATcBaOE6f/yiKlHsEO4DZiG76 zO7LqEdy+9cW901OYrz7HKHVbjx/ykv/Jxp8af72kmh9NSlROR8coV1EkB18ByM2F5C6 47sQEGfV9YFQAOi6qHa7mWlQ7xWxgz4dOokAIjCHjT+e02IRrALjXb5gPnYv+2Q6wZAQ udBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638423; x=1719243223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ba6V2jwrSohqfhLWHSsiGktUyB3OyaTdQBVDttl3Kfg=; b=uL1AgrlWFpVd3bahcmpQejKzBTfUG0hdijxxbBXFgi3z6tgjANAy+yeW857enFEpm4 /tY95078X/jlF3Rg+fDW+WAjWmQgG4l8ptpcmbWvesRO1W1IYkMCU9ZOxT9Qh8cbuuDK HqZUR+jFO/GcEL/nwJLZtu9FILucRXM6s6xWroBpLZfa6nuCoBwXAQnYdpLPgFT/8IOo K0XjwYpe+5F51klnDuVreQzIcYikNnpuTU1S8MZYVsvFnkkd6G2w7R7LwtP241Lkf9KH HA+8ikUQH/V34OFqqFSzxyV3GxkMnw9xcBjjx09wKf2d6hqccnvoyZmhPN3ZdbJnS1gX cT9w== X-Gm-Message-State: AOJu0YzNXmXkhb1eRVVjh9gWVMTv9SH/UlsP9VoQVlFGDHpkVpTJrNW2 8ESM+sdI563QmK/eHx6G2KmYMlwoLi8ujSw1GfmM5cmSoDNWG3J5H05QamTIt1iwPxFkBKv46rM QDHc= X-Received: by 2002:a05:600c:4fd6:b0:422:fb9a:90b3 with SMTP id 5b1f17b1804b1-42304844aaemr121686085e9.32.1718638423168; Mon, 17 Jun 2024 08:33:43 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:42 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Eddie James , Mattijs Korpershoek , AKASHI Takahiro , Francis Laniel , Peter Robinson Subject: [PATCH v4 07/14] net-lwip: add ping command Date: Mon, 17 Jun 2024 17:32:59 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add support for the the ping command with NET_LWIP. The implementation is derived from lwIP's contrib/apps/ping/ping.c. Signed-off-by: Jerome Forissier --- boot/Kconfig | 2 +- cmd/Kconfig | 6 ++ cmd/net-lwip.c | 8 +++ include/net-lwip.h | 1 + net-lwip/Makefile | 1 + net-lwip/ping.c | 174 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 net-lwip/ping.c diff --git a/boot/Kconfig b/boot/Kconfig index 004e69dd92a..983a284ec52 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -379,7 +379,7 @@ config BOOT_DEFAULTS_CMDS select CMD_FS_GENERIC select CMD_PART if PARTITIONS select CMD_DHCP if CMD_NET || CMD_NET_LWIP - select CMD_PING if CMD_NET + select CMD_PING if CMD_NET || CMD_NET_LWIP select CMD_PXE if CMD_NET select CMD_BOOTI if ARM64 select CMD_BOOTZ if ARM && !ARM64 diff --git a/cmd/Kconfig b/cmd/Kconfig index 94a8de266f6..07cfe824e3f 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2098,6 +2098,12 @@ config CMD_DHCP help Boot image via network using DHCP/TFTP protocol +config CMD_PING + bool "ping" + select PROT_RAW_LWIP + help + Send ICMP ECHO_REQUEST to network host + config CMD_TFTPBOOT bool "tftp" select PROT_UDP_LWIP diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c index 80f0872bb8f..feed719beef 100644 --- a/cmd/net-lwip.c +++ b/cmd/net-lwip.c @@ -12,6 +12,14 @@ U_BOOT_CMD( ); #endif +#if defined(CONFIG_CMD_PING) +U_BOOT_CMD( + ping, 2, 1, do_ping, + "send ICMP ECHO_REQUEST to network host", + "pingAddress" +); +#endif + #if defined(CONFIG_CMD_TFTPBOOT) U_BOOT_CMD( tftpboot, 3, 0, do_tftpb, diff --git a/include/net-lwip.h b/include/net-lwip.h index 46cf6875f7e..b34f53b4891 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -12,5 +12,6 @@ void net_lwip_remove_netif(struct netif *netif); struct netif *net_lwip_get_netif(void); int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); #endif /* __NET_LWIP_H__ */ diff --git a/net-lwip/Makefile b/net-lwip/Makefile index a56c32bfa74..e68d4e24197 100644 --- a/net-lwip/Makefile +++ b/net-lwip/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o obj-$(CONFIG_$(SPL_)DM_ETH) += net-lwip.o obj-$(CONFIG_CMD_DHCP) += dhcp.o +obj-$(CONFIG_CMD_PING) += ping.o obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o # Disable this warning as it is triggered by: diff --git a/net-lwip/ping.c b/net-lwip/ping.c new file mode 100644 index 00000000000..de0b633dc32 --- /dev/null +++ b/net-lwip/ping.c @@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PING_DELAY_MS 1000 +#define PING_COUNT 5 +/* Ping identifier - must fit on a u16_t */ +#define PING_ID 0xAFAF + +struct ping_ctx { + ip_addr_t target; + struct raw_pcb *pcb; + struct icmp_echo_hdr *iecho; + uint16_t seq_num; + bool alive; +}; + +static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, + const ip_addr_t *addr) +{ + struct ping_ctx *ctx = arg; + struct icmp_echo_hdr *iecho = ctx->iecho; + + if (addr->addr != ctx->target.addr) + return 0; + + if ((p->tot_len >= (IP_HLEN + sizeof(struct icmp_echo_hdr))) && + pbuf_remove_header(p, IP_HLEN) == 0) { + iecho = (struct icmp_echo_hdr *)p->payload; + + if ((iecho->id == PING_ID) && + (iecho->seqno == lwip_htons(ctx->seq_num))) { + ctx->alive = true; + printf("host %s is alive\n", ipaddr_ntoa(addr)); + pbuf_free(p); + return 1; /* eat the packet */ + } + /* not eaten, restore original packet */ + pbuf_add_header(p, IP_HLEN); + } + + return 0; /* don't eat the packet */ +} + +static int ping_raw_init(struct ping_ctx *ctx) +{ + ctx->pcb = raw_new(IP_PROTO_ICMP); + if (!ctx->pcb) + return -ENOMEM; + + raw_recv(ctx->pcb, ping_recv, ctx); + raw_bind(ctx->pcb, IP_ADDR_ANY); + + return 0; +} + +static void ping_raw_stop(struct ping_ctx *ctx) +{ + if (ctx->pcb) + raw_remove(ctx->pcb); +} + +static void ping_prepare_echo(struct ping_ctx *ctx) +{ + struct icmp_echo_hdr *iecho = ctx->iecho; + + ICMPH_TYPE_SET(iecho, ICMP_ECHO); + ICMPH_CODE_SET(iecho, 0); + iecho->chksum = 0; + iecho->id = PING_ID; + iecho->seqno = lwip_htons(ctx->seq_num); + + iecho->chksum = inet_chksum(iecho, sizeof(*iecho)); +} + +static void ping_send_icmp(struct ping_ctx *ctx) +{ + struct pbuf *p; + size_t ping_size = sizeof(struct icmp_echo_hdr); + + p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM); + if (!p) + return; + + if ((p->len == p->tot_len) && !p->next) { + ctx->iecho = (struct icmp_echo_hdr *)p->payload; + ping_prepare_echo(ctx); + raw_sendto(ctx->pcb, p, &ctx->target); + } + + pbuf_free(p); +} + +static void _ping_send(void *arg) +{ + struct ping_ctx *ctx = arg; + + ctx->seq_num++; + if (ctx->seq_num <= PING_COUNT) { + ping_send_icmp(ctx); + sys_timeout(PING_DELAY_MS, _ping_send, ctx); + } +} + +int ping_send(const ip_addr_t* addr) +{ + struct ping_ctx ctx = {}; + struct netif *netif; + int ret; + + netif = net_lwip_new_netif(); + if (!netif) + return CMD_RET_FAILURE; + + printf("Using %s device\n", eth_get_name()); + + ret = ping_raw_init(&ctx); + if (ret < 0) { + net_lwip_remove_netif(netif); + return ret; + } + + ctx.target = *addr; + + _ping_send(&ctx); + + do { + sys_check_timeouts(); + eth_rx(); + if (ctx.alive) + break; + if (ctrlc()) { + printf("\nAbort\n"); + break; + } + } while (ctx.seq_num <= PING_COUNT); + + sys_untimeout(_ping_send, &ctx); + ping_raw_stop(&ctx); + + net_lwip_remove_netif(netif); + + if (ctx.alive) + return 0; + + printf("ping failed; host %s is not alive\n", ipaddr_ntoa(addr)); + return -1; +} + +int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + ip_addr_t addr; + + if (argc < 2) + return CMD_RET_USAGE; + + if (!ipaddr_aton(argv[1], &addr)) + return CMD_RET_USAGE; + + if (ping_send(&addr) < 0) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} From patchwork Mon Jun 17 15:33:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804883 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611611wrr; Mon, 17 Jun 2024 08:35:00 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCW29MK6oiDYgfVZIPfGshyuhBv2GeIM4iPRZddyE9VNn+VwO/U/ZwyAAvEuWPT+LHH+FrrUYjn6jjOLEddRtzyV X-Google-Smtp-Source: AGHT+IGsPhPOng/vYVMq/Kwwur3W/WF3eNqmrb+q+/HwsUSlag806xSlVSF685H4sBabGEaZKwYm X-Received: by 2002:a50:8d45:0:b0:57c:6ba4:3d8a with SMTP id 4fb4d7f45d1cf-57cbd66341fmr6326978a12.10.1718638499867; Mon, 17 Jun 2024 08:34:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638499; cv=none; d=google.com; s=arc-20160816; b=Vn5T2dQPpW1t7iYgVIiX6smTyrz1ad9c9uAb90e2dbfHZiiDbNGa2QHyucCAa4cOB2 kagmUVh7n2ebebLsCEThO2zUd/NQx7BD85yRaRs1d+GiYKi8ipkZw+vKq42w+7IPw63A bIHL17B9G1Tl749T8RLM0uEcJPQVIQFkdhFZZxgAasa+X7Wu0z8uLBWLGRyEVPe1Wve6 gEdHo5j3vmdLNRQyG8S6Mkk/WY3P5lOGORiF4m0R24p0l3uF1yZLy2QRvm/NVW5CaIY1 LSqERhp99jLBBW24H5T/K/bQ5DkQ5/OZ1a1qGrBCve8iT120GCw6Vwt0E3BToN/UY8q/ ywHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2DjkQ5FcX0Lcg8810jjl75vE1EMobjhdgNckOlMDd4M=; fh=2NZSi0YJbXUV2aVmrYzP40c+UfdtOxyfPSK7nbHv47o=; b=yBeqVoZNrORR72pXWjvThbtp1zbVBJdz1LjYAwRS0/2ymz0DeXWKXwIZtZPY+Mo6Hs LL46VH8zvCsd/8Iy1YC2lo9E/13Gxb264wtjH5gBQWbKPmvx27uDwCMyqHElzE5gndzi qNhPRyaSekHmCJ2d09rHXqNbGCqbR0SErzEkFacn7twqDKANVvVtUqqtoAZA054DRs9B UCpYUOj1ACdCy1gOdCVv5FpJMIYpeww68kEH35AcIEjfIBE7O2JU0oQ/GHwfqG0/Z2fz fDM4PNaNQQBTZTFIAZHANw4lt0ZSj0il2dmo3dREo23FRNmfjtpvcFMmJmZfJfgYONH6 QECQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=js3x7Ql8; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb742ce42si4482938a12.336.2024.06.17.08.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:34:59 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=js3x7Ql8; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DED2D8839C; Mon, 17 Jun 2024 17:33:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="js3x7Ql8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BDC39883DA; Mon, 17 Jun 2024 17:33:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id B64A3883AE for ; Mon, 17 Jun 2024 17:33:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-4217a96de38so32812195e9.1 for ; Mon, 17 Jun 2024 08:33:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638425; x=1719243225; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2DjkQ5FcX0Lcg8810jjl75vE1EMobjhdgNckOlMDd4M=; b=js3x7Ql8RprFUZP3+0uXneAVm2UhJjeZhfs31rDPpatKGS2hz1n4bOhmZ3VY2B0bYk 1+MpCN15t7X/Olrqo77AJfkhZ6Fhbv8YlvumzCHEZM32uINxMtzPF8gIkWVIT2zf5Cnk uwv0V3GHOZQsSm7+KYKmf9PbLKZwQNI39JNZiZ+rEfuXF3BXuoSr+DjidcL17UFL9y/n Ag6Qz3IbhAIL0IO82J1t+3MZ9dR6NgOu6reQIxutr0a1hcRsIcWbpGxo+HWRIuSlkSc3 mGKzQTjlB58E0hfWVkdkj8w/gviRiePviFK1syOOPQpFK3gShzqpHh3kDMOB9hvdPnkv DJRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638425; x=1719243225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2DjkQ5FcX0Lcg8810jjl75vE1EMobjhdgNckOlMDd4M=; b=UTFi1VkVErAGz2aiHKxE9TdQds6YS7PxwDNpFL3ZSKwBSe9df0jwBQESElG1CzXyPJ hBj8ceoOyJFVopWPJIsDNUiGAvT3zL8nQzSj/gC+R8BSOamA1QWHr9g7riErplTB1T8j m0up8RB944cELNlVoxUgu2szJaAPugPuueSBEkqqf003uB9Y65ULr6LU5YeO9AgoM7/m XquEwYbwTw7tHJBlnybcBN2OqktxT9I92eONXdHdxGvwykhMf//suUULJY8ti9Mtk8/J kjEJ+jdeZVb2Hcu1MDEUBHlLn+h0ekE2OM2Ym//EaAUrZg+oEcI7BbOpa4JIOlg3KN4s l3qw== X-Gm-Message-State: AOJu0YwtN4djXxgFzEbBc9zO1LC+e0kwHnEROWkNsqJ3H+6e8up6jjzX u9e6cja+ZIYR7CZbW3o4jG7onAIxHRVnLe6MlFIVryKsavnOzKL2oAkBKn6thcUhKRhwlJTpQDg yS5E= X-Received: by 2002:a05:600c:45cd:b0:421:7eff:efb8 with SMTP id 5b1f17b1804b1-423056e01dbmr82123945e9.31.1718638425071; Mon, 17 Jun 2024 08:33:45 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:44 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Mattijs Korpershoek , AKASHI Takahiro , Michal Simek , Francis Laniel , Peter Robinson Subject: [PATCH v4 08/14] net-lwip: add dns command Date: Mon, 17 Jun 2024 17:33:00 +0200 Message-Id: <481f1b6d4ca8925060af62186ad2cb6b25f7e4f8.1718638104.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add CMD_DNS when NET_LWIP is enabled to provide the dns command using lwIP. Signed-off-by: Jerome Forissier --- cmd/Kconfig | 6 +++ cmd/net-lwip.c | 8 ++++ include/net-lwip.h | 1 + net-lwip/Makefile | 1 + net-lwip/dns.c | 117 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 net-lwip/dns.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 07cfe824e3f..6ef0b52cd34 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2098,6 +2098,12 @@ config CMD_DHCP help Boot image via network using DHCP/TFTP protocol +config CMD_DNS + bool "dns" + select PROT_DNS_LWIP + help + Lookup the IP of a hostname + config CMD_PING bool "ping" select PROT_RAW_LWIP diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c index feed719beef..c021da6a674 100644 --- a/cmd/net-lwip.c +++ b/cmd/net-lwip.c @@ -27,3 +27,11 @@ U_BOOT_CMD( "[loadAddress] [[hostIPaddr:]bootfilename]" ); #endif + +#if defined(CONFIG_CMD_DNS) +U_BOOT_CMD( + dns, 3, 1, do_dns, + "lookup the IP of a hostname", + "hostname [envvar]" +); +#endif diff --git a/include/net-lwip.h b/include/net-lwip.h index b34f53b4891..4d41b0208a3 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -12,6 +12,7 @@ void net_lwip_remove_netif(struct netif *netif); struct netif *net_lwip_get_netif(void); int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); #endif /* __NET_LWIP_H__ */ diff --git a/net-lwip/Makefile b/net-lwip/Makefile index e68d4e24197..aa247859483 100644 --- a/net-lwip/Makefile +++ b/net-lwip/Makefile @@ -7,6 +7,7 @@ obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth_common.o obj-$(CONFIG_$(SPL_)DM_ETH) += ../net/eth-uclass.o obj-$(CONFIG_$(SPL_)DM_ETH) += net-lwip.o obj-$(CONFIG_CMD_DHCP) += dhcp.o +obj-$(CONFIG_CMD_DNS) += dns.o obj-$(CONFIG_CMD_PING) += ping.o obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o diff --git a/net-lwip/dns.c b/net-lwip/dns.c new file mode 100644 index 00000000000..081f0933715 --- /dev/null +++ b/net-lwip/dns.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include +#include +#include +#include +#include +#include + +#define DNS_RESEND_MS 1000 +#define DNS_TIMEOUT_MS 10000 + +struct dns_cb_arg { + ip_addr_t host_ipaddr; + const char *var; + bool done; +}; + +static void do_dns_tmr(void *arg) +{ + dns_tmr(); +} + +static void dns_cb(const char *name, const ip_addr_t *ipaddr, void *arg) +{ + struct dns_cb_arg *dns_cb_arg = arg; + char *ipstr = ip4addr_ntoa(ipaddr); + + dns_cb_arg->done = true; + + if (!ipaddr) { + printf("DNS: host not found\n"); + dns_cb_arg->host_ipaddr.addr = 0; + return; + } + + if (dns_cb_arg->var) + env_set(dns_cb_arg->var, ipstr); + + printf("%s\n", ipstr); +} + +int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + struct dns_cb_arg dns_cb_arg = { }; + bool has_server = false; + struct netif *netif; + ip_addr_t ipaddr; + ip_addr_t ns; + ulong start; + char *nsenv; + char *name; + int ret; + + if (argc == 1 || argc > 3) + return CMD_RET_USAGE; + + if (argc >= 2) + name = argv[1]; + + if (argc == 3) + dns_cb_arg.var = argv[2]; + + netif = net_lwip_new_netif(); + if (!netif) + return -1; + + dns_init(); + + nsenv = env_get("dnsip"); + if (nsenv && ipaddr_aton(nsenv, &ns)) { + dns_setserver(0, &ns); + has_server = true; + } + + nsenv = env_get("dnsip2"); + if (nsenv && ipaddr_aton(nsenv, &ns)) { + dns_setserver(1, &ns); + has_server = true; + } + + if (!has_server) { + log_err("No valid name server (dnsip/dnsip2)\n"); + net_lwip_remove_netif(netif); + return CMD_RET_FAILURE; + } + + dns_cb_arg.done = false; + + ret = dns_gethostbyname(name, &ipaddr, dns_cb, &dns_cb_arg); + + if (ret == ERR_OK) { + dns_cb(name, &ipaddr, &dns_cb_arg); + } else if (ret == ERR_INPROGRESS) { + start = get_timer(0); + sys_timeout(DNS_RESEND_MS, do_dns_tmr, NULL); + do { + eth_rx(); + if (dns_cb_arg.done) + break; + sys_check_timeouts(); + if (ctrlc()) { + printf("\nAbort\n"); + break; + } + } while (get_timer(start) < DNS_TIMEOUT_MS); + sys_untimeout(do_dns_tmr, NULL); + } + + net_lwip_remove_netif(netif); + + if (dns_cb_arg.done && dns_cb_arg.host_ipaddr.addr != 0) + return CMD_RET_SUCCESS; + + return CMD_RET_FAILURE; +} From patchwork Mon Jun 17 15:33:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804884 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611705wrr; Mon, 17 Jun 2024 08:35:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVxenK/Vfgj3kwrBS+FDI9bsma73xO7xL4g8Myljb8KktSygVCDvr4Qf57XNPvPlT3bimyHXcqolV2Fuw2wMRQr X-Google-Smtp-Source: AGHT+IFOdBQ3k8QcmVUQgzFcJ5cdANdWp+LhGbXsQMBwIY9W9BNr2fZ3tsGNTRdgBRxlRF0wRejC X-Received: by 2002:a50:ccd5:0:b0:57c:8035:50ef with SMTP id 4fb4d7f45d1cf-57cbd8b98e6mr7500653a12.35.1718638511832; Mon, 17 Jun 2024 08:35:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638511; cv=none; d=google.com; s=arc-20160816; b=bcgNKuze8T3WyAmDqI0M1IrD39mWQNostJ12yj0i0guJHM1l0FYY5h4qodoaE+ObB/ yZSzVZiX301fvCcUfKGTnp6dYvTlZXfd5C7WHxkFiOFlntSPSR/BoOWg8u4n8U+mOx9w b9SGRDUg59oycOaNQOewANJWBpDPP/wnyoxtWwqvyZ1+edujNQ/QIUH9+gD0QkObhc4R lQOww1wbrqyPik172Wmmrjt0LyFpjdLg5Aiksqz+bI2txgXaKn8uXeU5L/uOJGbeRdtW 4GQ97fysnQpPji4kImClRegQ1KCqJwc8bQzhOugkDKZhUTz55z3sdxjIFd9W//sZREOa vz2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=m3qbyK31RMThpiUrcrmeTE01WYxS4Fh/X83z+XOCuec=; fh=f2/pdOYWXYGmoGDjgT4XEIgYb2+8olf+GaXZncKM50o=; b=iihECtLP/GaXCwvX5uvH0Sh06GMvTsee+P07HdPLlo178I7WQH97O7p7TRf4oC+Qc9 Y9Fn+y+c/9+GKPOrdmY/qjRWqw+rM5zDngK3WpmyEWpqiAnKWWTPcyNvJSQeqY1XXYup ArtNkvSVeHiyzv2nXn9eXOfMNTKpK+V8a7iyFt2jB77E0HPyalGvqBUedtnCdhHL77YT pnIT3JfTbHtAWr7wuous8daGyLfxixLLzT0aDBTIF+4dclu1qcKnZVrABiukOwEf/WvQ oSNBVl0K+n+kg8qL2HHf/EUA0NMhmNkTKr88/rAyT11ED46JJHuk2p7c1OnMdf9+eLYp MyCQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iNRy8f7n; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb72e1506si4480943a12.140.2024.06.17.08.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:35:11 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iNRy8f7n; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4995E883EB; Mon, 17 Jun 2024 17:33:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="iNRy8f7n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2FDAC883B6; Mon, 17 Jun 2024 17:33:49 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0CB13883B6 for ; Mon, 17 Jun 2024 17:33:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-421d32fda86so46793775e9.0 for ; Mon, 17 Jun 2024 08:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638426; x=1719243226; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=m3qbyK31RMThpiUrcrmeTE01WYxS4Fh/X83z+XOCuec=; b=iNRy8f7nHG8wOCQvbDaqOzkSNBnuswSdxWh6w6Q1iFkDP3banKCuEXqGvkK0r6pEeO BAvE4h24Q5bmor72jINFx0dgrjt/ExwE+8UjKgESKKqh6uGgRlo1EnwvRZ2qq5VWHDp8 +1QGXoaJtvF4vkAjX54ko9GuA8x5S7Gg4w2DxIPeWqj9wzny4fLKmyoni9ppijC59h4R VlhpgMFv+k0977saSclCdxbtIyCadTxRIIKwPlylbKY3cHWTuoKveV0Jg50FgcWtNfvU ntMY5gcABu+n7ckH8N3RQXpWgJC5jkuf55SeFh/eaNw0+EM4/DdSdvUBwIYMEQ8jcMSU eK1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638426; x=1719243226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m3qbyK31RMThpiUrcrmeTE01WYxS4Fh/X83z+XOCuec=; b=R3uuhHz23QwX82KjN0zLeqpZOR9ensicFWOURqy/U/VDhohMJj5etz4J13TCQRt9yx Ysu6nCvJRM6ixq9rX4XFyizBSe/KwiO5RkBE80EyUxD7runht2Eb8XZEVwzrAjhVL13/ 4QGOTwD5Io21S3Yr+iiPGYnMl8S5seGx369saHIBIbDbRCHb8hh+e4jXDmisoXc007JK 7lto+8xgqAd39VKzi2Gnn+GFLA6wOaa+DxFXj84GR2AzC9qRKDL+k+XSVopSIRwXNF+d 3uhkxFMSkmPY0PpfRLdumDWmWt2XK2Vb34mei1gYPBK8OgL7dbDh6YD43y7BgYZh2Z9n 0NmQ== X-Gm-Message-State: AOJu0Yypj6IRHglOOdBeDmH2ahbuPVLoME4GojcY57AYeCLYc/9RSU92 IaaRUNubyC8KvZrWW0gV3bjGEK7c2ImK0V2raY6sYyI0YiAApzFgRPp4fnlR+qQbjzibcB3uWRS P6q4= X-Received: by 2002:a05:600c:154f:b0:422:7a16:6986 with SMTP id 5b1f17b1804b1-42304820b5fmr87521175e9.9.1718638426336; Mon, 17 Jun 2024 08:33:46 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:46 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Francis Laniel , Abdellatif El Khlifi , Heinrich Schuchardt Subject: [PATCH v4 09/14] net: split cmd/net.c into cmd/net.c and cmd/net-common.c Date: Mon, 17 Jun 2024 17:33:01 +0200 Message-Id: <890c609387330d691d8c19dd9d56b87e69bc57e5.1718638104.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Extract some code from cmd/net.c that will be useful in a subsequent commit to implement wget with NET_LWIP. Signed-off-by: Jerome Forissier --- cmd/Makefile | 5 ++- cmd/net-common.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ cmd/net.c | 115 ----------------------------------------------- 3 files changed, 113 insertions(+), 116 deletions(-) create mode 100644 cmd/net-common.c diff --git a/cmd/Makefile b/cmd/Makefile index 535b6838ca5..e90f2f68211 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -129,8 +129,11 @@ obj-$(CONFIG_CMD_MUX) += mux.o obj-$(CONFIG_CMD_NAND) += nand.o obj-$(CONFIG_CMD_NET) += net.o obj-$(CONFIG_CMD_NET_LWIP) += net-lwip.o +obj-$(filter y,$(CONFIG_CMD_NET) $(CONFIG_CMD_NET_LWIP)) += net-common.o ifdef CONFIG_CMD_NET_LWIP -CFLAGS_net-lwip.o := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot +lwip-includes := -I$(srctree)/lib/lwip/lwip/src/include -I$(srctree)/lib/lwip/u-boot +CFLAGS_net-lwip.o := $(lwip-includes) +CFLAGS_net-common.o := $(lwip-includes) endif obj-$(CONFIG_ENV_SUPPORT) += nvedit.o obj-$(CONFIG_CMD_NVEDIT_EFI) += nvedit_efi.o diff --git a/cmd/net-common.c b/cmd/net-common.c new file mode 100644 index 00000000000..1c9fb83b896 --- /dev/null +++ b/cmd/net-common.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2000 + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. + */ + +#include +#include +#include +#include +#include +#include + +static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + const struct udevice *current = eth_get_dev(); + unsigned char env_enetaddr[ARP_HLEN]; + const struct udevice *dev; + struct uclass *uc; + + uclass_id_foreach_dev(UCLASS_ETH, dev, uc) { + eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr); + printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr, + current == dev ? "active" : ""); + } + return CMD_RET_SUCCESS; +} + +static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + int nstats, err, i, off; + struct udevice *dev; + u64 *values; + u8 *strings; + + if (argc < 2) + return CMD_RET_USAGE; + + err = uclass_get_device_by_name(UCLASS_ETH, argv[1], &dev); + if (err) { + printf("Could not find device %s\n", argv[1]); + return CMD_RET_FAILURE; + } + + if (!eth_get_ops(dev)->get_sset_count || + !eth_get_ops(dev)->get_strings || + !eth_get_ops(dev)->get_stats) { + printf("Driver does not implement stats dump!\n"); + return CMD_RET_FAILURE; + } + + nstats = eth_get_ops(dev)->get_sset_count(dev); + strings = kcalloc(nstats, ETH_GSTRING_LEN, GFP_KERNEL); + if (!strings) + return CMD_RET_FAILURE; + + values = kcalloc(nstats, sizeof(u64), GFP_KERNEL); + if (!values) + goto err_free_strings; + + eth_get_ops(dev)->get_strings(dev, strings); + eth_get_ops(dev)->get_stats(dev, values); + + off = 0; + for (i = 0; i < nstats; i++) { + printf(" %s: %llu\n", &strings[off], values[i]); + off += ETH_GSTRING_LEN; + }; + + kfree(strings); + kfree(values); + + return CMD_RET_SUCCESS; + +err_free_strings: + kfree(strings); + + return CMD_RET_FAILURE; +} + +static struct cmd_tbl cmd_net[] = { + U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""), + U_BOOT_CMD_MKENT(stats, 2, 0, do_net_stats, "", ""), +}; + +static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + struct cmd_tbl *cp; + + cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net)); + + /* Drop the net command */ + argc--; + argv++; + + if (!cp || argc > cp->maxargs) + return CMD_RET_USAGE; + if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) + return CMD_RET_SUCCESS; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD( + net, 3, 1, do_net, + "NET sub-system", + "list - list available devices\n" + "stats - dump statistics for specified device\n" +); diff --git a/cmd/net.c b/cmd/net.c index d407d8320a3..03b4582204f 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -676,118 +676,3 @@ U_BOOT_CMD( ); #endif /* CONFIG_CMD_LINK_LOCAL */ - -static int do_net_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - const struct udevice *current = eth_get_dev(); - unsigned char env_enetaddr[ARP_HLEN]; - const struct udevice *dev; - struct uclass *uc; - - uclass_id_foreach_dev(UCLASS_ETH, dev, uc) { - eth_env_get_enetaddr_by_index("eth", dev_seq(dev), env_enetaddr); - printf("eth%d : %s %pM %s\n", dev_seq(dev), dev->name, env_enetaddr, - current == dev ? "active" : ""); - } - return CMD_RET_SUCCESS; -} - -static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - int nstats, err, i, off; - struct udevice *dev; - u64 *values; - u8 *strings; - - if (argc < 2) - return CMD_RET_USAGE; - - err = uclass_get_device_by_name(UCLASS_ETH, argv[1], &dev); - if (err) { - printf("Could not find device %s\n", argv[1]); - return CMD_RET_FAILURE; - } - - if (!eth_get_ops(dev)->get_sset_count || - !eth_get_ops(dev)->get_strings || - !eth_get_ops(dev)->get_stats) { - printf("Driver does not implement stats dump!\n"); - return CMD_RET_FAILURE; - } - - nstats = eth_get_ops(dev)->get_sset_count(dev); - strings = kcalloc(nstats, ETH_GSTRING_LEN, GFP_KERNEL); - if (!strings) - return CMD_RET_FAILURE; - - values = kcalloc(nstats, sizeof(u64), GFP_KERNEL); - if (!values) - goto err_free_strings; - - eth_get_ops(dev)->get_strings(dev, strings); - eth_get_ops(dev)->get_stats(dev, values); - - off = 0; - for (i = 0; i < nstats; i++) { - printf(" %s: %llu\n", &strings[off], values[i]); - off += ETH_GSTRING_LEN; - }; - - return CMD_RET_SUCCESS; - -err_free_strings: - kfree(strings); - - return CMD_RET_FAILURE; -} - -static struct cmd_tbl cmd_net[] = { - U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""), - U_BOOT_CMD_MKENT(stats, 2, 0, do_net_stats, "", ""), -}; - -static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) -{ - struct cmd_tbl *cp; - - cp = find_cmd_tbl(argv[1], cmd_net, ARRAY_SIZE(cmd_net)); - - /* Drop the net command */ - argc--; - argv++; - - if (!cp || argc > cp->maxargs) - return CMD_RET_USAGE; - if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) - return CMD_RET_SUCCESS; - - return cp->cmd(cmdtp, flag, argc, argv); -} - -U_BOOT_CMD( - net, 3, 1, do_net, - "NET sub-system", - "list - list available devices\n" - "stats - dump statistics for specified device\n" -); - -#if defined(CONFIG_CMD_NCSI) -static int do_ncsi(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) -{ - if (!phy_interface_is_ncsi() || !ncsi_active()) { - printf("Device not configured for NC-SI\n"); - return CMD_RET_FAILURE; - } - - if (net_loop(NCSI) < 0) - return CMD_RET_FAILURE; - - return CMD_RET_SUCCESS; -} - -U_BOOT_CMD( - ncsi, 1, 1, do_ncsi, - "Configure attached NIC via NC-SI", - "" -); -#endif /* CONFIG_CMD_NCSI */ From patchwork Mon Jun 17 15:33:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804885 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611789wrr; Mon, 17 Jun 2024 08:35:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXiwRCRrZx5bFJK91JAsHju5O4Gw/mTwOnDgZDS3oWMW8qyqp5Ql8ayX9xf8NTqgc6OD0MZsmtO0prdnyXqwGWK X-Google-Smtp-Source: AGHT+IHfKIGrurdLx5rbI8NQAyGQcBePqlIUMgzKza/jAHEYQF06VDWy+3dXbeDBZfyc0xqnnwI7 X-Received: by 2002:a50:ee08:0:b0:57c:735f:3967 with SMTP id 4fb4d7f45d1cf-57cf7a59370mr21474a12.8.1718638523157; Mon, 17 Jun 2024 08:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638523; cv=none; d=google.com; s=arc-20160816; b=WbU0IdesEfwXKQYcHwXWoJnltVH4JKGP9iRrvo7Jw7f85AjNj9UxlNAiDHg8FjDEK7 K5hrHjFIACduCGbKPHm4M6K+6CMQQQikzJaSR7jOH3wd3lC8xm0dVZtPhneSeNbUGNZn x7Qlk7MeC9F4BkVzPaDj1w6dvkYngDijlm9owykX3lkBttxLsGGsYtd3WvD93SLuvp+4 Xz9xwSD84l71HlNio/I/BiRBrIMd1z2aAYPuuu3E6eu4Db/b/Ved81Pmz4+nJJFDVvMu F0fKtsWIhRTrG0OSjId3mrKb9uq672IopW8CTNS6v3H51aVfGVuO6LZF5k8RkYrygBgg /QYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=POc5N6ffv1Ucqvmw37l0ax09bGCRaPMQMvgbHo0ZnTU=; fh=2NZSi0YJbXUV2aVmrYzP40c+UfdtOxyfPSK7nbHv47o=; b=pUQKQPrL1fz13zWRDxEjJY5RmiadcAXvKXnbkKxc8nlP0Ajsyl90pgsGAXQEpfK7AM A2o2fh0ykFPdQrcq20LxIoZgpyut6KjvYs+zH9BnKDng5G/LZRwxMtVgT6OZ6wKnfInF rge6fOmFoG26Ar5Ov8KZUQxnhxGdMb3gvRKh1wnYl0SQhm9KNUyDgDdfdr0M7aWYj9j7 uqx1T6K2ZdHZNEDH9vDOKLrYpHPBupYV8iiL9I6i+DNT0JonNj0XbTzbJg0RiWGmX0rR wahrYMQbLP9ltAJv8EvYI0d85O67gSfaMmyvQ3U0YPY8tQMHRKUGGbz32LUgmBTxq/6K JIYQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="VE/nTBPS"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb72e222csi4790019a12.158.2024.06.17.08.35.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:35:23 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="VE/nTBPS"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A2B88883CF; Mon, 17 Jun 2024 17:33:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="VE/nTBPS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 15775883FB; Mon, 17 Jun 2024 17:33:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EBC78883C3 for ; Mon, 17 Jun 2024 17:33:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42108856c33so34099965e9.1 for ; Mon, 17 Jun 2024 08:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638428; x=1719243228; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=POc5N6ffv1Ucqvmw37l0ax09bGCRaPMQMvgbHo0ZnTU=; b=VE/nTBPSSn+Mjvf2LhZ2YONnlvi38Sy4OoDREZ/WDI8f/IO0nJGOD1613pddHjxwmb 0JetGoMJ39/+0/8VK4I0gvuqy8ZTi8kskL8h4AawvvH5E/XtKo1+EkGC91E+lNvAAh5x nnCpZx8XYmvfmVsxO+EAmi5GBMg8kl7O9FlxUB1U+Tv/O7FoBIGk1rP/hu/yefMqyvd+ bAFZz/Vs3M4myJkz5RsNA3PFBP5rHiSg5dsTFtUPBdgZzYD/szr59BRQlbnW0FwUIE4f jUZgZmIRQ7F+s1+0E8aV6QJponNczRgYcUThH0FtVTqQd8zmErmCUfy78FKvvGaZOUAE J3Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638428; x=1719243228; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=POc5N6ffv1Ucqvmw37l0ax09bGCRaPMQMvgbHo0ZnTU=; b=GRbsCR6qxMAsWARMAQobdCocFue7IBt+QNyPP1VjO2VfcczQlAuhlTnJinoStykHQC gu5swamMLwTrs5smYOLA6AeV9PwbvLMm6SBPt8nfkU6kjBFrBbSsUVUVksf53Q/sqRK6 5HfPoF4dzyD+Z7PoQZNpnzY/8J7xfDBsKwomNBAP+JdQK8o0Eop/0owp4mlVKgDrgZSC z/P9ZuMIK6sOmucRgpzZC1BfFBcj8m2Vx3FbeVe4Tz1fF7EA2yhfDbaCK/agvSFK45A2 WBxO07B77JhqkHPyT1onzsvN7zyoZwglqy3nK95yDsL3apvgKPJ8m0JLHKlZAEWQVL1j u2Ag== X-Gm-Message-State: AOJu0YwmXwvzzZSr0SHUHIs8Lm/bnEnJj+k8D5AbyTn5LbSvIjxoF5Nj QOxzIdcO4h3yFt6fmzeXU5ZAdZ6MjWSLNFUbxhGu7ZCIXZFXqngwyobRhm2st8O5b4O+aB4HvVu tR+o= X-Received: by 2002:adf:db4e:0:b0:360:7202:5a72 with SMTP id ffacd0b85a97d-3609ea6c1c5mr7579f8f.18.1718638428270; Mon, 17 Jun 2024 08:33:48 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:48 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Mattijs Korpershoek , AKASHI Takahiro , Michal Simek , Francis Laniel , Peter Robinson Subject: [PATCH v4 10/14] net-lwip: add wget command Date: Mon, 17 Jun 2024 17:33:02 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add support for the wget command with NET_LWIP. Based on code initially developed by Maxim U. Signed-off-by: Jerome Forissier Co-developed-by: Maxim Uvarov Cc: Maxim Uvarov Signed-off-by: Jerome Forissier Signed-off-by: Jonathan Humphreys Signed-off-by: Jonathan Humphreys Signed-off-by: Jonathan Humphreys --- cmd/Kconfig | 7 ++ cmd/net-lwip.c | 8 ++ include/net-lwip.h | 18 +++ net-lwip/Makefile | 1 + net-lwip/wget.c | 269 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 303 insertions(+) create mode 100644 net-lwip/wget.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 6ef0b52cd34..d9a86540be6 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -2117,6 +2117,13 @@ config CMD_TFTPBOOT help tftpboot - load file via network using TFTP protocol +config CMD_WGET + bool "wget" + select PROT_TCP_LWIP + help + wget is a simple command to download kernel, or other files, + from a http server over TCP. + endif endif diff --git a/cmd/net-lwip.c b/cmd/net-lwip.c index c021da6a674..42f8bd6b259 100644 --- a/cmd/net-lwip.c +++ b/cmd/net-lwip.c @@ -35,3 +35,11 @@ U_BOOT_CMD( "hostname [envvar]" ); #endif + +#if defined(CONFIG_CMD_WGET) +U_BOOT_CMD( + wget, 3, 1, do_wget, + "boot image via network using HTTP protocol", + "[loadAddress] URL" +); +#endif diff --git a/include/net-lwip.h b/include/net-lwip.h index 4d41b0208a3..ddf25e61417 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -11,8 +11,26 @@ struct netif *net_lwip_new_netif_noip(void); void net_lwip_remove_netif(struct netif *netif); struct netif *net_lwip_get_netif(void); +/** + * wget_with_dns() - runs dns host IP address resulution before wget + * + * @dst_addr: destination address to download the file + * @uri: uri string of target file of wget + * Return: downloaded file size, negative if failed + */ + +int wget_with_dns(ulong dst_addr, char *uri); +/** + * wget_validate_uri() - varidate the uri + * + * @uri: uri string of target file of wget + * Return: true if uri is valid, false if uri is invalid + */ +bool wget_validate_uri(char *uri); + int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); #endif /* __NET_LWIP_H__ */ diff --git a/net-lwip/Makefile b/net-lwip/Makefile index aa247859483..bc011bb0e32 100644 --- a/net-lwip/Makefile +++ b/net-lwip/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_CMD_DHCP) += dhcp.o obj-$(CONFIG_CMD_DNS) += dns.o obj-$(CONFIG_CMD_PING) += ping.o obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o +obj-$(CONFIG_CMD_WGET) += wget.o # Disable this warning as it is triggered by: # sprintf(buf, index ? "foo%d" : "foo", index) diff --git a/net-lwip/wget.c b/net-lwip/wget.c new file mode 100644 index 00000000000..069299bd469 --- /dev/null +++ b/net-lwip/wget.c @@ -0,0 +1,269 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (C) 2024 Linaro Ltd. */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SERVER_NAME_SIZE 200 +#define HTTP_PORT_DEFAULT 80 +#define PROGRESS_PRINT_STEP_BYTES (100 * 1024) + +enum done_state { + NOT_DONE = 0, + SUCCESS = 1, + FAILURE = 2 +}; + +struct wget_ctx { + ulong daddr; + ulong saved_daddr; + ulong size; + ulong prevsize; + ulong start_time; + enum done_state done; +}; + +static int parse_url(char *url, char *host, u16 *port, char **path) +{ + char *p, *pp; + long lport; + + p = strstr(url, "http://"); + if (!p) + return -EINVAL; + + p += strlen("http://"); + + /* Parse hostname */ + pp = strchr(p, ':'); + if (!pp) + pp = strchr(p, '/'); + if (!pp) + return -EINVAL; + + if (p + SERVER_NAME_SIZE <= pp) + return -EINVAL; + + memcpy(host, p, pp - p); + host[pp - p + 1] = '\0'; + + if (*pp == ':') { + /* Parse port number */ + p = pp + 1; + lport = simple_strtol(p, &pp, 10); + if (pp && *pp != '/') + return -EINVAL; + if (lport > 65535) + return -EINVAL; + *port = (u16)lport; + } else { + *port = HTTP_PORT_DEFAULT; + } + if (*pp != '/') + return -EINVAL; + *path = pp; + + return 0; +} + +static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, + err_t err) +{ + struct wget_ctx *ctx = arg; + struct pbuf *buf; + + if (!pbuf) + return ERR_BUF; + + for (buf = pbuf; buf; buf = buf->next) { + memcpy((void *)ctx->daddr, buf->payload, buf->len); + ctx->daddr += buf->len; + ctx->size += buf->len; + if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + printf("#"); + ctx->prevsize = ctx->size; + } + } + + altcp_recved(pcb, pbuf->tot_len); + pbuf_free(pbuf); + return ERR_OK; +} + +static void httpc_result_cb(void *arg, httpc_result_t httpc_result, + u32_t rx_content_len, u32_t srv_res, err_t err) +{ + struct wget_ctx *ctx = arg; + ulong elapsed; + + if (httpc_result != HTTPC_RESULT_OK) { + log_err("\nHTTP client error %d\n", httpc_result); + ctx->done = FAILURE; + return; + } + + elapsed = get_timer(ctx->start_time); + if (rx_content_len > PROGRESS_PRINT_STEP_BYTES) + printf("\n"); + printf("%u bytes transferred in %lu ms (", rx_content_len, + get_timer(ctx->start_time)); + print_size(rx_content_len / elapsed * 1000, "/s)\n"); + + if (env_set_hex("filesize", rx_content_len) || + env_set_hex("fileaddr", ctx->saved_daddr)) { + log_err("Could not set filesize or fileaddr\n"); + ctx->done = FAILURE; + return; + } + + ctx->done = SUCCESS; +} + +int wget_with_dns(ulong dst_addr, char *uri) +{ + char server_name[SERVER_NAME_SIZE]; + httpc_connection_t conn; + httpc_state_t *state; + struct netif *netif; + struct wget_ctx ctx; + char *path; + u16 port; + + ctx.daddr = dst_addr; + ctx.saved_daddr = dst_addr; + ctx.done = NOT_DONE; + ctx.size = 0; + ctx.prevsize = 0; + + if (parse_url(uri, server_name, &port, &path)) + return CMD_RET_USAGE; + + netif = net_lwip_new_netif(); + if (!netif) + return -1; + + memset(&conn, 0, sizeof(conn)); + conn.result_fn = httpc_result_cb; + ctx.start_time = get_timer(0); + if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb, + &ctx, &state)) { + net_lwip_remove_netif(netif); + return CMD_RET_FAILURE; + } + + while (!ctx.done) { + eth_rx(); + sys_check_timeouts(); + if (ctrlc()) + break; + } + + net_lwip_remove_netif(netif); + + if (ctx.done == SUCCESS) + return 0; + + return -1; +} + +int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + char *end; + char *url; + ulong dst_addr; + + if (argc < 2 || argc > 3) + return CMD_RET_USAGE; + + dst_addr = hextoul(argv[1], &end); + if (end == (argv[1] + strlen(argv[1]))) { + if (argc < 3) + return CMD_RET_USAGE; + url = argv[2]; + } else { + dst_addr = image_load_addr; + url = argv[1]; + } + + if (wget_with_dns(dst_addr, url)) + return CMD_RET_FAILURE; + + return CMD_RET_SUCCESS; +} + +/** + * wget_validate_uri() - validate the uri for wget + * + * @uri: uri string + * + * This function follows the current U-Boot wget implementation. + * scheme: only "http:" is supported + * authority: + * - user information: not supported + * - host: supported + * - port: not supported(always use the default port) + * + * Uri is expected to be correctly percent encoded. + * This is the minimum check, control codes(0x1-0x19, 0x7F, except '\0') + * and space character(0x20) are not allowed. + * + * TODO: stricter uri conformance check + * + * Return: true on success, false on failure + */ +bool wget_validate_uri(char *uri) +{ + char c; + bool ret = true; + char *str_copy, *s, *authority; + + for (c = 0x1; c < 0x21; c++) { + if (strchr(uri, c)) { + log_err("invalid character is used\n"); + return false; + } + } + if (strchr(uri, 0x7f)) { + log_err("invalid character is used\n"); + return false; + } + + if (strncmp(uri, "http://", 7)) { + log_err("only http:// is supported\n"); + return false; + } + str_copy = strdup(uri); + if (!str_copy) + return false; + + s = str_copy + strlen("http://"); + authority = strsep(&s, "/"); + if (!s) { + log_err("invalid uri, no file path\n"); + ret = false; + goto out; + } + s = strchr(authority, '@'); + if (s) { + log_err("user information is not supported\n"); + ret = false; + goto out; + } + s = strchr(authority, ':'); + if (s) { + log_err("user defined port is not supported\n"); + ret = false; + goto out; + } + +out: + free(str_copy); + + return ret; +} From patchwork Mon Jun 17 15:33:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804886 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611887wrr; Mon, 17 Jun 2024 08:35:34 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUAiOVDoAyhgxIkjN6EVU3RiHk+zH8A20GSDCSNn1qDvdYBFEW9E8Ms/6t9dABo7xNqJ9dsXU/xQVGU4iPfgbH9 X-Google-Smtp-Source: AGHT+IFoaMFqn/1dP/NvcLxYz7duVwCSxl9mNXPKei3fJukvgV23cGESIDZrOOo4snKmPHHWJjrr X-Received: by 2002:a17:906:7fc6:b0:a6e:fdc8:ae45 with SMTP id a640c23a62f3a-a6f60d170ccmr810828966b.1.1718638534360; Mon, 17 Jun 2024 08:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638534; cv=none; d=google.com; s=arc-20160816; b=kZLWY5E5AT/TA87OgOus4eDDOUjpU9Fsvwqw0DuuHn9wZpVgkxhkRoRQPH6OoTg9UO x8FmPktAc+aj9TgCwl7UQ1XC5Y768aOB96HtLmbwnlO8wE4Ba1VUwI6cLebMf11bKOJF TF9Q5W0gpUUerOCXgtzsPOOim0kF3lHtkZH4NIAYRJ/1IOXOLNO7wW5UkypnAVUOt+tH VfkukQ3mDNwCXoc3TcOv9G2NPm1bCRRPKumILgVwbDlrJZkaYd38kMgfPED1r8u5IanS FnI0c66fJYnT2bTUquO6bpDx+D4ld8BRKN4fd+zhDtrTuDc7pPMecO3gZoiBKxj77Wel wevQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wXawjeJXnycfE5xaoF+bqShNCUQW4mVfN0nOrxfadqA=; fh=8WQpMpm1L/fodCJFfYPhjZxaHfYgyB8wvAxF0Mcvg2A=; b=TnS/MgB73aV+ADnvHqqJVn/rw0UTivM77U4hWtFuyr73bIwitrKCNPUunVijrx/rfA IJLmahGP0lcqSEuaV4wch84//ihxJllkOIS2OAH62L+2T8GZFG1mb4IsCWTOdnAH9sZg phWJA50uOxAM51SPwRPgSXe4oTbp3nrUVWuLPn2Uk7o3RvuuiL181D9/2zfneMdWiJjh QBGaLoTsK8mD6CvmLLDbe8yMrDr0fdUtCbI6PmjMZA4VB2fKUpsq0BnS0tPr1aPybwdD kE+q/CFRrjAcvWdacy+upwPGWFt4yIhJein792telHYBjXqtsCa2JtYiVa+kNnyEE54q 7sSA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g8ahekNA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56e8210fsi454385966b.1042.2024.06.17.08.35.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:35:34 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=g8ahekNA; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 085BA883FE; Mon, 17 Jun 2024 17:33:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="g8ahekNA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 78D8F883B6; Mon, 17 Jun 2024 17:33:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 98670883E5 for ; Mon, 17 Jun 2024 17:33:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42249a4f9e4so31532565e9.2 for ; Mon, 17 Jun 2024 08:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638429; x=1719243229; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wXawjeJXnycfE5xaoF+bqShNCUQW4mVfN0nOrxfadqA=; b=g8ahekNANrogvGnPQY+0abqitDmhowkI3VTyn75szdcQUJ7wk1Odgq2Y2RVQhYVGk9 pKeghmL0bjHGo5yFb487rl4jNxBNSb2E8jkUOArDzIt+G+CPBQOqnQKX92+UuFNdPNeb P4W1R13Lzsgp8fcVXIgoczpL6wfsNrlwhwwCSFWfwh+y/0apEPPzZCtvjMf/SpAVziqb tcDJdHAN7yKoXmOOha0zJ4rQGkEakFIaVYGT6XmjhuGHAD729s+tmzLhlwmwS4ghL0OQ KJd8HFl6eS+Kz9l7sJ3YQQwYHw/H2OUxkQj4HLqmJn3Y5019JZ9zNrnKRlERFORI5xqm jjKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638429; x=1719243229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wXawjeJXnycfE5xaoF+bqShNCUQW4mVfN0nOrxfadqA=; b=uW1igr2FqXiL6YtS4CKJJPbiY25xwujtnk6W+yR2vmvxG51jH0ldApOAZinzdE9jd/ Muf6uNfWQyWZhMaIEOdTCYB3hsZTlUgRbu80bCSsI2HlUl+ghToN/4EoJTzNeX7lzxgo Z2q6MGX+o2xvByxuvd51pA1sc5zYeadeGVxl9UjSDm//xte+1X4UEIXoUcjcpqzgxArX pNi/49VDAwN3/BKikO3V33Umm8nCw+SzpjYg8oHfXgNI2NOVOva2QBviKImQFCntoPsO eICf1gj9qguSq9L88ShYQ0wJgngMsUS1gKVY1XCzKYiybOKqr27ITP/lqSjl9WJNlyR1 5fLw== X-Gm-Message-State: AOJu0Yyridn7PDYiCWFsa5AC+y/NA+YCjlv6vqZne4Uu7a/BtzujoXZ8 MdLStAD0jr2Wvkq6KX/HEbWzzYaatL9BY2JKQ0JXzxHD197h8wUgBOCFzDGZxMbGIV8yCSIXk/4 dO3A= X-Received: by 2002:a05:600c:4f49:b0:423:57f:fc7a with SMTP id 5b1f17b1804b1-423057ffe60mr105865755e9.32.1718638429050; Mon, 17 Jun 2024 08:33:49 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:48 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Bin Meng , Marek Vasut , Nikhil M Jain Subject: [PATCH v4 11/14] cmd: bdinfo: enable -e when CONFIG_CMD_NET_LWIP=y Date: Mon, 17 Jun 2024 17:33:03 +0200 Message-Id: <5efac81d0108b65fbb286cb8739a8ed6c14978b3.1718638104.git.jerome.forissier@linaro.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Support "bdinfo -e" when lwIP is selected. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas Reviewed-by: Tom Rini --- cmd/bdinfo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/bdinfo.c b/cmd/bdinfo.c index 79106caeec2..690fb894bf6 100644 --- a/cmd/bdinfo.c +++ b/cmd/bdinfo.c @@ -152,7 +152,7 @@ static int bdinfo_print_all(struct bd_info *bd) bdinfo_print_num_l("relocaddr", gd->relocaddr); bdinfo_print_num_l("reloc off", gd->reloc_off); printf("%-12s= %u-bit\n", "Build", (uint)sizeof(void *) * 8); - if (IS_ENABLED(CONFIG_CMD_NET)) + if (IS_ENABLED(CONFIG_CMD_NET) || IS_ENABLED(CONFIG_CMD_NET_LWIP)) print_eth(); bdinfo_print_num_l("fdt_blob", (ulong)map_to_sysmem(gd->fdt_blob)); bdinfo_print_num_l("new_fdt", (ulong)map_to_sysmem(gd->new_fdt)); @@ -198,7 +198,8 @@ int do_bdinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) case 'a': return bdinfo_print_all(bd); case 'e': - if (!IS_ENABLED(CONFIG_CMD_NET)) + if (!IS_ENABLED(CONFIG_CMD_NET) && + !IS_ENABLED(CONFIG_CMD_NET_LWIP)) return CMD_RET_USAGE; print_eth(); return CMD_RET_SUCCESS; From patchwork Mon Jun 17 15:33:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804887 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp611984wrr; Mon, 17 Jun 2024 08:35:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWfnsl5oIIkIO0+zPQbNgQBRvKwXg2Sp1rX/mbroBVDRX3U1Vk4js7MlhGaOd50jbMtgndZsS2p+nRztfuFNdBT X-Google-Smtp-Source: AGHT+IFvYLRhNMMcA3ObzOec/NwqDqkzb06PM16C3yChkN5Ka9AbmX8X0nJSUEfTe+dt+rXrNhkV X-Received: by 2002:a50:8a97:0:b0:57c:71ca:f651 with SMTP id 4fb4d7f45d1cf-57cbd690101mr7878544a12.20.1718638545389; Mon, 17 Jun 2024 08:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638545; cv=none; d=google.com; s=arc-20160816; b=sKBIHkGtrkehXq3exYTQa3q9L/bWzFp+/0zhEk9e0X+Ufc762OvgEOqXkpdCAnCqjd RPf8GIQyyJW2Y3MCtc0HKMM7VY+M+97fQaFQIsiBgaGf7Jj6md5znX0/Ma3ITf+fyM3U bJWO6zhdpx9MIbRW70vJRcImb8V/p5nOAbA11rHYSGk5S67fQg/AaKvQc31lcXpOduMK 4I1NJXcMFedW3rZTVl542Bq93hJBmMHl5EIrEltqDa/GM/gvtkOz1GfwVjCDrhs0BWCi 4pJ2hMxEv3KU+kGkEGPbACrFDSCnmLC4Ewp2HbzYm1pkoTa8U+mXuIdDqpznsy9PCicz 5KLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d5VffIYNcJu8ItnZYrnAKLEtjyTjAuXi/dkGvy3aV7U=; fh=cQhI5/EgogSkJ9u4BlGz7zOe5FopWH3wQtCDJ7yi0Z8=; b=awmXs3ajsqVbMrIKmDKPwksZGKROKJpJH5SUh7bJskNDG2hrK4YM5PqFO49+ywhxy4 PocRo8pV49AwWlVKukaY7d3ld//hLnNBhJW3AHsNdYk5IKdyidOtexf1oNA2Lu6Cy0ZY /TaUUrshFt6XP8+lot5Jq/zjBsbKTyDbUNDZ3hqBUMgIcSgbf4tJQ+ORRwQRIAEVUspN x5+TRYmIHNY/JYopAlwzZNRaBMjLanraE0PR9hdrdAdarecrsYV0PCk+p0ShrCSMPQrg OTZA8aU1C6pNhodQiqQHu1bXCpz3i4xXeLYbl1+p7R7rvs2YGu+BVXFhGIMR7smYgJ8l FX7g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=htfZLC2T; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb72d69e9si4516368a12.102.2024.06.17.08.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:35:45 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=htfZLC2T; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 67EBA883BB; Mon, 17 Jun 2024 17:33:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="htfZLC2T"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ED972883BB; Mon, 17 Jun 2024 17:33:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7B296883F5 for ; Mon, 17 Jun 2024 17:33:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4230366ad7bso39005305e9.1 for ; Mon, 17 Jun 2024 08:33:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638430; x=1719243230; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d5VffIYNcJu8ItnZYrnAKLEtjyTjAuXi/dkGvy3aV7U=; b=htfZLC2TwxjBF4ootH9IBhkxkgkPryD13EQckU7wlJQwKAffPIu9gfToo48T3S7JL3 wANfDcxjFQPDGMBtzDjRbfG8vl+0epwRgInwhCw5eJlNzdHI+zFyTwbyoBPtX2f5/D0o 9VZNV0MH21nsyKG30eIg6S/9xPfwswU5GdFm2liDus2j5x0PjzWHJDbn1kDwk87PxCPP ce2WGx8HoWzFtNrnNzZfDHpRUFn53bwCyKoh7Xt+mZBwHhbm2fMUeosXJYI6EJLf6bgX qhaDQh46YiNbMVlmZ96s1UT7Lhjb6l3R2BScntDuTf/AYpF7waRP1K+AcciiJevLgXu7 u89Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638430; x=1719243230; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d5VffIYNcJu8ItnZYrnAKLEtjyTjAuXi/dkGvy3aV7U=; b=WJO+elwTDfo1OaoZo6M7VDEL7dA32obWhcFmB89rTRuXUMb8Oq4F0mamOiipvfCiaU iDBPr7/S9eyTOKDE2kU+wqNBWGeT5Pt/f5dMd0EUmpjj2S0MR9/oQe46rsk8LCHLRD2i L7eUFmfK4jdow209tMjOsgr0gE5B0AbNpKOXDCl7VJZV8wxyh4IS2ac4SY/uVwL7+YQ/ wji4SvsCgfbsPPAN4BHD3/zxWY1Ne3BuBeKXWNvK4aaCNnho9jxwMbu9Sl5ujgZMRFpA 6YmETbceoJbNCFG/fiaHZmW4VHlgzb/UNo1qQzQNkCjvQiHW6O4pO/vEJZ0od+9RKJJ0 +e3g== X-Gm-Message-State: AOJu0Yy75T99vsHyfMGEBKc0nFE64d1ymkS6Gjl5TeU3Ph1Ul0+evcji W8JeWE4X7ejOHpjZHArULzpjo1PUgxlbh0mlVhm4P/yJo+SdJRAVUd+qc5XroQLB4joFoK65x1I F6ww= X-Received: by 2002:a05:600c:474d:b0:422:178b:bedd with SMTP id 5b1f17b1804b1-4230481a0bdmr86329605e9.1.1718638429856; Mon, 17 Jun 2024 08:33:49 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:49 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini Subject: [PATCH v4 12/14] configs: add qemu_arm64_lwip_defconfig Date: Mon, 17 Jun 2024 17:33:04 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add qemu_arm64_lwip_defconfig which #include's qemu_arm64_defconfig and selects NET_LWIP instead of NET. This config has all the supported net commands enabled. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- configs/qemu_arm64_lwip_defconfig | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 configs/qemu_arm64_lwip_defconfig diff --git a/configs/qemu_arm64_lwip_defconfig b/configs/qemu_arm64_lwip_defconfig new file mode 100644 index 00000000000..1f5fd097f0e --- /dev/null +++ b/configs/qemu_arm64_lwip_defconfig @@ -0,0 +1,4 @@ +#include +CONFIG_NET_LWIP=y +CONFIG_CMD_DNS=y +CONFIG_CMD_WGET=y From patchwork Mon Jun 17 15:33:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804888 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp612066wrr; Mon, 17 Jun 2024 08:35:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXld11+95q9J38jT3ssi3lWFFp0tKZwRnc3xUzmntfj8zTTEtocJqxRwfnjmi/CjxmU7YTZebn3c+wx9IQrCW3j X-Google-Smtp-Source: AGHT+IGJqALkd73w+t0U46WF2z8uJjIJ3eB5bfShlh9B5kgo5+9ft0FpCEUNThf5PNjeW77rY5jw X-Received: by 2002:a17:906:b4e:b0:a6e:fa0a:4899 with SMTP id a640c23a62f3a-a6f60cefe7emr626484266b.16.1718638556091; Mon, 17 Jun 2024 08:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638556; cv=none; d=google.com; s=arc-20160816; b=qUADwCE7CZW+PA7lg9PquPfAVYNuiZRQFPN6wfm6qFdUxjGhVuJWs1E3yCfVaSQlmm RNeFJ+lRimwfB6jo2rhu8i3gSiGmkP225cS2DdhKi3M2g7s6OnoQ2dOXYKpPmPXY9RA1 GGqcOWAQz4OVRgAqbCmEnoOVjE6zcWQIPKvUs8XgEOkTlCPw2O09mdOmDzq+xq0DzjKX j5fpzztG2o383r6BAIwyxjEXvv6A5fR9uWrN8HFjQtk5d1SZ+Y96W0xgtC2rdLkQ2K3j m8+V81p7coRVfOoXOCnelbjsYdVK0MmNtRAEKOjJ1mggRFxQJkBL147T5Yty0WQdzb0B T53Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qqVqLn066MM3njEiUrH9ehDx4F2etQZeP2c8uVrZpho=; fh=IkzJqtITEclL6sDM1PR7es4/AgcOIaC3QZR4jCY0rFU=; b=pdK/hvEj4vAUiGUjVI+d7VuxFLOq/GjbZ9Knb3S4plpqAeGKIy5WNjWZ+aYZCnaUlW iTpNyRFL6dut86Khx6zQdlb9h9i9eudBpPoryBIfKAW38iU/9ruFxf6nJpbCnvZlmbYU LPdNGsj0/h5O/g3FHPpR33prw45DUDgTVhycXVwNy8Ds5lA4EDY9t8AdYL2UWFYOhS1p ANw0/bLxCW6fHm+LC5ARD/Bk012MRBmPGe2bkxl92RQnInx5Zc2h4iBStktK4PTqiP7x L9j3hQN4vtPiLZqRf5vvMxdBj+a6MKxth0o0rpl5wIxqB40+UqqaOwQPSd3sjerEBiM0 KDEQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RgnUP3bO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56e26b3csi443325666b.785.2024.06.17.08.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:35:56 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RgnUP3bO; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C63D3883DB; Mon, 17 Jun 2024 17:33:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="RgnUP3bO"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 914AD883BB; Mon, 17 Jun 2024 17:33:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8CA3E88398 for ; Mon, 17 Jun 2024 17:33:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4218008c613so34287235e9.2 for ; Mon, 17 Jun 2024 08:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638431; x=1719243231; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qqVqLn066MM3njEiUrH9ehDx4F2etQZeP2c8uVrZpho=; b=RgnUP3bOCl7uaBlx+nZydm+Fy/pYYZsWY3AUB9/G0lzIlzRui50aWZafBvJ19Xkn/H 8faOfVBUFYMNnIZquxvQhnOwVe/sCrEfJT0hYjIZE4CkpLbzoZEZAlO0Z52dS968xd3X qw4ySWjIKwl+nK/pZNVJP+/uaXEk20UkgIY+EK5JDcvvkoiJJzHrSNT4bS96W9YlSMYo keng3ruMfn2IXTklCSk8TzLeEBZk8a5RicOmSqperXDz04An3tKwYkLqTVnzj7MNCLsj QEFRv/eXMeR5iBBXik3ILiE8b7cZd4mvP0/vb6iD6NI2Ur5Uj18EVU9JFSRsixhuvvQx gUow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638431; x=1719243231; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qqVqLn066MM3njEiUrH9ehDx4F2etQZeP2c8uVrZpho=; b=X6cIWeaDYpIKkj0GjCxygTGWv4QHAZoXS13WlPdFiwTuiMonE07Qbzd2KkF/4pUK1K VWkL739d6Qh/WQLH2No+yb4mzy2J5p4PbBRpA+gFxOe2JGqXTWZ7G1j9wzAXr/5RISYw 0Q9CUk14e84/7gVFR50L6ftMi8PG7qbIEmHsOMk8ukKYuRfM5QeWSuLwuaVOy0z8dndz /mpBq13ZAc68hjM7M6Vko6SHLv7aWEhOOUX9S6OfTjQIWhoQNEF/0Ybu/DRbAzvfC8ge dlQ+S0QB1isu0GDdLwL323mXG+HxR01bC/3BhVNh9qFw7Eli0QIOEN+1NLuL0ag+1u7o KKvQ== X-Gm-Message-State: AOJu0YzntwmuweRn3v4NKJA+SLuNFsDphuEX2o6CrDcmGJNudVIVXqXr DllUm4ssDFwS0YEi2VYkD9MLVOR+8MRNEKf2ga/KEwAr0sq/xANkRf4cvW0zWHDYS9PCb27Mw6X fQaE= X-Received: by 2002:a05:600c:314d:b0:421:eed3:5991 with SMTP id 5b1f17b1804b1-4230484eecemr102433755e9.32.1718638430890; Mon, 17 Jun 2024 08:33:50 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:50 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Mattijs Korpershoek , Abdellatif El Khlifi , Sumit Garg , Marek Vasut , Caleb Connolly , Sam Protsenko , Nathan Barrett-Morrison Subject: [PATCH v4 13/14] MAINTAINERS: net-lwip: add myself as a maintainer Date: Mon, 17 Jun 2024 17:33:05 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Add myself as a maintainer for the lwIP network stack integration code and network commands. The library code itself (i.e., most files under lib/lwip/ except README, Makefile and integration files in u-boot) is unmodified from upstream and therefore does not need a maintainer. Signed-off-by: Jerome Forissier Reviewed-by: Ilias Apalodimas --- MAINTAINERS | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index f8afd7d51e2..11105869304 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1310,6 +1310,17 @@ F: drivers/net/ F: include/net.h F: net/ +NETWORK (LWIP) +M: Jerome Forissier +S: Maintained +F: cmd/net-lwip.c +F: configs/qemu_arm64_lwip_defconfig +F: include/net-lwip.h +F: lib/lwip/Makefile +F: lib/lwip/README +F: lib/lwip/u-boot/ +F: net-lwip/ + NIOS M: Thomas Chou S: Maintained From patchwork Mon Jun 17 15:33:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 804889 Delivered-To: patch@linaro.org Received: by 2002:adf:fb90:0:b0:360:93e7:1765 with SMTP id a16csp612141wrr; Mon, 17 Jun 2024 08:36:08 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXBAvx3TEjjFMeqQW+dDTTw6XPqmiiWvP/Mq5PJYJukSi3wplhuhR73Mv1mHmVxVYOTFhpNJirGK0nE10tDZHIT X-Google-Smtp-Source: AGHT+IFiyySJGZs0y8t+K5JwfsSkKKdhM13JnNzUI412X+N5jqcZ6jG0PZzXML8lRtb/LCA7oYcK X-Received: by 2002:a17:907:a0d4:b0:a6f:61c7:deaa with SMTP id a640c23a62f3a-a6f61c7df4fmr857803266b.17.1718638567893; Mon, 17 Jun 2024 08:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718638567; cv=none; d=google.com; s=arc-20160816; b=bfh7DPd9lkjmgCLwBnD3Vw6/nqcqSCBL+ckAH980Q20gS72zBaDB95bnKPLdSrRDTI yhZZaJ4tkt79kTUhCeGqK0EfR6PMPXw3pSKHKa7qCJV2kwDapvbMdLgMYQr4UWnpia7E pWcXLnLhGCQN62zxROXZ6PkYgg3tFEu5Rra0iMsscUYxPa0cb/BvUmdjCBI6sO8hE70u NDA+GpNaYsO327ZcU+xoj6X/EMoOgn2UegGp7M2Iqu2FPUSkvAeBx1sbOZXVAGHEi+sy raDtIe4KFKRM1IVy77z6H3e5lhe4zqB55IQEwvA8DZIpFTvvLPDoY4wAFPwCpzEJo/H0 8+PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Fzw6cP1XwfYMFz7w3gkwzemqCEoUwHZFS1rmul+vcRs=; fh=oTBAHDNBhKGwfAq3kwV7wX80Q2la/bGxSGjtAskMngo=; b=zwrFLFCN+g4LqwLN73gn4J8/ie0I1fp1C/hs30S3s/7ZPu9ZiZ21IxikPpcY7JPgmq EJ57JKsXiVDPbmqAEuWk3FMoT2wy0npzyk8pJQU2MaCAo00swvOPssfN29UfzH42ZPnt wPMwm7v37I2vkz168+NHH2Igax4lHzE2Sb7eygt0D95ugkzIDgNzuma6rE/6paBOiUa3 m1M2jVB6qHJqKdFnJKVAuzbPogeyg4qIDPA7R/NKmCt79iMeRPo5I5z4idXd63fiyHmH AHyeFiRgHykI/gJdGXkyyWiByGTr4Gi6KgPMRm/eYAFYmP5MN+CsGCTLteoOcQhLQl8K nfqg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rpwhyHMx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f85a840d4si126082966b.826.2024.06.17.08.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:36:07 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rpwhyHMx; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2479F88403; Mon, 17 Jun 2024 17:33:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="rpwhyHMx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 10693883D2; Mon, 17 Jun 2024 17:33:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 52D8688403 for ; Mon, 17 Jun 2024 17:33:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-421798185f0so35083495e9.1 for ; Mon, 17 Jun 2024 08:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718638431; x=1719243231; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fzw6cP1XwfYMFz7w3gkwzemqCEoUwHZFS1rmul+vcRs=; b=rpwhyHMxasn1OK+K0PakxJKJQV5x7K73882KoR5UFhH1uELN4V5NucItydUEhbtKeR nQs4rlH6DVtPitK7vzlDGLnPqn8cco4nS2lQXEDUM6G4RQTEktZnEj03hGA+SbypURfF 9s0VmrlBeJSiGth8fgpPYlWom5BZByE/kweUIOVvGBV1eXSdKFHWsA0dqQzYbxKpTB4K +VCFrODosOsXz/70pY73CY9+EcfD+YbTT/SYvCh7eEsejgOXlaiWF9k85yWCUfKmHtWh z11Tply0OgcSl7OtbLkENrb3PGXB3AETll9POEIJuGW3BB1n6AYVkWmjYofmt3fRPcsw GWtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718638431; x=1719243231; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fzw6cP1XwfYMFz7w3gkwzemqCEoUwHZFS1rmul+vcRs=; b=JVoDxIupR+G+wHlyfkr523jjPXO1GAjtejUlBEpaHA1dCzU6hMo7l1uyIeN1fr2t0S HE8SPJAW9mWOMo6NfJw/g/TvKhuiufqzLYUzQA9qIiiOgxh3Xvr3fi+Ddj05dvu+GPwq nO6B4rEx8F3ezVteNMb2E+ky0OSGfX2L5eEd0LVvm5wq89xQX6seKZs2p7vNqnZRoaOi Y0k5BreVSjqmZVlZh2GRqVKayvtn+C398XhAsterdASn/lGC8Luw1E9LaZhTamjjUBUw FAEX6Uba6QJvz3ZOVa2EtJpeHELt6w71aGwU4F8bodPoimatsmpOeQunOEfl4HQUlFfT aITA== X-Gm-Message-State: AOJu0YxlxQJlAgT9b/2rri7WDt3yfN07EbHek4xoGgvgrtZt62oUXF/4 JbYEXct99bCyXEH+xDxIotF2axLFEh6lQF0/PcUg0LS8Fa0S7n1wfVGduJosErTWmvr7JuVe1p6 ka0A= X-Received: by 2002:a05:600c:524f:b0:422:5953:347d with SMTP id 5b1f17b1804b1-4230484502cmr79277285e9.27.1718638431693; Mon, 17 Jun 2024 08:33:51 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:6e75:be8f:56ae:2b5e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-422f602f620sm161350895e9.19.2024.06.17.08.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 08:33:51 -0700 (PDT) From: Jerome Forissier To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Javier Tia , Maxim Uvarov , Jerome Forissier , Tom Rini , Simon Glass , Leo Yu-Chi Liang Subject: [PATCH v4 14/14] CI: add qemu_arm64_lwip to the test matrix Date: Mon, 17 Jun 2024 17:33:06 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Build and run qemu_arm64_lwip_defconfig in CI. This tests the lightweight IP (lwIP) implementation of the dhcp, tftpboot and ping commands. Signed-off-by: Jerome Forissier --- .azure-pipelines.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 27f69583c65..4da1bb12fab 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -199,6 +199,10 @@ stages: cd \${WORK_DIR} git config --global --add safe.directory \${WORK_DIR} git clone --depth=1 https://source.denx.de/u-boot/u-boot-test-hooks /tmp/uboot-test-hooks + # qemu_arm64_lwip_defconfig is the same as qemu_arm64 but with NET_LWIP enabled. + # The test config and the boardenv file from qemu_arm64 can be re-used so create symlinks + ln -s conf.qemu_arm64_na /tmp/uboot-test-hooks/bin/travis-ci/conf.qemu_arm64_lwip_na + ln -s u_boot_boardenv_qemu_arm64_na.py /tmp/uboot-test-hooks/py/travis-ci/u_boot_boardenv_qemu_arm64_lwip_na.py ln -s travis-ci /tmp/uboot-test-hooks/bin/\`hostname\` ln -s travis-ci /tmp/uboot-test-hooks/py/\`hostname\` grub-mkimage --prefix=\"\" -o ~/grub_x86.efi -O i386-efi normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd @@ -371,6 +375,9 @@ stages: qemu_arm64: TEST_PY_BD: "qemu_arm64" TEST_PY_TEST_SPEC: "not sleep" + qemu_arm64_lwip: + TEST_PY_BD: "qemu_arm64_lwip" + TEST_PY_TEST_SPEC: "test_net_dhcp or test_net_ping or test_net_tftpboot" qemu_m68k: TEST_PY_BD: "M5208EVBE" TEST_PY_ID: "--id qemu"