Merge branch '2023-04-06-assorted-updates'

- Make use of the semi-formal "fallthrough" mechanism, update env tools
  to use /run for lockfile, add 2048 game (as a way to test console
  changes), update some CONFIG option logic in Kconfig, have lmb command
  show regions in use, remove some duplicate serial code, add
  __gnu_thumb1_case_si code and fix m68k custodian email address.
This commit is contained in:
Tom Rini 2023-04-07 10:44:19 -04:00
commit 340bebf9c7
21 changed files with 489 additions and 31 deletions

View file

@ -419,4 +419,21 @@ ENTRY(__gnu_thumb1_case_uhi)
ret lr
ENDPROC(__gnu_thumb1_case_uhi)
.popsection
/* Taken and adapted from: https://github.com/gcc-mirror/gcc/blob/4f181f9c7ee3efc509d185fdfda33be9018f1611/libgcc/config/arm/lib1funcs.S#L2156 */
.pushsection .text.__gnu_thumb1_case_si, "ax"
ENTRY(__gnu_thumb1_case_si)
push {r0, r1}
mov r1, lr
adds r1, r1, #2 /* Align to word. */
lsrs r1, r1, #2
lsls r0, r0, #2
lsls r1, r1, #2
ldr r0, [r1, r0]
adds r0, r0, r1
mov lr, r0
pop {r0, r1}
mov pc, lr /* We know we were called from thumb code. */
ENDPROC(__gnu_thumb1_case_si)
.popsection
#endif

397
cmd/2048.c Normal file
View file

@ -0,0 +1,397 @@
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: © 2014 Maurits van der Schee
/* Console version of the game "2048" for GNU/Linux */
#include <common.h>
#include <cli.h>
#include <command.h>
#include <rand.h>
#include <linux/delay.h>
#define SIZE 4
static uint score;
static void getColor(uint value, char *color, size_t length)
{
u8 original[] = {
8, 255, 1, 255, 2, 255, 3, 255,
4, 255, 5, 255, 6, 255, 7, 255,
9, 0, 10, 0, 11, 0, 12, 0, 13,
0, 14, 0, 255, 0, 255, 0};
u8 *scheme = original;
u8 *background = scheme + 0;
u8 *foreground = scheme + 1;
if (value > 0) {
while (value >>= 1) {
if (background + 2 < scheme + sizeof(original)) {
background += 2;
foreground += 2;
}
}
}
snprintf(color, length, "\033[38;5;%d;48;5;%dm", *foreground,
*background);
}
static void drawBoard(u16 board[SIZE][SIZE])
{
int x, y;
char color[40], reset[] = "\033[0m";
printf("\033[H");
printf("2048.c %17d pts\n\n", score);
for (y = 0; y < SIZE; y++) {
for (x = 0; x < SIZE; x++) {
getColor(board[x][y], color, 40);
printf("%s", color);
printf(" ");
printf("%s", reset);
}
printf("\n");
for (x = 0; x < SIZE; x++) {
getColor(board[x][y], color, 40);
printf("%s", color);
if (board[x][y] != 0) {
char s[8];
s8 t;
snprintf(s, 8, "%u", board[x][y]);
t = 7 - strlen(s);
printf("%*s%s%*s", t - t / 2, "", s, t / 2, "");
} else {
printf(" · ");
}
printf("%s", reset);
}
printf("\n");
for (x = 0; x < SIZE; x++) {
getColor(board[x][y], color, 40);
printf("%s", color);
printf(" ");
printf("%s", reset);
}
printf("\n");
}
printf("\n");
printf(" ←, ↑, →, ↓ or q \n");
printf("\033[A");
}
static int8_t findTarget(u16 array[SIZE], int x, int stop)
{
int t;
/* if the position is already on the first, don't evaluate */
if (x == 0)
return x;
for (t = x - 1; t >= 0; t--) {
if (array[t]) {
if (array[t] != array[x]) {
/* merge is not possible, take next position */
return t + 1;
}
return t;
}
/* we should not slide further, return this one */
if (t == stop)
return t;
}
/* we did not find a */
return x;
}
static bool slideArray(u16 array[SIZE])
{
bool success = false;
int x, t, stop = 0;
for (x = 0; x < SIZE; x++) {
if (array[x] != 0) {
t = findTarget(array, x, stop);
/*
* if target is not original position, then move or
* merge
*/
if (t != x) {
/*
* if target is not zero, set stop to avoid
* double merge
*/
if (array[t]) {
score += array[t] + array[x];
stop = t + 1;
}
array[t] += array[x];
array[x] = 0;
success = true;
}
}
}
return success;
}
static void rotateBoard(u16 board[SIZE][SIZE])
{
s8 i, j, n = SIZE;
int tmp;
for (i = 0; i < n / 2; i++) {
for (j = i; j < n - i - 1; j++) {
tmp = board[i][j];
board[i][j] = board[j][n - i - 1];
board[j][n - i - 1] = board[n - i - 1][n - j - 1];
board[n - i - 1][n - j - 1] = board[n - j - 1][i];
board[n - j - 1][i] = tmp;
}
}
}
static bool moveUp(u16 board[SIZE][SIZE])
{
bool success = false;
int x;
for (x = 0; x < SIZE; x++)
success |= slideArray(board[x]);
return success;
}
static bool moveLeft(u16 board[SIZE][SIZE])
{
bool success;
rotateBoard(board);
success = moveUp(board);
rotateBoard(board);
rotateBoard(board);
rotateBoard(board);
return success;
}
static bool moveDown(u16 board[SIZE][SIZE])
{
bool success;
rotateBoard(board);
rotateBoard(board);
success = moveUp(board);
rotateBoard(board);
rotateBoard(board);
return success;
}
static bool moveRight(u16 board[SIZE][SIZE])
{
bool success;
rotateBoard(board);
rotateBoard(board);
rotateBoard(board);
success = moveUp(board);
rotateBoard(board);
return success;
}
static bool findPairDown(u16 board[SIZE][SIZE])
{
bool success = false;
int x, y;
for (x = 0; x < SIZE; x++) {
for (y = 0; y < SIZE - 1; y++) {
if (board[x][y] == board[x][y + 1])
return true;
}
}
return success;
}
static int16_t countEmpty(u16 board[SIZE][SIZE])
{
int x, y;
int count = 0;
for (x = 0; x < SIZE; x++) {
for (y = 0; y < SIZE; y++) {
if (board[x][y] == 0)
count++;
}
}
return count;
}
static bool gameEnded(u16 board[SIZE][SIZE])
{
bool ended = true;
if (countEmpty(board) > 0)
return false;
if (findPairDown(board))
return false;
rotateBoard(board);
if (findPairDown(board))
ended = false;
rotateBoard(board);
rotateBoard(board);
rotateBoard(board);
return ended;
}
static void addRandom(u16 board[SIZE][SIZE])
{
int x, y;
int r, len = 0;
u16 n, list[SIZE * SIZE][2];
for (x = 0; x < SIZE; x++) {
for (y = 0; y < SIZE; y++) {
if (board[x][y] == 0) {
list[len][0] = x;
list[len][1] = y;
len++;
}
}
}
if (len > 0) {
r = rand() % len;
x = list[r][0];
y = list[r][1];
n = ((rand() % 10) / 9 + 1) * 2;
board[x][y] = n;
}
}
static int test(void)
{
u16 array[SIZE];
u16 data[] = {
0, 0, 0, 2, 2, 0, 0, 0,
0, 0, 2, 2, 4, 0, 0, 0,
0, 2, 0, 2, 4, 0, 0, 0,
2, 0, 0, 2, 4, 0, 0, 0,
2, 0, 2, 0, 4, 0, 0, 0,
2, 2, 2, 0, 4, 2, 0, 0,
2, 0, 2, 2, 4, 2, 0, 0,
2, 2, 0, 2, 4, 2, 0, 0,
2, 2, 2, 2, 4, 4, 0, 0,
4, 4, 2, 2, 8, 4, 0, 0,
2, 2, 4, 4, 4, 8, 0, 0,
8, 0, 2, 2, 8, 4, 0, 0,
4, 0, 2, 2, 4, 4, 0, 0
};
u16 *in, *out;
u16 t, tests;
int i;
bool success = true;
tests = (sizeof(data) / sizeof(data[0])) / (2 * SIZE);
for (t = 0; t < tests; t++) {
in = data + t * 2 * SIZE;
out = in + SIZE;
for (i = 0; i < SIZE; i++)
array[i] = in[i];
slideArray(array);
for (i = 0; i < SIZE; i++) {
if (array[i] != out[i])
success = false;
}
if (!success) {
for (i = 0; i < SIZE; i++)
printf("%d ", in[i]);
printf(" = > ");
for (i = 0; i < SIZE; i++)
printf("%d ", array[i]);
printf("expected ");
for (i = 0; i < SIZE; i++)
printf("%d ", in[i]);
printf(" = > ");
for (i = 0; i < SIZE; i++)
printf("%d ", out[i]);
printf("\n");
break;
}
}
if (success)
printf("All %u tests executed successfully\n", tests);
return !success;
}
static int do_2048(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct cli_ch_state cch_s, *cch = &cch_s;
u16 board[SIZE][SIZE];
bool success;
if (argc == 2 && strcmp(argv[1], "test") == 0)
return test();
score = 0;
printf("\033[?25l\033[2J\033[H");
memset(board, 0, sizeof(board));
addRandom(board);
addRandom(board);
drawBoard(board);
cli_ch_init(cch);
while (true) {
int c;
c = cli_ch_process(cch, 0);
if (!c) {
c = getchar();
c = cli_ch_process(cch, c);
}
switch (c) {
case CTL_CH('b'): /* left arrow */
success = moveLeft(board);
break;
case CTL_CH('f'): /* right arrow */
success = moveRight(board);
break;
case CTL_CH('p'):/* up arrow */
success = moveUp(board);
break;
case CTL_CH('n'): /* down arrow */
success = moveDown(board);
break;
default:
success = false;
}
if (success) {
drawBoard(board);
mdelay(150);
addRandom(board);
drawBoard(board);
if (gameEnded(board)) {
printf(" GAME OVER \n");
break;
}
}
if (c == 'q') {
printf(" QUIT \n");
break;
}
}
printf("\033[?25h");
return 0;
}
U_BOOT_CMD(
2048, 2, 1, do_2048,
"The 2048 game",
"Use your arrow keys to move the tiles. When two tiles with "
"the same number touch, they merge into one!"
);

View file

@ -1446,7 +1446,8 @@ config CMD_SATA
config CMD_SCSI
bool "scsi - Access to SCSI devices"
default y if SCSI
depends on SCSI
default y
help
This provides a 'scsi' command which provides access to SCSI (Small
Computer System Interface) devices. The command provides a way to
@ -1940,6 +1941,17 @@ endif
menu "Misc commands"
config CMD_2048
bool "Play 2048"
help
This is a simple sliding block puzzle game designed by Italian web
developer Gabriele Cirulli. The game's objective is to slide numbered
tiles on a grid to combine them to create a tile with the number
2048.
This needs ANSI support on your terminal to work. It is not fully
functional on a video device.
config CMD_BMP
bool "Enable 'bmp' command"
depends on VIDEO

View file

@ -12,6 +12,7 @@ obj-y += panic.o
obj-y += version.o
# command
obj-$(CONFIG_CMD_2048) += 2048.o
obj-$(CONFIG_CMD_ACPI) += acpi.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_AES) += aes.o

View file

@ -98,7 +98,7 @@ static int do_date(struct cmd_tbl *cmdtp, int flag, int argc,
puts("## Get date failed\n");
}
}
/* FALL TROUGH */
fallthrough;
case 1: /* get date & time */
#ifdef CONFIG_DM_RTC
rcode = dm_rtc_get(dev, &tm);

View file

@ -517,6 +517,7 @@ static int do_pci(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
addr = hextoul(argv[3], NULL);
if (argc > 4)
value = hextoul(argv[4], NULL);
fallthrough;
case 'h': /* header */
case 'b': /* bars */
if (argc < 3)

View file

@ -37,6 +37,7 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
printf("Can't get the regulator: %s!\n", name);
return failure(ret);
}
fallthrough;
case 1:
if (!currdev) {
printf("Regulator device is not set!\n\n");

View file

@ -72,6 +72,7 @@ CONFIG_ARP_TIMEOUT=200
CONFIG_NET_RETRY_COUNT=50
CONFIG_USE_ROOTPATH=y
CONFIG_SPL_OF_TRANSLATE=y
CONFIG_SYS_SATA_MAX_PORTS=2
CONFIG_SCSI_AHCI=y
CONFIG_DM_PCA953X=y
CONFIG_DM_I2C=y

View file

@ -30,6 +30,7 @@ CONFIG_RESET_TO_RETRY=y
CONFIG_MISC_INIT_R=y
# CONFIG_CMD_SETEXPR is not set
CONFIG_ENV_IS_IN_NVRAM=y
CONFIG_SYS_SATA_MAX_PORTS=5
CONFIG_SCSI_AHCI=y
CONFIG_SYS_64BIT_LBA=y
CONFIG_BOOTCOUNT_LIMIT=y

View file

@ -340,3 +340,4 @@ CONFIG_TEST_FDTDEC=y
CONFIG_UNIT_TEST=y
CONFIG_UT_TIME=y
CONFIG_UT_DM=y
CONFIG_CMD_2048=y

View file

@ -5,7 +5,7 @@ M68K / ColdFire
History
-------
* November 02, 2017 Angelo Dureghello <angelo@sysam.it>
* November 02, 2017 Angelo Dureghello <angelo@kernel-space.org>
* August 08, 2005 Jens Scharsig <esw@bus-elektronik.de>
MCF5282 implementation without preloader
* January 12, 2004 <josef.baumgartner@telex.de>

View file

@ -20,6 +20,14 @@ config SATA
See also CMD_SATA which provides command-line support.
config SYS_SATA_MAX_PORTS
int "Maximum supported SATA ports"
depends on SCSI_AHCI && !DM_SCSI
default 1
help
Sets the maximum number of ports to scan when looking for devices.
Ports from 0 to (this value - 1) are scanned.
config LIBATA
bool
help
@ -37,6 +45,7 @@ config AHCI_PCI
bool "Support for PCI-based AHCI controller"
depends on PCI
depends on DM_SCSI
depends on SCSI_AHCI
help
Enables support for the PCI-based AHCI controller.

View file

@ -211,8 +211,8 @@ static int ahci_host_init(struct ahci_uc_priv *uc_priv)
uc_priv->cap, uc_priv->port_map, uc_priv->n_ports);
#if !defined(CONFIG_DM_SCSI)
if (uc_priv->n_ports > CONFIG_SYS_SCSI_MAX_SCSI_ID)
uc_priv->n_ports = CONFIG_SYS_SCSI_MAX_SCSI_ID;
if (uc_priv->n_ports > CONFIG_SYS_SATA_MAX_PORTS)
uc_priv->n_ports = CONFIG_SYS_SATA_MAX_PORTS;
#endif
for (i = 0; i < uc_priv->n_ports; i++) {

View file

@ -31,7 +31,7 @@ static const unsigned long baudrate_table[] = CFG_SYS_BAUDRATE_TABLE;
static int serial_check_stdout(const void *blob, struct udevice **devp)
{
int node = -1;
const char *str, *p, *name;
const char *str, *p;
int namelen;
/* Check for a chosen console */
@ -39,20 +39,16 @@ static int serial_check_stdout(const void *blob, struct udevice **devp)
if (str) {
p = strchr(str, ':');
namelen = p ? p - str : strlen(str);
node = fdt_path_offset_namelen(blob, str, namelen);
if (node < 0) {
/*
* Deal with things like
* This also deals with things like
*
* stdout-path = "serial0:115200n8";
*
* We need to look up the alias and then follow it to
* the correct node.
* since fdt_path_offset_namelen() treats a str not
* beginning with '/' as an alias and thus applies
* fdt_get_alias_namelen() to it.
*/
name = fdt_get_alias_namelen(blob, str, namelen);
if (name)
node = fdt_path_offset(blob, name);
}
node = fdt_path_offset_namelen(blob, str, namelen);
}
if (node < 0)

View file

@ -573,6 +573,7 @@ endif # if DM_SPI
config FSL_ESPI
bool "Freescale eSPI driver"
depends on MPC85xx
imply SPI_FLASH_BAR
help
Enable the Freescale eSPI driver. This driver can be used to

View file

@ -35,6 +35,24 @@ struct lmb_property {
enum lmb_flags flags;
};
/*
* For regions size management, see LMB configuration in KConfig
* all the #if test are done with CONFIG_LMB_USE_MAX_REGIONS (boolean)
*
* case 1. CONFIG_LMB_USE_MAX_REGIONS is defined (legacy mode)
* => CONFIG_LMB_MAX_REGIONS is used to configure the region size,
* directly in the array lmb_region.region[], with the same
* configuration for memory and reserved regions.
*
* case 2. CONFIG_LMB_USE_MAX_REGIONS is not defined, the size of each
* region is configurated *independently* with
* => CONFIG_LMB_MEMORY_REGIONS: struct lmb.memory_regions
* => CONFIG_LMB_RESERVED_REGIONS: struct lmb.reserved_regions
* lmb_region.region is only a pointer to the correct buffer,
* initialized in lmb_init(). This configuration is useful to manage
* more reserved memory regions with CONFIG_LMB_RESERVED_REGIONS.
*/
/**
* struct lmb_region - Description of a set of region.
*
@ -68,7 +86,7 @@ struct lmb_region {
struct lmb {
struct lmb_region memory;
struct lmb_region reserved;
#ifdef CONFIG_LMB_MEMORY_REGIONS
#if !IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
struct lmb_property memory_regions[CONFIG_LMB_MEMORY_REGIONS];
struct lmb_property reserved_regions[CONFIG_LMB_RESERVED_REGIONS];
#endif

View file

@ -1057,7 +1057,6 @@ config LMB
config LMB_USE_MAX_REGIONS
bool "Use a common number of memory and reserved regions in lmb lib"
depends on LMB
default y
help
Define the number of supported memory regions in the library logical
@ -1067,7 +1066,7 @@ config LMB_USE_MAX_REGIONS
config LMB_MAX_REGIONS
int "Number of memory and reserved regions in lmb lib"
depends on LMB && LMB_USE_MAX_REGIONS
depends on LMB_USE_MAX_REGIONS
default 16
help
Define the number of supported regions, memory and reserved, in the
@ -1075,7 +1074,7 @@ config LMB_MAX_REGIONS
config LMB_MEMORY_REGIONS
int "Number of memory regions in lmb lib"
depends on LMB && !LMB_USE_MAX_REGIONS
depends on !LMB_USE_MAX_REGIONS
default 8
help
Define the number of supported memory regions in the library logical
@ -1084,7 +1083,7 @@ config LMB_MEMORY_REGIONS
config LMB_RESERVED_REGIONS
int "Number of reserved regions in lmb lib"
depends on LMB && !LMB_USE_MAX_REGIONS
depends on !LMB_USE_MAX_REGIONS
default 8
help
Define the number of supported reserved regions in the library logical

View file

@ -27,7 +27,7 @@ static void lmb_dump_region(struct lmb_region *rgn, char *name)
enum lmb_flags flags;
int i;
printf(" %s.cnt = 0x%lx\n", name, rgn->cnt);
printf(" %s.cnt = 0x%lx / max = 0x%lx\n", name, rgn->cnt, rgn->max);
for (i = 0; i < rgn->cnt; i++) {
base = rgn->region[i].base;
@ -110,7 +110,7 @@ void lmb_init(struct lmb *lmb)
#if IS_ENABLED(CONFIG_LMB_USE_MAX_REGIONS)
lmb->memory.max = CONFIG_LMB_MAX_REGIONS;
lmb->reserved.max = CONFIG_LMB_MAX_REGIONS;
#elif defined(CONFIG_LMB_MEMORY_REGIONS)
#else
lmb->memory.max = CONFIG_LMB_MEMORY_REGIONS;
lmb->reserved.max = CONFIG_LMB_RESERVED_REGIONS;
lmb->memory.region = lmb->memory_regions;

View file

@ -674,6 +674,7 @@ repeat:
case 'x':
flags |= SMALL;
/* fallthrough */
case 'X':
base = 16;
break;
@ -681,8 +682,10 @@ repeat:
case 'd':
if (fmt[1] == 'E')
flags |= ERRSTR;
/* fallthrough */
case 'i':
flags |= SIGN;
/* fallthrough */
case 'u':
break;

View file

@ -73,7 +73,7 @@ void usage_printenv(void)
" -c, --config configuration file, default:" CONFIG_FILE "\n"
#endif
" -n, --noheader do not repeat variable name in output\n"
" -l, --lock lock node, default:/var/lock\n"
" -l, --lock lock node, default:/run\n"
"\n");
}
@ -88,7 +88,7 @@ void usage_env_set(void)
#ifdef CONFIG_FILE
" -c, --config configuration file, default:" CONFIG_FILE "\n"
#endif
" -l, --lock lock node, default:/var/lock\n"
" -l, --lock lock node, default:/run\n"
" -s, --script batch mode to minimize writes\n"
"\n"
"Examples:\n"
@ -206,7 +206,7 @@ int parse_setenv_args(int argc, char *argv[])
int main(int argc, char *argv[])
{
char *lockname = "/var/lock/" CMD_PRINTENV ".lock";
char *lockname = "/run/" CMD_PRINTENV ".lock";
int lockfd = -1;
int retval = EXIT_SUCCESS;
char *_cmdname;

View file

@ -10,7 +10,7 @@ static const char *keyname = "key"; /* -n <keyname> */
static const char *require_keys; /* -r <conf|image> */
static const char *keydest; /* argv[n] */
static void print_usage(const char *msg)
static void __attribute__((__noreturn__)) print_usage(const char *msg)
{
fprintf(stderr, "Error: %s\n", msg);
fprintf(stderr, "Usage: %s [-a <algo>] [-k <keydir>] [-n <keyname>] [-r <conf|image>]"
@ -19,7 +19,7 @@ static void print_usage(const char *msg)
exit(EXIT_FAILURE);
}
static void print_help(void)
static void __attribute__((__noreturn__)) print_help(void)
{
fprintf(stderr, "Options:\n"
"\t-a <algo> Cryptographic algorithm. Optional parameter, default value: sha1,rsa2048\n"